MCPcopy Create free account
hub / github.com/apache/arrow / test_struct_array_sort

Function test_struct_array_sort

python/pyarrow/tests/test_array.py:4126–4169  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4124
4125
4126def test_struct_array_sort():
4127 arr = pa.StructArray.from_arrays([
4128 pa.array([5, 7, 7, 35], type=pa.int64()),
4129 pa.array(["foo", "car", "bar", "foobar"])
4130 ], names=["a", "b"])
4131
4132 sorted_arr = arr.sort("descending", by="a")
4133 assert sorted_arr.to_pylist() == [
4134 {"a": 35, "b": "foobar"},
4135 {"a": 7, "b": "car"},
4136 {"a": 7, "b": "bar"},
4137 {"a": 5, "b": "foo"},
4138 ]
4139
4140 sorted_arr = arr.sort()
4141 assert sorted_arr.to_pylist() == [
4142 {"a": 5, "b": "foo"},
4143 {"a": 7, "b": "bar"},
4144 {"a": 7, "b": "car"},
4145 {"a": 35, "b": "foobar"},
4146 ]
4147
4148 arr_with_nulls = pa.StructArray.from_arrays([
4149 pa.array([5, 7, 7, 35], type=pa.int64()),
4150 pa.array(["foo", "car", "bar", "foobar"])
4151 ], names=["a", "b"], mask=pa.array([False, False, True, False]))
4152
4153 sorted_arr = arr_with_nulls.sort(
4154 "descending", by="a", null_placement="at_start")
4155 assert sorted_arr.to_pylist() == [
4156 None,
4157 {"a": 35, "b": "foobar"},
4158 {"a": 7, "b": "car"},
4159 {"a": 5, "b": "foo"},
4160 ]
4161
4162 sorted_arr = arr_with_nulls.sort(
4163 "descending", by="a", null_placement="at_end")
4164 assert sorted_arr.to_pylist() == [
4165 {"a": 35, "b": "foobar"},
4166 {"a": 7, "b": "car"},
4167 {"a": 5, "b": "foo"},
4168 None
4169 ]
4170
4171
4172def test_array_accepts_pyarrow_array():

Callers

nothing calls this directly

Calls 1

arrayMethod · 0.45

Tested by

no test coverage detected