Skip to content

TST: simplify pyarrow tests, make mode work with temporal dtypes #50688

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
Jan 18, 2023

Conversation

jbrockmendel
Copy link
Member

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added type annotations to new arguments/methods/functions.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.

def test_getitem_scalar(self, data):
super().test_getitem_scalar(data)
# In the base class we expect data.dtype.type; but this (intentionally)
Copy link
Member Author

Choose a reason for hiding this comment

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

@mroeschke might it make sense to reconsider this? im not sure what context the current PyArrow.lib.DataType is really useful

Copy link
Member

Choose a reason for hiding this comment

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

Sure, yeah I am not exactly sure how ExtensionDtype.type is used internally, but I think it would make sense if it returns the native python type. Would be nice if there was a nice way to derive that from numpy_dtype

Copy link
Member Author

Choose a reason for hiding this comment

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

the main use case that comes to mind is if i want to do e.g. dtype.type(0) to get an object of the correct type

if pa.types.is_temporal(pa_type):
nbits = pa_type.bit_width
dtype = f"int{nbits}[pyarrow]"
obj = cast(ArrowExtensionArrayT, self.astype(dtype, copy=False))
Copy link
Member

Choose a reason for hiding this comment

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

Can we just self._data.cast to int type, continue the logic below, and then most_common.cast back?

Copy link
Member Author

Choose a reason for hiding this comment

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

we could. i preferred this way since it was self-contained

Copy link
Member

Choose a reason for hiding this comment

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

I suspect going through pa.array.cast may be more performant than astype. Mind checking?

Copy link
Member Author

Choose a reason for hiding this comment

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

updated + green

Copy link
Member

Choose a reason for hiding this comment

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

Looks like _mode here is still using astype

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, in some cases this needs an int32 and in some cases an int64, which makes the .cast version extra-complicated

@mroeschke mroeschke added Testing pandas testing functions or related to the test suite Arrow pyarrow functionality labels Jan 12, 2023
@mroeschke
Copy link
Member

If I am understanding apache/arrow#33685, then in pyarrow 11 we won't have to do the the int64 workaround?

@jbrockmendel
Copy link
Member Author

If I am understanding apache/arrow#33685, then in pyarrow 11 we won't have to do the the int64 workaround?

I don't know if that will affect mode directly.

@jbrockmendel
Copy link
Member Author

updated to use .cast instead of .astype

@mroeschke mroeschke added this to the 2.0 milestone Jan 18, 2023
@mroeschke mroeschke merged commit ac3c010 into pandas-dev:main Jan 18, 2023
@mroeschke
Copy link
Member

Thanks @jbrockmendel

@jbrockmendel jbrockmendel deleted the tst-pa branch January 18, 2023 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arrow pyarrow functionality Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants