Skip to content

DataFrame.iat indexing with duplicate columns #11754

Closed
@wavexx

Description

@wavexx
# error
In [27]: pd.DataFrame([[1, 1]], columns=['x','x']).iat[0,0]
TypeError: len() of unsized object

# ok
In [26]: pd.DataFrame([[1, 1]], columns=['x','y']).iat[0,0]
Out[26]: 1

I have some weird issue in a DataFrame I'm creating from a row-based array.
Using python3 and pandas 0.17.1 (from debian unstable), I get:

df = pandas.DataFrame(data=data[1:], columns=data[0])
df.iat[0, 0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/pandas/core/indexing.py", line 1555, in __getitem__
    return self.obj.get_value(*key, takeable=self._takeable)
  File "/usr/lib/python3/dist-packages/pandas/core/frame.py", line 1808, in get_value
    series = self._iget_item_cache(col)
  File "/usr/lib/python3/dist-packages/pandas/core/generic.py", line 1116, in _iget_item_cache
    lower = self.take(item, axis=self._info_axis_number, convert=True)
  File "/usr/lib/python3/dist-packages/pandas/core/generic.py", line 1371, in take
    convert=True, verify=True)
  File "/usr/lib/python3/dist-packages/pandas/core/internals.py", line 3628, in take
    axis=axis, allow_dups=True)
  File "/usr/lib/python3/dist-packages/pandas/core/internals.py", line 3510, in reindex_indexer
    indexer, fill_tuple=(fill_value,))
  File "/usr/lib/python3/dist-packages/pandas/core/internals.py", line 3536, in _slice_take_blocks_ax0
    slice_or_indexer, self.shape[0], allow_fill=allow_fill)
  File "/usr/lib/python3/dist-packages/pandas/core/internals.py", line 4865, in _preprocess_slice_or_indexer
    return 'fancy', indexer, len(indexer)
TypeError: len() of unsized object

Interestingly, I can otherwise manage the dataframe just fine.
The same code, running under python2.7 shows no issue.

What could be the cause of such error?

Metadata

Metadata

Assignees

No one assigned

    Labels

    IndexingRelated to indexing on series/frames, not to indexes themselvesNeeds TestsUnit test(s) needed to prevent regressionsgood first issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions