Bug - object has no attribute 'shape'
Brief Description
When the value of a key in a Series is of type dictionary, accessing the key in the following way raises an exception: s['dictionary']
System Information
python 3.6 ubuntu 18.04LTS
Minimally Reproducible Code
x=pd.DataFrame({'dictionary':[{100: 1, 200: 2}]})
s = x.iloc[0]
s['dictionary']
when this works fine:
x=pd.DataFrame({'dictionary':[{100: 1, 200: 2}]})
s = x.iloc[0]
s.dictionary
Error Messages
~/anaconda3/lib/python3.6/site-packages/dovpanda/core.py in suggest_at_iat(res, arguments) 186 def suggest_at_iat(res, arguments): 187 self = arguments.get('self') --> 188 shp = res.shape 189 if res.ndim < 1: # Sometimes specific slicing will return value 190 return
AttributeError: 'dict' object has no attribute 'shape'
I can confirm this bug also when I try to get one value from DataFrame in this way:
dataframe["columnname"][rowindex]
During creating a reproducer, I've found out that the error occurs only when the content of a cell is string. So this works:
df = pd.DataFrame([{"a": 1, "b": 2}, {"a": 3, "b": 4}, {"a": 5, "b": 6}])
df["b"][2]
6
But this fails:
df = pd.DataFrame([{"a": "Jon", "b": "Doe"}, {"a": "Jan", "b": "Novak"}, {"a": "Jose", "b": "Chalapeno"}])
df["b"][2]
AttributeError Traceback (most recent call last)
<ipython-input-26-dd9fedfb86fd> in <module>
1 df = pd.DataFrame([{"a": "Jon", "b": "Doe"}, {"a": "Jan", "b": "Novak"}, {"a": "Jose", "b": "Chalapeno"}])
----> 2 df["b"][2]
~/.virtualenvs/data_analysis/lib/python3.7/site-packages/dovpanda/base.py in run(*args, **kwargs)
161 for post in posts:
162 if self.similar <= post.stop_nudge:
--> 163 post.replacement(ret, arguments)
164 return ret
165
~/.virtualenvs/data_analysis/lib/python3.7/site-packages/dovpanda/core.py in suggest_at_iat(res, arguments)
186 def suggest_at_iat(res, arguments):
187 self = arguments.get('self')
--> 188 shp = res.shape
189 if res.ndim < 1: # Sometimes specific slicing will return value
190 return
AttributeError: 'str' object has no attribute 'shape'
Also, could you please change the bug title to contain object has no attribute 'shape' so other people can find it easily?
.loc way does not work as well. With the df containing strings in cells, this does not work:
df.loc[2, "b"]
.locway does not work as well. With the df containing strings in cells, this does not work:df.loc[2, "b"]
Yes, I have tried also, hope this get fixed soon.
Thanks for the report. This will be fixed for the next version. In the meantime, if you upgrade to v 0.0.5 dovpanda will alert of the bug but will not crash your code.