-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9128f21
commit 8f888a9
Showing
7 changed files
with
241 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# 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. | ||
|
||
# cython: language_level = 3 | ||
|
||
from libc.stdint cimport int64_t | ||
|
||
cdef extern from "nanoarrow.h": | ||
cdef int ARROW_FLAG_DICTIONARY_ORDERED | ||
cdef int ARROW_FLAG_NULLABLE | ||
cdef int ARROW_FLAG_MAP_KEYS_SORTED | ||
|
||
cdef struct ArrowSchema: | ||
const char* format | ||
const char* name | ||
const char* metadata | ||
int64_t flags | ||
int64_t n_children | ||
ArrowSchema** children | ||
ArrowSchema* dictionary | ||
void (*release)(ArrowSchema*) | ||
void* private_data | ||
|
||
cdef struct ArrowArray: | ||
int64_t length | ||
int64_t null_count | ||
int64_t offset | ||
int64_t n_buffers | ||
int64_t n_children | ||
const void** buffers | ||
ArrowArray** children | ||
ArrowArray* dictionary | ||
void (*release)(ArrowArray*) | ||
void* private_data | ||
|
||
cdef struct ArrowArrayStream: | ||
int (*get_schema)(ArrowArrayStream* stream, ArrowSchema* out) | ||
int (*get_next)(ArrowArrayStream* stream, ArrowArray* out) | ||
const char* (*get_last_error)(ArrowArrayStream*) | ||
void (*release)(ArrowArrayStream* stream) | ||
void* private_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,37 @@ | ||
import numpy as np | ||
import pyarrow as pa | ||
|
||
import nanoarrow | ||
import nanoarrow as na | ||
|
||
import pytest | ||
|
||
def test_version(): | ||
assert(na.version() == "0.1.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(): | ||
pa_schema = pa.schema([pa.field("some_name", pa.int32())]) | ||
na_schema = na.Schema.from_pyarrow(pa_schema) | ||
assert(na_schema.format == "+s") | ||
assert(na_schema.flags == 0) | ||
assert(len(na_schema.children), 1) | ||
assert(na_schema.children[0].format == "i") |