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

QST: Integer floordiv by nullable integer series containing zero #39847

Closed
2 tasks
brandon-b-miller opened this issue Feb 16, 2021 · 3 comments
Closed
2 tasks
Labels
Duplicate Report Duplicate issue or pull request NA - MaskedArrays Related to pd.NA and nullable extension arrays Numeric Operations Arithmetic, Comparison, and Logical operations

Comments

@brandon-b-miller
Copy link

  • I have searched the [pandas] tag on StackOverflow for similar questions.

  • I have asked my usage related question on StackOverflow.


Question about pandas

Hello Pandas, while working on cuDF binops, I noticed this edge case:

1 // pd.Series([0], dtype='Int64')
0    0
dtype: Int64

I'm not 100% sure what the right behavior here is, but we're thinking it's maybe to raise. I was wondering if anyone on the pandas side had thought about this and has strong feelings about what the answer should be here. For standard division, casting to float and returning inf seems sensible. But with floor division the point is to return an int.

Thanks so much for any thoughts.

@jorisvandenbossche
Copy link
Member

I think we "simply" follow numpy's behaviour in this case:

In [86]: np.array([1]) // np.array([0])
/home/joris/miniconda3/envs/dev/bin/ipython:1: RuntimeWarning: divide by zero encountered in floor_divide
  #!/home/joris/miniconda3/envs/dev/bin/python
Out[86]: array([0])

There have been some changes to floordiv in the latest numpy release related to this 1 // 0 case: https://numpy.org/doc/stable/release/1.20.0-notes.html#changed-behavior-of-divmod-1-0-and-related-functions. But that is for the float behavoiur, not integer. The PR changing it (numpy/numpy#16161) mentions the integer case as well, but it was decided to focus on float because there the expected result is clear (for integer floordiv, if you want an integer as result, the only option is 0 or raise an error).

@jorisvandenbossche
Copy link
Member

Ah, and also see #30188 for a longer discussion on this topic, will close this issue in favor of that.

@jorisvandenbossche
Copy link
Member

Duplicate of #30188

@jorisvandenbossche jorisvandenbossche marked this as a duplicate of #30188 Feb 17, 2021
@jorisvandenbossche jorisvandenbossche added Duplicate Report Duplicate issue or pull request NA - MaskedArrays Related to pd.NA and nullable extension arrays Numeric Operations Arithmetic, Comparison, and Logical operations and removed Needs Triage Issue that has not been reviewed by a pandas team member Usage Question labels Feb 17, 2021
@jorisvandenbossche jorisvandenbossche added this to the No action milestone Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request NA - MaskedArrays Related to pd.NA and nullable extension arrays Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

No branches or pull requests

2 participants