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

Converting pytable to DataFrame fails on v0.9 #180

Closed
czimm79 opened this issue Jun 8, 2022 · 1 comment
Closed

Converting pytable to DataFrame fails on v0.9 #180

czimm79 opened this issue Jun 8, 2022 · 1 comment

Comments

@czimm79
Copy link

czimm79 commented Jun 8, 2022

Converting from a julia DataFrame to a pytable then back to a DataFrame works as expected on PythonCall v0.8.

#PythonCall v0.8
a = DataFrame(A=1:4, B=["M", "F", "F", "M"])
b = pytable(a)
c = DataFrame(b)

c == a  # true

However, with v0.9, c is a 2x80 DataFrame with columns with names such as "__eq__" "capitalize" "format" "rsplit" "__contains__""__iter__" "__new__".

@cjdoris
Copy link
Collaborator

cjdoris commented Jun 9, 2022

Indeed this is one of the breaking changes in v0.9 (see point 4 here). You should do c = DataFrame(PyTable(b)) or c = DataFrame(PyPandasDataFrame(b)) instead.

This change is to make the behaviour of Python tables more consistent with the rest of the PythonCall API: a Python int is not considered a Julia Integer, and a Python list is not a Julia AbstractVector, so a Python table is not a Julia table. You use wrapper types (such as PyList or PyTable) or pyconvert to get objects satisfying Julia interfaces.

The fact you get that odd 2x80 DataFrame is due to the fact that Tables.columns(x) falls back to iterating over x, treating each item as a row, and treating its properties as columns. In the case of pandas dataframes, iteration returns the column names, so you get two rows (from the two columns "A" and "B" of the input) and the columns are the attributes of str!

@cjdoris cjdoris closed this as completed Jun 9, 2022
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