nudb_use.metadata.nudb_klass package

nudb_use.metadata.nudb_klass.codes module

Fetch and validate KLASS classification codes.

check_klass_codes(df, data_time_start=None, data_time_end=None, raise_errors=True)

Validate DataFrame columns against KLASS codelists from metadata.

Parameters:
  • df (DataFrame) – DataFrame containing columns to be validated.

  • data_time_start (str | None) – Start date for restricting code validation, overrides metadata.

  • data_time_end (str | None) – End date for restricting code validation, overrides metadata.

  • raise_errors (bool) – If True, raises an exception group on validation errors; otherwise, only logs warnings.

Returns:

List of quality errors detected during validation, empty if none.

Return type:

list[NudbQualityError]

get_klass_codes(klassid, data_time_start=None, data_time_end=None)

Fetch code dictionaries for a classification scheme within a given time range.

Parameters:
  • klassid (int) – Identifier from Klass.

  • data_time_start (str | None) – Start date (YYYY-MM-DD) for code filtering.

  • data_time_end (str | None) – End date (YYYY-MM-DD) for code filtering.

Returns:

List of codes for the classification.

Return type:

list[str]

Raises:

ValueError – If data_time_end is specified, but not data_time_start.

nudb_use.metadata.nudb_klass.correspondence module

klass_correspondence_to_mapping(var_meta)

Subfunction to get the mapping from klass for a correspondence to another classifcation.

Parameters:

var_meta (Variable) – The variable metadata from the settings relating to the derived variable.

Returns:

The mapping dict from klass.

Return type:

dict[str, str | None]

Raises:

TypeError – If the klass_codelist in the config for the variable is not an int, or klass_variant_search_term is not a str.

nudb_use.metadata.nudb_klass.klass_utils module

find_earliest_latest_klass_version_date(klass_classification_id)

Finds the earliest and latest version dates for a KLASS classification.

Retrieves all versions of a given KLASS classification and identifies the earliest and latest dates when the classification was valid. Used to determine the full historical range of a classification’s validity.

Parameters:

klass_classification_id (int) – The numeric ID of the KLASS classification to query.

Returns:

A (min_date, max_date) tuple representing the earliest and latest valid dates for the classification versions.

Return type:

tuple[str, str]

nudb_use.metadata.nudb_klass.labels module

get_klass_label_mapping(variable)

Subfunction to get the mapping from klass codes to code labels.

Parameters:

variable (str) – Variable name.

Returns:

The mapping dict from klass, or None if no mapping is found.

Return type:

dict[str, str] | None

nudb_use.metadata.nudb_klass.variants module

klass_variant_search_term_mapping(var_meta, key='code', value='parentCode', select_level=None)

Subfunction to get the mapping from klass for the variable.

Parameters:
  • var_meta (Variable) – The variable metadata from the settings relating to the derived variable.

  • key (str) – key argument passed to ‘klass.KlassVariant.to_dict’

  • value (str) – value argument passed to ‘klass.KlassVariant.to_dict’

  • select_level (int | None) – select_level argument passed to ‘klass.KlassVariant.to_dict’

Returns:

The mapping dict from klass.

Return type:

dict[str, str]

Raises:
  • TypeError – If the klass_codelist in the config for the variable is not an int, or klass_variant_search_term is not a str.

  • ValueError – If no variant or multiple variants match the search term.