Skip to content

Commit 690d52c

Browse files
gfyoungjreback
authored andcommitted
CLN: Removed SparsePanel
Title is self-explanatory. Picks up where #11157 left off. Author: gfyoung <[email protected]> Closes #13778 from gfyoung/remove-sparse-panel and squashes the following commits: f3fa93b [gfyoung] CLN: Removed SparsePanel
1 parent a208c56 commit 690d52c

File tree

16 files changed

+32
-1112
lines changed

16 files changed

+32
-1112
lines changed

bench/bench_sparse.py

-92
This file was deleted.

doc/source/sparse.rst

+10-10
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
Sparse data structures
1616
**********************
1717

18-
We have implemented "sparse" versions of Series, DataFrame, and Panel. These
19-
are not sparse in the typical "mostly 0". You can view these objects as being
20-
"compressed" where any data matching a specific value (NaN/missing by default,
21-
though any value can be chosen) is omitted. A special ``SparseIndex`` object
22-
tracks where data has been "sparsified". This will make much more sense in an
23-
example. All of the standard pandas data structures have a ``to_sparse``
24-
method:
18+
.. note:: The ``SparsePanel`` class has been removed in 0.19.0
19+
20+
We have implemented "sparse" versions of Series and DataFrame. These are not sparse
21+
in the typical "mostly 0". Rather, you can view these objects as being "compressed"
22+
where any data matching a specific value (``NaN`` / missing value, though any value
23+
can be chosen) is omitted. A special ``SparseIndex`` object tracks where data has been
24+
"sparsified". This will make much more sense in an example. All of the standard pandas
25+
data structures have a ``to_sparse`` method:
2526

2627
.. ipython:: python
2728
@@ -77,9 +78,8 @@ distinct from the ``fill_value``:
7778
sparr = pd.SparseArray(arr)
7879
sparr
7980
80-
Like the indexed objects (SparseSeries, SparseDataFrame, SparsePanel), a
81-
``SparseArray`` can be converted back to a regular ndarray by calling
82-
``to_dense``:
81+
Like the indexed objects (SparseSeries, SparseDataFrame), a ``SparseArray``
82+
can be converted back to a regular ndarray by calling ``to_dense``:
8383

8484
.. ipython:: python
8585

doc/source/whatsnew/v0.19.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ API changes
330330
~~~~~~~~~~~
331331

332332

333+
- ``Panel.to_sparse`` will raise a ``NotImplementedError`` exception when called (:issue:`13778`)
333334
- ``Index.reshape`` will raise a ``NotImplementedError`` exception when called (:issue:`12882`)
334335
- Non-convertible dates in an excel date column will be returned without conversion and the column will be ``object`` dtype, rather than raising an exception (:issue:`10001`)
335336
- ``eval``'s upcasting rules for ``float32`` types have been updated to be more consistent with NumPy's rules. New behavior will not upcast to ``float64`` if you multiply a pandas ``float32`` object by a scalar float64. (:issue:`12388`)
@@ -619,6 +620,7 @@ Deprecations
619620

620621
Removal of prior version deprecations/changes
621622
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
623+
- The ``SparsePanel`` class has been removed (:issue:`13778`)
622624
- The ``pd.sandbox`` module has been removed in favor of the external library ``pandas-qt`` (:issue:`13670`)
623625
- The ``pandas.io.data`` and ``pandas.io.wb`` modules are removed in favor of
624626
the `pandas-datareader package <https://github.com/pydata/pandas-datareader>`__ (:issue:`13724`).

pandas/api/tests/test_api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class TestPDApi(Base, tm.TestCase):
5757
'TimedeltaIndex', 'Timestamp']
5858

5959
# these are already deprecated; awaiting removal
60-
deprecated_classes = ['SparsePanel', 'TimeSeries', 'WidePanel',
60+
deprecated_classes = ['TimeSeries', 'WidePanel',
6161
'SparseTimeSeries', 'Panel4D']
6262

6363
# these should be deperecated in the future

pandas/core/panel.py

+6-16
Original file line numberDiff line numberDiff line change
@@ -393,25 +393,15 @@ def _get_plane_axes(self, axis):
393393

394394
fromDict = from_dict
395395

396-
def to_sparse(self, fill_value=None, kind='block'):
396+
def to_sparse(self, *args, **kwargs):
397397
"""
398-
Convert to SparsePanel
399-
400-
Parameters
401-
----------
402-
fill_value : float, default NaN
403-
kind : {'block', 'integer'}
398+
NOT IMPLEMENTED: do not call this method, as sparsifying is not
399+
supported for Panel objects and will raise an error.
404400
405-
Returns
406-
-------
407-
y : SparseDataFrame
401+
Convert to SparsePanel
408402
"""
409-
from pandas.core.sparse import SparsePanel
410-
frames = dict(self.iteritems())
411-
return SparsePanel(frames, items=self.items,
412-
major_axis=self.major_axis,
413-
minor_axis=self.minor_axis, default_kind=kind,
414-
default_fill_value=fill_value)
403+
raise NotImplementedError("sparsifying is not supported "
404+
"for Panel objects")
415405

416406
def to_excel(self, path, na_rep='', engine=None, **kwargs):
417407
"""

pandas/core/sparse.py

-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@
88

99
from pandas.sparse.series import SparseSeries
1010
from pandas.sparse.frame import SparseDataFrame
11-
from pandas.sparse.panel import SparsePanel

pandas/io/packers.py

+1-13
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
Panel, RangeIndex, PeriodIndex, DatetimeIndex, NaT,
5757
Categorical)
5858
from pandas.tslib import NaTType
59-
from pandas.sparse.api import SparseSeries, SparseDataFrame, SparsePanel
59+
from pandas.sparse.api import SparseSeries, SparseDataFrame
6060
from pandas.sparse.array import BlockIndex, IntIndex
6161
from pandas.core.generic import NDFrame
6262
from pandas.core.common import PerformanceWarning
@@ -447,18 +447,6 @@ def encode(obj):
447447
# d['data'] = dict([(name, ss)
448448
# for name, ss in compat.iteritems(obj)])
449449
# return d
450-
elif isinstance(obj, SparsePanel):
451-
raise NotImplementedError(
452-
'msgpack sparse frame is not implemented'
453-
)
454-
# d = {'typ': 'sparse_panel',
455-
# 'klass': obj.__class__.__name__,
456-
# 'items': obj.items}
457-
# for f in ['default_fill_value', 'default_kind']:
458-
# d[f] = getattr(obj, f, None)
459-
# d['data'] = dict([(name, df)
460-
# for name, df in compat.iteritems(obj)])
461-
# return d
462450
else:
463451

464452
data = obj._data

pandas/io/pytables.py

+1-36
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
MultiIndex, Int64Index, isnull)
3030
from pandas.core import config
3131
from pandas.io.common import _stringify_path
32-
from pandas.sparse.api import SparseSeries, SparseDataFrame, SparsePanel
32+
from pandas.sparse.api import SparseSeries, SparseDataFrame
3333
from pandas.sparse.array import BlockIndex, IntIndex
3434
from pandas.tseries.api import PeriodIndex, DatetimeIndex
3535
from pandas.tseries.tdi import TimedeltaIndex
@@ -169,7 +169,6 @@ class DuplicateWarning(Warning):
169169
SparseDataFrame: u('sparse_frame'),
170170
Panel: u('wide'),
171171
Panel4D: u('ndim'),
172-
SparsePanel: u('sparse_panel')
173172
}
174173

175174
# storer class map
@@ -183,7 +182,6 @@ class DuplicateWarning(Warning):
183182
u('frame'): 'FrameFixed',
184183
u('sparse_frame'): 'SparseFrameFixed',
185184
u('wide'): 'PanelFixed',
186-
u('sparse_panel'): 'SparsePanelFixed',
187185
}
188186

189187
# table class map
@@ -2777,39 +2775,6 @@ def write(self, obj, **kwargs):
27772775
self.write_index('columns', obj.columns)
27782776

27792777

2780-
class SparsePanelFixed(SparseFixed):
2781-
pandas_kind = u('sparse_panel')
2782-
attributes = ['default_kind', 'default_fill_value']
2783-
2784-
def read(self, **kwargs):
2785-
kwargs = self.validate_read(kwargs)
2786-
items = self.read_index('items')
2787-
2788-
sdict = {}
2789-
for name in items:
2790-
key = 'sparse_frame_%s' % name
2791-
s = SparseFrameFixed(self.parent, getattr(self.group, key))
2792-
s.infer_axes()
2793-
sdict[name] = s.read()
2794-
return SparsePanel(sdict, items=items, default_kind=self.default_kind,
2795-
default_fill_value=self.default_fill_value)
2796-
2797-
def write(self, obj, **kwargs):
2798-
super(SparsePanelFixed, self).write(obj, **kwargs)
2799-
self.attrs.default_fill_value = obj.default_fill_value
2800-
self.attrs.default_kind = obj.default_kind
2801-
self.write_index('items', obj.items)
2802-
2803-
for name, sdf in obj.iteritems():
2804-
key = 'sparse_frame_%s' % name
2805-
if key not in self.group._v_children:
2806-
node = self._handle.create_group(self.group, key)
2807-
else:
2808-
node = getattr(self.group, key)
2809-
s = SparseFrameFixed(self.parent, node)
2810-
s.write(sdf)
2811-
2812-
28132778
class BlockManagerFixed(GenericFixed):
28142779
attributes = ['ndim', 'nblocks']
28152780
is_shape_reversed = False

pandas/io/tests/test_packers.py

-20
Original file line numberDiff line numberDiff line change
@@ -542,26 +542,6 @@ def test_sparse_frame(self):
542542
self._check_roundtrip(ss3, tm.assert_frame_equal,
543543
check_frame_type=True)
544544

545-
def test_sparse_panel(self):
546-
547-
with tm.assert_produces_warning(FutureWarning,
548-
check_stacklevel=False):
549-
550-
items = ['x', 'y', 'z']
551-
p = Panel(dict((i, tm.makeDataFrame().ix[:2, :2]) for i in items))
552-
sp = p.to_sparse()
553-
554-
self._check_roundtrip(sp, tm.assert_panel_equal,
555-
check_panel_type=True)
556-
557-
sp2 = p.to_sparse(kind='integer')
558-
self._check_roundtrip(sp2, tm.assert_panel_equal,
559-
check_panel_type=True)
560-
561-
sp3 = p.to_sparse(fill_value=0)
562-
self._check_roundtrip(sp3, tm.assert_panel_equal,
563-
check_panel_type=True)
564-
565545

566546
class TestCompression(TestPackers):
567547
"""See https://github.com/pydata/pandas/pull/9783

pandas/io/tests/test_pytables.py

-17
Original file line numberDiff line numberDiff line change
@@ -2688,23 +2688,6 @@ def test_sparse_frame(self):
26882688
self._check_double_roundtrip(ss3, tm.assert_frame_equal,
26892689
check_frame_type=True)
26902690

2691-
def test_sparse_panel(self):
2692-
2693-
items = ['x', 'y', 'z']
2694-
p = Panel(dict((i, tm.makeDataFrame().ix[:2, :2]) for i in items))
2695-
sp = p.to_sparse()
2696-
2697-
self._check_double_roundtrip(sp, assert_panel_equal,
2698-
check_panel_type=True)
2699-
2700-
sp2 = p.to_sparse(kind='integer')
2701-
self._check_double_roundtrip(sp2, assert_panel_equal,
2702-
check_panel_type=True)
2703-
2704-
sp3 = p.to_sparse(fill_value=0)
2705-
self._check_double_roundtrip(sp3, assert_panel_equal,
2706-
check_panel_type=True)
2707-
27082691
def test_float_index(self):
27092692

27102693
# GH #454

pandas/sparse/api.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@
44
from pandas.sparse.list import SparseList
55
from pandas.sparse.series import SparseSeries, SparseTimeSeries
66
from pandas.sparse.frame import SparseDataFrame
7-
from pandas.sparse.panel import SparsePanel

0 commit comments

Comments
 (0)