Skip to content

Commit

Permalink
check ifattr exists
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenv committed Sep 11, 2023
1 parent 99f2049 commit 29b6982
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions apis/python/src/tiledbsoma/_arrow_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,14 @@ def df_to_arrow(df: pd.DataFrame) -> pa.Table:
for key in df:
column = df[key]
if is_categorical_dtype(column.dtype):
column = column.astype("category")
df[key] = pd.core.arrays.categorical.Categorical(
values=column,
categories=column.categories,
ordered=bool(column.ordered),
if hasattr(column.values, "categories"):
categories = column.values.categories

if hasattr(column.values, "ordered"):
ordered = column.values.ordered

df[key] = pd.Categorical(
values=column, categories=categories, ordered=ordered
)

arrow_table = pa.Table.from_pandas(df)
Expand Down

0 comments on commit 29b6982

Please sign in to comment.