Skip to content

BUG: read_json -> 'DataFrame' object has no attribute 'dtype' #4377

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
Komnomnomnom opened this issue Jul 27, 2013 · 4 comments · Fixed by #4388
Closed

BUG: read_json -> 'DataFrame' object has no attribute 'dtype' #4377

Komnomnomnom opened this issue Jul 27, 2013 · 4 comments · Fixed by #4388
Assignees
Labels
Indexing Related to indexing on series/frames, not to indexes themselves IO Data IO issues that don't fit into a more specific label IO JSON read_json, to_json, json_normalize
Milestone

Comments

@Komnomnomnom
Copy link
Contributor

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)
<ipython-input-11-aaa9a429e682> in <module>()
----> 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'
@jreback
Copy link
Contributor

jreback commented Jul 27, 2013

it is expecting the object to be a series at that point....let me look

@jreback
Copy link
Contributor

jreback commented Jul 27, 2013

actually this is a problem with iterating over the duplicate columns that are read back...easy fix

@Komnomnomnom
Copy link
Contributor Author

Nice, thanks @jreback!

@jreback
Copy link
Contributor

jreback commented Jul 30, 2013

turns out I discovered another bug with this...but all fixed up now...thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves IO Data IO issues that don't fit into a more specific label IO JSON read_json, to_json, json_normalize
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants