Skip to content

Commit

Permalink
fix(pandas): fix struct inference from dict in the pandas backend
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and kszucs committed Jun 7, 2022
1 parent 04fe2ca commit 5886a9a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ibis/backends/pandas/client.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
"""The pandas client implementation."""

from collections.abc import Mapping, Sequence

import numpy as np
import pandas as pd
import toolz
from pandas.api.types import CategoricalDtype, DatetimeTZDtype

import ibis.common.exceptions as com
import ibis.expr.datatypes as dt
import ibis.expr.operations as ops
import ibis.expr.schema as sch
Expand Down Expand Up @@ -139,9 +142,16 @@ def _infer_pandas_series_contents(s: pd.Series) -> dt.DataType:
if inferred_dtype == 'mixed':
# We need to inspect an element to determine the Ibis dtype
value = s.iloc[0]
if isinstance(value, (np.ndarray, list, pd.Series)):
if isinstance(value, (np.ndarray, pd.Series, Sequence)):
# Defer to individual `infer` functions for these
return dt.infer(value)
elif isinstance(value, Mapping):
try:
return dt.infer(value)
except com.IbisTypeError:
return dt.Struct.from_tuples(
(k, dt.infer(v)) for k, v in value.items()
)
else:
return dt.dtype('binary')
else:
Expand Down

0 comments on commit 5886a9a

Please sign in to comment.