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

pandas not working when printing dataframes #404

Open
Almenon opened this issue Jun 24, 2021 · 2 comments
Open

pandas not working when printing dataframes #404

Almenon opened this issue Jun 24, 2021 · 2 comments
Labels

Comments

@Almenon
Copy link
Owner

Almenon commented Jun 24, 2021

Describe the bug
Pandas does not work when printing multiple columns of dataframes

To Reproduce
Steps to reproduce the behavior:

import pandas as pd
cafes = pd.DataFrame({
'zip': [30324,],
'poc': ['jared', ]
})

# this works
print(cafes['zip'])
print('------')
print(cafes['poc'])

# this doesn't
print(cafes[['zip', 'poc']])

Expected behavior
Pandas prints without error as it does when running in the terminal

Other Information (please complete the following information):

  • OS: Win10
  • Python Version: 3.6

Additional context
It's weird because usually errors happen the second or third run, but this error happens immediately. So it's not related to the module or jsonpickle logic.

Error:

Traceback (most recent call last):
  line 14, in <module>
  File "C:\Users\almenon\AppData\Roaming\Python\Python36\site-packages\pandas\core\frame.py", line 2806, in __getitem__
    indexer = self.loc._get_listlike_indexer(key, axis=1, raise_missing=True)[1]
  File "C:\Users\almenon\AppData\Roaming\Python\Python36\site-packages\pandas\core\indexing.py", line 1552, in _get_listlike_indexer
    keyarr, indexer, o._get_axis_number(axis), raise_missing=raise_missing
  File "C:\Users\almenon\AppData\Roaming\Python\Python36\site-packages\pandas\core\indexing.py", line 1634, in _validate_read_indexer
    missing = (indexer < 0).sum()
  File "C:\Users\almenon\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy\core\_methods.py", line 47, in _sum
    return umr_sum(a, axis, dtype, out, keepdims, initial, where)
TypeError: int() argument must be a string, a bytes-like object or a number, not '_NoValueType'
@Almenon Almenon added the bug Something isn't working label Jun 24, 2021
@Almenon
Copy link
Owner Author

Almenon commented Jun 24, 2021

Just doing a normal exec works 🤔 why does my exec fail?

code = """
import pandas as pd
cafes = pd.DataFrame({
'zip': [30324,],
'poc': ['jared', ]
})

# this works
print(cafes['zip'])
print('------')
print(cafes['poc'])

# this doesn't
print(cafes[['zip', 'poc']])
"""

exec(code)

@Almenon
Copy link
Owner Author

Almenon commented Oct 3, 2021

Using runcontext also works:

locals = {}
import contextvars
run_context = contextvars.Context()
run_context.run(exec, code, locals)

The pandas code works in AREPL if python version 3.7 or above. This is still an issue with 3.6 but at least it has a workaround.

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

No branches or pull requests

1 participant