Skip to content

API: ArrowDtype.type #51307

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

Merged
merged 8 commits into from
Feb 16, 2023
Merged

API: ArrowDtype.type #51307

merged 8 commits into from
Feb 16, 2023

Conversation

jbrockmendel
Copy link
Member

cc @mroeschke we discussed this one of the pyarrow testing PRs.

Still has some failing pandas/tests/extension/test_arrow.py::TestBaseInterface::test_contains tests where eyeballs would be welcome.

ATM this returns Timestamp/Timedelta when the pyarrow unit is "ns" and pydatetime/pydatetime otherwise. We could reasonably update that to be always-Timestamp/Timedelta.

@@ -90,7 +100,36 @@ def type(self):
"""
Returns pyarrow.DataType.
Copy link
Member

Choose a reason for hiding this comment

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

This docstring will need updating

@jbrockmendel
Copy link
Member Author

So this is breaking the float[pyarrow] test_contains test because EA.__contains__ does

        if is_scalar(item) and isna(item):
            if not self._can_hold_na:
                return False
            elif item is self.dtype.na_value or isinstance(item, self.dtype.type):
                return self._hasna

In the relevant case item is np.nan. This PR makes it so that the isinstance(item, self.dtype.type) check is True, the pyarrow (and nullable) dont want to treat np.nan as isna. One option is to override ArrowArray.__contains__. More generally, I think we're going to need something like EADtype._is_valid_na_for that missing.is_valid_na_for_dtype can dispatch to.

Comment on lines +121 to +124
if pa_type.unit == "ns":
return Timestamp
else:
return datetime
Copy link
Member

Choose a reason for hiding this comment

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

(not for this PR, just noting from seeing the diff)

FWIW, now Timestamp supports multiple resolutions, we should make it return a Timestamp for all cases, I think (it's something we should also do on the pyarrow side, but on the short term it will be easier done on the pandas side to ensure consistent behaviour across pyarrow versions)

@mroeschke mroeschke added the Arrow pyarrow functionality label Feb 16, 2023
@mroeschke mroeschke added this to the 2.0 milestone Feb 16, 2023
Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

LGTM

@mroeschke mroeschke merged commit dba9ddd into pandas-dev:main Feb 16, 2023
@mroeschke
Copy link
Member

Thanks @jbrockmendel

@jbrockmendel jbrockmendel deleted the api-pa-type branch February 16, 2023 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arrow pyarrow functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants