digital_land.pipeline package
Submodules
digital_land.pipeline.main module
- class digital_land.pipeline.main.EntityNumGen(entity_num_state: dict | None = None)
Bases:
object- next()
- class digital_land.pipeline.main.Lookups(directory=None)
Bases:
object- add_entry(entry, is_new_entry=True)
Add a lookup entry, ignoring duplicates when validating a new entry.
- Parameters:
entry -- lookup mapping, stored without copying it.
is_new_entry -- if False, skip required-field and duplicate checks to accept older lookups that may lack the currently required columns.
- Raises:
ValueError -- if validation is enabled and prefix or reference is missing or false-valued.
TypeError -- if prefix, organisation or reference is unhashable.
- get_max_entity(prefix, specification) int
Find the highest entity number already assigned to this dataset, so a new EntityNumGen can be told where to carry on from. :param prefix: the dataset's own prefix, or its dataset_prefix alias, to match
entries against.
- Parameters:
specification -- Specification, used to resolve prefix's dataset_prefix.
- Returns:
the highest existing entity number for this dataset, or 0 if there are no entries, no prefix, or none of the entries have a usable entity number.
- load_csv(lookups_path=None)
load in lookups as df, not when we process pipeline but useful for other analysis
- save_csv(lookups_path=None, entries=None, old_entity_path=None)
Overwrite the lookup CSV, creating its parent directories as needed. Assign entity numbers in place via self.entity_num_gen to entries with a missing or false-valued entity. Skip numbers in the existing lookup CSV, both old-entity and entity columns in old-entity.csv, and numbers assigned by this call. Existing entity values supplied only in entries are not reserved. Empty entries and entries for which the available number range is exhausted are omitted without raising. :param lookups_path: where to write the CSV - defaults to self.lookups_path. :param entries: the entries to write - None uses self.entries. :param old_entity_path: CSV containing retired and replacement numbers -
defaults to self.old_entity_path.
- Returns:
a list of the original entry mappings assigned a new entity number by this call; an empty list if none were assigned.
- Raises:
OSError -- if directory creation or file access fails. The output may already have been overwritten when an error occurs.
KeyError -- if a row read from an existing CSV lacks a required entity or old-entity column.
- validate_entry(entry) bool
Check a new entry has the minimum required fields and isn't already present. :param entry: the lookup entry to check. :return: True if entry is new and valid; False if an entry with the same
(prefix, organisation, reference) already exists in self.entries. A missing organisation is treated as an empty string.
- Raises:
ValueError -- if entry is missing a non-empty "prefix" or "reference".
TypeError -- if prefix, organisation or reference is unhashable.
- class digital_land.pipeline.main.Pipeline(path, dataset, specification=None, config=None)
Bases:
object- columns(resource='', endpoints=[])
- combine_fields(endpoints=None)
- static compose(phases)
- concatenations(resource=None, endpoints=[])
- default_fields(resource=None, endpoints=[])
- default_values(endpoints=None)
- file_reader(filename)
- filters(resource='', endpoints=[])
- get_pipeline_callback()
- init_logs(dataset, resource)
- load_column()
- load_combine_fields()
- load_concat()
- load_default_fields()
- load_default_values()
- load_filter()
- load_lookup()
- load_lookup_rule()
- load_migrate()
- load_patch()
- load_redirect_lookup()
- load_skip_patterns()
- lookup_rules(resource=None)
- lookups(resource=None)
- migrations()
- patches(resource='', endpoints=[])
- reader(filename)
- redirect_lookups()
- run(*phases)
- static run_phases(*phases)
Execute a sequence of phases by composing their .process() pipelines.
Phases are expected to be objects with a process(iterable) method. Historically the chain has been started with None.
- save_logs(issue_path=None, column_field_path=None, dataset_resource_path=None, converted_resource_path=None)
Save logs to respective paths. Only saves when path is provided (not None).
- Returns:
True if all logs saved successfully, False otherwise.
- Return type:
bool
- skip_patterns(resource='', endpoints=[])
- transform(input_path: str, output_path: Path, organisation: Organisation, resource: str, valid_category_values: Dict, endpoints: List[str] | None = None, endpoint_plugins: List[str] | None = None, organisations: List[str] | None = None, entry_date: str = '', converted_path: str | None = None, harmonised_output_path: str | None = None, save_harmonised: bool = False, disable_lookups: bool = False) IssueLog
Build and run the default resource -> transformed phase list.
This mirrors the legacy commands.pipeline_run() phase wiring, but keeps the execution responsibility inside Pipeline.
- Parameters:
input_path (str) -- Path to the input resource CSV file to transform (i.e. collection/resource/{file-hash}).
output_path (Path) -- Path where the final transformed CSV will be written (i.e. transformed/{dataset-name}/{file-hash}.csv).
organisation (Organisation) -- Organisation object containing org-specific lookups and mappings.
resource (str) -- Resource file identifier (hash), TBD can be removed.
valid_category_values (dict) -- Dictionary of valid category values per field from the API/specification.
endpoints (list, optional) -- List of endpoint hashes/identifiers for this resource. Defaults to None.
endpoint_plugins (list, optional) -- Collector plugins used by those endpoints, e.g. ["arcgis"]. Lets date values be decoded by their known encoding instead of inferred. Defaults to None.
organisations (list, optional) -- List of organisation codes/identifiers associated with the resource. Defaults to None. If one is passed it becomes the default organisation for every row; if more than one, no default is applied and EntityLookupPhase resolves the entity once per organisation.
entry_date (str, optional) -- Default entry-date value to apply to all records. Defaults to "".
converted_path (str, optional) -- Path to save converted (pre-normalised) resource. Defaults to None.
harmonised_output_path (str, optional) -- Path to save the harmonised/intermediate output. Defaults to None.
save_harmonised (bool, optional) -- Whether to save the harmonised intermediate output. Defaults to False.
disable_lookups (bool, optional) -- Whether to disable entity lookups and pruning phases. Defaults to False. (useful for checking data before lookups are applied)
- Returns:
The completed issue log containing all data quality issues found during transformation.
- Return type:
- class digital_land.pipeline.main.PipelineStatus(value)
Bases:
EnumAn enumeration.
- COMPLETE = 3
- ERROR = 4
- FAILED = 5
- INITIALISED = 1
- RUNNING = 2
- digital_land.pipeline.main.chain_phases(phases)
- digital_land.pipeline.main.count_distinct_entities(csv_path)
- digital_land.pipeline.main.run_pipeline(*args)
Backward compatible wrapper.
Prefer calling Pipeline.run(*phases) on a configured Pipeline instance.
digital_land.pipeline.process module
- digital_land.pipeline.process.convert_tranformed_csv_to_pq(input_path, output_path)
function to convert a transformed resource to a parrquet file.
digital_land.pipeline.task module
- class digital_land.pipeline.task.TaskPipeline(config: TaskPipelineConfig | None = None)
Bases:
objectGenerates a task CSV from collection logs and/or issue logs.
- run(output_path: Path | None = None, dataset: str | None = None, organisation: str | None = None, endpoint: str | None = None, log_path: Path | None = None, issue_path: Path | None = None, column_field_path: Path | None = None, mandatory_fields: List[str] | None = None, severity_filter: List[str] | None = None, responsibility_filter: List[str] | None = None, entry_date: str | None = None) TaskPipelineStatus
- class digital_land.pipeline.task.TaskPipelineConfig(dataset: str, organisation: str, endpoint: str, output_path: Path, log_path: Optional[Path] = None, issue_path: Optional[Path] = None, severity_filter: List[str] = <factory>, responsibility_filter: List[str] = <factory>, entry_date: Optional[str] = None)
Bases:
object- dataset: str
- endpoint: str
- entry_date: str | None = None
- issue_path: Path | None = None
- log_path: Path | None = None
- organisation: str
- output_path: Path
- responsibility_filter: List[str] = FieldInfo(annotation=NoneType, required=False, default_factory=<lambda>)
- severity_filter: List[str] = FieldInfo(annotation=NoneType, required=False, default_factory=<lambda>)
Module contents
sub package containing code for processing resources into transformed resources