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

Import Pandas returns KeyError #1

Closed
krish240574 opened this issue Feb 18, 2018 · 11 comments
Closed

Import Pandas returns KeyError #1

krish240574 opened this issue Feb 18, 2018 · 11 comments

Comments

@krish240574
Copy link

krish240574 commented Feb 18, 2018

py←⎕New Py.Py

py.Import'pandas'
DOMAIN ERROR: KeyError('call',)
py.Import'pandas'
When I try to import 'pandas' as above, I keep getting a DOMAIN ERROR.
pandas is installed and working fine, I've double-checked.

Other imports work fine -
np←py.Import'numpy'
np
<module 'numpy' from '/opt/A3/lib/python3.6/site-packages/numpy/init.py'>

plt←py.Import'matplotlib'
plt
<module 'matplotlib' from '/opt/A3/lib/python3.6/site-packages/matplotlib/init.py'>

@jayfoad
Copy link
Contributor

jayfoad commented Feb 20, 2018

Thanks for the report. I can reproduce this. Any ideas, @marinuso ?

@jayfoad
Copy link
Contributor

jayfoad commented Feb 20, 2018

Can you try to work around the problem by doing py.Exec'import pandas' instead?

py.Import tries to return a result. res←py.Import'foo' is more or less equivalent to:

py.Exec'import foo'
res←py.Eval'foo'

For reasons I don't understand yet, it's only the second line that is failing with pandas.

@krish240574
Copy link
Author

krish240574 commented Feb 20, 2018 via email

@jayfoad
Copy link
Contributor

jayfoad commented Feb 20, 2018

This works for me on Ubuntu 17.10:

Dyalog APL/S-64 Version 16.0.32246
Unicode Edition
Tue Feb 20 09:21:49 2018
      ]load Py
#.Py
      py←⎕NEW Py.Py
      py.Import'sys' ⋄ py.Eval'sys.version'
3.6.3 (default, Oct  3 2017, 21:45:48)
[GCC 7.2.0]
      py.Exec'import pandas as pd'
      py.Eval'pd.Series([1,3,5,np.nan,6,8])'
 1.0  3.0  5.0  nan  6.0  8.0

At what point do you get an error?

@krish240574
Copy link
Author

krish240574 commented Feb 20, 2018 via email

@jayfoad
Copy link
Contributor

jayfoad commented Feb 20, 2018

What I
intend to do is to get 'pandas' into APL and use its methods, like Marinuso
explained in his youtube video - having to do an 'Eval' each time defeats
the purpose, IMHO.

Understood. I'm just trying to narrow down where the problem occurs.

@krish240574
Copy link
Author

krish240574 commented Feb 20, 2018 via email

@jayfoad
Copy link
Contributor

jayfoad commented Feb 20, 2018

I believe this is really a bug in the pandas code:

>>> import pandas
>>> getattr(pandas.options,'__call__')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/pandas/core/config.py", line 199, in __getattr__
    v = object.__getattribute__(self, "d")[key]
KeyError: '__call__'

getattr calls a custom __getattr__ method which is supposed to return a value or raise AttributeError, not raise KeyError.

This commit looks relevant: pandas-dev/pandas@63fc8af

However, since this bug is out there in the wild, I'll tweak pynapl to tolerate it and do the right thing.

@krish240574
Copy link
Author

krish240574 commented Feb 20, 2018 via email

@jayfoad
Copy link
Contributor

jayfoad commented Feb 20, 2018

No problem. I have raised an issue with pandas here: pandas-dev/pandas#19789

@krish240574
Copy link
Author

krish240574 commented Feb 20, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants