Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions cryosparc/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Any, Callable, ClassVar, Dict, Iterator, List, Optional, Tuple, TypedDict, Union

import httpx
from pydantic import BaseModel

from . import registry
from .errors import APIError
Expand Down Expand Up @@ -392,9 +393,9 @@ def _decode_json_response(value: Any, schema: dict):
return model_class(value)
elif model_class and issubclass(model_class, dict): # typed dict
return model_class(**value)
elif model_class: # pydantic model
elif model_class and issubclass(model_class, BaseModel): # pydantic model
# use model_validate in case validator result derives from subtype, e.g., Event model
return model_class.model_validate(value) # type: ignore
return model_class.model_validate(value)
warnings.warn(
f"[API] Warning: Received API response with unregistered schema type {schema['$ref']}. "
"Returning as plain object."
Expand Down
8 changes: 5 additions & 3 deletions cryosparc/dataset/dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ def get_data_field(data: Data, field: str) -> Field:

def get_data_field_dtype(data: Data, field: str) -> "DTypeLike":
t = data.type(field)
if t == 0 or t not in DSET_TO_TYPE_MAP:
raise KeyError(f"Unknown dataset field {field} or field type {t}")
dt = n.dtype(DSET_TO_TYPE_MAP[t])
if t == 0:
raise KeyError(f"Unknown dataset field {field}")
elif t not in DSET_TO_TYPE_MAP:
raise KeyError(f"Unknown dataset field type {t}")
dt = n.dtype(DSET_TO_TYPE_MAP[t]) # type: ignore
shape = data.getshp(field)
return (dt.str, shape) if shape else dt.str

Expand Down