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

CLN: Use type_mapper instead of manual conversion #51766

Merged
merged 6 commits into from
Mar 8, 2023

Conversation

phofl
Copy link
Member

@phofl phofl commented Mar 3, 2023

  • 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.

@jbrockmendel
Copy link
Member

pandas/io/parquet.py:253: error: Incompatible types in assignment (expression has type "Type[ArrowDtype]", target has type overloaded function) [assignment]

@phofl
Copy link
Member Author

phofl commented Mar 3, 2023

thx fixed

# Incompatible types in assignment (expression has type
# "Type[ArrowDtype]", target has type overloaded function
to_pandas_kwargs["types_mapper"] = pd.ArrowDtype # type: ignore[assignment] # noqa
result = pa_table.to_pandas(**to_pandas_kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

I think you should be able to move the if pandas: .. elif pyarrow: .. higher up where to_pandas_kwargs["types_mapper"] = ... is defined. And then just have a single result = pa_table.to_pandas(**to_pandas_kwargs) 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.

Avoided this on purpose, because this would chang semantics. The other if is only reached if nullable_dtypes is set as well and I wanted to wait for the other discussion before touching anything,

@mroeschke
Copy link
Member

Good call. I think there are a few more places where we can use type_mapper

./pandas/io/orc.py:                        pa_table.column_names, pa_table.itercolumns()
./pandas/io/feather_format.py:                        pa_table.column_names, pa_table.itercolumns()
./pandas/io/parsers/arrow_parser_wrapper.py:                    for col_name, pa_col in zip(table.column_names, table.itercolumns())
./pandas/io/parquet.py:                            pa_table.column_names, pa_table.itercolumns()
./pandas/io/json/_json.py:                                    pa_table.column_names, pa_table.itercolumns()
./pandas/tests/io/test_parquet.py:                    pa_table.column_names, pa_table.itercolumns()

@mroeschke mroeschke added the Arrow pyarrow functionality label Mar 6, 2023
@mroeschke mroeschke modified the milestone: 2.0 Mar 6, 2023
@mroeschke mroeschke added the Clean label Mar 6, 2023
@phofl
Copy link
Member Author

phofl commented Mar 7, 2023

Updated

@mroeschke mroeschke added this to the 2.1 milestone Mar 7, 2023
@phofl
Copy link
Member Author

phofl commented Mar 7, 2023

Merging this into 2.0 would have the benefit that we get index support as soon as pyarrow 12 is out

@mroeschke
Copy link
Member

Merging this into 2.0 would have the benefit that we get index support as soon as pyarrow 12 is out

SGTM

@mroeschke mroeschke modified the milestones: 2.1, 2.0 Mar 7, 2023
@phofl phofl merged commit 3e0c1da into pandas-dev:main Mar 8, 2023
@phofl phofl deleted the pyarrow_types_mapper branch March 8, 2023 09:12
@lumberbot-app
Copy link

lumberbot-app bot commented Mar 8, 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 3e0c1dab6bcbe95ea1349f144e6f4bc606471ae0
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #51766: CLN: Use type_mapper instead of manual conversion'
  1. Push to a named branch:
git push YOURFORK 2.0.x:auto-backport-of-pr-51766-on-2.0.x
  1. Create a PR against branch 2.0.x, I would have named this PR:

"Backport PR #51766 on branch 2.0.x (CLN: Use type_mapper instead of manual conversion)"

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.

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

Successfully merging this pull request may close these issues.

4 participants