Skip to content

Accessor behavior variances with multiindex #19916

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
allComputableThings opened this issue Feb 26, 2018 · 4 comments
Closed

Accessor behavior variances with multiindex #19916

allComputableThings opened this issue Feb 26, 2018 · 4 comments
Labels
Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex

Comments

@allComputableThings
Copy link

allComputableThings commented Feb 26, 2018

Code Sample, a copy-pastable example if possible

def gen():
    yield '1','2',1,2
    yield '1','2',1,2
    yield '1','3',3,2
    yield '2','4',1,2

ser = pd.DataFrame(gen(), columns=["a", "b", "c", "d",]).set_index(["a", "b"])["c"]
print ser

print ser.loc[('1','3')]
print ser.at[('1','3')]  # TypeError: _get_value() got multiple values for keyword argument 'takeable'

Problem description

The .at accessor should return the indexed value 3.

There doesn't seem any way reliably look up a single scalar in a multiindex. If this is not supported, a better error would be appreciated.

Expected Output

3

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 2.7.6.final.0
python-bits: 64
OS: Linux
OS-release: 3.13.0-24-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: None.None

pandas: 0.22.0
pytest: None
pip: 9.0.1
setuptools: 36.0.1
Cython: 0.27.3
numpy: 1.14.0
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 5.3.0
sphinx: None
patsy: 0.2.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: 3.1.1
numexpr: 2.6.2
feather: None
matplotlib: 2.0.2
openpyxl: 1.7.0
xlrd: 0.9.2
xlwt: 0.7.5
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999999999
sqlalchemy: 1.0.15
pymysql: None
psycopg2: 2.7.3.2 (dt dec pq3 ext lo64)
jinja2: 2.9.6
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@allComputableThings
Copy link
Author

Seems related to: #9259

@allComputableThings
Copy link
Author

allComputableThings commented Feb 26, 2018

An expanded example with even more weirdness.

It seems that, if I want to assign a new row, or lookup an existing row in a series or dataframe, I need to choose different accessors depending on whether the multindex label is defined for all indexes.

def gen():
    yield 's',None,'sval'

ser = pd.DataFrame(gen(), columns=["a", "b", "c", ]).set_index(["a", "b"])["c"]
print ser

# Writing ---

#ser[('s1',)] = "z" # AttributeError: 'float' object has no attribute 'axes'
ser.at[('s2',)] = "z" # success
#ser.loc[('s3',)] = "z" # AttributeError: 'float' object has no attribute 'axes'

ser[('s4','x')] = "z" # success
#ser.at[('s5','x')] = "z" # ValueError: Not enough indexers for scalar access (setting)!
ser.loc[('s6','x')] = "z" # success

# Reading ---

print type(ser.loc[('s6','x')])  # Success => scalar
#print type(ser.at[('s6','x')])  # _get_value() got multiple values for keyword argument 'takeable'
print type(ser[('s6','x')])    # Success => scalar

print type(ser.loc[('s2',)])  # Success => series
#print type(ser.at[('s2',)])  # AttributeError: 'numpy.ndarray' object has no attribute '_values'
print type(ser[('s2',)])      # Success => series

@allComputableThings allComputableThings changed the title TypeError in Series.at with multiindex Accessor behavior variances with multiindex Feb 26, 2018
@jreback
Copy link
Contributor

jreback commented Feb 27, 2018

this is a duplicate of #9259

.iat/.at are not too multi-index aware currently.

@jreback jreback closed this as completed Feb 27, 2018
@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves Duplicate Report Duplicate issue or pull request MultiIndex labels Feb 27, 2018
@jreback jreback added this to the No action milestone Feb 27, 2018
@allComputableThings
Copy link
Author

allComputableThings commented Feb 27, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex
Projects
None yet
Development

No branches or pull requests

2 participants