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

Duplicate items on Panel supported? #4960

Closed
dalejung opened this issue Sep 24, 2013 · 6 comments · Fixed by #5097

Comments

@dalejung
Copy link
Contributor

commented Sep 24, 2013

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

This comment has been minimized.

Copy link
Contributor

commented Sep 24, 2013

should work...

@dalejung

This comment has been minimized.

Copy link
Contributor Author

commented Sep 24, 2013

@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

This comment has been minimized.

Copy link
Contributor

commented Sep 24, 2013

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

@jreback

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

commented Sep 24, 2013

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

@jreback

This comment has been minimized.

Copy link
Contributor

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
Projects
None yet
2 participants
You can’t perform that action at this time.