Skip to content
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

BUG: setitem fails on mixed-type Panel4D #8702

Closed
wants to merge 1 commit into from
Closed

BUG: setitem fails on mixed-type Panel4D #8702

wants to merge 1 commit into from

Conversation

stahlous
Copy link
Contributor

@stahlous stahlous commented Nov 1, 2014

Trying to set a value on a mixed-type Panel4D currently fails:

In [1]: from pandas.util import testing as tmd

In [2]: p4d = tmd.makePanel4D()

In [3]: p4d['foo'] = 'bar'

In [4]: p4d.iloc[0,0,0,0] = 0
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-bb74b95f7244> in <module>()
----> 1 p4d.iloc[0,0,0,0] = 0

/home/stahlous/pd_dev/pandas/pandas/core/indexing.py in __setitem__(self, key, value)
    119                 indexer = self._convert_to_indexer(key, is_setter=True)
    120
--> 121         self._setitem_with_indexer(indexer, value)
    122
    123     def _has_valid_type(self, k, axis):

/home/stahlous/pd_dev/pandas/pandas/core/indexing.py in _setitem_with_indexer(self, indexer, value)
    356             # indexer here
    357             if (len(labels) == 1 and
--> 358                     isinstance(self.obj[labels[0]].index, MultiIndex)):
    359                 item = labels[0]
    360                 obj = self.obj[item]

/home/stahlous/pd_dev/pandas/pandas/core/generic.py in __getattr__(self, name)
   1927         """
   1928         if name in self._internal_names_set:
-> 1929             return object.__getattribute__(self, name)
   1930         elif name in self._metadata:
   1931             return object.__getattribute__(self, name)

AttributeError: 'Panel' object has no attribute 'index'

Fortunately, it looks like a simple fix. If this looks OK. I'll add a note to v0.15.1.txt (doesn't have a GH issue number yet).

This fix is needed for my latest attempt at the fillna bug #8395.

@jreback
Copy link
Contributor

jreback commented Nov 1, 2014

tests!

@stahlous
Copy link
Contributor Author

stahlous commented Nov 1, 2014

Ah... yeah. There is a test that highlights this in my fillna bug branch, but I guess that doesn't do any good here. I'll add a test as well to this branch.

@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves labels Nov 1, 2014
@stahlous
Copy link
Contributor Author

stahlous commented Nov 1, 2014

I added in a test which captures this issue. I also added in some tests for the non-mixed-type case since it looks like there weren't any tests of setting by index at all for Panel4D.

It looks like this only fixes setting by index for scalar values. Setting by index to a Series or DataFrame is still broken for mixed-type Panel4D. That fix is unfortunately not as trivial. I can work on the more comprehensive fix if you want to hold off merging in this partial fix. If you decide to merge in this PR, I can open an issue for the comprehensive fix.

@jreback
Copy link
Contributor

jreback commented Nov 1, 2014

keep things in separate PRs
open issues for things you believe are bugs

it's faster/easier to review s single fix at a time

@@ -227,3 +227,5 @@ Bug Fixes
- Fixed a bug where plotting a column ``y`` and specifying a label would mutate the index name of the original DataFrame (:issue:`8494`)

- Bug in ``date_range`` where partially-specified dates would incorporate current date (:issue:`6961`)

- Bug in `_NDFrameIndexer._setitem_with_indexer` that prevented setting scalar value by indexer in mixed-type Panel4D (:issue: `8702`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use internal routines the thr release notes
setitem with a mixed dtype Panel4D was failing when setting with a scalar right (something like this

@stahlous
Copy link
Contributor Author

stahlous commented Nov 1, 2014

Thanks. I added the issue number to test_setitem_by_indexer_mixed_type but not test_setitem_by_indexer since non-mixed-types were working as expected but just not tested.

@jreback jreback added this to the 0.15.1 milestone Nov 2, 2014
@jreback
Copy link
Contributor

jreback commented Nov 2, 2014

merged via 1041dff

thanks!

@jreback jreback closed this Nov 2, 2014
@stahlous stahlous deleted the p4d_setitem_bug branch November 2, 2014 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants