Skip to content

DOC: Improve docstring of Timedelta.delta #21135

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
wants to merge 13 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 72 additions & 2 deletions pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,36 @@ cdef class _Timedelta(timedelta):

@property
def delta(self):
""" return out delta in ns (for internal compat) """
"""
Return the timedelta in nanoseconds (ns), for internal compatibility.

Returns
-------
int
Timedelta in nanoseconds.

Examples
--------
**Using string input**

>>> td = pd.Timedelta('1 days 42 ns')
>>> td.delta
86400000000042

>>> td = pd.Timedelta('3 s')
>>> td.delta
3000000000

>>> td = pd.Timedelta('3 ms 5 us')
>>> td.delta
3005000

**Using integer input**

>>> td = pd.Timedelta(42, unit='ns')
>>> td.delta
42
"""
return self.value

@property
Expand All @@ -770,7 +799,48 @@ cdef class _Timedelta(timedelta):

@property
def resolution(self):
""" return a string representing the lowest resolution that we have """
"""
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this already a part of #21122?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@WillAyd

Yes...
I am not sure why that is in there.
I created separate branches for each of the changes I am proposing to:

  • delta
  • resolution
  • nanoseconds

etcetera, but the commit stream above seems to be sucking all of them into this PR.
super confused.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm this should just reflect what you have locally - any chance you merged your branches there accidentally?

Copy link
Contributor

Choose a reason for hiding this comment

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

when creating a new branch, do it off of upstream/master (or if you keep a local master then off of this). each branch should be independent.

you will need to revert the resolution part of this change (as its in the other PR). or can just close that one and do it here is ok too)

Return a string representing the lowest (i.e. smallest) time resolution.

Each timedelta has a defined resolution that represents the lowest OR
most granular level of precision. Each level of resolution is
represented by a short string as defined below:

- Days: 'D'
- Hours: 'H'
- Minutes: 'T'
- Seconds: 'S'
- Milliseconds: 'L'
- Microseconds: 'U'
- Nanoseconds: 'N'

Returns
-------
str
Time resolution.

Examples
--------
**Using string input**

>>> td = pd.Timedelta('1 days 2 min 3 us 42 ns')
>>> td.resolution
'N'

>>> td = pd.Timedelta('1 days 2 min 3 us')
>>> td.resolution
'U'

>>> td = pd.Timedelta('2 min 3 s')
>>> td.resolution
'S'

**Using integer input**

>>> td = pd.Timedelta(36, unit='us')
>>> td.resolution
'U'
"""

self._ensure_components()
if self._ns:
Expand Down