Skip to content

Commit

Permalink
fix trailing zeros
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-troy committed Feb 5, 2024
1 parent f320775 commit 49dd939
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 32 deletions.
20 changes: 10 additions & 10 deletions liiatools/annex_a_pipeline/spec/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ table_list:
- id: Child Unique ID
type: string
unique_key: true
enrich: add_la_suffix
enrich: [integer, add_la_suffix]
- id: Gender
type: category
- id: Ethnicity
Expand All @@ -32,7 +32,7 @@ table_list:
- id: Child Unique ID
type: string
unique_key: true
enrich: add_la_suffix
enrich: [integer, add_la_suffix]
- id: Gender
type: category
- id: Ethnicity
Expand Down Expand Up @@ -61,7 +61,7 @@ table_list:
- id: Child Unique ID
type: string
unique_key: true
enrich: add_la_suffix
enrich: [integer, add_la_suffix]
- id: Gender
type: category
- id: Ethnicity
Expand Down Expand Up @@ -99,7 +99,7 @@ table_list:
- id: Child Unique ID
type: string
unique_key: true
enrich: add_la_suffix
enrich: [integer, add_la_suffix]
- id: Gender
type: category
- id: Ethnicity
Expand Down Expand Up @@ -138,7 +138,7 @@ table_list:
- id: Child Unique ID
type: string
unique_key: true
enrich: add_la_suffix
enrich: [integer, add_la_suffix]
- id: Gender
type: category
- id: Ethnicity
Expand Down Expand Up @@ -181,7 +181,7 @@ table_list:
- id: Child Unique ID
type: string
unique_key: true
enrich: add_la_suffix
enrich: [integer, add_la_suffix]
- id: Gender
type: category
- id: Ethnicity
Expand Down Expand Up @@ -224,7 +224,7 @@ table_list:
- id: Child Unique ID
type: string
unique_key: true
enrich: add_la_suffix
enrich: [integer, add_la_suffix]
- id: Gender
type: category
- id: Ethnicity
Expand Down Expand Up @@ -273,7 +273,7 @@ table_list:
- id: Child Unique ID
type: string
unique_key: true
enrich: add_la_suffix
enrich: [integer, add_la_suffix]
- id: Gender
type: category
- id: Ethnicity
Expand Down Expand Up @@ -361,7 +361,7 @@ table_list:
- id: Child Unique ID
type: string
unique_key: true
enrich: add_la_suffix
enrich: [integer, add_la_suffix]
- id: Gender
type: category
- id: Ethnicity
Expand Down Expand Up @@ -399,7 +399,7 @@ table_list:
- id: Child Unique ID
type: string
unique_key: true
enrich: add_la_suffix
enrich: [integer, add_la_suffix]
- id: Family identifier
type: string
- id: Gender
Expand Down
1 change: 1 addition & 0 deletions liiatools/cin_census_pipeline/spec/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ table_list:
- id: LAchildID
type: string
unique_key: true
enrich: [integer, add_la_suffix]
- id: Date
type: date
unique_key: true
Expand Down
8 changes: 8 additions & 0 deletions liiatools/common/_transform_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,21 @@ def add_school_year(row: pd.Series, column_config: ColumnConfig, metadata: Metad
return school_year


def to_integer(row: pd.Series, column_config: ColumnConfig, metadata: Metadata) -> str | int:
try:
return int(float(row[column_config.id]))
except ValueError:
return row[column_config.id]


enrich_functions = {
"add_la_suffix": add_la_suffix,
"la_code": add_la_code,
"la_name": add_la_name,
"year": add_year,
"quarter": add_quarter,
"school_year": add_school_year,
"integer": to_integer,
}


Expand Down
2 changes: 1 addition & 1 deletion liiatools/common/data/__config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ColumnConfig(BaseModel):
id: str
type: str
unique_key: bool = False
enrich: str = None
enrich: str | list = None
degrade: str = None
sort: int = None
exclude: List[str] = []
Expand Down
24 changes: 17 additions & 7 deletions liiatools/common/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,23 @@ def _transform(
for column_config in table_config.columns:
transform_name = getattr(column_config, property)
if transform_name:
assert (
transform_name in functions
), f"Unknown transform for property '{property}': {transform_name}"
data[column_config.id] = data.apply(
lambda row: functions[transform_name](row, column_config, metadata),
axis=1,
)
if isinstance(transform_name, list):
for transform_name in transform_name:
assert (
transform_name in functions
), f"Unknown transform for property '{property}': {transform_name}"
data[column_config.id] = data.apply(
lambda row: functions[transform_name](row, column_config, metadata),
axis=1,
)
else:
assert (
transform_name in functions
), f"Unknown transform for property '{property}': {transform_name}"
data[column_config.id] = data.apply(
lambda row: functions[transform_name](row, column_config, metadata),
axis=1,
)


def data_transforms(
Expand Down
4 changes: 2 additions & 2 deletions liiatools/s251_pipeline/spec/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ table_list:
- id: Child ID
type: string
unique_key: true
enrich: add_la_suffix
enrich: [integer, add_la_suffix]
- id: Date of birth
type: date
degrade: first_of_month
Expand Down Expand Up @@ -85,7 +85,7 @@ table_list:
- id: Asset name
type: string
unique_key: true
enrich: add_la_suffix
enrich: [integer, add_la_suffix]
- id: Ofsted URN
type: string
- id: Start date
Expand Down
22 changes: 11 additions & 11 deletions liiatools/ssda903_pipeline/spec/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ table_list:
- id: CHILD
type: string
unique_key: true
enrich: add_la_suffix
enrich: [integer, add_la_suffix]
- id: DOB
type: date
degrade: first_of_month
Expand Down Expand Up @@ -37,7 +37,7 @@ table_list:
- id: CHILD
type: string
unique_key: true
enrich: add_la_suffix
enrich: [integer, add_la_suffix]
- id: DECOM
type: date
unique_key: true
Expand Down Expand Up @@ -81,7 +81,7 @@ table_list:
- id: CHILD
type: string
unique_key: true
enrich: add_la_suffix
enrich: [integer, add_la_suffix]
- id: SEX
type: category
- id: DOB
Expand Down Expand Up @@ -117,7 +117,7 @@ table_list:
- id: CHILD
type: string
unique_key: true
enrich: add_la_suffix
enrich: [integer, add_la_suffix]
- id: DOB
type: date
degrade: first_of_month
Expand All @@ -144,7 +144,7 @@ table_list:
- id: CHILD
type: string
unique_key: true
enrich: add_la_suffix
enrich: [integer, add_la_suffix]
- id: DOB
type: date
unique_key: true
Expand Down Expand Up @@ -203,7 +203,7 @@ table_list:
- id: CHILD
type: string
unique_key: true
enrich: add_la_suffix
enrich: [integer, add_la_suffix]
- id: DOB
type: date
unique_key: true
Expand All @@ -230,7 +230,7 @@ table_list:
columns:
- id: CHILD
type: string
enrich: add_la_suffix
enrich: [integer, add_la_suffix]
- id: DOB
type: date
degrade: first_of_month
Expand All @@ -256,7 +256,7 @@ table_list:
- id: CHILD
type: string
unique_key: true
enrich: add_la_suffix
enrich: [integer, add_la_suffix]
- id: DOB
type: date
degrade: first_of_month
Expand All @@ -281,7 +281,7 @@ table_list:
- id: CHILD
type: string
unique_key: true
enrich: add_la_suffix
enrich: [integer, add_la_suffix]
- id: DOB
type: date
degrade: first_of_month
Expand All @@ -305,7 +305,7 @@ table_list:
- id: CHILD
type: string
unique_key: true
enrich: add_la_suffix
enrich: [integer, add_la_suffix]
- id: DOB
type: date
degrade: first_of_month
Expand All @@ -325,7 +325,7 @@ table_list:
columns:
- id: CHILD
type: string
enrich: add_la_suffix
enrich: [integer, add_la_suffix]
- id: DOB
type: date
degrade: first_of_month
Expand Down
2 changes: 1 addition & 1 deletion tests/cin_census/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def test_s47_journeys():
"S47ActualStartDate",
"CPPstartDate",
"DateOfInitialCPC",
"YEAR",
"Year",
],
)

Expand Down

0 comments on commit 49dd939

Please sign in to comment.