From 5af245d7f7795750afb2c36de3f80b1e86d43a87 Mon Sep 17 00:00:00 2001 From: Tuhin Sharma Date: Thu, 26 Sep 2024 10:40:33 +0530 Subject: [PATCH 1/2] DOC: fix SA01, ES01 for pandas.Series.sparse.npoints --- ci/code_checks.sh | 1 - pandas/core/arrays/sparse/array.py | 12 ++++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index f662b4781e84b..149c5c0326733 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -97,7 +97,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -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.Timedelta.max PR02" \ -i "pandas.Timedelta.min PR02" \ -i "pandas.Timedelta.resolution PR02" \ diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index c8ec4068ca199..2b312dd543cd5 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -708,6 +708,18 @@ def npoints(self) -> int: """ The number of non- ``fill_value`` points. + This property returns the number of elements in the sparse series that are + not equal to the ``fill_value``. Sparse data structures store only the + non-``fill_value`` elements, reducing memory usage when the majority of + values are the same. + + See Also + -------- + Series.sparse.to_dense : Convert a Series from sparse values to dense. + Series.sparse.fill_value : Elements in `data` that are `fill_value` are + not stored. + Series.sparse.density : The percent of non- ``fill_value`` points, as decimal. + Examples -------- >>> from pandas.arrays import SparseArray From 52ac5411945ff653143eef3cee131ac9f5b316a4 Mon Sep 17 00:00:00 2001 From: Tuhin Sharma Date: Thu, 26 Sep 2024 22:24:43 +0530 Subject: [PATCH 2/2] Update pandas/core/arrays/sparse/array.py --- pandas/core/arrays/sparse/array.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index 2b312dd543cd5..0c76280e7fdb4 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -716,7 +716,7 @@ def npoints(self) -> int: See Also -------- Series.sparse.to_dense : Convert a Series from sparse values to dense. - Series.sparse.fill_value : Elements in `data` that are `fill_value` are + Series.sparse.fill_value : Elements in ``data`` that are ``fill_value`` are not stored. Series.sparse.density : The percent of non- ``fill_value`` points, as decimal.