Skip to content

BUG: SparsePanel cross sectional not working #9252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wholmgren opened this issue Jan 14, 2015 · 2 comments
Closed

BUG: SparsePanel cross sectional not working #9252

wholmgren opened this issue Jan 14, 2015 · 2 comments
Labels
Compat pandas objects compatability with Numpy or Python functions Enhancement Sparse Sparse Data Type

Comments

@wholmgren
Copy link
Contributor

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
@jreback
Copy link
Contributor

jreback commented Jan 15, 2015

The sparse handling for SparseSeries/Frame changed in 0.13 to inherit properly from NDFrame (as everything was integrated properly back then).

But SparsePanel is still using the 'old' system (basically its a dict of DataFrames). So I wouldn't expect really any API compat, as this has not gotten any attention. I'll mark this, but we need someone interested in making these changes.

@jreback jreback added Enhancement Compat pandas objects compatability with Numpy or Python functions Sparse Sparse Data Type labels Jan 15, 2015
@jreback jreback added this to the 0.17.0 milestone Jan 15, 2015
@jreback
Copy link
Contributor

jreback commented Sep 20, 2015

closing as deprecating in #11157

sparse is not really well supported, and this is NOT supported at all.

@jreback jreback closed this as completed Sep 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions Enhancement Sparse Sparse Data Type
Projects
None yet
Development

No branches or pull requests

2 participants