Skip to content

Commit

Permalink
check for instance DataFrameLike instead of __dataframe__ attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
mattijn committed Mar 24, 2024
1 parent 7feefd5 commit c119d1e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion altair/utils/_vegafusion_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def vegafusion_data_transformer(
# Use default transformer for geo interface objects
# # (e.g. a geopandas GeoDataFrame)
return default_data_transformer(data)
elif hasattr(data, "__dataframe__"):
elif isinstance(data, DataFrameLike):
table_name = f"table_{uuid.uuid4()}".replace("-", "_")
extracted_inline_tables[table_name] = data
return {"url": VEGAFUSION_PREFIX + table_name}
Expand Down
2 changes: 1 addition & 1 deletion altair/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ def parse_shorthand(

# if data is specified and type is not, infer type from data
if "type" not in attrs:
if pyarrow_available() and data is not None and hasattr(data, "__dataframe__"):
if pyarrow_available() and data is not None and isinstance(data, DataFrameLike):
dfi = data.__dataframe__()
if "field" in attrs:
unescaped_field = attrs["field"].replace("\\", "")
Expand Down
4 changes: 2 additions & 2 deletions altair/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ def to_values(data: DataType) -> ToValuesReturnType:


def check_data_type(data: DataType) -> None:
if not isinstance(data, (dict, pd.DataFrame)) and not any(
hasattr(data, attr) for attr in ["__geo_interface__", "__dataframe__"]
if not isinstance(data, (dict, pd.DataFrame, DataFrameLike)) and not any(
hasattr(data, attr) for attr in ["__geo_interface__"]
):
raise TypeError(
"Expected dict, DataFrame or a __geo_interface__ attribute, got: {}".format(
Expand Down
2 changes: 1 addition & 1 deletion altair/vegalite/v5/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _prepare_data(data, context=None):
elif isinstance(data, str):
data = core.UrlData(data)

elif hasattr(data, "__dataframe__"):
elif isinstance(data, DataFrameLike):
data = _pipe(data, data_transformers.get())

# consolidate inline data to top-level datasets
Expand Down

0 comments on commit c119d1e

Please sign in to comment.