From 45c7a172c87d6b6d0b98a59e52590a90e0f66b85 Mon Sep 17 00:00:00 2001 From: Dea Leon Date: Tue, 14 Feb 2023 17:45:13 +0100 Subject: [PATCH 1/2] DOC Fix EX01 issues in docstrings --- ci/code_checks.sh | 3 --- pandas/core/series.py | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 567ae6da92ae2..ae452a8c07ac8 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -86,14 +86,11 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then MSG='Partially validate docstrings (EX01)' ; echo $MSG $BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01 --ignore_functions \ pandas.Series.index \ - pandas.Series.dtype \ pandas.Series.nbytes \ pandas.Series.ndim \ pandas.Series.size \ pandas.Series.T \ pandas.Series.hasnans \ - pandas.Series.dtypes \ - pandas.Series.to_period \ pandas.Series.to_timestamp \ pandas.Series.to_list \ pandas.Series.__iter__ \ diff --git a/pandas/core/series.py b/pandas/core/series.py index c8b431abd1958..f1fa137f77be5 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -581,6 +581,12 @@ def _can_hold_na(self) -> bool: def dtype(self) -> DtypeObj: """ Return the dtype object of the underlying data. + + Examples + -------- + >>> s = pd.Series([1, 2, 3]) + >>> s.dtype + dtype('int64') """ return self._mgr.dtype @@ -588,6 +594,12 @@ def dtype(self) -> DtypeObj: def dtypes(self) -> DtypeObj: """ Return the dtype object of the underlying data. + + Examples + -------- + >>> s = pd.Series([1, 2, 3]) + >>> s.dtypes + dtype('int64') """ # DataFrame compatibility return self.dtype @@ -5723,6 +5735,17 @@ def to_period(self, freq: str | None = None, copy: bool | None = None) -> Series ------- Series Series with index converted to PeriodIndex. + + Examples + -------- + >>> idx = pd.DatetimeIndex(['2015-01-01', '2015-01-02', '2015-01-03']) + >>> idx = idx.to_period() + >>> s = pd.Series([1, 2, 3], index=idx) + >>> s + 2015-01-01 1 + 2015-01-02 2 + 2015-01-03 3 + Freq: D, dtype: int64 """ if not isinstance(self.index, DatetimeIndex): raise TypeError(f"unsupported Type {type(self.index).__name__}") From 03a9b2da52facd272511532c0e40d1861b2de83f Mon Sep 17 00:00:00 2001 From: Dea Leon Date: Wed, 15 Feb 2023 11:37:40 +0100 Subject: [PATCH 2/2] DOC Fix EX01 errors in docstrings --- pandas/core/series.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index adae2f1506e25..e4c7c4d3b3d73 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -5737,14 +5737,19 @@ def to_period(self, freq: str | None = None, copy: bool | None = None) -> Series Examples -------- - >>> idx = pd.DatetimeIndex(['2015-01-01', '2015-01-02', '2015-01-03']) - >>> idx = idx.to_period() + >>> idx = pd.DatetimeIndex(['2023', '2024', '2025']) >>> s = pd.Series([1, 2, 3], index=idx) + >>> s = s.to_period() >>> s - 2015-01-01 1 - 2015-01-02 2 - 2015-01-03 3 - Freq: D, dtype: int64 + 2023 1 + 2024 2 + 2025 3 + Freq: A-DEC, dtype: int64 + + Viewing the index + + >>> s.index + PeriodIndex(['2023', '2024', '2025'], dtype='period[A-DEC]') """ if not isinstance(self.index, DatetimeIndex): raise TypeError(f"unsupported Type {type(self.index).__name__}")