Skip to content

Call .max method on two timezone datetime columns results in nan #28821

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

Closed
albb318 opened this issue Oct 7, 2019 · 1 comment
Closed

Call .max method on two timezone datetime columns results in nan #28821

albb318 opened this issue Oct 7, 2019 · 1 comment

Comments

@albb318
Copy link

albb318 commented Oct 7, 2019

Code Sample, a copy-pastable example if possible

This works when comparing two non-timezone datetime columns

a = pd.DataFrame(
    {
        "a": [pd.Timestamp("20180101"), np.nan],
        "b": [pd.Timestamp("20190101"), pd.Timestamp("20190101")],
    }
)
a.max(axis=1)

Output:
0 2019-01-01
1 2019-01-01
dtype: datetime64[ns]

But it fails on time-zone datetime columns

a = pd.DataFrame(
    {
        "a": [pd.Timestamp("20180101", tz="utc"), np.nan],
        "b": [pd.Timestamp("20190101", tz="utc"), pd.Timestamp("20190101", tz="utc")],
    }
)
a.max(axis=1)

Output:
0 NaN
1 NaN
dtype: float64

Problem description

I'm expecting the .max function to work consistently on both non-timezone and timezone datetime columns. But as the above results shows, somehow the comparison of timezone datetime is adjusted to float and the results are all nan.

Expected Output

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.4.final.0
python-bits : 64
OS : Windows
OS-release : 7
machine : AMD64
processor : Intel64 Family 6 Model 62 Stepping 4, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None

pandas : 0.25.1
numpy : 1.16.5
pytz : 2019.2
dateutil : 2.8.0
pip : 19.2.2
setuptools : 41.0.1
Cython : 0.29.13
pytest : 5.0.1
hypothesis : None
sphinx : None
blosc : None
feather : 0.4.0
xlsxwriter : 1.1.8
lxml.etree : 4.4.1
html5lib : 1.0.1
pymysql : 0.9.3
psycopg2 : None
jinja2 : 2.10.1
IPython : 7.8.0
pandas_datareader: 0.7.4
bs4 : 4.8.0
bottleneck : 1.2.1
fastparquet : None
gcsfs : None
lxml.etree : 4.4.1
matplotlib : 3.1.1
numexpr : 2.7.0
odfpy : None
openpyxl : 2.6.2
pandas_gbq : None
pyarrow : 0.11.1
pytables : None
s3fs : None
scipy : 1.3.1
sqlalchemy : 1.3.7
tables : 3.5.2
xarray : 0.12.1
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : 1.1.8

@mroeschke
Copy link
Member

Duplicate of #27794. Investigations and PRs welcome!

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

No branches or pull requests

2 participants