dovpanda icon indicating copy to clipboard operation
dovpanda copied to clipboard

Bug - object has no attribute 'shape'

Open AmeenAli opened this issue 6 years ago • 5 comments

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'

AmeenAli avatar Nov 18 '19 14:11 AmeenAli

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'

frenzymadness avatar Nov 28 '19 06:11 frenzymadness

Also, could you please change the bug title to contain object has no attribute 'shape' so other people can find it easily?

frenzymadness avatar Nov 28 '19 06:11 frenzymadness

.loc way does not work as well. With the df containing strings in cells, this does not work: df.loc[2, "b"]

frenzymadness avatar Nov 28 '19 06:11 frenzymadness

.loc way 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.

AmeenAli avatar Nov 28 '19 06:11 AmeenAli

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.

DeanLa avatar Dec 01 '19 16:12 DeanLa