Skip to content

Commit c26dd1f

Browse files
authored
Merge branch 'main' into enforce-pdep6
2 parents 45cafc2 + 73ea3c1 commit c26dd1f

35 files changed

+268
-99
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
154154
-i "pandas.Series.dt.tz_convert PR01,PR02" \
155155
-i "pandas.Series.dt.tz_localize PR01,PR02" \
156156
-i "pandas.Series.dt.unit GL08" \
157-
-i "pandas.Series.ge SA01" \
158157
-i "pandas.Series.gt SA01" \
159158
-i "pandas.Series.list.__getitem__ SA01" \
160159
-i "pandas.Series.list.flatten SA01" \
@@ -213,7 +212,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
213212
-i "pandas.Timedelta.asm8 SA01" \
214213
-i "pandas.Timedelta.ceil SA01" \
215214
-i "pandas.Timedelta.components SA01" \
216-
-i "pandas.Timedelta.days SA01" \
217215
-i "pandas.Timedelta.floor SA01" \
218216
-i "pandas.Timedelta.max PR02" \
219217
-i "pandas.Timedelta.min PR02" \

doc/source/user_guide/missing_data.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ To detect these missing value, use the :func:`isna` or :func:`notna` methods.
6060
6161
.. warning::
6262

63-
Equality compaisons between ``np.nan``, :class:`NaT`, and :class:`NA`
63+
Equality comparisons between ``np.nan``, :class:`NaT`, and :class:`NA`
6464
do not act like ``None``
6565

6666
.. ipython:: python

doc/source/user_guide/timedeltas.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ You can construct a ``Timedelta`` scalar through various arguments, including `I
3535
pd.Timedelta(days=1, seconds=1)
3636
3737
# integers with a unit
38-
pd.Timedelta(1, unit="d")
38+
pd.Timedelta(1, unit="D")
3939
4040
# from a datetime.timedelta/np.timedelta64
4141
pd.Timedelta(datetime.timedelta(days=1, seconds=1))
@@ -94,7 +94,7 @@ is numeric:
9494
.. ipython:: python
9595
9696
pd.to_timedelta(np.arange(5), unit="s")
97-
pd.to_timedelta(np.arange(5), unit="d")
97+
pd.to_timedelta(np.arange(5), unit="D")
9898
9999
.. warning::
100100
If a string or array of strings is passed as an input then the ``unit`` keyword

doc/source/whatsnew/v0.13.0.rst

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -523,13 +523,25 @@ Enhancements
523523
Using the new top-level ``to_timedelta``, you can convert a scalar or array from the standard
524524
timedelta format (produced by ``to_csv``) into a timedelta type (``np.timedelta64`` in ``nanoseconds``).
525525

526-
.. ipython:: python
526+
.. code-block:: ipython
527+
528+
In [53]: pd.to_timedelta('1 days 06:05:01.00003')
529+
Out[53]: Timedelta('1 days 06:05:01.000030')
530+
531+
In [54]: pd.to_timedelta('15.5us')
532+
Out[54]: Timedelta('0 days 00:00:00.000015500')
533+
534+
In [55]: pd.to_timedelta(['1 days 06:05:01.00003', '15.5us', 'nan'])
535+
Out[55]: TimedeltaIndex(['1 days 06:05:01.000030', '0 days 00:00:00.000015500', NaT], dtype='timedelta64[ns]', freq=None)
536+
537+
In [56]: pd.to_timedelta(np.arange(5), unit='s')
538+
Out[56]:
539+
TimedeltaIndex(['0 days 00:00:00', '0 days 00:00:01', '0 days 00:00:02',
540+
'0 days 00:00:03', '0 days 00:00:04'],
541+
dtype='timedelta64[ns]', freq=None)
527542
528-
pd.to_timedelta('1 days 06:05:01.00003')
529-
pd.to_timedelta('15.5us')
530-
pd.to_timedelta(['1 days 06:05:01.00003', '15.5us', 'nan'])
531-
pd.to_timedelta(np.arange(5), unit='s')
532-
pd.to_timedelta(np.arange(5), unit='d')
543+
In [57]: pd.to_timedelta(np.arange(5), unit='d')
544+
Out[57]: TimedeltaIndex(['0 days', '1 days', '2 days', '3 days', '4 days'], dtype='timedelta64[ns]', freq=None)
533545
534546
A Series of dtype ``timedelta64[ns]`` can now be divided by another
535547
``timedelta64[ns]`` object, or astyped to yield a ``float64`` dtyped Series. This

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ Other Deprecations
273273
- Deprecated allowing non-keyword arguments in :meth:`Series.to_string` except ``buf``. (:issue:`57280`)
274274
- Deprecated behavior of :meth:`Series.dt.to_pytimedelta`, in a future version this will return a :class:`Series` containing python ``datetime.timedelta`` objects instead of an ``ndarray`` of timedelta; this matches the behavior of other :meth:`Series.dt` properties. (:issue:`57463`)
275275
- Deprecated parameter ``method`` in :meth:`DataFrame.reindex_like` / :meth:`Series.reindex_like` (:issue:`58667`)
276+
- Deprecated strings ``w``, ``d``, ``MIN``, ``MS``, ``US`` and ``NS`` denoting units in :class:`Timedelta` in favour of ``W``, ``D``, ``min``, ``ms``, ``us`` and ``ns`` (:issue:`59051`)
276277
- Deprecated using ``epoch`` date format in :meth:`DataFrame.to_json` and :meth:`Series.to_json`, use ``iso`` instead. (:issue:`57063`)
277278

278279
.. ---------------------------------------------------------------------------

pandas/_libs/tslibs/dtypes.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ cdef dict c_OFFSET_TO_PERIOD_FREQSTR
1515
cdef dict c_PERIOD_TO_OFFSET_FREQSTR
1616
cdef dict c_OFFSET_RENAMED_FREQSTR
1717
cdef dict c_DEPR_ABBREVS
18+
cdef dict c_DEPR_UNITS
1819
cdef dict c_PERIOD_AND_OFFSET_DEPR_FREQSTR
1920
cdef dict attrname_to_abbrevs
2021
cdef dict npy_unit_to_attrname

pandas/_libs/tslibs/dtypes.pyx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,17 @@ cdef dict c_DEPR_ABBREVS = {
346346
"S": "s",
347347
}
348348

349+
cdef dict c_DEPR_UNITS = {
350+
"w": "W",
351+
"d": "D",
352+
"H": "h",
353+
"MIN": "min",
354+
"S": "s",
355+
"MS": "ms",
356+
"US": "us",
357+
"NS": "ns",
358+
}
359+
349360
cdef dict c_PERIOD_AND_OFFSET_DEPR_FREQSTR = {
350361
"w": "W",
351362
"MIN": "min",

pandas/_libs/tslibs/timedeltas.pyx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ from pandas._libs.tslibs.conversion cimport (
4343
precision_from_unit,
4444
)
4545
from pandas._libs.tslibs.dtypes cimport (
46-
c_DEPR_ABBREVS,
46+
c_DEPR_UNITS,
4747
get_supported_reso,
4848
is_supported_unit,
4949
npy_unit_to_abbrev,
@@ -719,15 +719,15 @@ cpdef inline str parse_timedelta_unit(str unit):
719719
return "ns"
720720
elif unit == "M":
721721
return unit
722-
elif unit in c_DEPR_ABBREVS:
722+
elif unit in c_DEPR_UNITS:
723723
warnings.warn(
724724
f"\'{unit}\' is deprecated and will be removed in a "
725-
f"future version. Please use \'{c_DEPR_ABBREVS.get(unit)}\' "
725+
f"future version. Please use \'{c_DEPR_UNITS.get(unit)}\' "
726726
f"instead of \'{unit}\'.",
727727
FutureWarning,
728728
stacklevel=find_stack_level(),
729729
)
730-
unit = c_DEPR_ABBREVS[unit]
730+
unit = c_DEPR_UNITS[unit]
731731
try:
732732
return timedelta_abbrevs[unit.lower()]
733733
except KeyError:
@@ -1078,10 +1078,22 @@ cdef class _Timedelta(timedelta):
10781078
"""
10791079
Returns the days of the timedelta.
10801080
1081+
The `days` attribute of a `pandas.Timedelta` object provides the number
1082+
of days represented by the `Timedelta`. This is useful for extracting
1083+
the day component from a `Timedelta` that may also include hours, minutes,
1084+
seconds, and smaller time units. This attribute simplifies the process
1085+
of working with durations where only the day component is of interest.
1086+
10811087
Returns
10821088
-------
10831089
int
10841090
1091+
See Also
1092+
--------
1093+
Timedelta.seconds : Returns the seconds component of the timedelta.
1094+
Timedelta.microseconds : Returns the microseconds component of the timedelta.
1095+
Timedelta.total_seconds : Returns the total duration in seconds.
1096+
10851097
Examples
10861098
--------
10871099
>>> td = pd.Timedelta(1, "d")
@@ -1811,6 +1823,11 @@ class Timedelta(_Timedelta):
18111823
Values `H`, `T`, `S`, `L`, `U`, and `N` are deprecated in favour
18121824
of the values `h`, `min`, `s`, `ms`, `us`, and `ns`.
18131825
1826+
.. deprecated:: 3.0.0
1827+
1828+
Allowing the values `w`, `d`, `MIN`, `MS`, `US` and `NS` to denote units
1829+
are deprecated in favour of the values `W`, `D`, `min`, `ms`, `us` and `ns`.
1830+
18141831
**kwargs
18151832
Available kwargs: {days, seconds, microseconds,
18161833
milliseconds, minutes, hours, weeks}.

pandas/core/arrays/timedeltas.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ def total_seconds(self) -> npt.NDArray[np.float64]:
746746
--------
747747
**Series**
748748
749-
>>> s = pd.Series(pd.to_timedelta(np.arange(5), unit="d"))
749+
>>> s = pd.Series(pd.to_timedelta(np.arange(5), unit="D"))
750750
>>> s
751751
0 0 days
752752
1 1 days
@@ -765,7 +765,7 @@ def total_seconds(self) -> npt.NDArray[np.float64]:
765765
766766
**TimedeltaIndex**
767767
768-
>>> idx = pd.to_timedelta(np.arange(5), unit="d")
768+
>>> idx = pd.to_timedelta(np.arange(5), unit="D")
769769
>>> idx
770770
TimedeltaIndex(['0 days', '1 days', '2 days', '3 days', '4 days'],
771771
dtype='timedelta64[ns]', freq=None)
@@ -809,7 +809,7 @@ def to_pytimedelta(self) -> npt.NDArray[np.object_]:
809809
--------
810810
For Series:
811811
812-
>>> ser = pd.Series(pd.to_timedelta([1, 2, 3], unit='d'))
812+
>>> ser = pd.Series(pd.to_timedelta([1, 2, 3], unit='D'))
813813
>>> ser
814814
0 1 days
815815
1 2 days

pandas/core/indexes/accessors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ def to_pytimedelta(self) -> np.ndarray:
459459
460460
Examples
461461
--------
462-
>>> s = pd.Series(pd.to_timedelta(np.arange(5), unit="d"))
462+
>>> s = pd.Series(pd.to_timedelta(np.arange(5), unit="D"))
463463
>>> s
464464
0 0 days
465465
1 1 days

0 commit comments

Comments
 (0)