Skip to content
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

BUG: Assignment of pyarrow arrays yield unexpected dtypes #58601

Open
wants to merge 36 commits into
base: main
Choose a base branch
from

Conversation

droussea2001
Copy link
Contributor

@droussea2001 droussea2001 commented May 6, 2024

During a column assignment in a DataFrame:

  • If the column value is a pyarrow array (check tested with lib.is_pyarrow_array) sanitize_array sets dtype to ArrowDtype(value.type)
  • Else the standard sanitize_array processing are applied

@droussea2001 droussea2001 marked this pull request as ready for review May 7, 2024 13:55
from pandas.compat._constants import REF_COUNT
from pandas.compat._optional import import_optional_dependency
from pandas.compat.numpy import function as nv

if not pa_version_under11p0:
Copy link
Member

Choose a reason for hiding this comment

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

What prevents this from working with pyarrow 10?

Copy link
Contributor Author

@droussea2001 droussea2001 May 17, 2024

Choose a reason for hiding this comment

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

Nothing prevents it ! :-)

It was a misanderstanding.

At the beginning I thought that the version 11.0.0 was the minimum version (because "Minimum Versions" tests in the CI were not working with pyarrow 10). But actually value in _sanitize_column is:

  • A pa.lib.ChunkedArray in version 10.0.1
  • A pa.lib.Array in versions above
    So now I just test if value is an instance of the parent class pa.lib._PandasConvertible

pandas/core/frame.py Outdated Show resolved Hide resolved
Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Jul 28, 2024
@droussea2001
Copy link
Contributor Author

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

I'm still working on it.

@droussea2001
Copy link
Contributor Author

@jorisvandenbossche : Hello Joris, hope you're doing well would you have any news about BUG: Assignment of pyarrow arrays yields unexpected dtypes ? Previously I was saying that "if a Series or a DataFrame is created or assigned with data dtype 'X' I would expect if it is possible, that it keeps the same 'X' dtype" but its only my humble opinion :-) and I would be equally happy to talk about it : maybe there is somewhere a discussion about how pyarrow types could be managed ? (thanks in advance !)

@rhshadrach
Copy link
Member

Friendly ping @jorisvandenbossche

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Assignment of pyarrow arrays yields unexpected dtypes
5 participants