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

Cache dimension snakecase #181

Merged
merged 2 commits into from
Jan 19, 2024
Merged
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
11 changes: 7 additions & 4 deletions src/ferc_xbrl_extractor/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import zipfile
from collections import Counter, defaultdict
from enum import Enum, auto
from functools import cached_property
from pathlib import Path
from typing import BinaryIO
from zoneinfo import ZoneInfo
Expand Down Expand Up @@ -121,12 +122,14 @@ def from_xml(cls, elem: Element) -> "Entity":
dimensions=[Axis.from_xml(child) for child in dims],
)

@cached_property
def snakecase_dimensions(self) -> list[str]:
"""Return list of dimension names in snakecase."""
return [stringcase.snakecase(dim.name) for dim in self.dimensions]

def check_dimensions(self, primary_key: list[str]) -> bool:
"""Check if Context has extra axes not defined in primary key."""
for dim in self.dimensions:
if stringcase.snakecase(dim.name) not in primary_key:
return False
return True
return all(snake_dim in primary_key for snake_dim in self.snakecase_dimensions)


class Context(BaseModel):
Expand Down