Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(python): Add array creation/building from buffers #378

Merged
merged 68 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
622465d
re-render readme
paleolimbot Jan 31, 2024
3d36f97
tweak the Device Python wrapper
paleolimbot Jan 31, 2024
23480d2
use memoryview's iterator where possible
paleolimbot Jan 31, 2024
45b100f
more flexible buffer view
paleolimbot Jan 31, 2024
6ff52bc
suggestsions
paleolimbot Feb 1, 2024
693b0a8
buffer stuff compiling without error
paleolimbot Feb 2, 2024
a5cf096
working buffer
paleolimbot Feb 2, 2024
19def06
make work with Python 3.8, maybe better checking of buffer flags
paleolimbot Feb 2, 2024
778ebae
test some buffer things
paleolimbot Feb 3, 2024
b666fc3
more buffer tests
paleolimbot Feb 3, 2024
2c322a5
more tests
paleolimbot Feb 3, 2024
d203cde
start on buffer/array builders
paleolimbot Feb 3, 2024
aa044ac
working on array thing
paleolimbot Feb 3, 2024
712f471
fix array from pybuffer
paleolimbot Feb 4, 2024
92f3132
writable buffers
paleolimbot Feb 4, 2024
82dbece
a few tests
paleolimbot Feb 4, 2024
63613ae
move tests
paleolimbot Feb 4, 2024
6014a95
remove duplicate tests, tidy c_lib
paleolimbot Feb 4, 2024
8b3d44d
fix empty array building
paleolimbot Feb 4, 2024
3427e7f
fix buffer setting with empty
paleolimbot Feb 4, 2024
6dd74f6
actually fix empty array
paleolimbot Feb 4, 2024
b24e743
fix doctests
paleolimbot Feb 5, 2024
f6b9e59
better error handling
paleolimbot Feb 5, 2024
404da09
result -> code
paleolimbot Feb 5, 2024
a419807
builder tests
paleolimbot Feb 5, 2024
de3b550
document build from buffers
paleolimbot Feb 5, 2024
8c57e06
factor out c_format_from_arrow_type
paleolimbot Feb 5, 2024
181bc0e
from iterable
paleolimbot Feb 5, 2024
a82b5da
bitpacking
paleolimbot Feb 5, 2024
08acfbc
test intervals
paleolimbot Feb 6, 2024
d26a4e3
coverage
paleolimbot Feb 6, 2024
3833067
test coverage
paleolimbot Feb 6, 2024
5974a5b
document changes
paleolimbot Feb 6, 2024
34c8fea
better doc for buffer
paleolimbot Feb 8, 2024
17f127c
better construct for c_array
paleolimbot Feb 9, 2024
7ee63ec
unify buffer creation
paleolimbot Feb 9, 2024
a223952
consolidate c_buffer_from_iterable usage
paleolimbot Feb 9, 2024
cb31e64
maybe iterable support in c_array
paleolimbot Feb 9, 2024
1a7e8b8
isort
paleolimbot Feb 9, 2024
a0d7c96
maybe support Python 3.8
paleolimbot Feb 9, 2024
0058da7
clarify requested_schema behaviour
paleolimbot Feb 9, 2024
bee8bee
maybe fix pypy
paleolimbot Feb 9, 2024
642e116
pre-commit
paleolimbot Feb 9, 2024
d297a6f
fix doctests
paleolimbot Feb 9, 2024
c98e0dc
better coverage of array constructor
paleolimbot Feb 9, 2024
49199e2
coverage
paleolimbot Feb 9, 2024
a936a4b
use root na usage
paleolimbot Feb 9, 2024
3171e1c
separate array and buffer tests
paleolimbot Feb 9, 2024
e49bbc3
isort
paleolimbot Feb 9, 2024
2ced8aa
buffer protocol on CBufer
paleolimbot Feb 9, 2024
459c5e4
remove set_xx methods
paleolimbot Feb 15, 2024
f97fc63
Update python/src/nanoarrow/c_lib.py
paleolimbot Feb 15, 2024
16a22fa
Update python/src/nanoarrow/c_lib.py
paleolimbot Feb 15, 2024
b449a9f
Update python/src/nanoarrow/c_lib.py
paleolimbot Feb 15, 2024
ec7a42e
Update python/src/nanoarrow/c_lib.py
paleolimbot Feb 15, 2024
823f552
requested_schema -> schema
paleolimbot Feb 15, 2024
9ce4f6d
make setxx methods internal
paleolimbot Feb 15, 2024
109231e
separate buffer and buffer builder
paleolimbot Feb 15, 2024
44229e4
error for pybuffer + schema for now
paleolimbot Feb 15, 2024
1b4c3c6
maybe better array/buffer
paleolimbot Feb 15, 2024
87364f5
sort element vs. item maybe
paleolimbot Feb 15, 2024
d091b45
more element tests
paleolimbot Feb 15, 2024
c22d2d0
add requested_schema back in
paleolimbot Feb 15, 2024
8bdb881
Update python/src/nanoarrow/c_lib.py
paleolimbot Feb 15, 2024
10e0fb9
clarify comment
paleolimbot Feb 15, 2024
0c46b76
fix typo
paleolimbot Feb 15, 2024
05f104c
maybe fix array handling
paleolimbot Feb 15, 2024
a94f7fd
update language
paleolimbot Feb 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 17 additions & 32 deletions python/README.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@
"- storage_type: 'decimal128'\n",
"- decimal_bitwidth: 128\n",
"- decimal_precision: 10\n",
"- decimal_scale: 3"
"- decimal_scale: 3\n",
"- dictionary_ordered: False\n",
"- map_keys_sorted: False\n",
"- nullable: True\n",
"- storage_type_id: 24\n",
"- type_id: 24"
]
},
"execution_count": 3,
Expand Down Expand Up @@ -195,7 +200,7 @@
"- length: 4\n",
"- offset: 0\n",
"- null_count: 1\n",
"- buffers: (2939032895680, 2939032895616, 2939032895744)\n",
"- buffers: (5209191547072, 5209191547008, 5209191547136)\n",
"- dictionary: NULL\n",
"- children[0]:"
]
Expand Down Expand Up @@ -297,20 +302,7 @@
"data": {
"text/plain": [
"<nanoarrow.c_lib.CArrayStream>\n",
"- get_schema(): <nanoarrow.c_lib.CSchema struct>\n",
" - format: '+s'\n",
" - name: ''\n",
" - flags: 0\n",
" - metadata: NULL\n",
" - dictionary: NULL\n",
" - children[1]:\n",
" 'some_column': <nanoarrow.c_lib.CSchema int32>\n",
" - format: 'i'\n",
" - name: 'some_column'\n",
" - flags: 2\n",
" - metadata: NULL\n",
" - dictionary: NULL\n",
" - children[0]:"
"- get_schema(): struct<some_column: int32>"
]
},
"execution_count": 8,
Expand Down Expand Up @@ -343,7 +335,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"<nanoarrow.c_lib.CArray struct>\n",
"<nanoarrow.c_lib.CArray struct<some_column: int32>>\n",
"- length: 3\n",
"- offset: 0\n",
"- null_count: 0\n",
Expand All @@ -354,7 +346,7 @@
" - length: 3\n",
" - offset: 0\n",
" - null_count: 0\n",
" - buffers: (0, 2939033026688)\n",
" - buffers: (0, 5209191678080)\n",
" - dictionary: NULL\n",
" - children[0]:\n"
]
Expand Down Expand Up @@ -382,20 +374,7 @@
"data": {
"text/plain": [
"<nanoarrow.c_lib.CArrayStream>\n",
"- get_schema(): <nanoarrow.c_lib.CSchema struct>\n",
" - format: '+s'\n",
" - name: ''\n",
" - flags: 0\n",
" - metadata: NULL\n",
" - dictionary: NULL\n",
" - children[1]:\n",
" 'some_column': <nanoarrow.c_lib.CSchema int32>\n",
" - format: 'i'\n",
" - name: 'some_column'\n",
" - flags: 2\n",
" - metadata: NULL\n",
" - dictionary: NULL\n",
" - children[0]:"
"- get_schema(): struct<some_column: int32>"
]
},
"execution_count": 10,
Expand Down Expand Up @@ -433,6 +412,12 @@
"\n",
"# Run tests\n",
"pytest -vvx\n",
"```\n",
"\n",
"If you need to debug or edit any .c files used to build the native extension, you can generate the `compile_commands.json` usable by most IDEs/clang tools using [Bear](https://github.com/rizsotto/Bear).\n",
"\n",
"```shell\n",
"bear -- python setup.py build_ext --inplace && mv compile_commands.json build\n",
"```"
]
}
Expand Down
47 changes: 16 additions & 31 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ na.c_schema_view(schema)
- decimal_bitwidth: 128
- decimal_precision: 10
- decimal_scale: 3
- dictionary_ordered: False
- map_keys_sorted: False
- nullable: True
- storage_type_id: 24
- type_id: 24



Expand Down Expand Up @@ -131,7 +136,7 @@ array
- length: 4
- offset: 0
- null_count: 1
- buffers: (2939032895680, 2939032895616, 2939032895744)
- buffers: (5209191547072, 5209191547008, 5209191547136)
- dictionary: NULL
- children[0]:

Expand Down Expand Up @@ -194,20 +199,7 @@ array_stream


<nanoarrow.c_lib.CArrayStream>
- get_schema(): <nanoarrow.c_lib.CSchema struct>
- format: '+s'
- name: ''
- flags: 0
- metadata: NULL
- dictionary: NULL
- children[1]:
'some_column': <nanoarrow.c_lib.CSchema int32>
- format: 'i'
- name: 'some_column'
- flags: 2
- metadata: NULL
- dictionary: NULL
- children[0]:
- get_schema(): struct<some_column: int32>



Expand All @@ -219,7 +211,7 @@ for array in array_stream:
print(array)
```

<nanoarrow.c_lib.CArray struct>
<nanoarrow.c_lib.CArray struct<some_column: int32>>
- length: 3
- offset: 0
- null_count: 0
Expand All @@ -230,7 +222,7 @@ for array in array_stream:
- length: 3
- offset: 0
- null_count: 0
- buffers: (0, 2939033026688)
- buffers: (0, 5209191678080)
- dictionary: NULL
- children[0]:

Expand All @@ -248,20 +240,7 @@ array_stream


<nanoarrow.c_lib.CArrayStream>
- get_schema(): <nanoarrow.c_lib.CSchema struct>
- format: '+s'
- name: ''
- flags: 0
- metadata: NULL
- dictionary: NULL
- children[1]:
'some_column': <nanoarrow.c_lib.CSchema int32>
- format: 'i'
- name: 'some_column'
- flags: 2
- metadata: NULL
- dictionary: NULL
- children[0]:
- get_schema(): struct<some_column: int32>



Expand All @@ -285,3 +264,9 @@ pip install -e .[test]
# Run tests
pytest -vvx
```

If you need to debug or edit any .c files used to build the native extension, you can generate the `compile_commands.json` usable by most IDEs/clang tools using [Bear](https://github.com/rizsotto/Bear).

```shell
bear -- python setup.py build_ext --inplace && mv compile_commands.json build
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, this is a bit cryptic to me what this does / can help you with, but I am also not familiar with the tool or the compile_commands

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave it out for now since it's probably just me who has to remember that command. If build/compile_commands.json is present, most editors "just work" with the .c/.cc./.h files without additional configuration.

Loading
Loading