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

Fix unhashable list #15

Merged
merged 6 commits into from
Jan 29, 2024
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pysdmx"
version = "1.0.0-beta-5"
version = "1.0.0-beta-6"
description = "Your opinionated Python SDMX library"
authors = [
"Xavier Sosnovsky <xavier.sosnovsky@bis.org>",
Expand Down
2 changes: 1 addition & 1 deletion src/pysdmx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Your opinionated Python SDMX library."""

__version__ = "1.0.0-beta-5"
__version__ = "1.0.0-beta-6"
22 changes: 13 additions & 9 deletions src/pysdmx/model/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""

from datetime import datetime
from typing import FrozenSet, Iterator, Optional, Sequence
from typing import Iterator, Optional, Sequence

from msgspec import Struct

Expand Down Expand Up @@ -211,17 +211,21 @@ def __extract_code(
return None

def __by_id(
self, id: str, codes: Sequence[HierarchicalCode]
) -> FrozenSet[HierarchicalCode]:
out = []
self,
id: str,
codes: Sequence[HierarchicalCode],
out: Optional[Sequence[HierarchicalCode]] = None,
) -> Sequence[HierarchicalCode]:
if out is None:
out = []
for i in codes:
if i.id == id:
out.append(i)
if i.id == id and i not in out:
out.append(i) # type: ignore[attr-defined]
if i.codes:
out.extend(self.__by_id(id, i.codes))
return frozenset(out)
self.__by_id(id, i.codes, out)
return out

def by_id(self, id: str) -> FrozenSet[HierarchicalCode]:
def by_id(self, id: str) -> Sequence[HierarchicalCode]:
"""Get a code without knowing its parent IDs.

Codes in a hierarchy can be retrieved using their full ID,
Expand Down
2 changes: 1 addition & 1 deletion tests/model/test_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_codes_by_id_is_a_set(id, name, agency):
assert m[0] == grandchild1


def test_codes_by_id_dff_names(id, name, agency):
def test_codes_by_id_diff_names(id, name, agency):
grandchild1 = HierarchicalCode("child211", "Child 2.1.1")
grandchild2 = HierarchicalCode("child212", "Child 2.1.2")
grandchild3 = HierarchicalCode("child211", "Child 2.1.1 - Diff name")
Expand Down
Loading