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: inconsistency when transposing empty datetime column #44336

Open
3 tasks done
CloseChoice opened this issue Nov 6, 2021 · 0 comments
Open
3 tasks done

BUG: inconsistency when transposing empty datetime column #44336

CloseChoice opened this issue Nov 6, 2021 · 0 comments
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions

Comments

@CloseChoice
Copy link
Member

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the master branch of pandas.

Reproducible Example

>>> import pandas as pd
>>> srs = pd.Series(pd.to_datetime([]))
>>> srs
Series([], dtype: datetime64[ns])
>>> srs.T.T
Series([], dtype: datetime64[ns])  # this works as expected
>>> srs.T
Series([], dtype: datetime64[ns])
>>> df = pd.DataFrame({"x": pd.to_datetime([])})
>>> df
Empty DataFrame
Columns: [x]
Index: []
>>> df.dtypes
x    datetime64[ns]
dtype: object
>>> df.T.dtypes
Series([], dtype: object)
>>> df.T.T.dtypes  # this might be unexpected behaviour, datetime64[ns] is expected
x    float64
dtype: object

Issue Description

When transposing an empty dataframe with one datetime column, we get an object dtype for the columns. When transposing this once more we should end up with the original dataframe, but we get a float64 dtype instead. This works fine for pd.Series

Expected Behavior

I would expect

>>> df.T.T.dtypes
x    datetime64[ns]
dtype: object

Installed Versions

INSTALLED VERSIONS ------------------ commit : 969b07c python : 3.8.11.final.0 python-bits : 64 OS : Linux OS-release : 5.4.0-77-generic Version : #86~18.04.1-Ubuntu SMP Fri Jun 18 01:23:22 UTC 2021 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8

pandas : 1.4.0.dev0+1057.g969b07c82a
numpy : 1.21.1
pytz : 2021.1
dateutil : 2.8.2
pip : 21.0.1
setuptools : 58.0.4
Cython : 0.29.24
pytest : 6.2.5
hypothesis : 5.37.4
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.4.3
numexpr : None
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : 1.4.26
tables : None
tabulate : None
xarray : None
xlrd : 2.0.1
xlwt : None
numba : None

@CloseChoice CloseChoice added Bug Needs Triage Issue that has not been reviewed by a pandas team member Dtype Conversions Unexpected or buggy dtype conversions Timezones Timezone data dtype and removed Timezones Timezone data dtype labels Nov 6, 2021
@CloseChoice CloseChoice changed the title BUG: BUG: inconsistency when transposing empty datetime column Nov 6, 2021
@mroeschke mroeschke removed the Needs Triage Issue that has not been reviewed by a pandas team member label Nov 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

No branches or pull requests

2 participants