Skip to content
Merged
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
6 changes: 5 additions & 1 deletion dascore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
reset_config,
set_config,
)
from dascore.examples import get_example_patch, get_example_spool
from dascore.examples import (
get_example_inventory,
get_example_patch,
get_example_spool,
)
from dascore.io.core import get_format, read, scan, scan_payloads, scan_to_df, write
from dascore.units import get_quantity, get_unit
from dascore.utils.patch import patch_function
Expand Down
4 changes: 2 additions & 2 deletions dascore/core/annotation_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import numpy as np
import pandas as pd
import yaml
from pydantic import ValidationError

from dascore.core.annotations import (
Expand All @@ -60,7 +61,7 @@
)
from dascore.exceptions import InvalidAnnotationError, ParameterError
from dascore.models.registry import TAG_FIELD
from dascore.utils.misc import iterate, optional_import
from dascore.utils.misc import iterate
from dascore.utils.paths import quote_path
from dascore.utils.tables import (
parse_cell,
Expand Down Expand Up @@ -119,7 +120,6 @@ def _read_object(path: Path) -> dict[str, Any]:
msg = f"Could not parse JSON from {quote_path(path)}: {error}."
raise ParameterError(msg) from error
else:
yaml = optional_import("yaml", required_for="YAML annotation storage")
try:
data = yaml.safe_load(text)
except yaml.YAMLError as error:
Expand Down
10 changes: 3 additions & 7 deletions dascore/core/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from uuid import uuid4

import numpy as np
import yaml
from pydantic import (
AfterValidator,
BeforeValidator,
Expand Down Expand Up @@ -64,7 +65,6 @@
from dascore.utils.misc import (
check_code,
is_strictly_monotonic,
optional_import,
validate_acquisition_key,
)
from dascore.utils.namespace import NamespaceOwner
Expand Down Expand Up @@ -2501,7 +2501,6 @@ def from_yaml(cls, text: str) -> Self:
"Load a path with dascore.inventory."
)
raise InvalidInventoryError(msg)
yaml = optional_import("yaml", required_for="YAML inventory parsing")
try:
data = yaml.safe_load(text)
except yaml.YAMLError as error:
Expand Down Expand Up @@ -2554,13 +2553,10 @@ def inventory_to_yaml(inventory: Inventory, path: str | Path | None = None) -> s
--------
>>> import dascore as dc
>>> _, inventory = dc.examples.inventory_patch_pair()
>>> # Writing YAML needs pyyaml, which is not a core dependency.
>>> text = inventory.io.to_yaml() # doctest: +SKIP
>>> dc.inventory(text) == inventory # doctest: +SKIP
>>> text = inventory.io.to_yaml()
>>> dc.inventory(text) == inventory
True
"""
yaml = optional_import("yaml", required_for="YAML inventory serialization")

# Everything defaulted is dropped, so the document records which
# envelope it was written against even when that is the default.
dumped = inventory.model_dump(mode="json", exclude_defaults=True)
Expand Down
12 changes: 4 additions & 8 deletions dascore/core/inventory_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from typing import Any, NamedTuple

import pandas as pd
import yaml

from dascore.core.inventory import (
Acquisition,
Expand All @@ -58,14 +59,10 @@
_overlapping_epochs,
_times_equal,
)
from dascore.exceptions import (
InvalidInventoryError,
MissingOptionalDependencyError,
ParameterError,
)
from dascore.exceptions import InvalidInventoryError, ParameterError
from dascore.models import InventoryModel, TimeRangedModel
from dascore.models.registry import TAG_FIELD
from dascore.utils.misc import check_code, optional_import
from dascore.utils.misc import check_code
from dascore.utils.paths import quote_path as _quote
from dascore.utils.tables import (
ordered_rows,
Expand Down Expand Up @@ -221,7 +218,6 @@ def _read_object(path: Path) -> dict[str, Any]:
msg = f"Could not parse JSON from {_quote(path)}: {error}."
raise InvalidInventoryError(msg) from error
else:
yaml = optional_import("yaml", required_for="YAML inventory serialization")
try:
data = yaml.safe_load(text)
except yaml.YAMLError as error:
Expand All @@ -245,7 +241,7 @@ def _declared_type(path: Path) -> str | None:
"""
try:
data = _read_object(path)
except (InvalidInventoryError, MissingOptionalDependencyError):
except InvalidInventoryError:
return None
declared = data.get(TAG_FIELD)
return declared if isinstance(declared, str) else None
Expand Down
Loading