Skip to content

Commit 5418dd5

Browse files
committed
round 2
1 parent acf5f2f commit 5418dd5

File tree

19 files changed

+16
-447
lines changed

19 files changed

+16
-447
lines changed

doc/source/reference/frame.rst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,3 @@ Serialization / IO / conversion
361361
DataFrame.to_string
362362
DataFrame.to_clipboard
363363
DataFrame.style
364-
365-
Sparse
366-
~~~~~~
367-
.. autosummary::
368-
:toctree: api/
369-
370-
SparseDataFrame.to_coo

doc/source/reference/series.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -581,13 +581,3 @@ Serialization / IO / conversion
581581
Series.to_string
582582
Series.to_clipboard
583583
Series.to_latex
584-
585-
586-
Sparse
587-
------
588-
589-
.. autosummary::
590-
:toctree: api/
591-
592-
SparseSeries.to_coo
593-
SparseSeries.from_coo

doc/source/user_guide/sparse.rst

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
Sparse data structures
77
**********************
88

9-
.. note::
10-
11-
``SparseSeries`` and ``SparseDataFrame`` have been deprecated. Their purpose
12-
is served equally well by a :class:`Series` or :class:`DataFrame` with
13-
sparse values. See :ref:`sparse.migration` for tips on migrating.
14-
159
Pandas provides data structures for efficiently storing sparse data.
1610
These are not necessarily sparse in the typical "mostly 0". Rather, you can view these
1711
objects as being "compressed" where any data matching a specific value (``NaN`` / missing value, though any value
@@ -168,6 +162,11 @@ the correct dense result.
168162
Migrating
169163
---------
170164

165+
.. note::
166+
167+
``SparseSeries`` and ``SparseDataFrame`` were removed in pandas 1.0.0. This migration
168+
guide is present to aid in migrating from previous versions.
169+
171170
In older versions of pandas, the ``SparseSeries`` and ``SparseDataFrame`` classes (documented below)
172171
were the preferred way to work with sparse data. With the advent of extension arrays, these subclasses
173172
are no longer needed. Their purpose is better served by using a regular Series or DataFrame with
@@ -366,12 +365,3 @@ row and columns coordinates of the matrix. Note that this will consume a signifi
366365
367366
ss_dense = pd.Series.sparse.from_coo(A, dense_index=True)
368367
ss_dense
369-
370-
371-
.. _sparse.subclasses:
372-
373-
Sparse subclasses
374-
-----------------
375-
376-
The :class:`SparseSeries` and :class:`SparseDataFrame` classes are deprecated. Visit their
377-
API pages for usage.

pandas/_typing.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@
1212
from pandas.core.dtypes.dtypes import ExtensionDtype # noqa: F401
1313
from pandas.core.indexes.base import Index # noqa: F401
1414
from pandas.core.series import Series # noqa: F401
15-
from pandas.core.sparse.series import SparseSeries # noqa: F401
1615
from pandas.core.generic import NDFrame # noqa: F401
1716

1817

19-
AnyArrayLike = TypeVar(
20-
"AnyArrayLike", "ExtensionArray", "Index", "Series", "SparseSeries", np.ndarray
21-
)
18+
AnyArrayLike = TypeVar("AnyArrayLike", "ExtensionArray", "Index", "Series", np.ndarray)
2219
ArrayLike = TypeVar("ArrayLike", "ExtensionArray", np.ndarray)
2320
DatetimeLikeScalar = TypeVar("DatetimeLikeScalar", "Period", "Timestamp", "Timedelta")
2421
Dtype = Union[str, np.dtype, "ExtensionDtype"]

pandas/core/arrays/sparse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,7 +1968,7 @@ def _delegate_method(self, name, *args, **kwargs):
19681968
@classmethod
19691969
def from_coo(cls, A, dense_index=False):
19701970
"""
1971-
Create a SparseSeries from a scipy.sparse.coo_matrix.
1971+
Create a Series with sparse values from a scipy.sparse.coo_matrix.
19721972
19731973
Parameters
19741974
----------
@@ -2009,7 +2009,7 @@ def from_coo(cls, A, dense_index=False):
20092009
from pandas.core.sparse.scipy_sparse import _coo_to_sparse_series
20102010
from pandas import Series
20112011

2012-
result = _coo_to_sparse_series(A, dense_index=dense_index, sparse_series=False)
2012+
result = _coo_to_sparse_series(A, dense_index=dense_index)
20132013
result = Series(result.array, index=result.index, copy=False)
20142014

20152015
return result

pandas/core/dtypes/common.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,6 @@ def is_sparse(arr):
273273
274274
See Also
275275
--------
276-
DataFrame.to_sparse : Convert DataFrame to a SparseDataFrame.
277-
Series.to_sparse : Convert Series to SparseSeries.
278276
Series.to_dense : Return dense representation of a Series.
279277
280278
Examples
@@ -283,7 +281,7 @@ def is_sparse(arr):
283281
284282
>>> is_sparse(pd.SparseArray([0, 0, 1, 0]))
285283
True
286-
>>> is_sparse(pd.SparseSeries([0, 0, 1, 0]))
284+
>>> is_sparse(pd.Series(pd.SparseArray([0, 0, 1, 0])))
287285
True
288286
289287
Returns `False` if the parameter is not sparse.
@@ -300,14 +298,6 @@ def is_sparse(arr):
300298
False
301299
302300
Returns `False` if the parameter has more than one dimension.
303-
304-
>>> df = pd.SparseDataFrame([389., 24., 80.5, np.nan],
305-
columns=['max_speed'],
306-
index=['falcon', 'parrot', 'lion', 'monkey'])
307-
>>> is_sparse(df)
308-
False
309-
>>> is_sparse(df.max_speed)
310-
True
311301
"""
312302
from pandas.core.arrays.sparse import SparseDtype
313303

@@ -340,8 +330,6 @@ def is_scipy_sparse(arr):
340330
True
341331
>>> is_scipy_sparse(pd.SparseArray([1, 2, 3]))
342332
False
343-
>>> is_scipy_sparse(pd.SparseSeries([1, 2, 3]))
344-
False
345333
"""
346334

347335
global _is_scipy_sparse
@@ -1715,9 +1703,6 @@ def is_extension_type(arr):
17151703
True
17161704
>>> is_extension_type(pd.SparseArray([1, 2, 3]))
17171705
True
1718-
>>> is_extension_type(pd.SparseSeries([1, 2, 3]))
1719-
True
1720-
>>>
17211706
>>> from scipy.sparse import bsr_matrix
17221707
>>> is_extension_type(bsr_matrix([1, 2, 3]))
17231708
False

pandas/core/frame.py

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,81 +1925,6 @@ def _from_arrays(cls, arrays, columns, index, dtype=None):
19251925
mgr = arrays_to_mgr(arrays, columns, index, columns, dtype=dtype)
19261926
return cls(mgr)
19271927

1928-
def to_sparse(self, fill_value=None, kind="block"):
1929-
"""
1930-
Convert to SparseDataFrame.
1931-
1932-
.. deprecated:: 0.25.0
1933-
1934-
Implement the sparse version of the DataFrame meaning that any data
1935-
matching a specific value it's omitted in the representation.
1936-
The sparse DataFrame allows for a more efficient storage.
1937-
1938-
Parameters
1939-
----------
1940-
fill_value : float, default None
1941-
The specific value that should be omitted in the representation.
1942-
kind : {'block', 'integer'}, default 'block'
1943-
The kind of the SparseIndex tracking where data is not equal to
1944-
the fill value:
1945-
1946-
- 'block' tracks only the locations and sizes of blocks of data.
1947-
- 'integer' keeps an array with all the locations of the data.
1948-
1949-
In most cases 'block' is recommended, since it's more memory
1950-
efficient.
1951-
1952-
Returns
1953-
-------
1954-
SparseDataFrame
1955-
The sparse representation of the DataFrame.
1956-
1957-
See Also
1958-
--------
1959-
DataFrame.to_dense :
1960-
Converts the DataFrame back to the its dense form.
1961-
1962-
Examples
1963-
--------
1964-
>>> df = pd.DataFrame([(np.nan, np.nan),
1965-
... (1., np.nan),
1966-
... (np.nan, 1.)])
1967-
>>> df
1968-
0 1
1969-
0 NaN NaN
1970-
1 1.0 NaN
1971-
2 NaN 1.0
1972-
>>> type(df)
1973-
<class 'pandas.core.frame.DataFrame'>
1974-
1975-
>>> sdf = df.to_sparse() # doctest: +SKIP
1976-
>>> sdf # doctest: +SKIP
1977-
0 1
1978-
0 NaN NaN
1979-
1 1.0 NaN
1980-
2 NaN 1.0
1981-
>>> type(sdf) # doctest: +SKIP
1982-
<class 'pandas.core.sparse.frame.SparseDataFrame'>
1983-
"""
1984-
warnings.warn(
1985-
"DataFrame.to_sparse is deprecated and will be removed "
1986-
"in a future version",
1987-
FutureWarning,
1988-
stacklevel=2,
1989-
)
1990-
1991-
from pandas.core.sparse.api import SparseDataFrame
1992-
1993-
with warnings.catch_warnings():
1994-
warnings.filterwarnings("ignore", message="SparseDataFrame")
1995-
return SparseDataFrame(
1996-
self._series,
1997-
index=self.index,
1998-
columns=self.columns,
1999-
default_kind=kind,
2000-
default_fill_value=fill_value,
2001-
)
2002-
20031928
@deprecate_kwarg(old_arg_name="encoding", new_arg_name=None)
20041929
def to_stata(
20051930
self,
@@ -7192,7 +7117,6 @@ def join(self, other, on=None, how="left", lsuffix="", rsuffix="", sort=False):
71927117
4 K4 A4 NaN
71937118
5 K5 A5 NaN
71947119
"""
7195-
# For SparseDataFrame's benefit
71967120
return self._join_compat(
71977121
other, on=on, how=how, lsuffix=lsuffix, rsuffix=rsuffix, sort=sort
71987122
)

pandas/core/generic.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5575,9 +5575,6 @@ def get_ftype_counts(self):
55755575
55765576
.. deprecated:: 0.23.0
55775577
5578-
This is useful for SparseDataFrame or for DataFrames containing
5579-
sparse arrays.
5580-
55815578
Returns
55825579
-------
55835580
dtype : Series
@@ -5672,7 +5669,6 @@ def ftypes(self):
56725669
See Also
56735670
--------
56745671
DataFrame.dtypes: Series with just dtype information.
5675-
SparseDataFrame : Container for sparse tabular data.
56765672
56775673
Notes
56785674
-----
@@ -5688,13 +5684,6 @@ def ftypes(self):
56885684
2 float64:dense
56895685
3 float64:dense
56905686
dtype: object
5691-
5692-
>>> pd.SparseDataFrame(arr).ftypes # doctest: +SKIP
5693-
0 float64:sparse
5694-
1 float64:sparse
5695-
2 float64:sparse
5696-
3 float64:sparse
5697-
dtype: object
56985687
"""
56995688
warnings.warn(
57005689
"DataFrame.ftypes is deprecated and will "

pandas/core/ops/methods.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ def _get_method_wrappers(cls):
6161
comp_special = _comp_method_SERIES
6262
bool_special = _bool_method_SERIES
6363
elif issubclass(cls, ABCDataFrame):
64-
# Same for DataFrame and SparseDataFrame
6564
arith_flex = _arith_method_FRAME
6665
comp_flex = _flex_comp_method_FRAME
6766
arith_special = _arith_method_FRAME

pandas/core/reshape/concat.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,6 @@ def _get_series_result_type(result, objs=None):
726726
def _get_frame_result_type(result, objs):
727727
"""
728728
return appropriate class of DataFrame-like concat
729-
if all blocks are sparse, return SparseDataFrame
730-
otherwise, return 1st obj
731729
"""
730+
# TODO: just inline this
732731
return objs[0]

pandas/core/reshape/reshape.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class _Unstacker:
5757
float and missing values will be set to NaN.
5858
constructor : object
5959
Pandas ``DataFrame`` or subclass used to create unstacked
60-
response. If None, DataFrame or SparseDataFrame will be used.
60+
response. If None, DataFrame will be used.
6161
6262
Examples
6363
--------

pandas/core/series.py

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
import pandas as pd
5656
from pandas.core import algorithms, base, generic, nanops, ops
5757
from pandas.core.accessor import CachedAccessor
58-
from pandas.core.arrays import ExtensionArray, SparseArray
58+
from pandas.core.arrays import ExtensionArray
5959
from pandas.core.arrays.categorical import Categorical, CategoricalAccessor
6060
from pandas.core.arrays.sparse import SparseAccessor
6161
import pandas.core.common as com
@@ -384,10 +384,6 @@ def from_array(
384384
FutureWarning,
385385
stacklevel=2,
386386
)
387-
if isinstance(arr, ABCSparseArray):
388-
from pandas.core.sparse.series import SparseSeries
389-
390-
cls = SparseSeries
391387
return cls(
392388
arr, index=index, name=name, dtype=dtype, copy=copy, fastpath=fastpath
393389
)
@@ -1776,38 +1772,6 @@ def to_frame(self, name=None):
17761772

17771773
return df
17781774

1779-
def to_sparse(self, kind="block", fill_value=None):
1780-
"""
1781-
Convert Series to SparseSeries.
1782-
1783-
.. deprecated:: 0.25.0
1784-
1785-
Parameters
1786-
----------
1787-
kind : {'block', 'integer'}, default 'block'
1788-
fill_value : float, defaults to NaN (missing)
1789-
Value to use for filling NaN values.
1790-
1791-
Returns
1792-
-------
1793-
SparseSeries
1794-
Sparse representation of the Series.
1795-
"""
1796-
1797-
warnings.warn(
1798-
"Series.to_sparse is deprecated and will be removed in a future version",
1799-
FutureWarning,
1800-
stacklevel=2,
1801-
)
1802-
from pandas.core.sparse.series import SparseSeries
1803-
1804-
values = SparseArray(self, kind=kind, fill_value=fill_value)
1805-
with warnings.catch_warnings():
1806-
warnings.filterwarnings("ignore", message="SparseSeries")
1807-
return SparseSeries(values, index=self.index, name=self.name).__finalize__(
1808-
self
1809-
)
1810-
18111775
def _set_name(self, name, inplace=False):
18121776
"""
18131777
Set the Series name.

0 commit comments

Comments
 (0)