Skip to content

Operations on NaT returning float instead of datetime64[ns] #12941

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
rrbarbosa opened this issue Apr 21, 2016 · 3 comments
Closed

Operations on NaT returning float instead of datetime64[ns] #12941

rrbarbosa opened this issue Apr 21, 2016 · 3 comments
Labels
Bug Datetime Datetime data dtype
Milestone

Comments

@rrbarbosa
Copy link

Code Sample, a copy-pastable example if possible

df = pd.DataFrame({'t1': pd.NaT, 't2': pd.NaT}, index=[1])
df.min(axis=1)
df.max(axis=1)
df.sum(axis=1)

Expected Output

All results above return a float64 series instead of a datetime64[ns] series.

output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.5.1.final.0
python-bits: 64
OS: Darwin
OS-release: 15.4.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8

pandas: 0.18.0
nose: None
pip: 8.1.1
setuptools: 20.9.0
Cython: None
numpy: 1.11.0
scipy: 0.17.0
statsmodels: 0.6.1
xarray: None
IPython: 4.2.0
sphinx: None
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.3
blosc: None
bottleneck: None
tables: None
numexpr: 2.5.2
matplotlib: 1.5.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.12
pymysql: 0.7.2.None
psycopg2: 2.6.1 (dt dec pq3 ext lo64)
jinja2: 2.8
boto: None
@jorisvandenbossche jorisvandenbossche added Bug Datetime Datetime data dtype labels Apr 21, 2016
@jorisvandenbossche
Copy link
Member

The min/max should return NaT, but the sum should fail I think for datetime64

@jreback
Copy link
Contributor

jreback commented Apr 21, 2016

so .sum(..) is correct, in the the underlying operation raises a TypeError, which is then caught and numeric_only=True is passed so you end up with .sum() of an empty frame and get 0.0.

The other 2 are not being masked correctly inside nanops._maybe_null_out which needs to handle M8,m8 dtypes (rather than converting to float).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype
Projects
None yet
3 participants