From 78bd864f1c887ab7d15dd4526833a64624c1c8da Mon Sep 17 00:00:00 2001 From: arthurlw Date: Sun, 20 Jul 2025 00:47:28 +0700 Subject: [PATCH 1/2] Fix doctest errors related to new string repr, as well as other misc doctests (asof and squeeze) --- pandas/core/generic.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 6424589843d76..1db204ddd73a0 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -885,7 +885,7 @@ def squeeze(self, axis: Axis | None = None) -> Scalar | Series | DataFrame: dtype: int64 >>> even_primes.squeeze() - np.int64(2) + 2 Squeezing objects with more than one value in every axis does nothing: @@ -943,7 +943,7 @@ def squeeze(self, axis: Axis | None = None) -> Scalar | Series | DataFrame: Squeezing all axes will project directly into a scalar: >>> df_0a.squeeze() - np.int64(1) + 1 """ axes = range(self._AXIS_LEN) if axis is None else (self._get_axis_number(axis),) result = self.iloc[ @@ -1918,7 +1918,7 @@ def keys(self) -> Index: b 2 4 c 3 8 >>> d.keys() - Index(['A', 'B'], dtype='object') + Index(['A', 'B'], dtype='str') """ return self._info_axis @@ -6276,7 +6276,7 @@ def dtypes(self): float float64 int int64 datetime datetime64[s] - string object + string str dtype: object """ data = self._mgr.get_dtypes() @@ -6838,7 +6838,7 @@ def convert_dtypes( 0 a 1 b 2 NaN - dtype: object + dtype: str Obtain a Series with dtype ``StringDtype``. @@ -7968,7 +7968,7 @@ def asof(self, where, subset=None): dtype: float64 >>> s.asof(20) - np.float64(2.0) + 2.0 For a sequence `where`, a Series is returned. The first value is NaN, because the first element of `where` is before the first @@ -7983,7 +7983,7 @@ def asof(self, where, subset=None): NaN, even though NaN is at the index location for ``30``. >>> s.asof(30) - np.float64(2.0) + 2.0 Take all columns into consideration @@ -8138,7 +8138,7 @@ def isna(self) -> Self: ... ) >>> df age born name toy - 0 5.0 NaT Alfred None + 0 5.0 NaT Alfred NaN 1 6.0 1939-05-27 Batman Batmobile 2 NaN 1940-04-25 Joker @@ -8211,7 +8211,7 @@ def notna(self) -> Self: ... ) >>> df age born name toy - 0 5.0 NaT Alfred None + 0 5.0 NaT Alfred NaN 1 6.0 1939-05-27 Batman Batmobile 2 NaN 1940-04-25 Joker @@ -10401,7 +10401,7 @@ def truncate( 2 b 3 c 4 d - Name: A, dtype: object + Name: A, dtype: str The index values in ``truncate`` can be datetimes or string dates. @@ -11804,7 +11804,7 @@ def first_valid_index(self) -> Hashable: >>> print(df.last_valid_index()) None - If all elements in DataFrame are NA/null, returns None. + If all elements in DataFrame are NA/null, returns NaN. >>> df = pd.DataFrame() >>> df From 22611ad133743688d4a96182f4708493f9e11806 Mon Sep 17 00:00:00 2001 From: arthurlw Date: Sun, 20 Jul 2025 22:25:56 +0700 Subject: [PATCH 2/2] Revert asof and squeeze docstring changes --- pandas/core/generic.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 1db204ddd73a0..f7143fa32d2c9 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -885,7 +885,7 @@ def squeeze(self, axis: Axis | None = None) -> Scalar | Series | DataFrame: dtype: int64 >>> even_primes.squeeze() - 2 + np.int64(2) Squeezing objects with more than one value in every axis does nothing: @@ -943,7 +943,7 @@ def squeeze(self, axis: Axis | None = None) -> Scalar | Series | DataFrame: Squeezing all axes will project directly into a scalar: >>> df_0a.squeeze() - 1 + np.int64(1) """ axes = range(self._AXIS_LEN) if axis is None else (self._get_axis_number(axis),) result = self.iloc[ @@ -7968,7 +7968,7 @@ def asof(self, where, subset=None): dtype: float64 >>> s.asof(20) - 2.0 + np.float64(2.0) For a sequence `where`, a Series is returned. The first value is NaN, because the first element of `where` is before the first @@ -7983,7 +7983,7 @@ def asof(self, where, subset=None): NaN, even though NaN is at the index location for ``30``. >>> s.asof(30) - 2.0 + np.float64(2.0) Take all columns into consideration