From eb5b998d0cd2fac341779aa47e962620c08c7a00 Mon Sep 17 00:00:00 2001 From: saldanhad Date: Mon, 23 Sep 2024 21:08:20 +0530 Subject: [PATCH 01/17] add tag dt.to_timestamp, series.rst --- doc/source/reference/series.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/reference/series.rst b/doc/source/reference/series.rst index 43d7480899dc4..cf90969d0f82b 100644 --- a/doc/source/reference/series.rst +++ b/doc/source/reference/series.rst @@ -345,6 +345,7 @@ Datetime methods Series.dt.isocalendar Series.dt.to_period + Series.dt.to_timestamp Series.dt.to_pydatetime Series.dt.tz_localize Series.dt.tz_convert From 66f7453d98c04b83e8a6d47d5310e9e10fb13912 Mon Sep 17 00:00:00 2001 From: saldanhad Date: Tue, 24 Sep 2024 02:30:49 +0530 Subject: [PATCH 02/17] add doc strings for dt.to_timestamp --- pandas/core/arrays/datetimes.py | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 201c449185057..60933b4f96737 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -261,6 +261,7 @@ def _scalar_type(self) -> type[Timestamp]: ) _datetimelike_methods: list[str] = [ "to_period", + "to_timestamp", "tz_localize", "tz_convert", "normalize", @@ -1271,6 +1272,51 @@ def to_period(self, freq=None) -> PeriodArray: freq = res return PeriodArray._from_datetime64(self._ndarray, freq, tz=self.tz) + def to_timestamp(self): + """ + Convert ``Series`` of ``Periods`` to ``DatetimeIndex/Array``. + + This method converts a Series of Periods to a ``DatetimeIndex/Array``. + The ``freq`` and ``how`` parameters cannot be used when calling + ``to_timestamp`` the ``.dt`` accessor. + + Returns + ------- + DatetimeArray/Index + A `DatetimeArray` or `DatetimeIndex` object representing the period + converted to a timestamp. + + See Also + -------- + PeriodIndex.day : The days of the period. + PeriodIndex.from_fields : Construct a PeriodIndex from fields + (year, month, day, etc.). + PeriodIndex.from_ordinals : Construct a PeriodIndex from ordinals. + PeriodIndex.hour : The hour of the period. + PeriodIndex.minute : The minute of the period. + PeriodIndex.month : The month as January=1, December=12. + PeriodIndex.second : The second of the period. + PeriodIndex.year : The year of the period. + + Examples + -------- + >>> s = pd.Series(pd.period_range("2023-01", periods=3, freq="M")) + >>> s + 0 2023-01 + 1 2023-02 + 2 2023-03 + dtype: period[M] + >>> s.dt.to_timestamp() + 0 2023-01-01 + 1 2023-02-01 + 2 2023-03-01 + dtype: datetime64[ns] + """ + # Call the to_timestamp function in PeriodArray() class, ignoring freq and how + from pandas.core.arrays import PeriodArray + + return PeriodArray(self._data).to_timestamp() + # ----------------------------------------------------------------- # Properties - Vectorized Timestamp Properties/Methods From c5d9f54ee0d4d80fca31ab996b7f712084658e58 Mon Sep 17 00:00:00 2001 From: saldanhad Date: Tue, 24 Sep 2024 03:18:20 +0530 Subject: [PATCH 03/17] update datetimes.py --- pandas/core/arrays/datetimes.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 60933b4f96737..20aa4e0bf3433 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -1312,10 +1312,9 @@ def to_timestamp(self): 2 2023-03-01 dtype: datetime64[ns] """ - # Call the to_timestamp function in PeriodArray() class, ignoring freq and how - from pandas.core.arrays import PeriodArray - - return PeriodArray(self._data).to_timestamp() + # Uses to_timestamp method defined in PeriodArray Class() + # function here only used to update docstring + return # ----------------------------------------------------------------- # Properties - Vectorized Timestamp Properties/Methods From 7efa1c6a29f298281b6b052f86143aa76ecbc5cc Mon Sep 17 00:00:00 2001 From: saldanhad Date: Tue, 24 Sep 2024 14:37:38 +0530 Subject: [PATCH 04/17] refactor _create_delegator_method to use functools wrap --- pandas/core/accessor.py | 10 ++++++---- pandas/core/arrays/categorical.py | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/pandas/core/accessor.py b/pandas/core/accessor.py index d8463fda34caa..51b9af3d37ef3 100644 --- a/pandas/core/accessor.py +++ b/pandas/core/accessor.py @@ -116,12 +116,14 @@ def _setter(self, new_values): doc=getattr(delegate, accessor_mapping(name)).__doc__, ) + from functools import wraps + def _create_delegator_method(name: str): - def f(self, *args, **kwargs): - return self._delegate_method(name, *args, **kwargs) + original_method = getattr(delegate, accessor_mapping(name)) - f.__name__ = name - f.__doc__ = getattr(delegate, accessor_mapping(name)).__doc__ + @wraps(original_method) + def f(self): + return self._delegate_method(name) return f diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 8e0225b31e17b..ccf6e634ad585 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -1155,6 +1155,12 @@ def rename_categories(self, new_categories) -> Self: """ Rename categories. + This method is commonly used to re-label or adjust the + category names in categorical data without changing the + underlying data. It is useful in situations where you want + to modify the labels used for clarity, consistency, + or readability. + Parameters ---------- new_categories : list-like, dict-like or callable @@ -1371,8 +1377,8 @@ def remove_categories(self, removals) -> Self: """ Remove the specified categories. - `removals` must be included in the old categories. Values which were in - the removed categories will be set to NaN + ``removals`` must be included in the old categories, + values which were in the removed categories will be set to NaN Parameters ---------- @@ -1431,6 +1437,10 @@ def remove_unused_categories(self) -> Self: """ Remove categories which are not used. + This method is useful when working with datasets + that undergo dynamic changes where categories may no longer be + relevant, allowing to maintain a clean, efficient data structure. + Returns ------- Categorical From 7d61178cbf198a1972d4e5b0bc0c8716f7d744b7 Mon Sep 17 00:00:00 2001 From: saldanhad Date: Tue, 24 Sep 2024 15:06:16 +0530 Subject: [PATCH 05/17] changes to accessor.py --- pandas/core/accessor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/accessor.py b/pandas/core/accessor.py index 51b9af3d37ef3..ca8e12b906b26 100644 --- a/pandas/core/accessor.py +++ b/pandas/core/accessor.py @@ -122,8 +122,8 @@ def _create_delegator_method(name: str): original_method = getattr(delegate, accessor_mapping(name)) @wraps(original_method) - def f(self): - return self._delegate_method(name) + def f(self, *args, **kwargs): + return self._delegate_method(name, *args, **kwargs) return f From a81edf7b49ac719a102cc304ceaaa495838a9c89 Mon Sep 17 00:00:00 2001 From: saldanhad Date: Tue, 24 Sep 2024 16:07:03 +0530 Subject: [PATCH 06/17] remove from code_checks.sh --- ci/code_checks.sh | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 21104c2e00450..d8aa8e5794d34 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -74,28 +74,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.Period.ordinal GL08" \ -i "pandas.RangeIndex.from_range PR01,SA01" \ -i "pandas.RangeIndex.step SA01" \ - -i "pandas.Series.cat.add_categories PR01,PR02" \ - -i "pandas.Series.cat.as_ordered PR01" \ - -i "pandas.Series.cat.as_unordered PR01" \ - -i "pandas.Series.cat.remove_categories PR01,PR02" \ - -i "pandas.Series.cat.remove_unused_categories PR01" \ - -i "pandas.Series.cat.rename_categories PR01,PR02" \ - -i "pandas.Series.cat.reorder_categories PR01,PR02" \ - -i "pandas.Series.cat.set_categories PR01,PR02" \ - -i "pandas.Series.dt.as_unit PR01,PR02" \ - -i "pandas.Series.dt.ceil PR01,PR02" \ - -i "pandas.Series.dt.day_name PR01,PR02" \ - -i "pandas.Series.dt.floor PR01,PR02" \ - -i "pandas.Series.dt.freq GL08" \ - -i "pandas.Series.dt.month_name PR01,PR02" \ - -i "pandas.Series.dt.normalize PR01" \ - -i "pandas.Series.dt.round PR01,PR02" \ - -i "pandas.Series.dt.strftime PR01,PR02" \ - -i "pandas.Series.dt.to_period PR01,PR02" \ - -i "pandas.Series.dt.total_seconds PR01" \ - -i "pandas.Series.dt.tz_convert PR01,PR02" \ - -i "pandas.Series.dt.tz_localize PR01,PR02" \ - -i "pandas.Series.dt.unit GL08" \ -i "pandas.Series.pad PR01,SA01" \ -i "pandas.Series.sparse.fill_value SA01" \ -i "pandas.Series.sparse.from_coo PR07,SA01" \ From 8b06215442d775c49e440fee7361994feb04c0be Mon Sep 17 00:00:00 2001 From: saldanhad Date: Tue, 24 Sep 2024 16:36:17 +0530 Subject: [PATCH 07/17] update code_checks.sh --- ci/code_checks.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index d8aa8e5794d34..6d622d3183584 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -90,6 +90,8 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.Timestamp.resolution PR02" \ -i "pandas.Timestamp.tzinfo GL08" \ -i "pandas.Timestamp.year GL08" \ + -i "pandas.Series.dt.freq GL08" \ + -i "pandas.Series.dt.unit GL08" \ -i "pandas.api.types.is_dict_like PR07,SA01" \ -i "pandas.api.types.is_file_like PR07,SA01" \ -i "pandas.api.types.is_float PR01,SA01" \ From bd4025a3546fc1830def1606ade9f7d3f76b2f63 Mon Sep 17 00:00:00 2001 From: saldanhad Date: Tue, 24 Sep 2024 16:38:37 +0530 Subject: [PATCH 08/17] update code_checks.sh --- ci/code_checks.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 6d622d3183584..5f2e8f40c9614 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -79,6 +79,8 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.Series.sparse.from_coo PR07,SA01" \ -i "pandas.Series.sparse.npoints SA01" \ -i "pandas.Series.sparse.sp_values SA01" \ + -i "pandas.Series.dt.freq GL08" \ + -i "pandas.Series.dt.unit GL08" \ -i "pandas.Timedelta.max PR02" \ -i "pandas.Timedelta.min PR02" \ -i "pandas.Timedelta.resolution PR02" \ @@ -90,8 +92,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.Timestamp.resolution PR02" \ -i "pandas.Timestamp.tzinfo GL08" \ -i "pandas.Timestamp.year GL08" \ - -i "pandas.Series.dt.freq GL08" \ - -i "pandas.Series.dt.unit GL08" \ -i "pandas.api.types.is_dict_like PR07,SA01" \ -i "pandas.api.types.is_file_like PR07,SA01" \ -i "pandas.api.types.is_float PR01,SA01" \ From a072c6be506628095cbd75631543d6070b810dae Mon Sep 17 00:00:00 2001 From: saldanhad Date: Tue, 24 Sep 2024 21:57:26 +0530 Subject: [PATCH 09/17] rewrite functools, adjust unit tests --- pandas/core/accessor.py | 6 +++--- pandas/tests/series/accessors/test_cat_accessor.py | 2 +- pandas/tests/series/accessors/test_dt_accessor.py | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pandas/core/accessor.py b/pandas/core/accessor.py index ca8e12b906b26..ef42879acaf5a 100644 --- a/pandas/core/accessor.py +++ b/pandas/core/accessor.py @@ -116,12 +116,12 @@ def _setter(self, new_values): doc=getattr(delegate, accessor_mapping(name)).__doc__, ) - from functools import wraps + import functools as ft def _create_delegator_method(name: str): - original_method = getattr(delegate, accessor_mapping(name)) + method = getattr(delegate, accessor_mapping(name)) - @wraps(original_method) + @ft.wraps(method) def f(self, *args, **kwargs): return self._delegate_method(name, *args, **kwargs) diff --git a/pandas/tests/series/accessors/test_cat_accessor.py b/pandas/tests/series/accessors/test_cat_accessor.py index ce8ea27ea1fa2..edb476c22fe02 100644 --- a/pandas/tests/series/accessors/test_cat_accessor.py +++ b/pandas/tests/series/accessors/test_cat_accessor.py @@ -177,7 +177,7 @@ def test_dt_accessor_api_for_categorical(self, idx): _special_func_names = [f[0] for f in special_func_defs] - _ignore_names = ["components", "tz_localize", "tz_convert"] + _ignore_names = ["components", "to_timestamp", "tz_localize", "tz_convert"] func_names = [ fname diff --git a/pandas/tests/series/accessors/test_dt_accessor.py b/pandas/tests/series/accessors/test_dt_accessor.py index 9b9a8ea3600ae..a5df098f146aa 100644 --- a/pandas/tests/series/accessors/test_dt_accessor.py +++ b/pandas/tests/series/accessors/test_dt_accessor.py @@ -45,6 +45,7 @@ ok_for_dt = DatetimeArray._datetimelike_ops ok_for_dt_methods = [ "to_period", + "to_timestamp", "to_pydatetime", "tz_localize", "tz_convert", From f02786262e00660910078483b927977535d87deb Mon Sep 17 00:00:00 2001 From: saldanhad Date: Tue, 1 Oct 2024 18:39:53 +0530 Subject: [PATCH 10/17] update change log --- doc/source/whatsnew/v3.0.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index c2a56afbc580e..aa88f1a20f880 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -57,6 +57,7 @@ Other enhancements - :meth:`pandas.concat` will raise a ``ValueError`` when ``ignore_index=True`` and ``keys`` is not ``None`` (:issue:`59274`) - :meth:`str.get_dummies` now accepts a ``dtype`` parameter to specify the dtype of the resulting DataFrame (:issue:`47872`) - Multiplying two :class:`DateOffset` objects will now raise a ``TypeError`` instead of a ``RecursionError`` (:issue:`59442`) +- Refactored :meth:`_create_delegator_method` under core/accessor.py using ``functools``, improving code clarity and maintainability. (:issue:`59783`) - Restore support for reading Stata 104-format and enable reading 103-format dta files (:issue:`58554`) - Support passing a :class:`Iterable[Hashable]` input to :meth:`DataFrame.drop_duplicates` (:issue:`59237`) - Support reading Stata 102-format (Stata 1) dta files (:issue:`58978`) From 53bbc480c44180d7c4e5d49e19ad301687df9ea5 Mon Sep 17 00:00:00 2001 From: saldanhad Date: Tue, 1 Oct 2024 19:51:04 +0530 Subject: [PATCH 11/17] remove dup entry --- ci/code_checks.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 6b85c6afc98fd..0124b91efc3d7 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -86,7 +86,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.Series.dt.ceil PR01,PR02" \ -i "pandas.Series.dt.day_name PR01,PR02" \ -i "pandas.Series.dt.floor PR01,PR02" \ - -i "pandas.Series.dt.freq GL08" \ -i "pandas.Series.dt.month_name PR01,PR02" \ -i "pandas.Series.dt.normalize PR01" \ -i "pandas.Series.dt.round PR01,PR02" \ From 7498d5936b8f59ccc67b83e3d7dc49d0a0e4ed64 Mon Sep 17 00:00:00 2001 From: saldanhad Date: Tue, 1 Oct 2024 20:10:32 +0530 Subject: [PATCH 12/17] update code_checks.sh --- ci/code_checks.sh | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 0124b91efc3d7..ce1760de94498 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -73,34 +73,10 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.Period.freq GL08" \ -i "pandas.Period.ordinal GL08" \ -i "pandas.RangeIndex.from_range PR01,SA01" \ - -i "pandas.RangeIndex.step SA01" \ - -i "pandas.Series.cat.add_categories PR01,PR02" \ - -i "pandas.Series.cat.as_ordered PR01" \ - -i "pandas.Series.cat.as_unordered PR01" \ - -i "pandas.Series.cat.remove_categories PR01,PR02" \ - -i "pandas.Series.cat.remove_unused_categories PR01" \ - -i "pandas.Series.cat.rename_categories PR01,PR02" \ - -i "pandas.Series.cat.reorder_categories PR01,PR02" \ - -i "pandas.Series.cat.set_categories PR01,PR02" \ - -i "pandas.Series.dt.as_unit PR01,PR02" \ - -i "pandas.Series.dt.ceil PR01,PR02" \ - -i "pandas.Series.dt.day_name PR01,PR02" \ - -i "pandas.Series.dt.floor PR01,PR02" \ - -i "pandas.Series.dt.month_name PR01,PR02" \ - -i "pandas.Series.dt.normalize PR01" \ - -i "pandas.Series.dt.round PR01,PR02" \ - -i "pandas.Series.dt.strftime PR01,PR02" \ - -i "pandas.Series.dt.to_period PR01,PR02" \ - -i "pandas.Series.dt.total_seconds PR01" \ - -i "pandas.Series.dt.tz_convert PR01,PR02" \ - -i "pandas.Series.dt.tz_localize PR01,PR02" \ + -i "pandas.Series.dt.freq GL08" \ -i "pandas.Series.dt.unit GL08" \ -i "pandas.Series.pad PR01,SA01" \ -i "pandas.Series.sparse.from_coo PR07,SA01" \ - -i "pandas.Series.sparse.npoints SA01" \ - -i "pandas.Series.sparse.sp_values SA01" \ - -i "pandas.Series.dt.freq GL08" \ - -i "pandas.Series.dt.unit GL08" \ -i "pandas.Timedelta.max PR02" \ -i "pandas.Timedelta.min PR02" \ -i "pandas.Timedelta.resolution PR02" \ @@ -392,4 +368,4 @@ if [[ -z "$CHECK" || "$CHECK" == "single-docs" ]]; then python doc/make.py --warnings-are-errors --no-browser --single pandas.Series.str.split fi -exit $RET +exit $RET \ No newline at end of file From 23a58c2c051a82421b0c1e409eb774098abf1d7f Mon Sep 17 00:00:00 2001 From: saldanhad Date: Tue, 1 Oct 2024 20:23:46 +0530 Subject: [PATCH 13/17] update --- ci/code_checks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index ce1760de94498..1501b09106973 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -368,4 +368,4 @@ if [[ -z "$CHECK" || "$CHECK" == "single-docs" ]]; then python doc/make.py --warnings-are-errors --no-browser --single pandas.Series.str.split fi -exit $RET \ No newline at end of file +exit $RET From c9f6094c8d8fb7188fa57c651f0ec803db9edcad Mon Sep 17 00:00:00 2001 From: saldanhad Date: Sun, 6 Oct 2024 00:45:34 +0530 Subject: [PATCH 14/17] revert all dt related changes --- doc/source/reference/series.rst | 1 - doc/source/whatsnew/v3.0.0.rst | 1 - pandas/core/arrays/categorical.py | 4 +- pandas/core/arrays/datetimes.py | 45 ------------------- .../series/accessors/test_cat_accessor.py | 2 +- .../series/accessors/test_dt_accessor.py | 1 - 6 files changed, 3 insertions(+), 51 deletions(-) diff --git a/doc/source/reference/series.rst b/doc/source/reference/series.rst index cf90969d0f82b..950c8230e35ad 100644 --- a/doc/source/reference/series.rst +++ b/doc/source/reference/series.rst @@ -49,7 +49,6 @@ Conversion Series.copy Series.to_numpy Series.to_period - Series.to_timestamp Series.to_list Series.__array__ diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index db2c8d6ddecb0..41ba80989a0ce 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -58,7 +58,6 @@ Other enhancements - :meth:`pandas.concat` will raise a ``ValueError`` when ``ignore_index=True`` and ``keys`` is not ``None`` (:issue:`59274`) - :meth:`str.get_dummies` now accepts a ``dtype`` parameter to specify the dtype of the resulting DataFrame (:issue:`47872`) - Multiplying two :class:`DateOffset` objects will now raise a ``TypeError`` instead of a ``RecursionError`` (:issue:`59442`) -- Refactored :meth:`_create_delegator_method` under core/accessor.py using ``functools``, improving code clarity and maintainability. (:issue:`59783`) - Restore support for reading Stata 104-format and enable reading 103-format dta files (:issue:`58554`) - Support passing a :class:`Iterable[Hashable]` input to :meth:`DataFrame.drop_duplicates` (:issue:`59237`) - Support reading Stata 102-format (Stata 1) dta files (:issue:`58978`) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index b29581fce217f..0484ef89f61c2 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -1377,8 +1377,8 @@ def remove_categories(self, removals) -> Self: """ Remove the specified categories. - ``removals`` must be included in the old categories, - values which were in the removed categories will be set to NaN + The ``removals`` argument must be a subset of the current categories. + Any values that were part of the removed categories will be set to NaN. Parameters ---------- diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index c0279807d424b..43f4428118aa7 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -261,7 +261,6 @@ def _scalar_type(self) -> type[Timestamp]: ) _datetimelike_methods: list[str] = [ "to_period", - "to_timestamp", "tz_localize", "tz_convert", "normalize", @@ -1268,50 +1267,6 @@ def to_period(self, freq=None) -> PeriodArray: freq = res return PeriodArray._from_datetime64(self._ndarray, freq, tz=self.tz) - def to_timestamp(self): - """ - Convert ``Series`` of ``Periods`` to ``DatetimeIndex/Array``. - - This method converts a Series of Periods to a ``DatetimeIndex/Array``. - The ``freq`` and ``how`` parameters cannot be used when calling - ``to_timestamp`` the ``.dt`` accessor. - - Returns - ------- - DatetimeArray/Index - A `DatetimeArray` or `DatetimeIndex` object representing the period - converted to a timestamp. - - See Also - -------- - PeriodIndex.day : The days of the period. - PeriodIndex.from_fields : Construct a PeriodIndex from fields - (year, month, day, etc.). - PeriodIndex.from_ordinals : Construct a PeriodIndex from ordinals. - PeriodIndex.hour : The hour of the period. - PeriodIndex.minute : The minute of the period. - PeriodIndex.month : The month as January=1, December=12. - PeriodIndex.second : The second of the period. - PeriodIndex.year : The year of the period. - - Examples - -------- - >>> s = pd.Series(pd.period_range("2023-01", periods=3, freq="M")) - >>> s - 0 2023-01 - 1 2023-02 - 2 2023-03 - dtype: period[M] - >>> s.dt.to_timestamp() - 0 2023-01-01 - 1 2023-02-01 - 2 2023-03-01 - dtype: datetime64[ns] - """ - # Uses to_timestamp method defined in PeriodArray Class() - # function here only used to update docstring - return - # ----------------------------------------------------------------- # Properties - Vectorized Timestamp Properties/Methods diff --git a/pandas/tests/series/accessors/test_cat_accessor.py b/pandas/tests/series/accessors/test_cat_accessor.py index edb476c22fe02..ce8ea27ea1fa2 100644 --- a/pandas/tests/series/accessors/test_cat_accessor.py +++ b/pandas/tests/series/accessors/test_cat_accessor.py @@ -177,7 +177,7 @@ def test_dt_accessor_api_for_categorical(self, idx): _special_func_names = [f[0] for f in special_func_defs] - _ignore_names = ["components", "to_timestamp", "tz_localize", "tz_convert"] + _ignore_names = ["components", "tz_localize", "tz_convert"] func_names = [ fname diff --git a/pandas/tests/series/accessors/test_dt_accessor.py b/pandas/tests/series/accessors/test_dt_accessor.py index 601a691abf28a..885adb3543b46 100644 --- a/pandas/tests/series/accessors/test_dt_accessor.py +++ b/pandas/tests/series/accessors/test_dt_accessor.py @@ -45,7 +45,6 @@ ok_for_dt = DatetimeArray._datetimelike_ops ok_for_dt_methods = [ "to_period", - "to_timestamp", "to_pydatetime", "tz_localize", "tz_convert", From ba44d879d7e2fe66189a996b81cd9a9c572bd0d6 Mon Sep 17 00:00:00 2001 From: saldanhad Date: Sun, 6 Oct 2024 00:56:08 +0530 Subject: [PATCH 15/17] update series.rst --- doc/source/reference/series.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/reference/series.rst b/doc/source/reference/series.rst index 950c8230e35ad..43d7480899dc4 100644 --- a/doc/source/reference/series.rst +++ b/doc/source/reference/series.rst @@ -49,6 +49,7 @@ Conversion Series.copy Series.to_numpy Series.to_period + Series.to_timestamp Series.to_list Series.__array__ @@ -344,7 +345,6 @@ Datetime methods Series.dt.isocalendar Series.dt.to_period - Series.dt.to_timestamp Series.dt.to_pydatetime Series.dt.tz_localize Series.dt.tz_convert From c7cc6dbd6f3dd5de5e453124b8398f537b5c22c8 Mon Sep 17 00:00:00 2001 From: saldanhad Date: Sun, 6 Oct 2024 01:45:55 +0530 Subject: [PATCH 16/17] update imports --- pandas/core/accessor.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/core/accessor.py b/pandas/core/accessor.py index ef42879acaf5a..cc93c54a1ee15 100644 --- a/pandas/core/accessor.py +++ b/pandas/core/accessor.py @@ -7,6 +7,7 @@ from __future__ import annotations +import functools as ft from typing import ( TYPE_CHECKING, final, @@ -116,8 +117,6 @@ def _setter(self, new_values): doc=getattr(delegate, accessor_mapping(name)).__doc__, ) - import functools as ft - def _create_delegator_method(name: str): method = getattr(delegate, accessor_mapping(name)) From 4115e04dc82f3c2c3ad8be7a55abb9b22c15b377 Mon Sep 17 00:00:00 2001 From: saldanhad Date: Mon, 7 Oct 2024 01:02:48 +0530 Subject: [PATCH 17/17] format use of functools import --- pandas/core/accessor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/accessor.py b/pandas/core/accessor.py index cc93c54a1ee15..78684eacf2d66 100644 --- a/pandas/core/accessor.py +++ b/pandas/core/accessor.py @@ -7,7 +7,7 @@ from __future__ import annotations -import functools as ft +import functools from typing import ( TYPE_CHECKING, final, @@ -120,7 +120,7 @@ def _setter(self, new_values): def _create_delegator_method(name: str): method = getattr(delegate, accessor_mapping(name)) - @ft.wraps(method) + @functools.wraps(method) def f(self, *args, **kwargs): return self._delegate_method(name, *args, **kwargs)