From 37e5c17de90c8bf93fd984da6469d0a19fbc0fd4 Mon Sep 17 00:00:00 2001 From: Jovan Veljanoski Date: Fri, 18 Nov 2022 18:17:49 +0100 Subject: [PATCH] test(core): create a pyarrow struct out of expressions --- tests/struct_test.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/struct_test.py b/tests/struct_test.py index 46078bccb4..7d138f1c0c 100644 --- a/tests/struct_test.py +++ b/tests/struct_test.py @@ -280,3 +280,23 @@ def test_struct_flatten_recursive(df): df_flat = df.struct.flatten(recursive=False) assert df_flat.get_column_names() == ['array_copy1', 'array_copy2', 'integer'] + + +def test_struct_create(): + data = { + 'index': [1, 2, 3, 4, 5], + 'value': [10, 20, 30, 40, 50], + 'place': ['Amsterdam', 'London', 'Paris', 'Ohrid', 'Edinburgh'], + } + + df = vaex.from_dict(data) + + df['content'] = df.struct.create(['index', 'value', df.place]) + + assert df.shape == (5, 4) + assert df['content'].dtype == 'struct' # perhaps we should have a better way to check this + + df['content_new_names'] = df.struct.create({'index': 'Index', 'value': 'Value', df.place: 'Location'}) + + assert df.shape == (5, 5) + assert df['content_new_names'].dtype == 'struct'