ENH: Add a clear option to interpret strings as Pandas dtypes specifically. #59777
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
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
The text was updated successfully, but these errors were encountered: