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

[REVIEW]Handle index when dispatching __array_function__ and __array_ufunc__ to cupy for cudf.Series #6839

Conversation

VibhuJawa
Copy link
Member

@VibhuJawa VibhuJawa commented Nov 24, 2020

This pr adds index handling when dispatching to cupy functions with __ufunc__ and __array_function__ for cudf.Series.

This PR does the following:

  • Adds index handling for __ufunc__ and __array_function (when being dispatched to cupy)
  • Adds test to ensure the same results as pandas with aligned index
  • Adds tests for appropriate errors non-aligned index
  • Removs support for list inputs (should not have been supported initially too)

Please note that I am unsure how to handle list inputs here.
The problem being solved here is below:

With this PR #6839 we get the correct index when we do the following:

>>> cudf_s1 = cudf.Series(data=[-1, 2, 3, 0], index=[2, 3, 1, 0])
>>> cudf_s2 = cudf.Series(data=[-1, -2, 3, 0], index=[2, 3, 1, 0])
>>> o = np.logaddexp(cudf_s1, cudf_s2)
>>> o.index
Int64Index([2, 3, 1, 0], dtype='int64')
>>> print(o)
2   -0.306853
3    2.018150
1    3.693147
0    0.693147
dtype: float64

On Master we get:

>>> cudf_s1 = cudf.Series(data=[-1, 2, 3, 0], index=[2, 3, 1, 0])
>>> cudf_s2 = cudf.Series(data=[-1, -2, 3, 0], index=[2, 3, 1, 0])
>>> o = np.logaddexp(cudf_s1, cudf_s2)
>>> o.index
RangeIndex(start=0, stop=4, step=1)
>>> print(o)
0   -0.306853
1    2.018150
2    3.693147
3    0.693147
dtype: float64

@VibhuJawa VibhuJawa changed the title [WIP]Index handling with cupy fallback functions [WIP]Index handling with cupy fallback functions[Skip-CI] Nov 24, 2020
@GPUtester
Copy link
Collaborator

Please update the changelog in order to start CI tests.

View the gpuCI docs here.

@VibhuJawa VibhuJawa changed the title [WIP]Index handling with cupy fallback functions[Skip-CI] [WIP]Index handling with cupy fallback functions [skip ci] Nov 24, 2020
@codecov
Copy link

codecov bot commented Nov 24, 2020

Codecov Report

Merging #6839 (7a12226) into branch-0.17 (cdc53b7) will increase coverage by 0.01%.
The diff coverage is 93.75%.

Impacted file tree graph

@@               Coverage Diff               @@
##           branch-0.17    #6839      +/-   ##
===============================================
+ Coverage        81.94%   81.95%   +0.01%     
===============================================
  Files               96       96              
  Lines            16164    16168       +4     
===============================================
+ Hits             13246    13251       +5     
+ Misses            2918     2917       -1     
Impacted Files Coverage Δ
python/cudf/cudf/utils/utils.py 84.93% <93.75%> (+0.68%) ⬆️

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 cdc53b7...7a12226. Read the comment docs.

@VibhuJawa VibhuJawa changed the title [WIP]Index handling with cupy fallback functions [skip ci] [WIP]Handle index when dispatching __array_function__ and __array_ufunc__ to cupy for cudf.Series [skip ci] Nov 24, 2020
@VibhuJawa VibhuJawa changed the title [WIP]Handle index when dispatching __array_function__ and __array_ufunc__ to cupy for cudf.Series [skip ci] [REVIEW]Handle index when dispatching __array_function__ and __array_ufunc__ to cupy for cudf.Series [skip ci] Nov 24, 2020
@VibhuJawa VibhuJawa changed the title [REVIEW]Handle index when dispatching __array_function__ and __array_ufunc__ to cupy for cudf.Series [skip ci] [REVIEW]Handle index when dispatching __array_function__ and __array_ufunc__ to cupy for cudf.Series Nov 24, 2020
@VibhuJawa VibhuJawa marked this pull request as ready for review November 24, 2020 20:53
@VibhuJawa VibhuJawa requested a review from a team as a code owner November 24, 2020 20:53
expect = np.concatenate([ar, ar, ar])
got = np.concatenate([s, s, s])
assert_eq(expect, got.to_array())
with pytest.raises(TypeError):
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed this as the index is undefined when dispatching to cupyfor these functions.

@VibhuJawa
Copy link
Member Author

rerun tests

@brandon-b-miller
Copy link
Contributor

In the process of looking this over - I am building this branch to better understand the problem being solved here.

@VibhuJawa
Copy link
Member Author

In the process of looking this over - I am building this branch to better understand the problem being solved here.

Below might help. With this PR we get the correct index on the following:

>>> cudf_s1 = cudf.Series(data=[-1, 2, 3, 0], index=[2, 3, 1, 0])
>>> cudf_s2 = cudf.Series(data=[-1, -2, 3, 0], index=[2, 3, 1, 0])
>>> o = np.logaddexp(cudf_s1, cudf_s2)
>>> o.index
Int64Index([2, 3, 1, 0], dtype='int64')
>>> print(o)
2   -0.306853
3    2.018150
1    3.693147
0    0.693147
dtype: float64

On Master we get:

>>> cudf_s1 = cudf.Series(data=[-1, 2, 3, 0], index=[2, 3, 1, 0])
>>> cudf_s2 = cudf.Series(data=[-1, -2, 3, 0], index=[2, 3, 1, 0])
>>> o = np.logaddexp(cudf_s1, cudf_s2)
>>> o.index
RangeIndex(start=0, stop=4, step=1)
>>> print(o)
0   -0.306853
1    2.018150
2    3.693147
3    0.693147
dtype: float64

@VibhuJawa VibhuJawa added 0 - Waiting on Author Waiting for author to respond to review and removed 3 - Ready for Review Ready for review by team 4 - Needs cuDF (Python) Reviewer labels Dec 1, 2020
@VibhuJawa VibhuJawa added the Python Affects Python cuDF API. label Dec 1, 2020
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 some general questions.

python/cudf/cudf/tests/test_array_ufunc.py Show resolved Hide resolved
python/cudf/cudf/tests/test_array_ufunc.py Outdated Show resolved Hide resolved
python/cudf/cudf/utils/utils.py Outdated Show resolved Hide resolved
@VibhuJawa VibhuJawa added 3 - Ready for Review Ready for review by team improvement Improvement / enhancement to an existing function and removed 0 - Waiting on Author Waiting for author to respond to review labels Dec 1, 2020
@VibhuJawa VibhuJawa added the non-breaking Non-breaking change label Dec 1, 2020
@VibhuJawa
Copy link
Member Author

All reviews have been addressed, this should be ready for another review.

CC: @brandon-b-miller , @isVoid

@brandon-b-miller
Copy link
Contributor

One last question otherwise LGTM.

@VibhuJawa
Copy link
Member Author

@isVoid, Please let me know if there is anything else I need to address.

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.

lgtm!

@VibhuJawa VibhuJawa added 5 - Ready to Merge Testing and reviews complete, ready to merge and removed 3 - Ready for Review Ready for review by team labels Dec 2, 2020
@rapids-bot rapids-bot bot merged commit 70ebbee into rapidsai:branch-0.17 Dec 3, 2020
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 improvement Improvement / enhancement to an existing function non-breaking Non-breaking change Python Affects Python cuDF API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants