def test_step_row_ungroup_max(): source = Resource(path="data/transform-groups.csv") source.infer() target = transform( source, steps=[ steps.row_ungroup(group_name="name", selection="max", value_name="population"), ], ) assert target.schema == source.schema assert target.read_rows() == [ { "id": 3, "name": "france", "population": 66, "year": 2020 }, { "id": 1, "name": "germany", "population": 83, "year": 2020 }, { "id": 5, "name": "spain", "population": 47, "year": 2020 }, ]
def test_step_row_ungroup_last(): source = Resource(path="data/transform-groups.csv") source.infer() target = transform( source, steps=[ steps.row_ungroup(group_name="name", selection="last"), ], ) assert target.schema == source.schema assert target.read_rows() == [ { "id": 4, "name": "france", "population": 54, "year": 1920 }, { "id": 2, "name": "germany", "population": 77, "year": 1920 }, { "id": 6, "name": "spain", "population": 33, "year": 1920 }, ]
def test_step_row_ungroup_max(): source = Resource("data/transform-groups.csv") target = transform( source, steps=[ steps.row_ungroup(group_name="name", selection="max", value_name="population"), ], ) assert target.schema == { "fields": [ { "name": "id", "type": "integer" }, { "name": "name", "type": "string" }, { "name": "population", "type": "integer" }, { "name": "year", "type": "integer" }, ] } assert target.read_rows() == [ { "id": 3, "name": "france", "population": 66, "year": 2020 }, { "id": 1, "name": "germany", "population": 83, "year": 2020 }, { "id": 5, "name": "spain", "population": 47, "year": 2020 }, ]