Skip to content

API: ArrowExtensionArray._cmp_method to return pyarrow.bool_ type #51643

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 10 commits into from
Mar 9, 2023

Conversation

lukemanley
Copy link
Member

@lukemanley lukemanley commented Feb 26, 2023

Per #51462 (comment), updating ArrowExtensionArray._cmp_method to return boolean[pyarrow] dtype instead of boolean.

@lukemanley lukemanley added the Arrow pyarrow functionality label Feb 26, 2023
@@ -126,6 +126,6 @@
},
"build_command":
["python -m pip install versioneer[toml]",
"python setup.py build -j4",
"python setup.py build -j1",
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 this is failing asvs?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've reverted this. The asv job was failing before I tried this change. This was just an attempt to find the issue.

"and_": pc.and_kleene,
"rand_": lambda x, y: pc.and_kleene(y, x),
"or_": pc.or_kleene,
"ror_": lambda x, y: pc.or_kleene(y, x),
"xor": pc.xor,
Copy link
Member Author

Choose a reason for hiding this comment

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

I think(?) the first four here should have underscores. These were raising in an ASV.

Copy link
Member Author

@lukemanley lukemanley Feb 26, 2023

Choose a reason for hiding this comment

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

for example, this raises on main:

import pandas as pd

s1 = pd.Series([True], dtype="boolean[pyarrow]")
s2 = pd.Series([False], dtype="boolean[pyarrow]")

# raises: KeyError: 'or_'
s1 | s2  

Copy link
Member

Choose a reason for hiding this comment

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

Good find! Could you move into a separate pr and add tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

sure, will do

Copy link
Member Author

Choose a reason for hiding this comment

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

opened #51688 for this

Copy link
Member

@phofl phofl left a comment

Choose a reason for hiding this comment

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

the min versions failure looks legit?

@lukemanley
Copy link
Member Author

the min versions failure looks legit?

yep. just pushed a fix. I think the failure is related to the deepcopy you added in #50984

It looks like that test combined with the deepcopy was hitting this bug in older versions of numpy: numpy/numpy#21883

I think this will work now. What is the reason to use deepcopy instead of ndarray.copy there? It can be very slow for an object dtype array:

import numpy as np
from copy import deepcopy

arr = np.arange(1_000_000, dtype=object)

%timeit arr.copy()
%timeit deepcopy(arr)

# 9.83 ms ± 757 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
# 298 ms ± 4.82 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)    

@phofl
Copy link
Member

phofl commented Mar 8, 2023

@mroeschke argued back then that this would cover eas without a copy method, but if this is slow, then I'd say we can switch to copy

@mroeschke
Copy link
Member

Fine to switch to copy()

@mroeschke mroeschke added this to the 2.1 milestone Mar 9, 2023
@mroeschke mroeschke merged commit b3d18af into pandas-dev:main Mar 9, 2023
@mroeschke
Copy link
Member

Thanks @lukemanley

@phofl
Copy link
Member

phofl commented Mar 15, 2023

@mroeschke thoughts on back porting? This would fix #51980

@mroeschke
Copy link
Member

Sure, +1 to backport

@phofl
Copy link
Member

phofl commented Mar 15, 2023

@meeseeksdev backport 2.0.x

@lumberbot-app
Copy link

lumberbot-app bot commented Mar 15, 2023

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout 2.0.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 b3d18af7d7ae2c454b9dcef0f2c0c2ae89bea047
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #51643: API: ArrowExtensionArray._cmp_method to return pyarrow.bool_ type'
  1. Push to a named branch:
git push YOURFORK 2.0.x:auto-backport-of-pr-51643-on-2.0.x
  1. Create a PR against branch 2.0.x, I would have named this PR:

"Backport PR #51643 on branch 2.0.x (API: ArrowExtensionArray.cmp_method to return pyarrow.bool type)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

@phofl phofl modified the milestones: 2.1, 2.0 Mar 15, 2023
phofl pushed a commit to phofl/pandas that referenced this pull request Mar 15, 2023
…ndas-dev#51643)

* API: ArrowExtensionArray._cmp_method to return pyarrow.bool_ type

* whatsnew

* try removing asv parallel build

* fix logical func keys

* cleanup

* fix test

* subclass ExtensionArraySupportsAnyAll
mroeschke pushed a commit that referenced this pull request Mar 16, 2023
…hod to return pyarrow.bool_ type) (#51987)

* API: ArrowExtensionArray._cmp_method to return pyarrow.bool_ type (#51643)

* API: ArrowExtensionArray._cmp_method to return pyarrow.bool_ type

* whatsnew

* try removing asv parallel build

* fix logical func keys

* cleanup

* fix test

* subclass ExtensionArraySupportsAnyAll

* Add whatsnew

---------

Co-authored-by: Luke Manley <[email protected]>
@lukemanley lukemanley deleted the arrow-cmp-method-bool-type branch March 17, 2023 22:04
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