Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fallback to default feature casting in case custom features not available during dataset loading #7224

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/datasets/features/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -1788,7 +1788,12 @@ def from_arrow_schema(cls, pa_schema: pa.Schema) -> "Features":
if pa_schema.metadata is not None and "huggingface".encode("utf-8") in pa_schema.metadata:
metadata = json.loads(pa_schema.metadata["huggingface".encode("utf-8")].decode())
if "info" in metadata and "features" in metadata["info"] and metadata["info"]["features"] is not None:
metadata_features = Features.from_dict(metadata["info"]["features"])
try:
metadata_features = Features.from_dict(metadata["info"]["features"])
except Exception as e:
logger.warning(
f"Warning: failed to load features from Arrow schema metadata: {e}, decoding may not be as intended"
)
metadata_features_schema = metadata_features.arrow_schema
obj = {
field.name: (
Expand Down
8 changes: 7 additions & 1 deletion src/datasets/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,13 @@ def _to_yaml_dict(self) -> dict:
def _from_yaml_dict(cls, yaml_data: dict) -> "DatasetInfo":
yaml_data = copy.deepcopy(yaml_data)
if yaml_data.get("features") is not None:
yaml_data["features"] = Features._from_yaml_list(yaml_data["features"])
try:
yaml_data["features"] = Features._from_yaml_list(yaml_data["features"])
except Exception as e:
logger.warning(
f"Warning: failed to load features from Arrow schema metadata: {e}, decoding may not be as intended"
)
del yaml_data["features"]
if yaml_data.get("splits") is not None:
yaml_data["splits"] = SplitDict._from_yaml_list(yaml_data["splits"])
field_names = {f.name for f in dataclasses.fields(cls)}
Expand Down