FieldMapping¶
field_mapping
¶
Classes¶
FieldMapping
¶
FieldMapping(df: DataFrame, aliases: Dict[str, List[str]], output_fields: Dict[str, str], overrides: Dict[str, str] | None = None)
Generic mapping class for data fields with input/output field separation.
Provides strong typing support and alias matching for automatic discovery. Input fields use alias mechanism, output fields use internal names directly.
Source code in packages/core/src/sphere/core/schemas/field_mapping.py
Attributes¶
Functions¶
find_best_match
¶
Find the best matching column for a property.
Priority order: 1. Override (if provided, always takes precedence) 2. Alias matches for input fields (in order of preference, case-insensitive) 3. Direct name match for output fields (case-insensitive)
Note: This method only returns matches found in the DataFrame columns. Fallback values are handled in discover_mappings.
Source code in packages/core/src/sphere/core/schemas/field_mapping.py
discover_mappings
¶
Discover field mappings in a DataFrame.
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
Dictionary mapping internal property names to discovered external column names |
Raises:
| Type | Description |
|---|---|
ValueError
|
If required input fields are not found |
Source code in packages/core/src/sphere/core/schemas/field_mapping.py
set_field_mapping
¶
Manually set a field mapping (acts as override).
get_field_name
¶
Retrieves the field name for the given internal property name.