-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed
Labels
Compatpandas objects compatability with Numpy or Python functionspandas objects compatability with Numpy or Python functionsEnhancementSparseSparse Data TypeSparse Data Type
Description
My understanding is that SparsePanel is supposed to have the same API as Panel, so I expected sparse_pan[:,:,1]
to work:
In [11]: data = np.zeros((3,3,3))
In [12]: data[:] = np.nan
In [13]: data[1,1,1] = 1
In [14]: pan = pd.Panel(data)
In [15]: pan[:,:,1]
Out[15]:
0 1 2
0 NaN NaN NaN
1 NaN 1 NaN
2 NaN NaN NaN
In [16]: sparse_pan = pan.to_sparse()
In [17]: sparse_pan[:,:,1]
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-17-e57ddf7a7092> in <module>()
----> 1 sparse_pan[:,:,1]
/home/will/.virtualenvs/dev3/lib/python3.4/site-packages/pandas/core/panel.py in __getitem__(self, key)
256 if lib.isscalar(key):
257 return super(Panel, self).__getitem__(key)
--> 258 return self.ix[key]
259
260 def _getitem_multilevel(self, key):
/home/will/.virtualenvs/dev3/lib/python3.4/site-packages/pandas/core/indexing.py in __getitem__(self, key)
68 pass
69
---> 70 return self._getitem_tuple(key)
71 else:
72 return self._getitem_axis(key, axis=0)
/home/will/.virtualenvs/dev3/lib/python3.4/site-packages/pandas/core/indexing.py in _getitem_tuple(self, tup)
697 def _getitem_tuple(self, tup):
698 try:
--> 699 return self._getitem_lowerdim(tup)
700 except IndexingError:
701 pass
/home/will/.virtualenvs/dev3/lib/python3.4/site-packages/pandas/core/indexing.py in _getitem_lowerdim(self, tup)
822 for i, key in enumerate(tup):
823 if _is_label_like(key) or isinstance(key, tuple):
--> 824 section = self._getitem_axis(key, axis=i)
825
826 # we have yielded a scalar ?
/home/will/.virtualenvs/dev3/lib/python3.4/site-packages/pandas/core/indexing.py in _getitem_axis(self, key, axis)
926 return self._get_loc(key, axis=axis)
927
--> 928 return self._get_label(key, axis=axis)
929
930 def _getitem_iterable(self, key, axis=0):
/home/will/.virtualenvs/dev3/lib/python3.4/site-packages/pandas/core/indexing.py in _get_label(self, label, axis)
86 raise IndexingError('no slices here, handle elsewhere')
87
---> 88 return self.obj._xs(label, axis=axis)
89
90 def _get_loc(self, key, axis=0):
/home/will/.virtualenvs/dev3/lib/python3.4/site-packages/pandas/core/panel.py in xs(self, key, axis, copy)
787 self._consolidate_inplace()
788 axis_number = self._get_axis_number(axis)
--> 789 new_data = self._data.xs(key, axis=axis_number, copy=False)
790 result = self._construct_return_type(new_data)
791 copy = new_data.is_mixed_type
/home/will/.virtualenvs/dev3/lib/python3.4/site-packages/pandas/core/generic.py in __getattr__(self, name)
1938
1939 if name in self._internal_names_set:
-> 1940 return object.__getattribute__(self, name)
1941 elif name in self._metadata:
1942 return object.__getattribute__(self, name)
AttributeError: 'SparsePanel' object has no attribute '_data'
No surprise: same behavior with ix and iloc.
Accessing via minor_xs
does work
In [23]: sparse_pan.minor_xs(1)
Out[23]:
0 1 2
0 NaN NaN NaN
1 NaN 1 NaN
2 NaN NaN NaN
In [3]: pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 3.4.1.final.0
python-bits: 64
OS: Linux
OS-release: 2.6.32-431.17.1.el6.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
pandas: 0.15.2
nose: 1.3.4
Cython: 0.20.2
numpy: 1.9.1
scipy: 0.14.1
Metadata
Metadata
Assignees
Labels
Compatpandas objects compatability with Numpy or Python functionspandas objects compatability with Numpy or Python functionsEnhancementSparseSparse Data TypeSparse Data Type