From f87f4e381be17408b6c5ba0c6a7abee6861abc0a Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 20 May 2022 23:59:57 -0400 Subject: [PATCH] DOC: Fix assorted doc warnings --- doc/source/conf.py | 7 +++++-- pandas/core/arrays/sparse/array.py | 16 ++++++++-------- pandas/core/generic.py | 4 ++-- pandas/core/groupby/groupby.py | 18 +++++++++--------- pandas/core/indexes/base.py | 4 ++-- 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index 184bdcfd39bf6..49025288f0449 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -9,13 +9,13 @@ # # All configuration values have a default; values that are commented out # serve to show the default. - from datetime import datetime import importlib import inspect import logging import os import sys +import warnings import jinja2 from numpydoc.docscrape import NumpyDocString @@ -640,7 +640,10 @@ def linkcode_resolve(domain, info): obj = submod for part in fullname.split("."): try: - obj = getattr(obj, part) + with warnings.catch_warnings(): + # Accessing deprecated objects will generate noisy warnings + warnings.simplefilter("ignore", FutureWarning) + obj = getattr(obj, part) except AttributeError: return None diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index 0e340bd7a7e97..427bf50ca7424 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -1253,7 +1253,7 @@ def astype(self, dtype: AstypeArg | None = None, copy: bool = True): IntIndex Indices: array([2, 3], dtype=int32) - >>> arr.astype(np.dtype('int32')) + >>> arr.astype(SparseDtype(np.dtype('int32'))) [0, 0, 1, 2] Fill: 0 IntIndex @@ -1262,19 +1262,19 @@ def astype(self, dtype: AstypeArg | None = None, copy: bool = True): Using a NumPy dtype with a different kind (e.g. float) will coerce just ``self.sp_values``. - >>> arr.astype(np.dtype('float64')) + >>> arr.astype(SparseDtype(np.dtype('float64'))) ... # doctest: +NORMALIZE_WHITESPACE - [0.0, 0.0, 1.0, 2.0] - Fill: 0.0 + [nan, nan, 1.0, 2.0] + Fill: nan IntIndex Indices: array([2, 3], dtype=int32) - Use a SparseDtype if you wish to be change the fill value as well. + Using a SparseDtype, you can also change the fill value as well. - >>> arr.astype(SparseDtype("float64", fill_value=np.nan)) + >>> arr.astype(SparseDtype("float64", fill_value=0.0)) ... # doctest: +NORMALIZE_WHITESPACE - [nan, nan, 1.0, 2.0] - Fill: nan + [0.0, 0.0, 1.0, 2.0] + Fill: 0.0 IntIndex Indices: array([2, 3], dtype=int32) """ diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 24c3bcb7bf669..33e0b3e62b817 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8109,9 +8109,9 @@ def resample( Freq: 30S, dtype: float64 Upsample the series into 30 second bins and fill the ``NaN`` - values using the ``pad`` method. + values using the ``ffill`` method. - >>> series.resample('30S').pad()[0:5] + >>> series.resample('30S').ffill()[0:5] 2000-01-01 00:00:00 0 2000-01-01 00:00:30 0 2000-01-01 00:01:00 1 diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index f7c89b6e7dc49..33bda0cf2a22f 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -415,7 +415,7 @@ class providing the base-class of operations. ... 'two', 'two'], ... 'C' : [1, 5, 5, 2, 5, 5], ... 'D' : [2.0, 5., 8., 1., 2., 9.]}) ->>> grouped = df.groupby('A') +>>> grouped = df.groupby('A')[['C', 'D']] >>> grouped.transform(lambda x: (x - x.mean()) / x.std()) C D 0 -1.154701 -0.577350 @@ -428,20 +428,20 @@ class providing the base-class of operations. Broadcast result of the transformation >>> grouped.transform(lambda x: x.max() - x.min()) - C D -0 4 6.0 -1 3 8.0 -2 4 6.0 -3 3 8.0 -4 4 6.0 -5 3 8.0 + C D +0 4.0 6.0 +1 3.0 8.0 +2 4.0 6.0 +3 3.0 8.0 +4 4.0 6.0 +5 3.0 8.0 .. versionchanged:: 1.3.0 The resulting dtype will reflect the return value of the passed ``func``, for example: ->>> grouped[['C', 'D']].transform(lambda x: x.astype(int).max()) +>>> grouped.transform(lambda x: x.astype(int).max()) C D 0 5 8 1 5 9 diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index c4a3afbb282cf..8d8b413b53792 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -5514,10 +5514,10 @@ def equals(self, other: Any) -> bool: The dtype is *not* compared - >>> int64_idx = pd.Int64Index([1, 2, 3]) + >>> int64_idx = pd.Index([1, 2, 3], dtype='int64') >>> int64_idx Int64Index([1, 2, 3], dtype='int64') - >>> uint64_idx = pd.UInt64Index([1, 2, 3]) + >>> uint64_idx = pd.Index([1, 2, 3], dtype='uint64') >>> uint64_idx UInt64Index([1, 2, 3], dtype='uint64') >>> int64_idx.equals(uint64_idx)