CodeList¶
- class nomenclature.codelist.CodeList(*, name, mapping={})[source]¶
A class for nomenclature codelists & attributes
- Attributes:
- namestr
Name of the CodeList
- mappingdict
Dictionary of Code objects
Methods
filter(**kwargs)Filter a CodeList by any attribute-value pairs.
from_directory(name, path[, config, ...])Initialize a CodeList from a directory with codelist files
read_excel(name, source, sheet_name, col[, ...])Parses an xlsx file with a codelist
to_csv([path, sort])Write the codelist to a comma-separated values (csv) file
to_excel(excel_writer[, sheet_name, sort])Write the codelist to an Excel spreadsheet
to_pandas([sort])Export the CodeList to a
pandas.DataFrameto_yaml([path, sort])Write mapping to yaml file or return as stream
validate_items(items)Validate that a list of items are valid codes
- filter(**kwargs)[source]¶
Filter a CodeList by any attribute-value pairs.
- Parameters:
- **kwargs
Attribute-value mappings to be used for filtering.
- Returns:
- CodeList
CodeList with Codes that match attribute-value pairs.
- classmethod from_directory(name, path, config=None, file_glob_pattern='**/*')[source]¶
Initialize a CodeList from a directory with codelist files
- Parameters:
- namestr
Name of the CodeList
- path
pathlib.Pathor path-like Directory with the codelist files
- config: :class:`NomenclatureConfig`, optional
Attributes for configuring the CodeList
- file_glob_patternstr, optional
Pattern to downselect codelist files by name
- Returns:
- instance of cls (
CodeListif not inherited)
- instance of cls (
- classmethod read_excel(name, source, sheet_name, col, attrs=None)[source]¶
Parses an xlsx file with a codelist
- Parameters:
- namestr
Name of the CodeList
- sourcestr, path, file-like object
Path to Excel file with definitions (codelists).
- sheet_namestr
Sheet name of source.
- colstr
Column from sheet_name to use as codes.
- attrslist, optional
Columns from sheet_name to use as attributes.
- to_csv(path=None, sort=None, **kwargs)[source]¶
Write the codelist to a comma-separated values (csv) file
- Parameters:
- pathstr, path or file-like, optional
File path as string or
pathlib.Path, or file-like object. If None, the result is returned as a csv-formatted string. Seepandas.DataFrame.to_csv()for details.- sortstr, optional
Sort order: “asc” (ascending) or “desc” (descending). If None (default), codes are not sorted.
- **kwargs
Passed to
pandas.DataFrame.to_csv().
- Returns:
- None or csv-formatted string (if path is None)
- to_excel(excel_writer, sheet_name=None, sort=None, **kwargs)[source]¶
Write the codelist to an Excel spreadsheet
- Parameters:
- excel_writerpath-like, file-like, or ExcelWriter object
File path as string or
pathlib.Path, or existingpandas.ExcelWriter.- sheet_namestr, optional
Name of sheet that will have the codelist. If None, use the codelist name.
- sortstr, optional
Sort order: “asc” (ascending) or “desc” (descending). If None (default), codes are not sorted.
- **kwargs
Passed to
pandas.ExcelWriter(if excel_writer is path-like).
- to_pandas(sort=None)[source]¶
Export the CodeList to a
pandas.DataFrame- Parameters:
- sortstr, optional
Sort order: “asc” (ascending) or “desc” (descending). If None (default), codes are not sorted.
- to_yaml(path=None, sort=None)[source]¶
Write mapping to yaml file or return as stream
- Parameters:
- path
pathlib.Pathor str, optional Write to file path if not None, otherwise return as stream
- sortstr, optional
Sort order: “asc” (ascending) or “desc” (descending). If None (default), codes are not sorted.
- path
- class nomenclature.codelist.VariableCodeList(*, name, mapping={})[source]¶
A subclass of CodeList specified for variables
- Attributes:
- namestr
Name of the VariableCodeList
- mappingdict
Dictionary of VariableCode objects
Methods
Check that any variable "region-aggregation" mappings are valid
Check that all variables specified in 'weight' are present in the codelist
- class nomenclature.codelist.RegionCodeList(*, name, mapping={})[source]¶
A subclass of CodeList specified for regions
- Attributes:
- namestr
Name of the RegionCodeList
- mappingdict
Dictionary of RegionCode objects
Methods
filter(**kwargs)Filter a CodeList by any attribute-value pairs.
from_directory(name, path[, config, ...])Initialize a RegionCodeList from a directory with codelist files
- filter(**kwargs)¶
Filter a CodeList by any attribute-value pairs.
- Parameters:
- **kwargs
Attribute-value mappings to be used for filtering.
- Returns:
- CodeList
CodeList with Codes that match attribute-value pairs.
- classmethod from_directory(name, path, config=None, file_glob_pattern='**/*')[source]¶
Initialize a RegionCodeList from a directory with codelist files
- Parameters:
- namestr
Name of the CodeList
- path
pathlib.Pathor path-like Directory with the codelist files
- config
RegionCodeListConfig, optional Attributes for configuring the CodeList
- file_glob_patternstr, optional
Pattern to downselect codelist files by name, default: “**/*” (i.e. all files in all sub-folders)
- Returns:
- RegionCodeList
- property hierarchy¶
Return the hierarchies defined in the RegionCodeList
- Returns:
- list[str]