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

ENH: Add a clear option to interpret strings as Pandas dtypes specifically. #59777

Open
1 of 3 tasks
vitkosbence opened this issue Sep 11, 2024 · 1 comment
Open
1 of 3 tasks
Labels
Enhancement IO Excel read_excel, to_excel Needs Info Clarification about behavior needed to assess issue Strings String extension data type and string data

Comments

@vitkosbence
Copy link

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

When the pd.read_excel function encounters an empty cell with a numeric dtype, it leads to a conversion error. The solution to this, is to use the Pandas specific nullable numeric types, which work extremely well. The problem is that these datatypes are hard to access via strings. pd.read_excel is especially keen on interpreting strings as numpy datatypes, while pd.api.types.pandas_dtype is capable of returning pandas dtypes, but it's unclear what this is based on.

Feature Description

Since the pandas dtypes often have several advantages over their numpy counterparts, it would make sense that functions which are capable of interpreting strings as datatypes have a flag, which forces them (if possible) to interpret strings as pandas datatypes and not their numpy counterparts.

Alternative Solutions

A workaround for now, is to run every datatype through the pd.api.types.pandas_dtype function, with very specific capitalization.
Running:
type(pd.api.types.pandas_dtype("Int64"))
Returns:
<class 'pandas.core.arrays.integer.Int64Dtype'>
Which is good, but running:
type(pd.api.types.pandas_dtype("int64"))
Returns:
<class 'numpy.dtypes.Int64DType'>
So while this is technically a solution, trying to use the pandas interpreter for input from a user who doesn't have intricate knowledge of the issue is not possible.

Additional Context

No response

@vitkosbence vitkosbence added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 11, 2024
@rhshadrach
Copy link
Member

Thanks for the report, does specifying pd.options.future.infer_string = True do the trick?

See https://pandas.pydata.org/pdeps/0014-string-dtype.html for more details.

@rhshadrach rhshadrach added IO Excel read_excel, to_excel Strings String extension data type and string data Needs Info Clarification about behavior needed to assess issue and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement IO Excel read_excel, to_excel Needs Info Clarification about behavior needed to assess issue Strings String extension data type and string data
Projects
None yet
Development

No branches or pull requests

2 participants