Skip to content

GH 9273: Timedelta constructor should accept nanoseconds keyword. #9289

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

Merged
merged 1 commit into from
Jan 19, 2015
Merged

GH 9273: Timedelta constructor should accept nanoseconds keyword. #9289

merged 1 commit into from
Jan 19, 2015

Conversation

tvyomkesh
Copy link
Contributor

closes #9273

This patch adds nanoseconds keyword support in Timedelta constructor.

In [1]: from pandas import Timedelta

In [2]: td = Timedelta(nanoseconds=1)

In [3]: td1 = Timedelta(microseconds=1)

In [4]: td.components
Out[4]: Components(days=0, hours=0, minutes=0, seconds=0, milliseconds=0, microseconds=0, nanoseconds=1)

In [5]: (td + td1).components
Out[5]: Components(days=0, hours=0, minutes=0, seconds=0, milliseconds=0, microseconds=1, nanoseconds=1)

@jreback jreback added API Design Timedelta Timedelta data type labels Jan 18, 2015
@jreback jreback added this to the 0.16.0 milestone Jan 18, 2015
@@ -1722,10 +1722,16 @@ class Timedelta(_Timedelta):
kwargs = dict([ (k, _to_py_int_float(v)) for k, v in iteritems(kwargs) ])

try:
value = timedelta(**kwargs)
if 'nanoseconds' in kwargs:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a nitpick - I think the following is better

nano = kwargs.pop('nanoseconds',0)
value = convert_to_timedelta64(timedelta(**kwargs),'ns',False) + nano

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok fine. done.

@jreback
Copy link
Contributor

jreback commented Jan 19, 2015

minor comment. ping when you have pushed

@tvyomkesh
Copy link
Contributor Author

yes, much better that way. done. thanks.

jreback added a commit that referenced this pull request Jan 19, 2015
GH 9273: Timedelta constructor should accept nanoseconds keyword.
@jreback jreback merged commit b2ce495 into pandas-dev:master Jan 19, 2015
@jreback
Copy link
Contributor

jreback commented Jan 19, 2015

thanks!

@tvyomkesh tvyomkesh deleted the vyom/pd_issue_9273 branch January 19, 2015 06:47
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 this pull request may close these issues.

pd.Timedelta constructor should accept nanoseconds attribute in the arguments
2 participants