Skip to content

BUG: NaT does not propagate in row-wise max for datetime64 rows #36907

Closed
@isVoid

Description

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

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

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


Code Sample, a copy-pastable example

import pandas as pd
pdf = pd.DataFrame()
pdf['a'] = pd.Series(['2020-01-01 08:00:00', '1920-02-01 09:00:00'], dtype='datetime64[ns]')
pdf['b'] = pd.Series(['2020-02-01 08:00:00', pd.NaT], dtype='datetime64[ns]')
pdf.max(axis=1, skipna=False)

Problem description

Current output is

0   2020-02-01 08:00:00
1   1920-02-01 09:00:00
dtype: datetime64[ns]

In general, missing values involved in reduction should propagate.

Expected Output

0   2020-02-01 08:00:00
1   NaT
dtype: datetime64[ns]

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit : 2a7d332 python : 3.7.8.final.0 python-bits : 64 OS : Linux OS-release : 5.4.0-48-generic Version : #52~18.04.1-Ubuntu SMP Thu Sep 10 12:50:22 UTC 2020 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : None LOCALE : en_US.UTF-8

pandas : 1.1.2
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.3
setuptools : 49.6.0.post20200917
Cython : 0.29.21
pytest : 6.1.1
hypothesis : 5.28.0
sphinx : 3.2.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.3.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 0.8.3
fastparquet : None
gcsfs : None
matplotlib : 3.3.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 1.0.1
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : 0.51.0rc1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions