From e2479403dad00ef8a98034e28c96a818660d7d65 Mon Sep 17 00:00:00 2001 From: "Derek T. Jones" Date: Tue, 26 Nov 2024 23:18:28 +0000 Subject: [PATCH] Address code coverage in tests --- src/nested_pandas/nestedframe/core.py | 2 +- tests/nested_pandas/nestedframe/test_nestedframe.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/nested_pandas/nestedframe/core.py b/src/nested_pandas/nestedframe/core.py index bd5814c..eddd80b 100644 --- a/src/nested_pandas/nestedframe/core.py +++ b/src/nested_pandas/nestedframe/core.py @@ -872,7 +872,7 @@ def reduce(self, func, *args, **kwargs) -> NestedFrame: # type: ignore[override Takes a function and applies it to each top-level row of the NestedFrame. The user may specify which columns the function is applied to, with - columns from the 'base' layer being passsed to the function as + columns from the 'base' layer being passed to the function as scalars and columns from the nested layers being passed as numpy arrays. Parameters diff --git a/tests/nested_pandas/nestedframe/test_nestedframe.py b/tests/nested_pandas/nestedframe/test_nestedframe.py index bd07d29..d4a97db 100644 --- a/tests/nested_pandas/nestedframe/test_nestedframe.py +++ b/tests/nested_pandas/nestedframe/test_nestedframe.py @@ -870,6 +870,14 @@ def offset_avg(offset, col_to_avg, column_names): for i in range(len(result)): assert result["offset_avg"].values[i] == expected_offset_avg[i] + # Verify that we can understand a string argument to the reduce function, + # so long as it isn't a column name. + def make_id(col1, prefix_str): + return f"{prefix_str}{col1}" + + result = nf.reduce(make_id, "b", "some_id_") + assert result[0][1] == "some_id_4" + def test_reduce_duplicated_cols(): """Tests nf.reduce() to correctly handle duplicated column names."""