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

BUG: calling at[] on a Series with a single-level MultiIndex returns a Series, not a scalar #38053

Closed
bpteague opened this issue Nov 25, 2020 · 2 comments · Fixed by #38101
Closed
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex
Milestone

Comments

@bpteague
Copy link

  • [YES] I have checked that this issue has not already been reported.

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

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


Code Sample, a copy-pastable example

idx1 = pd.MultiIndex.from_tuples([(False, 1.0), 
                                  (False, 10.0),
                                  (True, 1.0), 
                                  (True, 10.0)])
s1 = pd.Series((0, 1, 2, 3), index = idx1)
s1.at[(False, 1.0)]   # returns '0', expected output

idx2 = pd.MultiIndex.from_tuples([(False,), (True,)])
s2 = pd.Series((0, 1), index = idx2)
s2.at[False]  # returns a pandas.Series with one element

Problem description

As per the user guide, I expect at[] to return a scalar. However, when I index a Series with a MultiIndex with only one level, at[] returns a Series with a single element. A Series with a multi-level MultiIndex works as expected.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : db08276
python : 3.6.12.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-54-generic
Version : #60-Ubuntu SMP Fri Nov 6 10:37:59 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.1.3
numpy : 1.19.2
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.4
setuptools : 50.3.1.post20201107
Cython : None
pytest : None
hypothesis : None
sphinx : 3.2.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.16.1
pandas_datareader: None
bs4 : None
bottleneck : 1.3.2
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.2
numexpr : 2.7.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@bpteague bpteague added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 25, 2020
@bpteague
Copy link
Author

I wonder if this is related to #29749?

@phofl
Copy link
Member

phofl commented Nov 25, 2020

Hi,

thanks for your report. #29749 did not fix this.

@phofl phofl added Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 25, 2020
@jreback jreback added this to the 1.2 milestone Nov 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants