-
Notifications
You must be signed in to change notification settings - Fork 50
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
Add arrow adapter #755
Merged
Merged
Add arrow adapter #755
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
caa27f1
rebased 1st commit
c8e28d9
rebased
034749c
tried to implement streamed batch writing
12eaad4
appending trial for arrow adapter
585bf7d
create two instance of arrow adapter for stream and random access format
85ae8fb
tested open_append_stream. note: closing stream does not allow open_a…
fc3bd94
only filereader is allowed. note: unit tests are to be implemented
75006c8
some more refactoring
a22c717
some more refactoring. still needs unit testing
3c28b62
implemented some unit tests, to be continued ...
74b0320
refactor and fix test
23e270c
fixed changelog error
35e829f
addressed comments
a605c92
rebased the branch
043a808
addressed comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Empty file.
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,69 @@ | ||
import tempfile | ||
|
||
import pyarrow as pa | ||
import pytest | ||
|
||
from tiled.adapters.arrow import ArrowAdapter | ||
from tiled.structures.table import TableStructure | ||
|
||
names = ["f0", "f1", "f2"] | ||
data0 = [ | ||
pa.array([1, 2, 3, 4, 5]), | ||
pa.array(["foo0", "bar0", "baz0", None, "goo0"]), | ||
pa.array([True, None, False, True, None]), | ||
] | ||
data1 = [ | ||
pa.array([6, 7, 8, 9, 10, 11, 12]), | ||
pa.array(["foo1", "bar1", None, "baz1", "biz", None, "goo"]), | ||
pa.array([None, True, True, False, False, None, True]), | ||
] | ||
data2 = [pa.array([13, 14]), pa.array(["foo2", "baz2"]), pa.array([False, None])] | ||
|
||
batch0 = pa.record_batch(data0, names=names) | ||
batch1 = pa.record_batch(data1, names=names) | ||
batch2 = pa.record_batch(data2, names=names) | ||
data_uri = "file://localhost/" + tempfile.gettempdir() | ||
|
||
|
||
@pytest.fixture | ||
def adapter() -> ArrowAdapter: | ||
table = pa.Table.from_arrays(data0, names) | ||
structure = TableStructure.from_arrow_table(table, npartitions=3) | ||
assets = ArrowAdapter.init_storage(data_uri, structure=structure) | ||
return ArrowAdapter([asset.data_uri for asset in assets], structure=structure) | ||
|
||
|
||
def test_attributes(adapter: ArrowAdapter) -> None: | ||
assert adapter.structure().columns == names | ||
assert adapter.structure().npartitions == 3 | ||
|
||
|
||
def test_write_read(adapter: ArrowAdapter) -> None: | ||
# test writing to a partition and reading it | ||
adapter.write_partition(batch0, 0) | ||
assert pa.Table.from_arrays(data0, names) == pa.Table.from_pandas( | ||
adapter.read_partition(0) | ||
) | ||
|
||
adapter.write_partition([batch0, batch1], 1) | ||
assert pa.Table.from_batches([batch0, batch1]) == pa.Table.from_pandas( | ||
adapter.read_partition(1) | ||
) | ||
|
||
adapter.write_partition([batch0, batch1, batch2], 2) | ||
assert pa.Table.from_batches([batch0, batch1, batch2]) == pa.Table.from_pandas( | ||
adapter.read_partition(2) | ||
) | ||
|
||
# test write to all partitions and read all | ||
adapter.write_partition([batch0, batch1, batch2], 0) | ||
adapter.write_partition([batch2, batch0, batch1], 1) | ||
adapter.write_partition([batch1, batch2, batch0], 2) | ||
|
||
assert pa.Table.from_pandas(adapter.read()) == pa.Table.from_batches( | ||
[batch0, batch1, batch2, batch2, batch0, batch1, batch1, batch2, batch0] | ||
) | ||
|
||
# test adapter.write() raises NotImplementedError when there are more than 1 partitions | ||
with pytest.raises(NotImplementedError): | ||
adapter.write(batch0) |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that if you run
pytest
it won't discover this file because it only discovers subpackages and modules that have the wordtest
in them. The directory_tests/adapters
needs to be renamed_tests/test_adapters
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added also MyPy check for the
adapter/test_arrow.py
. I was thinking of migrating unit tests in relevant directories in the future and thought that we can type check them too.