Skip to content

Commit 7eb38e8

Browse files
committed
pre-commit run
1 parent 3fd1743 commit 7eb38e8

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

src/nested_pandas/nestedframe/core.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ def reduce(self, func, *args, infer_nesting=True, **kwargs) -> NestedFrame: # t
924924
results_nf = NestedFrame(results, index=self.index)
925925

926926
if infer_nesting:
927-
# find potential nested structures
927+
# find potential nested structures from columns
928928
nested_cols = []
929929
for column in results_nf.columns:
930930
if isinstance(column, str) and "." in column:
@@ -937,7 +937,9 @@ def reduce(self, func, *args, infer_nesting=True, **kwargs) -> NestedFrame: # t
937937
layer_cols = [col for col in results_nf.columns if col.startswith(f"{layer}.")]
938938
rename_df = results_nf[layer_cols].rename(columns=lambda x: x.split(".", 1)[1])
939939
nested_col = pack_lists(rename_df, name=layer)
940-
results_nf = results_nf[[col for col in results_nf.columns if not col.startswith(f"{layer}.")]].join(nested_col)
940+
results_nf = results_nf[
941+
[col for col in results_nf.columns if not col.startswith(f"{layer}.")]
942+
].join(nested_col)
941943

942944
return results_nf
943945

tests/nested_pandas/nestedframe/test_nestedframe.py

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,39 +1024,46 @@ def cols_allclose(col1, col2):
10241024
def test_reduce_infer_nesting():
10251025
"""Test that nesting inference works in reduce"""
10261026

1027-
ndf = generate_data(3,20, seed=1)
1027+
ndf = generate_data(3, 20, seed=1)
10281028

10291029
# Test simple case
10301030
def complex_output(flux):
1031-
return {"max_flux":np.max(flux), "lc.flux_quantiles":np.quantile(flux, [0.1,0.2,0.3,0.4,0.5])}
1032-
1031+
return {
1032+
"max_flux": np.max(flux),
1033+
"lc.flux_quantiles": np.quantile(flux, [0.1, 0.2, 0.3, 0.4, 0.5]),
1034+
}
1035+
10331036
result = ndf.reduce(complex_output, "nested.flux")
10341037
assert list(result.columns) == ["max_flux", "lc"]
1035-
assert list(result.lc.nest.fields) == ['flux_quantiles']
1038+
assert list(result.lc.nest.fields) == ["flux_quantiles"]
10361039

10371040
# Test multi-column nested output
10381041
def complex_output(flux):
1039-
return {"max_flux":np.max(flux),
1040-
"lc.flux_quantiles":np.quantile(flux, [0.1,0.2,0.3,0.4,0.5]),
1041-
"lc.labels":[0.1,0.2,0.3,0.4,0.5]}
1042+
return {
1043+
"max_flux": np.max(flux),
1044+
"lc.flux_quantiles": np.quantile(flux, [0.1, 0.2, 0.3, 0.4, 0.5]),
1045+
"lc.labels": [0.1, 0.2, 0.3, 0.4, 0.5],
1046+
}
10421047

10431048
result = ndf.reduce(complex_output, "nested.flux")
10441049
assert list(result.columns) == ["max_flux", "lc"]
1045-
assert list(result.lc.nest.fields) == ['flux_quantiles', "labels"]
1050+
assert list(result.lc.nest.fields) == ["flux_quantiles", "labels"]
10461051

10471052
# Test integer names
10481053
def complex_output(flux):
1049-
return np.max(flux), np.quantile(flux, [0.1,0.2,0.3,0.4,0.5]),[0.1,0.2,0.3,0.4,0.5]
1050-
1054+
return np.max(flux), np.quantile(flux, [0.1, 0.2, 0.3, 0.4, 0.5]), [0.1, 0.2, 0.3, 0.4, 0.5]
1055+
10511056
result = ndf.reduce(complex_output, "nested.flux")
10521057
assert list(result.columns) == [0, 1, 2]
10531058

1054-
# Test multiple nested structure output
1059+
# Test multiple nested structures output
10551060
def complex_output(flux):
1056-
return {"max_flux":np.max(flux),
1057-
"lc.flux_quantiles":np.quantile(flux, [0.1,0.2,0.3,0.4,0.5]),
1058-
"lc.labels":[0.1,0.2,0.3,0.4,0.5],
1059-
"meta.colors":["green", "red", "blue"]}
1061+
return {
1062+
"max_flux": np.max(flux),
1063+
"lc.flux_quantiles": np.quantile(flux, [0.1, 0.2, 0.3, 0.4, 0.5]),
1064+
"lc.labels": [0.1, 0.2, 0.3, 0.4, 0.5],
1065+
"meta.colors": ["green", "red", "blue"],
1066+
}
10601067

10611068
result = ndf.reduce(complex_output, "nested.flux")
10621069
assert list(result.columns) == ["max_flux", "lc", "meta"]
@@ -1065,8 +1072,10 @@ def complex_output(flux):
10651072

10661073
# Test only nested structure output
10671074
def complex_output(flux):
1068-
return {"lc.flux_quantiles":np.quantile(flux, [0.1,0.2,0.3,0.4,0.5]),
1069-
"lc.labels":[0.1,0.2,0.3,0.4,0.5]}
1075+
return {
1076+
"lc.flux_quantiles": np.quantile(flux, [0.1, 0.2, 0.3, 0.4, 0.5]),
1077+
"lc.labels": [0.1, 0.2, 0.3, 0.4, 0.5],
1078+
}
10701079

10711080
result = ndf.reduce(complex_output, "nested.flux")
10721081
assert list(result.columns) == ["lc"]

0 commit comments

Comments
 (0)