question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: The difference in behaviour of indexing between 1.2.4 and 1.3.0

See original GitHub issue
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


I have some code that I used to extract the index columns as data frame, which worked in pandas 1.2.4 but not in 1.3.0. I have read what’s new (https://pandas.pydata.org/pandas-docs/version/1.3.0/whatsnew/v1.3.0.html). To my best knowledge, this seems to be an undocumented change. I wonder if I can get some advice on how to make the code work for both 1.2 and 1.3 and potentially 1.4.

Code Sample, a copy-pastable example

# To extract the index columns
col = df.reset_index()[df.index.names[:]]

Problem description

Say if we have a data frame.

>>> d = {'col1': [1, 2], 'col2': [3, 4]}
>>> df = pd.DataFrame(data=d)
>>> df = df.set_index('col1')
>>> df
      col2
col1      
1        3
2        4

Expected Output

For pandas == 1.2.4,

>>> df.reset_index()[df.index.names[:]]
   col1
0     1
1     2

For pandas >= 1.3.0,

>>> df.reset_index()[df.index.names[:]]
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "~/GitHub/pandas/pandas/core/frame.py", line 3444, in __getitem__
    if com.is_bool_indexer(key):
  File "~/GitHub/pandas/pandas/core/common.py", line 147, in is_bool_indexer
    return len(key) > 0 and lib.is_bool_list(key)
TypeError: Argument 'obj' has incorrect type (expected list, got FrozenList)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pwwangcommented, Jul 9, 2021

I am hoping so, too. But for 1.3.0, we cannot bypass this as I mentioned in my issue.

0reactions
xiki-tempulacommented, Jul 9, 2021

@pwwang I was hoping to have some more elegant solution but thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What's new in 1.4.0 (January 22, 2022) - Pandas
site-packages/pandas/core/indexing.py:1951: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame.
Read more >
News - Logback - QOS.ch
A bug was introduced in 1.3.0-alpha13 which caused the second appender-ref ... this version contains the same fixes as in logback versions 1.2.4...
Read more >
Omega - Xapian
Omega 1.4.1 (2016-10-21): general: documentation: * Document bug in how ... Patch from James Aylett. indexers: * omindex: * Also index leafname with...
Read more >
What's new — fmriprep version documentation
This release increases the minimum Nipype version to include better error messages on ... MAINT: Remove derivatives from layout index ignores (#2258).
Read more >
Docker Compose release notes
Dependencies update: Bumped buildx from v0.7.1 to v0.8.0. Bug fixes and enhancements . Recovered behavior for 'compose up -d' of recreating containers...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found