BUG: read_json -> 'DataFrame' object has no attribute 'dtype' · Issue #4377 · pandas-dev/pandas (original) (raw)
Came across this when creating #4376. Not sure what's going on as I was under the impression that DataFrame always has a dtype
attribute.
The error only seems to occur when the columns are not unique:
In [5]: import pandas as pd
In [6]: df = pd.DataFrame([['a','b'],['c','d']], index=[1,2], columns=['x','y'])
In [7]: df Out[7]: x y 1 a b 2 c d
In [8]: pd.read_json(df.to_json(orient='split'), orient='split') Out[8]: x y 1 a b 2 c d
In [9]: df = pd.DataFrame([['a','b'],['c','d']], index=[1,2], columns=['x','x'])
In [10]: df Out[10]: x x 1 a b 2 c d
In [11]: pd.read_json(df.to_json(orient='split'), orient='split')
AttributeError Traceback (most recent call last) in () ----> 1 pd.read_json(df.to_json(orient='split'), orient='split')
/home/kieran/work/git/pandas_kom/pandas/io/json.pyc in read_json(path_or_buf, orient, typ, dtype, convert_axes, convert_dates, keep_default_dates, numpy, precise_float) 196 obj = None 197 if typ == 'frame': --> 198 obj = FrameParser(json, orient, dtype, convert_axes, convert_dates, keep_default_dates, numpy).parse() 199 200 if typ == 'series' or obj is None:
/home/kieran/work/git/pandas_kom/pandas/io/json.pyc in parse(self) 241 if self.convert_axes: 242 self._convert_axes() --> 243 self._try_convert_types() 244 return self.obj 245
/home/kieran/work/git/pandas_kom/pandas/io/json.pyc in _try_convert_types(self) 453 self._try_convert_dates() 454 for col in self.obj.columns: --> 455 new_data, result = self._try_convert_data(col, self.obj[col], convert_dates=False) 456 if result: 457 self.obj[col] = new_data
/home/kieran/work/git/pandas_kom/pandas/io/json.pyc in _try_convert_data(self, name, data, use_dtypes, convert_dates) 282 result = False 283 --> 284 if data.dtype == 'object': 285 286 # try float
/home/kieran/work/git/pandas_kom/pandas/core/frame.pyc in getattr(self, name) 2086 return self[name] 2087 raise AttributeError("'%s' object has no attribute '%s'" % -> 2088 (type(self).name, name)) 2089 2090 def setattr(self, name, value):
AttributeError: 'DataFrame' object has no attribute 'dtype'