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

Problem with DataFrame.lookup() #1001

Closed
ijmcf opened this issue Apr 5, 2012 · 1 comment
Closed

Problem with DataFrame.lookup() #1001

ijmcf opened this issue Apr 5, 2012 · 1 comment
Labels
Milestone

Comments

@ijmcf
Copy link

ijmcf commented Apr 5, 2012

If the row and/or column labels are not present in the DataFrame, the lookup() method returns ... whatever it wants, apparently. I would expect either a NaN or an exception, personally - but whatever the result, it shouldn't be the wrong piece of data.

df = pandas.DataFrame({'A': pandas.Series(['A', 'B', 'C', 'D', 'E'], index=range(5))})

df.lookup([2], ['A']) # Correct
array([C], dtype=object)

df.lookup([10], ['A']) # 10 is not present in the index, so we get .. the last value in A?
array([E], dtype=object)

df.lookup([3], ['B']) # There is no column 'B', so we get ... the value from the last column (A) in that row?
array([C], dtype=object)

df.lookup([10], ['B']) # Neither row or column label is valid, so we get ... I can't rationalize this one.
array([D], dtype=object)

@adamklein
Copy link
Contributor

Indexing lookup returns -1 for non-existing label, which is then used to "wrap around" per python array indexing semantics. Probably should have check in lookup function:

        if (ridx == -1).any():
            raise ValueError("Bad row label(s)")
        if (cidx == -1).any():
            raise ValueError("Bad col label(s)")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants