Skip to content

BUG: Interchange Column.null_count is a NumPy scalar, not a builtin int #47789

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

Closed
3 tasks done
honno opened this issue Jul 19, 2022 · 1 comment · Fixed by #47804
Closed
3 tasks done

BUG: Interchange Column.null_count is a NumPy scalar, not a builtin int #47789

honno opened this issue Jul 19, 2022 · 1 comment · Fixed by #47804
Labels
Bug Interchange Dataframe Interchange Protocol

Comments

@honno
Copy link
Contributor

honno commented Jul 19, 2022

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of pandas.
  • I have confirmed this bug exists on the main branch of pandas.

In PandasColumn used for the dataframe interchange protocol, null_count returns the result of Series.sum(), which defaults to returning a 0d ndarray of the default integer (specifically a NumPy scalar). This is opposed to int, which is specified for null_count in the spec.

>>> df = pd.DataFrame({"foo": [42]})
>>> interchange_df = df.__dataframe__()
>>> interchange_col = interchange_df.get_column_by_name("foo")
>>> interchange_col.null_count
0
>>> type(interchange_col.null_count)
numpy.int64  # should be Python's int

Relevant code

def null_count(self) -> int:
"""
Number of null elements. Should always be known.
"""
return self._col.isna().sum()

This doesn't seem to be affecting interchange thus far, so might be a low-prio or wont-fix situation. I'd just add these 0d array situations has often tripped up logic assuming a Python int on the Array API side of things, and indeed there's currently a similiar issue for vaex's interchange implementation in vaexio/vaex#2093.

Using local build of main upstream.

@honno honno added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 19, 2022
@jbrockmendel
Copy link
Member

No idea if it's relevant, but a np.int64 object is a scalar, which is distinct from a 0d numpy ndarray

@mroeschke mroeschke added Interchange Dataframe Interchange Protocol and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 20, 2022
@honno honno changed the title BUG: Interchange Column.null_count is a 0d NumPy array, not a builtin int BUG: Interchange Column.null_count is a NumPy scalar, not a builtin int Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Interchange Dataframe Interchange Protocol
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants