paleolimbot commented on code in PR #117: URL: https://github.com/apache/arrow-nanoarrow/pull/117#discussion_r1132717128
########## python/tests/test_nanoarrow.py: ########## @@ -1,27 +1,155 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + import numpy as np import pyarrow as pa -import nanoarrow +import nanoarrow as na import pytest +def test_version(): + assert(na.version() == "0.2.0-SNAPSHOT") def test_as_numpy_array(): - + arr = pa.array([1, 2, 3]) - result = nanoarrow.as_numpy_array(arr) + result = na.as_numpy_array(arr) expected = arr.to_numpy() np.testing.assert_array_equal(result, expected) arr = pa.array([1, 2, 3], pa.uint8()) - result = nanoarrow.as_numpy_array(arr) + result = na.as_numpy_array(arr) expected = arr.to_numpy() np.testing.assert_array_equal(result, expected) arr = pa.array([1, 2, None]) with pytest.raises(ValueError, match="Cannot convert array with nulls"): - nanoarrow.as_numpy_array(arr) + na.as_numpy_array(arr) arr = pa.array([[1], [2, 3]]) with pytest.raises(TypeError, match="Cannot convert a non-primitive array"): - nanoarrow.as_numpy_array(arr) + na.as_numpy_array(arr) + +def test_schema_basic(): + # Blank invalid schema + schema = na.CSchema.Empty() + assert(schema.is_valid() is False) + assert(repr(schema) == "[invalid: schema is released]") + + pa_schema = pa.schema([pa.field("some_name", pa.int32())]) + pa_schema._export_to_c(schema._addr()) + + assert(schema.format == "+s") + assert(schema.flags == 0) + assert(len(schema.children) == 1) + assert(schema.children[0].format == "i") + assert(schema.children[0].name == "some_name") + assert(repr(schema.children[0]) == "int32") + + with pytest.raises(IndexError): + schema.children[1] + +def test_schema_parse(): + schema = na.CSchema.Empty() + with pytest.raises(RuntimeError): + schema.parse() + + pa.schema([pa.field("col1", pa.int32())])._export_to_c(schema._addr()) + + info = schema.parse() + assert(info['type'] == 'struct') + assert(info['storage_type'] == 'struct') + assert(info['name'] == '') + + # Check on the child + child = schema.children[0] + child_info = child.parse() + assert(child_info['type'] == 'int32') + assert(child_info['storage_type'] == 'int32') + assert(child_info['name'] == 'col1') + +def test_schema_info_params(): + schema = na.CSchema.Empty() + pa.binary(12)._export_to_c(schema._addr()) Review Comment: I'm going to punt on pyarrow integration just this second...for the tests it's only one extra line to `_export_to_c()`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
