Skip to content

Commit

Permalink
Revert "Remove conversion of categorical dtype columns"
Browse files Browse the repository at this point in the history
This reverts commit 5828b8f.
  • Loading branch information
binste committed Aug 1, 2023
1 parent 2a50f84 commit 580b190
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion altair/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,13 @@ def to_list_if_array(val):

for col_name, dtype in df.dtypes.items():
dtype_name = str(dtype)
if dtype_name == "string":
if dtype_name == "category":
# Work around bug in to_json for categorical types in older versions of pandas
# https://github.com/pydata/pandas/issues/10778
# https://github.com/altair-viz/altair/pull/2170
col = df[col_name].astype(object)
df[col_name] = col.where(col.notnull(), None)
elif dtype_name == "string":
# dedicated string datatype (since 1.0)
# https://pandas.pydata.org/pandas-docs/version/1.0.0/whatsnew/v1.0.0.html#dedicated-string-data-type
col = df[col_name].astype(object)
Expand Down

0 comments on commit 580b190

Please sign in to comment.