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

Pass sources to DataSource.from_id() #4013

Merged
merged 4 commits into from
Jan 15, 2025
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
9 changes: 9 additions & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ Bug Fixes
Major Dependency Updates
^^^^^^^^^^^^^^^^^^^^^^^^

Quality of Life Improvements
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* We added a ``sources`` parameter to ``pudl.metadata.classes.DataSource.from_id()``
in order to make it possible to use the `pudl-archiver
<https://www.github.com/catalyst-cooperative/pudl-archiver>`__ repository to
archive datasets that won't necessarily be ingested into PUDL. See `this PUDL archiver
issue <https://github.com/catalyst-cooperative/pudl-archiver/pull/506>`__ and PRs
:pr:`4003` and :pr:`4013`.

.. _release-v2024.11.0:

---------------------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions src/pudl/metadata/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,22 +1039,22 @@ def from_field_namespace(
) -> list["DataSource"]:
"""Return list of DataSource objects by field namespace."""
return [
cls(**cls.dict_from_id(name))
cls(**cls.dict_from_id(name, sources))
for name, val in sources.items()
if val.get("field_namespace") == x
]

@staticmethod
def dict_from_id(x: str, sources: dict[str, Any] = SOURCES) -> dict:
def dict_from_id(x: str, sources: dict[str, Any]) -> dict:
"""Look up the source by source name in the metadata."""
# If ID ends with _xbrl strip end to find data source
lookup_id = x.replace("_xbrl", "")
return {"name": x, **copy.deepcopy(sources[lookup_id])}

@classmethod
def from_id(cls, x: str) -> "DataSource":
def from_id(cls, x: str, sources: dict[str, Any] = SOURCES) -> "DataSource":
"""Construct Source by source name in the metadata."""
return cls(**cls.dict_from_id(x))
return cls(**cls.dict_from_id(x, sources=sources))


class ResourceHarvest(PudlMeta):
Expand Down
Loading