-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: fix timestamp timedelta quotes #25118
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
Changes from 15 commits
dc0b8c3
2bac2c6
f645380
b0b23b9
e2261f9
ac0003f
a02a7b4
bd97e5e
6e2fb3a
099cd57
7815ef0
bc1fb28
2aec3e1
b84ef90
c09d83a
27c97d1
fd0de80
6349040
5cb7828
549633d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -815,28 +815,63 @@ cdef class _Timedelta(timedelta): | |
|
||
cpdef timedelta to_pytimedelta(_Timedelta self): | ||
""" | ||
return an actual datetime.timedelta object | ||
note: we lose nanosecond resolution if any | ||
Converts a Timedelta object into a python datetime.timedelta object. | ||
|
||
Timedelta objects are typecast to numpy datetime64[ns] dtype, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'd use a stop mark to separate the second sentence instead of a comma, would make this easier to read.
|
||
use to_pytimedelta() to convert back to object dtype. | ||
|
||
Returns | ||
------- | ||
datetime.timedelta or numpy.array of datetime.timedelta | ||
|
||
See Also | ||
-------- | ||
to_timedelta : Convert argument to Timedelta type. | ||
|
||
Notes | ||
----- | ||
Any nanosecond resolution will be lost. | ||
|
||
Examples | ||
-------- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure i would add all of these examples, 1 example at most and it should actually use this function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do these doctests pass? It looks like the whitespace formatting is off. You may need to add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think any of these examples are needed, they are not showing this internal rountine. I would simply remove them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dcreekp as I said above I would remove all of these examples |
||
Converting an array of Timedeltas: | ||
TomAugspurger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
>>> arr = pd.to_timedelta(['1 days 06:05:01.00003', '15.5us', 'nan']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. our convention is to use |
||
>>> arr | ||
TimedeltaIndex(['1 days 06:05:01.000030', '0 days 00:00:00.000015', | ||
NaT], | ||
dtype='timedelta64[ns]', freq=None) | ||
>>> arr[1].to_pytimedelta() | ||
TomAugspurger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
datetime.timedelta(0, 0, 16) | ||
>>> arr.to_pytimedelta() | ||
array([datetime.timedelta(1, 21901, 30), datetime.timedelta(0, 0, 16), | ||
NaT], dtype=object) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be indented. to align with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. $ python scripts/validate_docstrings.py pandas.Timedelta.to_pytimedelta
It passed but I changed it to your spec. I also found NORMALIZE_WHITESPACE in
|
||
""" | ||
return timedelta(microseconds=int(self.value) / 1000) | ||
|
||
def to_timedelta64(self): | ||
""" Returns a numpy.timedelta64 object with 'ns' precision """ | ||
""" | ||
Returns a numpy.timedelta64 object with 'ns' precision. | ||
TomAugspurger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
return np.timedelta64(self.value, 'ns') | ||
|
||
def total_seconds(self): | ||
""" | ||
Total duration of timedelta in seconds (to ns precision) | ||
Total duration of timedelta in seconds (to ns precision). | ||
""" | ||
return self.value / 1e9 | ||
|
||
def view(self, dtype): | ||
""" array view compat """ | ||
""" | ||
Array view compatibility. | ||
""" | ||
return np.timedelta64(self.value).view(dtype) | ||
|
||
@property | ||
def components(self): | ||
""" Return a Components NamedTuple-like """ | ||
""" | ||
Return a Components NamedTuple-like. | ||
TomAugspurger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
self._ensure_components() | ||
# return the named tuple | ||
return Components(self._d, self._h, self._m, self._s, | ||
|
@@ -1135,8 +1170,8 @@ class Timedelta(_Timedelta): | |
Notes | ||
----- | ||
The ``.value`` attribute is always in ns. | ||
|
||
""" | ||
|
||
def __new__(cls, object value=_no_input, unit=None, **kwargs): | ||
cdef _Timedelta td_base | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convert
instead ofConverts
I think it'd be more clear: Convert a pandas Timedelta object into a python timedelta object.