Skip to content

BUG: transpose unnecessarily returning object #43337

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

Open
rhshadrach opened this issue Aug 31, 2021 · 1 comment
Open

BUG: transpose unnecessarily returning object #43337

rhshadrach opened this issue Aug 31, 2021 · 1 comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Enhancement

Comments

@rhshadrach
Copy link
Member

Ref: https://github.com/pandas-dev/pandas/pull/43213/files#r699680952

Example:

df = pd.DataFrame({'a': [1], 'b': [2]})
print(df.T.dtypes)
df['b'] = df['b'].astype('Int64')
print(df.T.dtypes)

gives int64 for the first example, and object for the 2nd. However, the 2nd arguably would be better off as Int64.

The code from #43213 could be used in the transpose method, something akin to

from pandas.core.dtypes.cast import find_common_type

df = pd.DataFrame({'a': [1], 'b': [2]})
df['b'] = df['b'].astype('Int64')
common_type = find_common_type(df.dtypes.tolist())
print(df.T.astype(common_type, copy=False).dtypes)

Perhaps there are undesirable side-effects by doing this?

@rhshadrach rhshadrach added Enhancement Dtype Conversions Unexpected or buggy dtype conversions Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 31, 2021
@jbrockmendel
Copy link
Member

Shout it from the rooftops: the solution is 2D EAs

@jreback jreback added this to the Contributions Welcome milestone Aug 31, 2021
@simonjayhawkins simonjayhawkins removed the Needs Triage Issue that has not been reviewed by a pandas team member label Sep 1, 2021
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants