Skip to content
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

Bug - object has no attribute 'shape' #103

Open
AmeenAli opened this issue Nov 18, 2019 · 5 comments
Open

Bug - object has no attribute 'shape' #103

AmeenAli opened this issue Nov 18, 2019 · 5 comments
Labels
bug Something isn't working

Comments

@AmeenAli
Copy link

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 AmeenAli added the bug Something isn't working label Nov 18, 2019
@frenzymadness
Copy link

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
Copy link

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

@AmeenAli AmeenAli changed the title Bug Bug - object has no attribute 'shape' Nov 28, 2019
@frenzymadness
Copy link

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

@AmeenAli
Copy link
Author

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

@DeanLa
Copy link
Member

DeanLa commented Dec 1, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants