Skip to content

Commit

Permalink
Rename contents -> parts.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielballan committed Feb 27, 2024
1 parent 7e86646 commit 92db498
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 40 deletions.
24 changes: 12 additions & 12 deletions tiled/_tests/test_writing.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +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()
x.parts["table1"].write(df1)
x.parts["table2"].write(df2)
x.parts["table1"].read()
x.parts["table2"].read()


def test_union_two_tables_colliding_names(tree):
Expand Down Expand Up @@ -583,16 +583,16 @@ def test_union_two_tables_two_arrays(tree):
key="x",
)
# Write by data source.
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.parts["table1"].write(df1)
x.parts["table2"].write(df2)
x.parts["F"].write_block(arr1, (0, 0))
x.parts["G"].write_block(arr2, (0, 0))

# Read by data source.
x.contents["table1"].read()
x.contents["table2"].read()
x.contents["F"].read()
x.contents["G"].read()
x.parts["table1"].read()
x.parts["table2"].read()
x.parts["F"].read()
x.parts["G"].read()

# Read by column.
for column in ["A", "B", "C", "D", "E", "F", "G"]:
Expand Down
11 changes: 5 additions & 6 deletions tiled/catalog/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
)
from ..query_registration import QueryTranslationRegistry
from ..server.pydantic_container import ContainerStructure
from ..server.pydantic_union import UnionStructure, UnionStructureItem
from ..server.pydantic_union import UnionStructure, UnionStructurePart
from ..server.schemas import Asset, DataSource, Management, Revision, Spec
from ..structures.core import StructureFamily
from ..utils import (
Expand Down Expand Up @@ -353,12 +353,11 @@ def structure(self):
# Give no inlined contents.
return ContainerStructure(contents=None, count=None)
if self.structure_family == StructureFamily.union:
contents = []
parts = []
all_keys = []
for data_source in self.data_sources:
contents.append(
UnionStructureItem(
data_source_id=data_source.id,
parts.append(
UnionStructurePart(
structure=data_source.structure,
structure_family=data_source.structure_family,
name=data_source.name,
Expand All @@ -368,7 +367,7 @@ def structure(self):
all_keys.extend(data_source.structure.columns)
else:
all_keys.append(data_source.name)
return UnionStructure(contents=contents, all_keys=all_keys)
return UnionStructure(parts=parts, all_keys=all_keys)
if self.data_sources:
assert len(self.data_sources) == 1 # more not yet implemented
return self.data_sources[0].structure
Expand Down
8 changes: 4 additions & 4 deletions tiled/client/union.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __repr__(self):
)

@property
def contents(self):
def parts(self):
return UnionContents(self)

def __getitem__(self, key):
Expand Down Expand Up @@ -53,12 +53,12 @@ def __init__(self, node):
def __repr__(self):
return (
f"<{type(self).__name__} {{"
+ ", ".join(f"'{item.name}'" for item in self.node.structure().contents)
+ ", ".join(f"'{item.name}'" for item in self.node.structure().parts)
+ "}>"
)

def __getitem__(self, name):
for index, union_item in enumerate(self.node.structure().contents):
for index, union_item in enumerate(self.node.structure().parts):
if union_item.name == name:
structure_family = union_item.structure_family
structure_dict = union_item.structure
Expand All @@ -68,7 +68,7 @@ def __getitem__(self, name):
item = copy.deepcopy(self.node.item)
item["attributes"]["structure_family"] = structure_family
item["attributes"]["structure"] = structure_dict
item["links"] = item["links"]["contents"][index]
item["links"] = item["links"]["parts"][index]
structure_type = STRUCTURE_TYPES[structure_family]
structure = structure_type.from_json(structure_dict)
return client_for_item(
Expand Down
6 changes: 3 additions & 3 deletions tiled/server/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def links_for_table(structure_family, structure, base_url, path_str, data_source
def links_for_union(structure_family, structure, base_url, path_str):
links = {}
# This contains the links for each structure.
links["contents"] = []
for item in structure.contents:
links["parts"] = []
for item in structure.parts:
item_links = LINKS_BY_STRUCTURE_FAMILY[item.structure_family](
item.structure_family,
item.structure,
Expand All @@ -69,7 +69,7 @@ def links_for_union(structure_family, structure, base_url, path_str):
data_source=item.name,
)
item_links["self"] = f"{base_url}/metadata/{path_str}"
links["contents"].append(item_links)
links["parts"].append(item_links)
return links


Expand Down
9 changes: 3 additions & 6 deletions tiled/server/pydantic_union.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from ..structures.core import StructureFamily


class UnionStructureItem(pydantic.BaseModel):
data_source_id: Optional[int]
class UnionStructurePart(pydantic.BaseModel):
structure_family: StructureFamily
structure: Any # Union of Structures, but we do not want to import them...
name: str
Expand All @@ -17,14 +16,12 @@ def from_json(cls, item):


class UnionStructure(pydantic.BaseModel):
contents: List[UnionStructureItem]
parts: List[UnionStructurePart]
all_keys: Optional[List[str]]

@classmethod
def from_json(cls, structure):
return cls(
contents=[
UnionStructureItem.from_json(item) for item in structure["contents"]
],
parts=[UnionStructurePart.from_json(item) for item in structure["parts"]],
all_keys=structure["all_keys"],
)
6 changes: 3 additions & 3 deletions tiled/server/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from starlette.responses import FileResponse

from .. import __version__
from ..server.pydantic_union import UnionStructure, UnionStructureItem
from ..server.pydantic_union import UnionStructure, UnionStructurePart
from ..structures.core import StructureFamily
from ..utils import ensure_awaitable, path_from_uri
from ..validation_registration import ValidationError
Expand Down Expand Up @@ -1127,8 +1127,8 @@ async def _create_node(
metadata_modified = False
if structure_family == StructureFamily.union:
structure = UnionStructure(
contents=[
UnionStructureItem(
parts=[
UnionStructurePart(
data_source_id=data_source.id,
structure=data_source.structure,
structure_family=data_source.structure_family,
Expand Down
9 changes: 3 additions & 6 deletions tiled/structures/union.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@


@dataclasses.dataclass
class UnionStructureItem:
data_source_id: int
class UnionStructurePart:
structure_family: StructureFamily
structure: Any # Union of Structures, but we do not want to import them...
name: Optional[str]
Expand All @@ -18,14 +17,12 @@ def from_json(cls, item):

@dataclasses.dataclass
class UnionStructure:
contents: List[UnionStructureItem]
parts: List[UnionStructurePart]
all_keys: List[str]

@classmethod
def from_json(cls, structure):
return cls(
contents=[
UnionStructureItem.from_json(item) for item in structure["contents"]
],
parts=[UnionStructurePart.from_json(item) for item in structure["parts"]],
all_keys=structure["all_keys"],
)

0 comments on commit 92db498

Please sign in to comment.