JuliaPy / JuliaPy/PythonCall.jl

pandas.Categorical not preserved during DataFrame conversion and jl.convert fails

Ouverte
#630 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
question
Langage dominant
Julia
Étoiles
1.1k
Forks
86
Merge moyen
1 j 22 h
PR mergées (30 j)
3

Description

Hi and thanks for the great package!

While working with `juliacall` + `PythonCall.jl`, I ran into two issues related to pandas.Categorical handling.

(In all examples below, `jl`refers to Main from `juliacall`, i.e., f`rom juliacall import Main as jl`.)

**DataFrame conversion ignores Categorical columns**
When passing a `pandas.DataFrame` with categorical columns (i.e., `dtype='category'`), those columns are silently converted to `Int64` vectors in Julia (presumably the .codes). This results in CategoricalArray semantics being lost — so interactions in Julia formulas like `id & η1` are treated as numeric rather than generating dummy variables.

**`jl.convert()` can’t convert pandas.Categorical to any Julia type**
I tried using `jl.convert(CategoricalArray, col)` directly on a `pandas.Series` with categorical dtype, but got a `MethodError`. It appears `PythonCall` doesn’t yet support converting `pandas.Categorical` to any Julia-native type.

To work around this, I convert the column to `str` in Python (so it arrives as a `Vector{String}`), then manually wrap it in `categorical(...)` on the Julia side. This works, but it's not ideal for type fidelity or automatic translation.

Let me know if there's a cleaner workaround — or if you'd be open to a PR to improve automatic `CategoricalArray` support.

Thanks again!

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Start with the pandas.DataFrame conversion path and the jl.convert(CategoricalArray, col) case described in the issue. Trace how pandas.Categorical columns are represented, then verify that conversion preserves CategoricalArray semantics and that direct conversion no longer fails.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
pandas, python
Domaine
data
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.