diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 94644ca6049c3..28fec987efd1a 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -82,12 +82,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then $BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01 --ignore_functions \ pandas.Series.backfill \ pandas.Series.pad \ - pandas.DataFrame.sparse \ - pandas.Series.attrs \ - pandas.Series.plot \ pandas.Series.hist \ - pandas.Series.to_string \ - pandas.errors.AbstractMethodError \ pandas.errors.AccessorRegistrationWarning \ pandas.errors.AttributeConflictWarning \ pandas.errors.DataError \ diff --git a/pandas/core/arrays/sparse/accessor.py b/pandas/core/arrays/sparse/accessor.py index ede58c86aa78d..6eb1387c63a0a 100644 --- a/pandas/core/arrays/sparse/accessor.py +++ b/pandas/core/arrays/sparse/accessor.py @@ -234,6 +234,13 @@ def to_dense(self) -> Series: class SparseFrameAccessor(BaseAccessor, PandasDelegate): """ DataFrame accessor for sparse data. + + Examples + -------- + >>> df = pd.DataFrame({"a": [1, 2, 0, 0], + ... "b": [3, 0, 0, 4]}, dtype="Sparse[int]") + >>> df.sparse.density + 0.5 """ def _validate(self, data): diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 90a0444872ec7..aa7dd9006d911 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -334,6 +334,13 @@ def attrs(self) -> dict[Hashable, Any]: See Also -------- DataFrame.flags : Global flags applying to this object. + + Examples + -------- + >>> ser = pd.Series([1, 2, 3]) + >>> ser.attrs = {"A": [10, 20, 30]} + >>> ser.attrs + {'A': [10, 20, 30]} """ if self._attrs is None: self._attrs = {} diff --git a/pandas/core/series.py b/pandas/core/series.py index 41a32cb60c39f..9c7110cc21082 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1713,6 +1713,12 @@ def to_string( ------- str or None String representation of Series if ``buf=None``, otherwise None. + + Examples + -------- + >>> ser = pd.Series([1, 2, 3]).to_string() + >>> ser + '0 1\\n1 2\\n2 3' """ formatter = fmt.SeriesFormatter( self, diff --git a/pandas/errors/__init__.py b/pandas/errors/__init__.py index 1ead53d2cfc4d..438f504968b2d 100644 --- a/pandas/errors/__init__.py +++ b/pandas/errors/__init__.py @@ -193,6 +193,22 @@ class AccessorRegistrationWarning(Warning): class AbstractMethodError(NotImplementedError): """ Raise this error instead of NotImplementedError for abstract methods. + + Examples + -------- + >>> class Foo: + ... @classmethod + ... def classmethod(cls): + ... raise pd.errors.AbstractMethodError(cls, methodtype="classmethod") + ... def method(self): + ... raise pd.errors.AbstractMethodError(self) + >>> test = Foo.classmethod() + Traceback (most recent call last): + AbstractMethodError: This classmethod must be defined in the concrete class Foo + + >>> test2 = Foo().method() + Traceback (most recent call last): + AbstractMethodError: This classmethod must be defined in the concrete class Foo """ def __init__(self, class_instance, methodtype: str = "method") -> None: diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 38e1be302b054..0f9fd948b6fe5 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -775,6 +775,15 @@ class PlotAccessor(PandasObject): for bar plot layout by `position` keyword. From 0 (left/bottom-end) to 1 (right/top-end). Default is 0.5 (center) + + Examples + -------- + + .. plot:: + :context: close-figs + + >>> ser = pd.Series([1, 2, 3, 3]) + >>> plot = ser.plot(kind='hist', title="My plot") """ _common_kinds = ("line", "bar", "barh", "kde", "density", "area", "hist", "box")