Skip to content

QST: Subclassed lists are not allowed as indexers of dfs in v1.3.0 #42431

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
2 tasks done
pwwang opened this issue Jul 7, 2021 · 1 comment
Closed
2 tasks done

QST: Subclassed lists are not allowed as indexers of dfs in v1.3.0 #42431

pwwang opened this issue Jul 7, 2021 · 1 comment
Labels
Needs Triage Issue that has not been reviewed by a pandas team member Usage Question

Comments

@pwwang
Copy link

pwwang commented Jul 7, 2021

  • I have searched the [pandas] tag on StackOverflow for similar questions.

  • I have asked my usage related question on StackOverflow.


Question about pandas

Note: If you'd still like to submit a question, please read this guide detailing how to provide the necessary information for us to reproduce your question.

>>> from pandas import DataFrame
>>> df = DataFrame(dict(x=[1,2,3]))
>>> class MyList(list): 
...     ...
...
>>> 
>>> 
>>> key = MyList(['x'])
>>> key
['x']
>>> 
>>> df[key]
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    df[key]
  File "/.../python3.7/site-packages/pandas/core/frame.py", line 3445, in __getitem__
    if com.is_bool_indexer(key):
  File "/...python3.7/site-packages/pandas/core/common.py", line 146, in is_bool_indexer
    return len(key) > 0 and lib.is_bool_list(key)
TypeError: Argument 'obj' has incorrect type (expected list, got MyList)

This works in v1.2.*.

It is mentioned in the docstring of is_bool_indexer that

with _is_boolean set are considered boolean indexers.

But I had no luck with that property being set with MyList.

Not sure if this is an intended change or not. I did find any documentation for this.

@pwwang pwwang added Needs Triage Issue that has not been reviewed by a pandas team member Usage Question labels Jul 7, 2021
@pwwang pwwang changed the title QST: Subclassed lists are not allowed as indexers of dfs in v1.3.0 BUG: Subclassed lists are not allowed as indexers of dfs in v1.3.0 Jul 7, 2021
@pwwang pwwang changed the title BUG: Subclassed lists are not allowed as indexers of dfs in v1.3.0 QST: Subclassed lists are not allowed as indexers of dfs in v1.3.0 Jul 7, 2021
@pwwang
Copy link
Author

pwwang commented Jul 7, 2021

Now I think this is a bug.

#42433

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Triage Issue that has not been reviewed by a pandas team member Usage Question
Projects
None yet
Development

No branches or pull requests

1 participant