Skip to content

pd.Timedelta constructor should accept nanoseconds attribute in the arguments #9273

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
tvyomkesh opened this issue Jan 16, 2015 · 4 comments · Fixed by #9289
Closed

pd.Timedelta constructor should accept nanoseconds attribute in the arguments #9273

tvyomkesh opened this issue Jan 16, 2015 · 4 comments · Fixed by #9289
Labels
API Design Timedelta Timedelta data type
Milestone

Comments

@tvyomkesh
Copy link
Contributor

xref #9226

Noticing an inconsistency. pd.Timedelta doesn't allow nanoseconds in constructor but its components list till nanoseconds. Here is what I can reproduce. (used then current master on OS X 10.10.1)

Example:

Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from pandas.tslib import Timedelta
>>> td = Timedelta(nanoseconds=1)
Traceback (most recent call last):
File "", line 1, in 
File "pandas/tslib.pyx", line 1723, in pandas.tslib.Timedelta.__new__ (pandas/tslib.c:29743)
raise ValueError("cannot construct a TimeDelta from the passed arguments, allowed keywords 
are " [days, seconds, microseconds, milliseconds, minutes, hours, weeks]
>>> td=Timedelta(seconds=1)
>>> td.components._fields
('days', 'hours', 'minutes', 'seconds', 'milliseconds', 'microseconds', 'nanoseconds')
@jreback
Copy link
Contributor

jreback commented Jan 16, 2015

This is ONLY for an actual passed argument of 'nanoseconds'. String parsing/interp is good.

In [3]: pd.Timedelta('1ns').components
Out[3]: Components(days=0, hours=0, minutes=0, seconds=0, milliseconds=0, microseconds=0, nanoseconds=1)

@jreback jreback added Timedelta Timedelta data type API Design labels Jan 16, 2015
@jreback jreback added this to the 0.16.0 milestone Jan 16, 2015
@tvyomkesh tvyomkesh changed the title Support for nanoseconds broken in pd.Timedelta pd.Timedelta constructor should accept nanoseconds in the arguments Jan 17, 2015
@tvyomkesh
Copy link
Contributor Author

@jreback I have changed the title accordingly. Timdelta constructor fails to accept when nanoseconds is supplied as an attribute but otherwise pd.Timedelta does support nanoseconds. Also default resolution in the constructor is nanoseconds. For e.g.,

In [7]: t4 = Timedelta(100)
In [8]: t4.components
Out[8]: Components(days=0, hours=0, minutes=0, seconds=0, milliseconds=0, microseconds=0, nanoseconds=100)

@tvyomkesh
Copy link
Contributor Author

I am testing a fix for this. will submit a PR

@tvyomkesh
Copy link
Contributor Author

Moved DateOffset nano related issue to a separate one here #9284 as it seems like a separate issue and not related to this one.

@tvyomkesh tvyomkesh changed the title pd.Timedelta constructor should accept nanoseconds in the arguments pd.Timedelta constructor should accept nanoseconds attribute in the arguments Jan 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants