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

Orange.data.Table.from_pandas_dfs() causes AttributeError: 'DataFrame' object has no attribute 'orange_attributes' #5622

Closed
hcchengithub opened this issue Oct 4, 2021 · 4 comments · Fixed by #5652
Assignees
Labels
bug A bug confirmed by the core team

Comments

@hcchengithub
Copy link

hcchengithub commented Oct 4, 2021

What's wrong?
Orange.data.Table.from_pandas_dfs() requires 'orange_attributes' in the given DataFrame <--- problem!! Chicken-egg paradox

How can we reproduce the problem?
Run the below snippet to see the problem

# Jupyter notebook
import pandas as pd
import Orange
area = pd.Series({'California': 423967.12345, 'Texas': 695662.56789,
                  'Florida': 170312.43219,
                  'Illinois': 149995.34543})
pop = pd.Series({'Illinois': 12882135, 'Texas': 26448193,
                 'New York': 19651127, 'Florida': 19552860
                 })
data = pd.DataFrame({'area':area, 'pop':pop})
display(data)

data["M"] = ""  # is there a better way to express mdf and ydf as nothing? 
data["Y"] = ""
dataTable = Orange.data.Table.from_pandas_dfs(data, pd.DataFrame(data['Y']),pd.DataFrame(data['M']))

Result:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_39172/3276878460.py in <module>
     11 data["Y"] = ""
     12 
---> 13 dataTable = Orange.data.Table.from_pandas_dfs(data, pd.DataFrame(data['Y']),pd.DataFrame(data['M']))

~\AppData\Local\Continuum\anaconda3\envs\Orange3\lib\site-packages\Orange\data\table.py in from_pandas_dfs(xdf, ydf, mdf)
    760     @staticmethod
    761     def from_pandas_dfs(xdf, ydf, mdf):
--> 762         return Orange.data.pandas_compat.table_from_frames(xdf, ydf, mdf)
    763 
    764     @property

~\AppData\Local\Continuum\anaconda3\envs\Orange3\lib\site-packages\Orange\data\pandas_compat.py in table_from_frames(xdf, ydf, mdf)
    407         else:
    408             W = None
--> 409         attributes.update(df.orange_attributes)
    410 
    411     return Table.from_numpy(

~\AppData\Local\Continuum\anaconda3\envs\Orange3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
   5485         ):
   5486             return self[name]
-> 5487         return object.__getattribute__(self, name)
   5488 
   5489     def __setattr__(self, name: str, value) -> None:

AttributeError: 'DataFrame' object has no attribute 'orange_attributes'

What's your environment?

  • Operating system: Windows 10
  • Orange version: '3.30.1'
  • How you installed Orange: conda install oragne3
@hcchengithub hcchengithub added the bug report Bug is reported by user, not yet confirmed by the core team label Oct 4, 2021
@JakaKokosar
Copy link
Member

Hi, try this

from Orange.data.pandas_compat import table_from_frame

dataTable = table_from_frame(data)

@markotoplak markotoplak added bug A bug confirmed by the core team and removed bug report Bug is reported by user, not yet confirmed by the core team labels Oct 4, 2021
@markotoplak
Copy link
Member

Thanks for bringing this chicken and egg problem to our attention. It is indeed a needless limitation and I think should get fixed.

@PrimozGodec PrimozGodec self-assigned this Oct 4, 2021
@PrimozGodec
Copy link
Contributor

I can fix this issue when fixing #5620

@hcchengithub
Copy link
Author

Hi, try this

from Orange.data.pandas_compat import table_from_frame

dataTable = table_from_frame(data)

Yeah! the obstacle in front can be resolved this way. Thank you very much!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug confirmed by the core team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants