Skip to content

BUG: Fix regression when using Series with arrow string array #52076

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 2 commits into from
Mar 22, 2023

Conversation

phofl
Copy link
Member

@phofl phofl commented Mar 19, 2023

@phofl phofl added Regression Functionality that used to work in a prior pandas version Arrow pyarrow functionality labels Mar 19, 2023
@phofl phofl added this to the 2.0 milestone Mar 19, 2023
arr = arr.to_numpy()
if hasattr(arr, "type"):
# pyarrow array
arr = np.array(arr)
Copy link
Member

Choose a reason for hiding this comment

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

  1. can we handle this at a higher level? 2) why doesnt the pyarrow object's to_numpy work here?

Copy link
Member Author

Choose a reason for hiding this comment

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

It sets zero_copy_only to True which causes raising here.

we have to do a check like this somewhere as long as arrow is not a hard dependency, can do it at a higher level as well

Copy link
Member Author

Choose a reason for hiding this comment

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

moved it to a higher level, not sure if it is better though

Copy link
Member

@jbrockmendel jbrockmendel left a comment

Choose a reason for hiding this comment

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

LGTM

@jbrockmendel jbrockmendel merged commit 7e92ca6 into pandas-dev:main Mar 22, 2023
@jbrockmendel
Copy link
Member

thanks @phofl

@lumberbot-app
Copy link

lumberbot-app bot commented Mar 22, 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 7e92ca6ae81a0260a24ba3440be556bb71d30848
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #52076: BUG: Fix regression when using Series with arrow string array'
  1. Push to a named branch:
git push YOURFORK 2.0.x:auto-backport-of-pr-52076-on-2.0.x
  1. Create a PR against branch 2.0.x, I would have named this PR:

"Backport PR #52076 on branch 2.0.x (BUG: Fix regression when using Series with arrow string array)"

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 deleted the 51844 branch March 22, 2023 18:41
phofl added a commit to phofl/pandas that referenced this pull request Mar 22, 2023
…-dev#52076)

* BUG: Fix regression when using Series with arrow string array

* Move
mroeschke pushed a commit that referenced this pull request Mar 22, 2023
…ries with arrow string array) (#52121)

BUG: Fix regression when using Series with arrow string array (#52076)

* BUG: Fix regression when using Series with arrow string array

* Move
@@ -352,6 +352,9 @@ def _from_sequence(cls, scalars, *, dtype: Dtype | None = None, copy: bool = Fal
result[na_values] = libmissing.NA

else:
if hasattr(scalars, "type"):
Copy link
Member

Choose a reason for hiding this comment

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

Why can't we do an actual isinstance check?

If we have some helper method is_pyarrow_array like the following, this should be quite easy?

def is_pyarrow_array(obj):
    if _pyarrow_installed:
        return isinstance(obj, pa.Array)
    return False

with variables _pyarrow_installed and pa filled in once on first import.

Copy link
Member

Choose a reason for hiding this comment

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

PR that does this -> #52830

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arrow pyarrow functionality Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Passing pyarrow string array + dtype to pd.Series throws ArrowInvalidError on 2.0rc
4 participants