Skip to content

Commit acf5f2f

Browse files
committed
CLN: Remove sparse
1 parent 6908be7 commit acf5f2f

34 files changed

+47
-7757
lines changed

pandas/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@
116116

117117
from pandas.core.sparse.api import (
118118
SparseArray,
119-
SparseDataFrame,
120-
SparseSeries,
121119
SparseDtype,
122120
)
123121

pandas/core/arrays/sparse.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
ABCIndexClass,
4444
ABCSeries,
4545
ABCSparseArray,
46-
ABCSparseSeries,
4746
)
4847
from pandas.core.dtypes.missing import isna, na_value_for_dtype, notna
4948

@@ -607,7 +606,7 @@ def __init__(
607606
if fill_value is None and isinstance(dtype, SparseDtype):
608607
fill_value = dtype.fill_value
609608

610-
if isinstance(data, (type(self), ABCSparseSeries)):
609+
if isinstance(data, type(self)):
611610
# disable normal inference on dtype, sparse_index, & fill_value
612611
if sparse_index is None:
613612
sparse_index = data.sp_index
@@ -1982,7 +1981,8 @@ def from_coo(cls, A, dense_index=False):
19821981
19831982
Returns
19841983
-------
1985-
s : SparseSeries
1984+
s : Series
1985+
A Series with sparse values.
19861986
19871987
Examples
19881988
--------
@@ -1996,7 +1996,7 @@ def from_coo(cls, A, dense_index=False):
19961996
matrix([[ 0., 0., 1., 2.],
19971997
[ 3., 0., 0., 0.],
19981998
[ 0., 0., 0., 0.]])
1999-
>>> ss = pd.SparseSeries.from_coo(A)
1999+
>>> ss = pd.Series.sparse.from_coo(A)
20002000
>>> ss
20012001
0 2 1
20022002
3 2
@@ -2016,7 +2016,7 @@ def from_coo(cls, A, dense_index=False):
20162016

20172017
def to_coo(self, row_levels=(0,), column_levels=(1,), sort_labels=False):
20182018
"""
2019-
Create a scipy.sparse.coo_matrix from a SparseSeries with MultiIndex.
2019+
Create a scipy.sparse.coo_matrix from a Series with MultiIndex.
20202020
20212021
Use row_levels and column_levels to determine the row and column
20222022
coordinates respectively. row_levels and column_levels are the names

pandas/core/dtypes/generic.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,7 @@ def _check(cls, inst):
5252

5353
ABCSeries = create_pandas_abc_type("ABCSeries", "_typ", ("series",))
5454
ABCDataFrame = create_pandas_abc_type("ABCDataFrame", "_typ", ("dataframe",))
55-
ABCSparseDataFrame = create_pandas_abc_type(
56-
"ABCSparseDataFrame", "_subtyp", ("sparse_frame",)
57-
)
58-
ABCSparseSeries = create_pandas_abc_type(
59-
"ABCSparseSeries", "_subtyp", ("sparse_series", "sparse_time_series")
60-
)
55+
6156
ABCSparseArray = create_pandas_abc_type(
6257
"ABCSparseArray", "_subtyp", ("sparse_array", "sparse_series")
6358
)

pandas/core/groupby/generic.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
import pandas.core.indexes.base as ibase
5959
from pandas.core.internals import BlockManager, make_block
6060
from pandas.core.series import Series
61-
from pandas.core.sparse.frame import SparseDataFrame
6261

6362
from pandas.plotting import boxplot_frame_groupby
6463

@@ -258,12 +257,6 @@ def aggregate(self, func, *args, **kwargs):
258257
result.columns.levels[0], name=self._selected_obj.columns.name
259258
)
260259

261-
if isinstance(self.obj, SparseDataFrame):
262-
# Backwards compat for groupby.agg() with sparse
263-
# values. concat no longer converts DataFrame[Sparse]
264-
# to SparseDataFrame, so we do it here.
265-
result = SparseDataFrame(result._data)
266-
267260
if not self.as_index:
268261
self._insert_inaxis_grouper_inplace(result)
269262
result.index = np.arange(len(result))

pandas/core/ops/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
ABCExtensionArray,
3333
ABCIndexClass,
3434
ABCSeries,
35-
ABCSparseSeries,
3635
ABCTimedeltaArray,
3736
ABCTimedeltaIndex,
3837
)
@@ -1151,8 +1150,6 @@ def wrapper(self, other):
11511150
if isinstance(other, ABCDataFrame):
11521151
return NotImplemented
11531152
elif isinstance(other, ABCSeries):
1154-
if not isinstance(other, ABCSparseSeries):
1155-
other = other.to_sparse(fill_value=self.fill_value)
11561153
return _sparse_series_op(self, other, op, op_name)
11571154
elif is_scalar(other):
11581155
with np.errstate(all="ignore"):

pandas/core/ops/methods.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
"""
44
import operator
55

6-
from pandas.core.dtypes.generic import (
7-
ABCDataFrame,
8-
ABCSeries,
9-
ABCSparseArray,
10-
ABCSparseSeries,
11-
)
6+
from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries, ABCSparseArray
127

138
from pandas.core.ops.roperator import (
149
radd,
@@ -51,25 +46,15 @@ def _get_method_wrappers(cls):
5146
from pandas.core.ops import (
5247
_arith_method_FRAME,
5348
_arith_method_SERIES,
54-
_arith_method_SPARSE_SERIES,
5549
_bool_method_SERIES,
5650
_comp_method_FRAME,
5751
_comp_method_SERIES,
5852
_flex_comp_method_FRAME,
5953
_flex_method_SERIES,
6054
)
6155

62-
if issubclass(cls, ABCSparseSeries):
63-
# Be sure to catch this before ABCSeries and ABCSparseArray,
64-
# as they will both come see SparseSeries as a subclass
65-
arith_flex = _flex_method_SERIES
66-
comp_flex = _flex_method_SERIES
67-
arith_special = _arith_method_SPARSE_SERIES
68-
comp_special = _arith_method_SPARSE_SERIES
69-
bool_special = _bool_method_SERIES
70-
# TODO: I don't think the functions defined by bool_method are tested
71-
elif issubclass(cls, ABCSeries):
72-
# Just Series; SparseSeries is caught above
56+
if issubclass(cls, ABCSeries):
57+
# Just Series
7358
arith_flex = _flex_method_SERIES
7459
comp_flex = _flex_method_SERIES
7560
arith_special = _arith_method_SERIES
@@ -176,7 +161,7 @@ def _create_methods(cls, arith_method, comp_method, bool_method, special):
176161
# constructors.
177162

178163
have_divmod = issubclass(cls, ABCSeries)
179-
# divmod is available for Series and SparseSeries
164+
# divmod is available for Series
180165

181166
# yapf: disable
182167
new_methods = dict(

pandas/core/reshape/concat.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
import numpy as np
88

9-
from pandas.core.dtypes.generic import ABCSparseDataFrame
10-
119
from pandas import DataFrame, Index, MultiIndex, Series
1210
from pandas.core import common as com
1311
from pandas.core.arrays.categorical import (
@@ -715,15 +713,11 @@ def _get_series_result_type(result, objs=None):
715713
return appropriate class of Series concat
716714
input is either dict or array-like
717715
"""
718-
from pandas import SparseSeries, SparseDataFrame, DataFrame
716+
from pandas import DataFrame
719717

720718
# concat Series with axis 1
721719
if isinstance(result, dict):
722-
# concat Series with axis 1
723-
if all(isinstance(c, (SparseSeries, SparseDataFrame)) for c in result.values()):
724-
return SparseDataFrame
725-
else:
726-
return DataFrame
720+
return DataFrame
727721

728722
# otherwise it is a SingleBlockManager (axis = 0)
729723
return objs[0]._constructor
@@ -735,10 +729,4 @@ def _get_frame_result_type(result, objs):
735729
if all blocks are sparse, return SparseDataFrame
736730
otherwise, return 1st obj
737731
"""
738-
739-
if result.blocks and (any(isinstance(obj, ABCSparseDataFrame) for obj in objs)):
740-
from pandas.core.sparse.api import SparseDataFrame
741-
742-
return SparseDataFrame
743-
else:
744-
return next(obj for obj in objs if not isinstance(obj, ABCSparseDataFrame))
732+
return objs[0]

pandas/core/series.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
ABCDatetimeIndex,
4545
ABCSeries,
4646
ABCSparseArray,
47-
ABCSparseSeries,
4847
)
4948
from pandas.core.dtypes.missing import (
5049
isna,
@@ -246,7 +245,7 @@ def __init__(
246245

247246
elif isinstance(data, np.ndarray):
248247
pass
249-
elif isinstance(data, (ABCSeries, ABCSparseSeries)):
248+
elif isinstance(data, ABCSeries):
250249
if name is None:
251250
name = data.name
252251
if index is None:

pandas/core/sparse/api.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# flake8: noqa
21
from pandas.core.arrays.sparse import SparseArray, SparseDtype
3-
from pandas.core.sparse.frame import SparseDataFrame
4-
from pandas.core.sparse.series import SparseSeries
2+
3+
__all__ = ["SparseArray", "SparseDtype"]

0 commit comments

Comments
 (0)