Skip to content

Commit

Permalink
Writing and reading tables works
Browse files Browse the repository at this point in the history
  • Loading branch information
danielballan committed Feb 25, 2024
1 parent 0aadaca commit d62e9f8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
20 changes: 16 additions & 4 deletions tiled/_tests/test_writing.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def test_union_two_tables(tree):
df2 = pandas.DataFrame({"C": [], "D": [], "E": []})
structure1 = TableStructure.from_pandas(df1)
structure2 = TableStructure.from_pandas(df2)
client.create_union(
x = client.create_union(
[
DataSource(
structure_family=StructureFamily.table,
Expand All @@ -490,6 +490,10 @@ def test_union_two_tables(tree):
],
key="x",
)
x.contents["table1"].write(df1)
x.contents["table2"].write(df2)
x.contents["table1"].read()
x.contents["table2"].read()


def test_union_two_tables_colliding_names(tree):
Expand Down Expand Up @@ -547,13 +551,13 @@ def test_union_two_tables_two_arrays(tree):
client = from_context(context)
df1 = pandas.DataFrame({"A": [], "B": []})
df2 = pandas.DataFrame({"C": [], "D": [], "E": []})
arr1 = numpy.array([], dtype=numpy.float64)
arr2 = numpy.array([], dtype=numpy.int8)
arr1 = numpy.ones((5, 5), dtype=numpy.float64)
arr2 = 2 * numpy.ones((5, 5), dtype=numpy.int8)
structure1 = TableStructure.from_pandas(df1)
structure2 = TableStructure.from_pandas(df2)
structure3 = ArrayStructure.from_array(arr1)
structure4 = ArrayStructure.from_array(arr2)
client.create_union(
x = client.create_union(
[
DataSource(
structure_family=StructureFamily.table,
Expand All @@ -578,6 +582,14 @@ def test_union_two_tables_two_arrays(tree):
],
key="x",
)
x.contents["table1"].write(df1)
x.contents["table2"].write(df2)
x.contents["F"].write_block(arr1, (0, 0))
x.contents["G"].write_block(arr2, (0, 0))
x.contents["table1"].read()
x.contents["table2"].read()
x.contents["F"].read()
x.contents["G"].read()


def test_union_table_column_array_key_collision(tree):
Expand Down
5 changes: 5 additions & 0 deletions tiled/catalog/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,11 @@ class CatalogUnionAdapter(CatalogNodeAdapter):
async def read(self, *args, **kwargs):
return await ensure_awaitable((await self.get_adapter()).read, *args, **kwargs)

async def read_block(self, *args, **kwargs):
return await ensure_awaitable(
(await self.get_adapter()).read_block, *args, **kwargs
)

async def write(self, *args, **kwargs):
return await ensure_awaitable((await self.get_adapter()).write, *args, **kwargs)

Expand Down
6 changes: 5 additions & 1 deletion tiled/server/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,17 @@ async def array_block(
expected_shape=Depends(expected_shape),
format: Optional[str] = None,
filename: Optional[str] = None,
data_source: Optional[str] = None,
serialization_registry=Depends(get_serialization_registry),
settings: BaseSettings = Depends(get_settings),
):
"""
Fetch a chunk of array-like data.
"""
shape = entry.structure().shape
if data_source is None:
shape = entry.structure().shape
else:
shape = entry.data_source.structure.shape
# Check that block dimensionality matches array dimensionality.
ndim = len(shape)
if len(block) != ndim:
Expand Down

0 comments on commit d62e9f8

Please sign in to comment.