-
-
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 16 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,62 @@ cdef class _Timedelta(timedelta): | |
|
||
cpdef timedelta to_pytimedelta(_Timedelta self): | ||
""" | ||
return an actual datetime.timedelta object | ||
note: we lose nanosecond resolution if any | ||
Convert a Timedelta object into a python datetime.timedelta object. | ||
|
||
Timedelta objects are internally saved as numpy datetime64[ns] dtype. | ||
Use to_pytimedelta() to convert 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 | ||
-------- | ||
>>> idx = pd.to_timedelta(['1 days 06:05:01.00003', '15.5us', 'nan']) | ||
>>> idx | ||
TimedeltaIndex(['1 days 06:05:01.000030', '0 days 00:00:00.000015', | ||
NaT], | ||
dtype='timedelta64[ns]', freq=None) | ||
|
||
>>> idx.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
|
||
>>> idx[1].to_pytimedelta() | ||
datetime.timedelta(0, 0, 16) | ||
""" | ||
return timedelta(microseconds=int(self.value) / 1000) | ||
|
||
def to_timedelta64(self): | ||
""" Returns a numpy.timedelta64 object with 'ns' precision """ | ||
""" | ||
Return a numpy.timedelta64 object with 'ns' precision. | ||
""" | ||
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. | ||
""" | ||
self._ensure_components() | ||
# return the named tuple | ||
return Components(self._d, self._h, self._m, self._s, | ||
|
@@ -1135,8 +1169,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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
@jreback
I've made these changes: c09d83a
If there's anything else, please let me know.
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.
Do these doctests pass? It looks like the whitespace formatting is off.
You may need to add a
doctest: +NORMALIZE_WHITESPACE
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
@dcreekp as I said above I would remove all of these examples