Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmmease committed Sep 30, 2023
1 parent 19bd5a5 commit f445e9d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions altair/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,10 @@ def parse_shorthand(
column = dfi.get_column_by_name(unescaped_field)
try:
attrs["type"] = infer_vegalite_type_for_dfi_column(column)
except NotImplementedError:
# Fall back to pandas-based inference
except (NotImplementedError, AttributeError):
# Fall back to pandas-based inference.
# Note: The AttributeError catch is a workaround for
# https://github.com/pandas-dev/pandas/issues/55332
if isinstance(data, pd.DataFrame):
attrs["type"] = infer_vegalite_type(data[unescaped_field])
else:
Expand Down
2 changes: 2 additions & 0 deletions tests/utils/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def check(s, data, **kwargs):
{
"x": [1, 2, 3, 4, 5],
"y": ["A", "B", "C", "D", "E"],
"b": pd.Series([True, False, True, False, None], dtype="boolean"),
"z": pd.date_range("2018-01-01", periods=5, freq="D"),
"t": pd.date_range("2018-01-01", periods=5, freq="D").tz_localize("UTC"),
}
Expand All @@ -153,6 +154,7 @@ def check(s, data, **kwargs):

check("x", data, field="x", type="quantitative")
check("y", data, field="y", type="nominal")
check("b", data, field="b", type="nominal")
check("z", data, field="z", type="temporal")
check("t", data, field="t", type="temporal")
check("count(x)", data, field="x", aggregate="count", type="quantitative")
Expand Down

0 comments on commit f445e9d

Please sign in to comment.