From 0a1502093b6c334628f44cd38b9def5faad6094b Mon Sep 17 00:00:00 2001 From: gboeker Date: Thu, 18 Apr 2024 17:55:48 -0400 Subject: [PATCH 1/8] fix docstring error for sparse method --- ci/code_checks.sh | 2 +- pandas/core/arrays/sparse/accessor.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 66f6bfd7195f9..ab07983a8dd1d 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -108,7 +108,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.DataFrame.reorder_levels SA01" \ -i "pandas.DataFrame.sem PR01,RT03,SA01" \ -i "pandas.DataFrame.skew RT03,SA01" \ - -i "pandas.DataFrame.sparse PR01,SA01" \ + -i "pandas.DataFrame.sparse PR01" \ -i "pandas.DataFrame.sparse.density SA01" \ -i "pandas.DataFrame.sparse.from_spmatrix SA01" \ -i "pandas.DataFrame.sparse.to_coo SA01" \ diff --git a/pandas/core/arrays/sparse/accessor.py b/pandas/core/arrays/sparse/accessor.py index 58199701647d1..908c613f31af4 100644 --- a/pandas/core/arrays/sparse/accessor.py +++ b/pandas/core/arrays/sparse/accessor.py @@ -243,6 +243,10 @@ class SparseFrameAccessor(BaseAccessor, PandasDelegate): """ DataFrame accessor for sparse data. + See Also + -------- + DataFrame.sparse.density : Ratio of non-sparse points to total (dense) data points. + Examples -------- >>> df = pd.DataFrame({"a": [1, 2, 0, 0], "b": [3, 0, 0, 4]}, dtype="Sparse[int]") From 6b8bbe8488d79e5caa9a1c243f405a3e81daf99c Mon Sep 17 00:00:00 2001 From: gboeker Date: Thu, 18 Apr 2024 18:05:50 -0400 Subject: [PATCH 2/8] fix line too long --- ci/code_checks.sh | 1 - pandas/core/arrays/sparse/accessor.py | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index ab07983a8dd1d..bfc05fb4e8fda 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -109,7 +109,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.DataFrame.sem PR01,RT03,SA01" \ -i "pandas.DataFrame.skew RT03,SA01" \ -i "pandas.DataFrame.sparse PR01" \ - -i "pandas.DataFrame.sparse.density SA01" \ -i "pandas.DataFrame.sparse.from_spmatrix SA01" \ -i "pandas.DataFrame.sparse.to_coo SA01" \ -i "pandas.DataFrame.sparse.to_dense SA01" \ diff --git a/pandas/core/arrays/sparse/accessor.py b/pandas/core/arrays/sparse/accessor.py index 908c613f31af4..0b6a43914e820 100644 --- a/pandas/core/arrays/sparse/accessor.py +++ b/pandas/core/arrays/sparse/accessor.py @@ -392,6 +392,11 @@ def density(self) -> float: """ Ratio of non-sparse points to total (dense) data points. + See Also + -------- + DataFrame.sparse.from_spmatrix : Create a new DataFrame from a + scipy sparse matrix. + Examples -------- >>> df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 1, 0, 1])}) From 95d72b4fac7bd86ae7994b26b2758052228dd8e8 Mon Sep 17 00:00:00 2001 From: gboeker Date: Sat, 20 Apr 2024 12:23:05 -0400 Subject: [PATCH 3/8] fix see also docstring error --- pandas/core/arrays/sparse/accessor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/arrays/sparse/accessor.py b/pandas/core/arrays/sparse/accessor.py index 0b6a43914e820..5afca8d197d19 100644 --- a/pandas/core/arrays/sparse/accessor.py +++ b/pandas/core/arrays/sparse/accessor.py @@ -395,7 +395,7 @@ def density(self) -> float: See Also -------- DataFrame.sparse.from_spmatrix : Create a new DataFrame from a - scipy sparse matrix. + scipy sparse matrix. Examples -------- From b82699ca19733cea31e1c69c64b7a25f63dadfd9 Mon Sep 17 00:00:00 2001 From: gboeker Date: Sat, 20 Apr 2024 12:32:22 -0400 Subject: [PATCH 4/8] fix line too long --- ci/code_checks.sh | 2 -- pandas/core/arrays/sparse/accessor.py | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index bfc05fb4e8fda..f44477d06b657 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -109,8 +109,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.DataFrame.sem PR01,RT03,SA01" \ -i "pandas.DataFrame.skew RT03,SA01" \ -i "pandas.DataFrame.sparse PR01" \ - -i "pandas.DataFrame.sparse.from_spmatrix SA01" \ - -i "pandas.DataFrame.sparse.to_coo SA01" \ -i "pandas.DataFrame.sparse.to_dense SA01" \ -i "pandas.DataFrame.std PR01,RT03,SA01" \ -i "pandas.DataFrame.sum RT03" \ diff --git a/pandas/core/arrays/sparse/accessor.py b/pandas/core/arrays/sparse/accessor.py index 5afca8d197d19..1b358b42500e0 100644 --- a/pandas/core/arrays/sparse/accessor.py +++ b/pandas/core/arrays/sparse/accessor.py @@ -278,6 +278,11 @@ def from_spmatrix(cls, data, index=None, columns=None) -> DataFrame: Each column of the DataFrame is stored as a :class:`arrays.SparseArray`. + See Also + -------- + DataFrame.sparse.to_coo : Return the contents of the frame as a + sparse SciPy COO matrix. + Examples -------- >>> import scipy.sparse From 5afb82dfb15e93bd73e9889258cc65ea2852c376 Mon Sep 17 00:00:00 2001 From: gboeker Date: Sat, 20 Apr 2024 12:39:52 -0400 Subject: [PATCH 5/8] fix sparse.to_dense docstring errors --- ci/code_checks.sh | 1 - pandas/core/arrays/sparse/accessor.py | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index f44477d06b657..d9d603f73f2dd 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -109,7 +109,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.DataFrame.sem PR01,RT03,SA01" \ -i "pandas.DataFrame.skew RT03,SA01" \ -i "pandas.DataFrame.sparse PR01" \ - -i "pandas.DataFrame.sparse.to_dense SA01" \ -i "pandas.DataFrame.std PR01,RT03,SA01" \ -i "pandas.DataFrame.sum RT03" \ -i "pandas.DataFrame.swaplevel SA01" \ diff --git a/pandas/core/arrays/sparse/accessor.py b/pandas/core/arrays/sparse/accessor.py index 1b358b42500e0..b3eab07724ec5 100644 --- a/pandas/core/arrays/sparse/accessor.py +++ b/pandas/core/arrays/sparse/accessor.py @@ -328,6 +328,12 @@ def to_dense(self) -> DataFrame: DataFrame A DataFrame with the same values stored as dense arrays. + See Also + -------- + DataFrame.sparse.density : Ratio of non-sparse points to total + (dense) data points. + + Examples -------- >>> df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 1, 0])}) From ded7a630f548cd1341af71634ee4e6c6955f85a7 Mon Sep 17 00:00:00 2001 From: gboeker Date: Sat, 20 Apr 2024 13:15:41 -0400 Subject: [PATCH 6/8] delete empty line --- pandas/core/arrays/sparse/accessor.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/arrays/sparse/accessor.py b/pandas/core/arrays/sparse/accessor.py index b3eab07724ec5..2c304ecad23c1 100644 --- a/pandas/core/arrays/sparse/accessor.py +++ b/pandas/core/arrays/sparse/accessor.py @@ -333,7 +333,6 @@ def to_dense(self) -> DataFrame: DataFrame.sparse.density : Ratio of non-sparse points to total (dense) data points. - Examples -------- >>> df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 1, 0])}) From 30bedf07f49cb2301bdcb38b673888c6d27d805c Mon Sep 17 00:00:00 2001 From: gboeker Date: Sat, 20 Apr 2024 13:18:20 -0400 Subject: [PATCH 7/8] add see also for sparse.to_coo --- pandas/core/arrays/sparse/accessor.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/core/arrays/sparse/accessor.py b/pandas/core/arrays/sparse/accessor.py index 2c304ecad23c1..39ef3b9fd6961 100644 --- a/pandas/core/arrays/sparse/accessor.py +++ b/pandas/core/arrays/sparse/accessor.py @@ -367,6 +367,10 @@ def to_coo(self) -> spmatrix: float32. By numpy.find_common_type convention, mixing int64 and and uint64 will result in a float64 dtype. + See Also + -------- + DataFrame.sparse.to_dense : Convert a DataFrame with sparse values to dense. + Examples -------- >>> df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 1, 0, 1])}) From 5a7f776cd0c0bd0b725b62c92a59fa7c42650e21 Mon Sep 17 00:00:00 2001 From: gboeker Date: Sat, 20 Apr 2024 13:48:33 -0400 Subject: [PATCH 8/8] correct order --- pandas/core/arrays/sparse/accessor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/arrays/sparse/accessor.py b/pandas/core/arrays/sparse/accessor.py index 39ef3b9fd6961..1f82285e3e40e 100644 --- a/pandas/core/arrays/sparse/accessor.py +++ b/pandas/core/arrays/sparse/accessor.py @@ -357,6 +357,10 @@ def to_coo(self) -> spmatrix: If the caller is heterogeneous and contains booleans or objects, the result will be of dtype=object. See Notes. + See Also + -------- + DataFrame.sparse.to_dense : Convert a DataFrame with sparse values to dense. + Notes ----- The dtype will be the lowest-common-denominator type (implicit @@ -367,10 +371,6 @@ def to_coo(self) -> spmatrix: float32. By numpy.find_common_type convention, mixing int64 and and uint64 will result in a float64 dtype. - See Also - -------- - DataFrame.sparse.to_dense : Convert a DataFrame with sparse values to dense. - Examples -------- >>> df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 1, 0, 1])})