Skip to content

Duplicate items on Panel supported? #4960

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
dalejung opened this issue Sep 24, 2013 · 6 comments · Fixed by #5097
Closed

Duplicate items on Panel supported? #4960

dalejung opened this issue Sep 24, 2013 · 6 comments · Fixed by #5097
Assignees
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@dalejung
Copy link
Contributor

import pandas as pd
import numpy as np

data = np.random.randn(5, 100, 5)
panel = pd.Panel(data, items=list("AACDE"))

panel.iloc[0] # ValueError: Wrong number of dimensions

fr = panel.loc["E"]
fr.values.shape # (5, 100, 5) wrong

So this is another contrived example that I got from just running a battery of tests on random objects. Basically having a duplicate item key will bork the Panel.

I'm actually not sure whether Panel is meant to be a collection of uniquely identified DataFrames, or more like a generic 3d container that has convenient semantics for its axes. I think at one point it was the former, but as more things pull from generic it's becoming the later?

@ghost ghost assigned jreback Sep 24, 2013
@jreback
Copy link
Contributor

jreback commented Sep 24, 2013

should work...

@dalejung
Copy link
Contributor Author

@jreback Also should Panel support non-scalar arith methods like: panel * panel? I hear mention of an arith refactor and wasn't sure if that was included.

@jreback
Copy link
Contributor

jreback commented Sep 24, 2013

that's a bit more complicated as it involves panel alignment (which is only partially done)

@jreback
Copy link
Contributor

jreback commented Sep 24, 2013

@dalejung I take it back, I think you can just remove that test and it should work (but needs some tests)....want to do a PR?

def _arith_method(func, name):
    # work only for scalars

    def f(self, other):
        #if not np.isscalar(other):
        #    raise ValueError('Simple arithmetic with %s can only be '
        #                     'done with scalar values' % self._constructor.__name__)

        return self._combine(other, func)
    f.__name__ = name
    return f

then this works

In [20]: p = tm.makePanel()

In [21]: tm.assert_frame_equal(2*p['ItemA'],(p + p.loc[['ItemA']])['ItemA'])

@jreback
Copy link
Contributor

jreback commented Sep 24, 2013

let me do a quick PR to fix something related......

@jreback
Copy link
Contributor

jreback commented Sep 24, 2013

jreback@adf9d48

if you would like to add some tests and do a PR....I think it will pretty much work (forgot had written the panel combiner)

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 a pull request may close this issue.

2 participants