Skip to content

DataFrame.min/max with axis=1, datetime64[ns, tz] types and NaT values returns NaNs #28468

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
jkukul opened this issue Sep 16, 2019 · 1 comment
Labels
Duplicate Report Duplicate issue or pull request

Comments

@jkukul
Copy link

jkukul commented Sep 16, 2019

Code Sample, a copy-pastable example if possible

s1 = pd.Series([pd.Timestamp('2017-01-01T10', tz='UTC'), pd.Timestamp('2017-01-01T11', tz='UTC')])
s2 = pd.Series([pd.Timestamp('2017-01-01T12', tz='UTC'), pd.NaT])

df = pd.DataFrame(dict(s1=s1, s2=s2))
df.min(axis=1)

produces:

0  NaN
1  NaN
dtype: float64

Problem description

For tz-aware timestamp columns, as soon as pd.NaT value is present in any row in any of the columns, than the column-wise min()/max() operations returns all NaNs.

If columns are non-tz-aware, then min()/max() work as expected, i.e. the result is similar to the one pasted below (except for the timezone part).

Expected Output

0   2017-01-01 10:00:00+00:00
1   2017-01-01 11:00:00+00:00
dtype: datetime64[ns, UTC]

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.6.9.final.0
python-bits : 64
OS : Darwin
OS-release : 18.7.0
machine : x86_64
processor : i386
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 0.25.1
numpy : 1.17.2
pytz : 2019.2
dateutil : 2.8.0
pip : 18.0
setuptools : 41.2.0
Cython : 0.27.3
pytest : 4.4.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.2.6
html5lib : None
pymysql : None
psycopg2 : 2.7.3.2 (dt dec pq3 ext lo64)
jinja2 : 2.10.1
IPython : 7.7.0
pandas_datareader: None
bs4 : 4.6.3
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.2.6
matplotlib : 3.1.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : 0.11.0
pyarrow : 0.13.0
pytables : None
s3fs : None
scipy : 1.0.0
sqlalchemy : 1.3.8
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None

@mroeschke
Copy link
Member

Thanks for the report. I think this is a duplicate of #27794.

@mroeschke mroeschke added the Duplicate Report Duplicate issue or pull request label Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

2 participants