AREPL-vscode icon indicating copy to clipboard operation
AREPL-vscode copied to clipboard

pandas not working when printing dataframes

Open Almenon opened this issue 3 years ago • 2 comments

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 avatar Jun 24 '21 15:06 Almenon

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 avatar Jun 24 '21 15:06 Almenon

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.

Almenon avatar Oct 03 '21 19:10 Almenon