Navigation Menu

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: timedelta64 dtype inference in Series #5689

Closed
cancan101 opened this issue Dec 12, 2013 · 3 comments · Fixed by #5995
Closed

BUG: timedelta64 dtype inference in Series #5689

cancan101 opened this issue Dec 12, 2013 · 3 comments · Fixed by #5995
Labels
API Design Bug Dtype Conversions Unexpected or buggy dtype conversions Timedelta Timedelta data type
Milestone

Comments

@cancan101
Copy link
Contributor

related #5690

This works:

pd.Series(np.array([np.timedelta64(300000000)]))
0   00:00:00.300000
dtype: timedelta64

but this does not:

pd.Series([np.timedelta64(300000000)])

on Numpy 1.7:

TypeError: don't know how to convert scalar number to float

and on Numpy 1.8:

0    300000000
dtype: int64
@jreback
Copy link
Contributor

jreback commented Dec 13, 2013

on master/numpy 1.7

inference could be improvied in the non-dtype specified case

In [23]: pd.Series([np.timedelta64(300000000)])
Out[23]: 
0    300000000 generic time units
dtype: object

In [24]: pd.Series([np.timedelta64(300000000)],dtype='m8[ns]')
Out[24]: 
0   00:00:00.300000
dtype: timedelta64[ns]

In [25]: pd.to_timedelta([np.timedelta64(300000000)])
Out[25]: 
0   00:00:00.300000
dtype: timedelta64[ns]

@cancan101
Copy link
Contributor Author

I am not sure if this is a related issue or not, but the notion of nullness is not handled well for timedelta64 columns when performing a left join:

In [194]:
pd.DataFrame(pd.Series([np.timedelta64(300000000),np.timedelta64(300000000)],dtype='m8[ns]',index=["A","B"])).join(
     pd.DataFrame(pd.Series([np.timedelta64(300000000)],dtype='m8[ns]',index=["A"])),rsuffix='r', how="left").info()

Out [194]:
<class 'pandas.core.frame.DataFrame'>
Index: 2 entries, A to B
Data columns (total 2 columns):
0     2  non-null values
0r    1  non-null values
dtypes: float64(1), timedelta64[ns](1)

The column with a mix of timedelta64 and nulls gets cast to a float64.

This seems incorrect since NaT should be usable to indicate the null:

In [196]:
pd.Series([np.timedelta64(300000000), pd.NaT],dtype='m8[ns]')

Out[196]:
0   00:00:00.300000
1               NaT
dtype: timedelta64[ns]

@jreback
Copy link
Contributor

jreback commented Dec 13, 2013

that's unrelated I think, so maybe open a different issue for it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Bug Dtype Conversions Unexpected or buggy dtype conversions Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants