Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Datetime/Timedelta dtypes in Masked UDFs #9451

Merged

Conversation

brandon-b-miller
Copy link
Contributor

Closes #9432.

Enables UDFs that do this:

import cudf

df = cudf.DataFrame({'a':['2011-01-01'], 'b':[1]})
df['a'] = df['a'].astype('datetime64[ns]')
df['b'] = df['b'].astype('timedelta64[ns]')

def f(row):
    return row['a'] + row['b']

res = df.apply(f, axis=1)
0   2011-01-01 00:00:00.000000001
dtype: datetime64[ns]

@brandon-b-miller brandon-b-miller added feature request New feature or request 3 - Ready for Review Ready for review by team numba Numba issue Python Affects Python cuDF API. non-breaking Non-breaking change labels Oct 15, 2021
@brandon-b-miller brandon-b-miller requested a review from a team as a code owner October 15, 2021 16:34
@brandon-b-miller brandon-b-miller self-assigned this Oct 15, 2021
@brandon-b-miller
Copy link
Contributor Author

cc @gmarkall

@codecov
Copy link

codecov bot commented Oct 15, 2021

Codecov Report

Merging #9451 (d12a474) into branch-21.12 (ab4bfaa) will increase coverage by 0.03%.
The diff coverage is n/a.

❗ Current head d12a474 differs from pull request most recent head 773e711. Consider uploading reports for the commit 773e711 to get more accurate results
Impacted file tree graph

@@               Coverage Diff                @@
##           branch-21.12    #9451      +/-   ##
================================================
+ Coverage         10.79%   10.82%   +0.03%     
================================================
  Files               116      117       +1     
  Lines             18869    19451     +582     
================================================
+ Hits               2036     2106      +70     
- Misses            16833    17345     +512     
Impacted Files Coverage Δ
python/cudf/cudf/__init__.py 0.00% <ø> (ø)
python/cudf/cudf/_lib/__init__.py 0.00% <ø> (ø)
python/cudf/cudf/io/csv.py 0.00% <0.00%> (ø)
python/cudf/cudf/io/hdf.py 0.00% <0.00%> (ø)
python/cudf/cudf/io/orc.py 0.00% <0.00%> (ø)
python/cudf/cudf/_version.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/abc.py 0.00% <0.00%> (ø)
python/cudf/cudf/api/types.py 0.00% <0.00%> (ø)
python/cudf/cudf/io/dlpack.py 0.00% <0.00%> (ø)
... and 64 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7fa2738...773e711. Read the comment docs.

Copy link
Contributor

@isVoid isVoid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one question: numpy rejects operators between a datetime64 with a datetime64 type. Will numba do the same type check here?

@galipremsagar
Copy link
Contributor

Just one question: numpy rejects operators between a datetime64 with a datetime64 type. Will numba do the same type check here?

Does numpy reject subtract operation on datetime64 vs datetime64 too? I'm aware that this is an operation supported in pandas and cudf.

@brandon-b-miller
Copy link
Contributor Author

Just one question: numpy rejects operators between a datetime64 with a datetime64 type. Will numba do the same type check here?

Does numpy reject subtract operation on datetime64 vs datetime64 too? I'm aware that this is an operation supported in pandas and cudf.

This brings up an interesting point in general. The space of allowed operations is a complex function allowed(lhs, rhs, op) -> bool. Technically, we should test all of them, right? There's some functions that might be able to be adapted for this generally here but the result might be thousands of tests. Since all these tests require different jit compilation, it would be a huge inflation of the pytest runtime. I have been debating what to do about this without a great answer yet.

@isVoid
Copy link
Contributor

isVoid commented Oct 15, 2021

Does numpy reject subtract operation on datetime64 vs datetime64 too?

Numpy does support subtraction, only rejects addition

There's some functions that might be able to be adapted for this generally here but the result might be thousands of tests.

I'm in general favor of testing the delegations when we can't have a full coverage (or full coverage cost is high), and add tests when corner cases pops up.

@brandon-b-miller
Copy link
Contributor Author

Just one question: numpy rejects operators between a datetime64 with a datetime64 type. Will numba do the same type check here?

Does numpy reject subtract operation on datetime64 vs datetime64 too? I'm aware that this is an operation supported in pandas and cudf.

This seems to be handled with this diff:

import cudf
x = cudf.DataFrame({
    'a': ['2011-01-01'],
    'b': ['2011-02-02']
})
x['a'] = x['a'].astype('datetime64[ns]')
x['b'] = x['b'].astype('datetime64[ns]')

def f(row):
    return row['a'] - row['b']

res = x.apply(f, axis=1)
0    -32 days 00:00:00
dtype: timedelta64[ns]

added a few tests for this.

Copy link
Contributor

@gmarkall gmarkall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me at the moment. I had one question on the diff, which probably stems from something I don't understand about datetime types.

python/cudf/cudf/tests/test_udf_masked_ops.py Show resolved Hide resolved
@brandon-b-miller brandon-b-miller added 5 - Ready to Merge Testing and reviews complete, ready to merge and removed 3 - Ready for Review Ready for review by team labels Oct 20, 2021
@brandon-b-miller
Copy link
Contributor Author

@gpucibot merge

@rapids-bot rapids-bot bot merged commit 919fedf into rapidsai:branch-21.12 Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Ready to Merge Testing and reviews complete, ready to merge feature request New feature or request non-breaking Non-breaking change numba Numba issue Python Affects Python cuDF API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEA] Support Datetime/Timedelta types in Masked UDFs
4 participants