Python 3.6.7 | packaged by conda-forge | (default, Nov 21 2018, 03:09:43)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import pandas as pd
In [2]: df = pd.DataFrame({('A_%d' % i): [i] for i in range(254)})
In [3]: r = df.to_dict('records')
In [4]: len(r)
Out[4]: 1
In [5]: len(r[0])
Out[5]: 254
In [6]: df_bad = pd.DataFrame({('A_%d' % i): [i] for i in range(255)})
In [7]: r_fail = df_bad.to_dict('records')
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-7-4dd3de569735> in <module>
----> 1 r_fail = df_bad.to_dict('records')
~/.conda/envs/pandas-0.24/lib/python3.6/site-packages/pandas/core/frame.py in to_dict(self, orient, into)
1300 into_c((k, com.maybe_box_datetimelike(v))
1301 for k, v in compat.iteritems(row._asdict()))
-> 1302 for row in self.itertuples(index=False)]
1303 elif orient.lower().startswith('i'):
1304 if not self.index.is_unique:
~/.conda/envs/pandas-0.24/lib/python3.6/site-packages/pandas/core/frame.py in <listcomp>(.0)
1300 into_c((k, com.maybe_box_datetimelike(v))
1301 for k, v in compat.iteritems(row._asdict()))
-> 1302 for row in self.itertuples(index=False)]
1303 elif orient.lower().startswith('i'):
1304 if not self.index.is_unique:
AttributeError: 'tuple' object has no attribute '_asdict'
Our test suite is failing with the latest release (0.24.0) on conda-forge. After looking into it, I've discovered that when 255 or more columns exist, the to_dict('records') method fails with AttributeError: 'tuple' object has no attribute '_asdict'.
Code Sample, a copy-pastable example if possible
Python 3.6.7 | packaged by conda-forge | (default, Nov 21 2018, 03:09:43) Type 'copyright', 'credits' or 'license' for more information IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: import pandas as pd In [2]: df = pd.DataFrame({('A_%d' % i): [i] for i in range(254)}) In [3]: r = df.to_dict('records') In [4]: len(r) Out[4]: 1 In [5]: len(r[0]) Out[5]: 254 In [6]: df_bad = pd.DataFrame({('A_%d' % i): [i] for i in range(255)}) In [7]: r_fail = df_bad.to_dict('records') --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-7-4dd3de569735> in <module> ----> 1 r_fail = df_bad.to_dict('records') ~/.conda/envs/pandas-0.24/lib/python3.6/site-packages/pandas/core/frame.py in to_dict(self, orient, into) 1300 into_c((k, com.maybe_box_datetimelike(v)) 1301 for k, v in compat.iteritems(row._asdict())) -> 1302 for row in self.itertuples(index=False)] 1303 elif orient.lower().startswith('i'): 1304 if not self.index.is_unique: ~/.conda/envs/pandas-0.24/lib/python3.6/site-packages/pandas/core/frame.py in <listcomp>(.0) 1300 into_c((k, com.maybe_box_datetimelike(v)) 1301 for k, v in compat.iteritems(row._asdict())) -> 1302 for row in self.itertuples(index=False)] 1303 elif orient.lower().startswith('i'): 1304 if not self.index.is_unique: AttributeError: 'tuple' object has no attribute '_asdict'Problem description
Our test suite is failing with the latest release (0.24.0) on conda-forge. After looking into it, I've discovered that when 255 or more columns exist, the
to_dict('records')method fails withAttributeError: 'tuple' object has no attribute '_asdict'.Conda info
Details
Output of
pd.show_versions()Details