|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import json as js |
6 | | -from dataclasses import dataclass, field, fields |
| 6 | +from dataclasses import MISSING, dataclass, field, fields |
7 | 7 | from typing import TYPE_CHECKING, Any |
8 | 8 |
|
9 | 9 | import pandas as pd |
@@ -314,7 +314,55 @@ def _from_dict(cls: type[Dataset], data: dict[str, Any]) -> Dataset: |
314 | 314 | data = {k: v for k, v in data.items() if k in keys} |
315 | 315 | if "type" in data: |
316 | 316 | data["type_"] = data.pop("type") |
317 | | - return cls(**data) |
| 317 | + field_map = {field_.name: field_ for field_ in fields(cls)} |
| 318 | + |
| 319 | + def _value(name: str) -> Any: |
| 320 | + if name in data: |
| 321 | + return data[name] |
| 322 | + field_ = field_map[name] |
| 323 | + if field_.default_factory is not MISSING: |
| 324 | + return field_.default_factory() |
| 325 | + return field_.default |
| 326 | + |
| 327 | + return cls( |
| 328 | + identifier=data["identifier"], |
| 329 | + title=_value("title"), |
| 330 | + category=_value("category"), |
| 331 | + description=_value("description"), |
| 332 | + frequency=_value("frequency"), |
| 333 | + is_internal_only_dataset=_value("is_internal_only_dataset"), |
| 334 | + is_third_party_data=_value("is_third_party_data"), |
| 335 | + is_restricted=_value("is_restricted"), |
| 336 | + is_raw_data=_value("is_raw_data"), |
| 337 | + maintainer=_value("maintainer"), |
| 338 | + source=_value("source"), |
| 339 | + region=_value("region"), |
| 340 | + publisher=_value("publisher"), |
| 341 | + product=_value("product"), |
| 342 | + sub_category=_value("sub_category"), |
| 343 | + tags=_value("tags"), |
| 344 | + created_date=_value("created_date"), |
| 345 | + modified_date=_value("modified_date"), |
| 346 | + delivery_channel=_value("delivery_channel"), |
| 347 | + language=_value("language"), |
| 348 | + status=_value("status"), |
| 349 | + type_=_value("type_"), |
| 350 | + container_type=_value("container_type"), |
| 351 | + snowflake=_value("snowflake"), |
| 352 | + complexity=_value("complexity"), |
| 353 | + is_immutable=_value("is_immutable"), |
| 354 | + is_mnpi=_value("is_mnpi"), |
| 355 | + is_pci=_value("is_pci"), |
| 356 | + is_pii=_value("is_pii"), |
| 357 | + is_client=_value("is_client"), |
| 358 | + is_public=_value("is_public"), |
| 359 | + is_internal=_value("is_internal"), |
| 360 | + is_confidential=_value("is_confidential"), |
| 361 | + is_highly_confidential=_value("is_highly_confidential"), |
| 362 | + is_active=_value("is_active"), |
| 363 | + owners=_value("owners"), |
| 364 | + application_id=_value("application_id"), |
| 365 | + ) |
318 | 366 |
|
319 | 367 | @classmethod |
320 | 368 | def _from_csv(cls: type[Dataset], file_path: str, identifier: str | None = None) -> Dataset: |
|
0 commit comments