From 1ae087f22c7bf5690f9d478b1225a9e8d03d2c16 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Sat, 20 Aug 2022 19:29:55 +0200 Subject: [PATCH 1/3] DOC: Add deprecation marks to deprecated functions --- pandas/_libs/tslibs/timedeltas.pyx | 13 +++++++++++++ pandas/core/base.py | 4 ++++ pandas/core/frame.py | 30 +++++++++++++++++++++++++++++- pandas/core/indexes/base.py | 5 +++++ pandas/core/series.py | 23 ++++++++++++++++++++++- 5 files changed, 73 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index f53d4ccf2d555..6df13bd5264fc 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -1054,6 +1054,11 @@ cdef class _Timedelta(timedelta): @property def freq(self) -> None: + """ + .. deprecated:: 1.5.0 + This argument is deprecated. + + """ # GH#46430 warnings.warn( "Timedelta.freq is deprecated and will be removed in a future version", @@ -1064,6 +1069,11 @@ cdef class _Timedelta(timedelta): @property def is_populated(self) -> bool: + """ + .. deprecated:: 1.5.0 + This argument is deprecated. + + """ # GH#46430 warnings.warn( "Timedelta.is_populated is deprecated and will be removed in a future version", @@ -1245,6 +1255,9 @@ cdef class _Timedelta(timedelta): """ Return the timedelta in nanoseconds (ns), for internal compatibility. + .. deprecated:: 1.5.0 + This argument is deprecated. + Returns ------- int diff --git a/pandas/core/base.py b/pandas/core/base.py index e1775628d09ee..ca3ba5ec4bdd4 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -1057,6 +1057,10 @@ def is_monotonic(self) -> bool: """ Return boolean if values in the object are monotonically increasing. + .. deprecated:: 1.5.0 + is_monotonic is deprecated and will be removed in a future version. + Use is_monotonic_increasing instead. + Returns ------- bool diff --git a/pandas/core/frame.py b/pandas/core/frame.py index bcc7a2ae8f83f..2befc979ed017 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1324,7 +1324,35 @@ def items(self) -> Iterable[tuple[Hashable, Series]]: for i, k in enumerate(self.columns): yield k, self._ixs(i, axis=1) - @Appender(_shared_docs["items"]) + _shared_docs[ + "iteritems" + ] = r""" + .. deprecated:: 1.5.0 + iteritems is deprecated and will be removed in a future version. + Use .items instead. + + Iterate over (column name, Series) pairs. + + Iterates over the DataFrame columns, returning a tuple with + the column name and the content as a Series. + + Yields + ------ + label : object + The column names for the DataFrame being iterated over. + content : Series + The column entries belonging to each label, as a Series. + + See Also + -------- + DataFrame.iter : Recommended alternative. + DataFrame.iterrows : Iterate over DataFrame rows as + (index, Series) pairs. + DataFrame.itertuples : Iterate over DataFrame rows as namedtuples + of the values. + """ + + @Appender(_shared_docs["iteritems"]) def iteritems(self) -> Iterable[tuple[Hashable, Series]]: warnings.warn( "iteritems is deprecated and will be removed in a future version. " diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 1e8ba81c877ac..03a3148ffe5b0 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2285,6 +2285,11 @@ def _can_hold_na(self) -> bool: def is_monotonic(self) -> bool: """ Alias for is_monotonic_increasing. + + .. deprecated:: 1.5.0 + is_monotonic is deprecated and will be removed in a future version. + Use is_monotonic_increasing instead. + """ warnings.warn( "is_monotonic is deprecated and will be removed in a future version. " diff --git a/pandas/core/series.py b/pandas/core/series.py index 13aa12287072c..4369dc9da98c9 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1807,8 +1807,29 @@ def items(self) -> Iterable[tuple[Hashable, Any]]: """ return zip(iter(self.index), iter(self)) - @Appender(items.__doc__) def iteritems(self) -> Iterable[tuple[Hashable, Any]]: + """ + .. deprecated:: 1.5.0 + iteritems is deprecated and will be removed in a future version. + Use .items instead. + + Lazily iterate over (index, value) tuples. + + This method returns an iterable tuple (index, value). This is + convenient if you want to create a lazy iterator. + + Returns + ------- + iterable + Iterable of tuples containing the (index, value) pairs from a + Series. + + See Also + -------- + Series.items : Recommended alternative + DataFrame.items : Iterate over (column name, Series) pairs. + DataFrame.iterrows : Iterate over DataFrame rows as (index, Series) pairs. + """ warnings.warn( "iteritems is deprecated and will be removed in a future version. " "Use .items instead.", From 8f6d3a4ee0347f15b1779f6bc003a82d334bb796 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Sat, 20 Aug 2022 20:17:36 +0200 Subject: [PATCH 2/3] Address docs --- pandas/_libs/tslibs/timedeltas.pyx | 2 -- pandas/core/frame.py | 4 ++-- pandas/core/indexes/base.py | 1 - pandas/core/series.py | 6 +++--- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index 6df13bd5264fc..af3420b7d29b8 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -1057,7 +1057,6 @@ cdef class _Timedelta(timedelta): """ .. deprecated:: 1.5.0 This argument is deprecated. - """ # GH#46430 warnings.warn( @@ -1072,7 +1071,6 @@ cdef class _Timedelta(timedelta): """ .. deprecated:: 1.5.0 This argument is deprecated. - """ # GH#46430 warnings.warn( diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 2befc979ed017..821062ff92084 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1327,12 +1327,12 @@ def items(self) -> Iterable[tuple[Hashable, Series]]: _shared_docs[ "iteritems" ] = r""" + Iterate over (column name, Series) pairs. + .. deprecated:: 1.5.0 iteritems is deprecated and will be removed in a future version. Use .items instead. - Iterate over (column name, Series) pairs. - Iterates over the DataFrame columns, returning a tuple with the column name and the content as a Series. diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 03a3148ffe5b0..6e620bc072a23 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2289,7 +2289,6 @@ def is_monotonic(self) -> bool: .. deprecated:: 1.5.0 is_monotonic is deprecated and will be removed in a future version. Use is_monotonic_increasing instead. - """ warnings.warn( "is_monotonic is deprecated and will be removed in a future version. " diff --git a/pandas/core/series.py b/pandas/core/series.py index 4369dc9da98c9..2e6722ccc5797 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1809,12 +1809,12 @@ def items(self) -> Iterable[tuple[Hashable, Any]]: def iteritems(self) -> Iterable[tuple[Hashable, Any]]: """ + Lazily iterate over (index, value) tuples. + .. deprecated:: 1.5.0 iteritems is deprecated and will be removed in a future version. Use .items instead. - Lazily iterate over (index, value) tuples. - This method returns an iterable tuple (index, value). This is convenient if you want to create a lazy iterator. @@ -1826,7 +1826,7 @@ def iteritems(self) -> Iterable[tuple[Hashable, Any]]: See Also -------- - Series.items : Recommended alternative + Series.items : Recommended alternative. DataFrame.items : Iterate over (column name, Series) pairs. DataFrame.iterrows : Iterate over DataFrame rows as (index, Series) pairs. """ From a5fe4872a0043b77b1f02097786096a9ac6062ca Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Sat, 20 Aug 2022 20:40:59 +0200 Subject: [PATCH 3/3] docstrings --- pandas/_libs/tslibs/timedeltas.pyx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index af3420b7d29b8..4019f02f32a29 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -1055,6 +1055,8 @@ cdef class _Timedelta(timedelta): @property def freq(self) -> None: """ + Freq property. + .. deprecated:: 1.5.0 This argument is deprecated. """ @@ -1069,6 +1071,8 @@ cdef class _Timedelta(timedelta): @property def is_populated(self) -> bool: """ + Is_populated property. + .. deprecated:: 1.5.0 This argument is deprecated. """