Code Sample, a copy-pastable example if possible

import pandas as pd
df = pd.DataFrame({'x': [1., 5., 3.]}, index=[0, 2, 4])
df.index.name = 'frame'
df.reset_index('frame')

Problem description

Resetting the index on pandas 0.20.1 and python 2.7 results in the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Anaconda3\envs\tpissue\lib\site-packages\pandas\core\frame.py", line 3055, in reset_index
    if level is None or i in level:
TypeError: 'in <string>' requires string as left operand, not int

In the example, it doesn't matter if you use Unicode or non-unicode strings. (using from __future__ import unicode_literals). Ref https://github.com/soft-matter/trackpy/issues/446 @manuescobedo

Expected Output

A reindexed DataFrame.

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 2.7.13.final.0 python-bits: 64 OS: Windows OS-release: 7 machine: AMD64 processor: Intel64 Family 6 Model 58 Stepping 9, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None pandas: 0.20.1 pytest: None pip: 9.0.1 setuptools: 27.2.0 Cython: None numpy: 1.12.1 scipy: 0.19.1 xarray: None IPython: None sphinx: None patsy: None dateutil: 2.6.0 pytz: 2017.2 blosc: None bottleneck: None tables: 3.4.2 numexpr: 2.6.2 feather: None matplotlib: 2.0.2 openpyxl: None xlrd: None xlwt: None xlsxwriter: None lxml: None bs4: None html5lib: None sqlalchemy: None pymysql: None psycopg2: None jinja2: 2.9.5 s3fs: None pandas_gbq: None pandas_datareader: None

Comment From: gfyoung

I believe you are incorrectly using the reset_index method. The label you pass in MUST belong to the index of the DataFrame. In the context of your example, that means DataFrame.index.name must be "frame" per the documentation here.

That being said, this error message makes no sense, so we can improve on that so that it won't be as confusing next. Would you like to update / improve it?

Comment From: caspervdw

@gfyoung Thanks for the fast reply. I think I might have simplified the code example too much. Sorry about that. The same exception is there if I execute the following script:

import pandas as pd
df = pd.DataFrame({'x': [1., 5., 3.]}, index=[0, 2, 4])
df.index.name = 'frame'
df.reset_index('frame')

Specifying the name of the only indexer does work on pandas 0.13/py27, 0.16/py27, 0.19/py35, and 0.20.1/py35.

Comment From: jreback

these are as expected. You cannot reset a named index that doesn't exist.

Comment From: caspervdw

@jreback The named index does exist, I made a mistake in my first code example. For clarity, I now edited my first message.

Comment From: gfyoung

@caspervdw : I can't reproduce the error. The code works perfectly fine on Python 2.7 and 3.6 (using 0.20.2 though). Can you double-check this?

Comment From: gfyoung

Also @jreback , I'd like to keep this open, as I would like to see if we can improve the error message

Comment From: caspervdw

Thanks @gfyoung for reopening. I can have a look a the error message for sure, but first I want to see where my issue is coming from.

@manuescobedo brought this up at https://github.com/soft-matter/trackpy/issues/446. We use CI and never encountered this, however with the specific configuration Py27, pandas 0.20.1, I can reproduce. @manuescobedo, could you try to reproduce your error using my minimal example above?

When I have more time I'll try to dive a bit deeper into this. I'll let you know if I find anything.

Comment From: gfyoung

Thanks @jreback for reopening.

Ummm...that was me in fact 😉

Also, try upgrading pandas to 0.20.2, I can't reproduce the issue there. I can however, confirm that that was (we're past that release now) on 0.20.1.

Comment From: caspervdw

I can confirm that the issue disappears on 0.20.2. If I try to reindex using a non-existing index name, I get TypeError: Level name must be same as name '(None)', which is OK I think. So the issue can be closed for my part.

Comment From: jreback

this was fixed by https://github.com/pandas-dev/pandas/pull/16266