Skip to content

Commit 12677f7

Browse files
committed
Rename builder class
1 parent 50bb7be commit 12677f7

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

src/mdio/core/v1/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55

66
from ._overloads import mdio
7-
from .builder import Builder
7+
from .builder import MDIODatasetBuilder
88
from .builder import write_mdio_metadata
99
from ._serializer import (
1010
make_coordinate,
@@ -17,7 +17,7 @@
1717

1818

1919
__all__ = [
20-
"Builder",
20+
"MDIODatasetBuilder",
2121
"AbstractTemplateFactory",
2222
"make_coordinate",
2323
"make_dataset",

src/mdio/core/v1/builder.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ class _BuilderState(Enum):
4343
HAS_VARIABLES = auto()
4444

4545

46-
class Builder:
46+
class MDIODatasetBuilder:
4747
"""Builder for creating MDIO datasets with enforced build order.
4848
49-
The build order is:
49+
This builder implements the builder pattern to create MDIO datasets with a v1 schema.
50+
It enforces a specific build order to ensure valid dataset construction:
5051
1. Must add dimensions first via add_dimension()
5152
2. Can optionally add coordinates via add_coordinate()
5253
3. Must add variables via add_variable()
@@ -77,7 +78,7 @@ def add_dimension(
7778
long_name: str = None,
7879
data_type: ScalarType | StructuredType = ScalarType.INT32,
7980
metadata: Optional[List[AllUnits | UserAttributes]] | Dict[str, Any] = None,
80-
) -> "Builder":
81+
) -> "MDIODatasetBuilder":
8182
"""Add a dimension.
8283
8384
This must be called at least once before adding coordinates or variables.
@@ -117,7 +118,7 @@ def add_coordinate(
117118
dimensions: Optional[List[NamedDimension | str]] = None,
118119
data_type: ScalarType | StructuredType = ScalarType.FLOAT32,
119120
metadata: Optional[List[AllUnits | UserAttributes]] | Dict[str, Any] = None,
120-
) -> "Builder":
121+
) -> "MDIODatasetBuilder":
121122
"""Add a coordinate after adding at least one dimension."""
122123
if self._state == _BuilderState.INITIAL:
123124
raise ValueError(
@@ -164,7 +165,7 @@ def add_variable(
164165
compressor: Blosc | ZFP | None = None,
165166
coordinates: Optional[List[Coordinate | str]] = None,
166167
metadata: Optional[VariableMetadata] = None,
167-
) -> "Builder":
168+
) -> "MDIODatasetBuilder":
168169
"""Add a variable after adding at least one dimension."""
169170
if self._state == _BuilderState.INITIAL:
170171
raise ValueError("Must add at least one dimension before adding variables")

tests/unit/schema/v1/test_template_builder.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pytest
66

7-
from mdio.core.v1.builder import Builder as TemplateBuilder
7+
from mdio.core.v1.builder import MDIODatasetBuilder
88
from mdio.core.v1.builder import _BuilderState
99
from mdio.core.v1.builder import write_mdio_metadata
1010
from mdio.schema.compressors import Blosc
@@ -15,7 +15,7 @@
1515

1616
def test_builder_initialization():
1717
"""Test basic builder initialization."""
18-
builder = TemplateBuilder("test_dataset")
18+
builder = MDIODatasetBuilder("test_dataset")
1919
assert builder.name == "test_dataset"
2020
assert builder.api_version == "1.0.0"
2121
assert isinstance(builder.created_on, datetime)
@@ -27,7 +27,7 @@ def test_builder_initialization():
2727

2828
def test_dimension_builder_state():
2929
"""Test dimension builder state transitions and functionality."""
30-
builder = TemplateBuilder("test_dataset")
30+
builder = MDIODatasetBuilder("test_dataset")
3131

3232
# First dimension should change state to HAS_DIMENSIONS and create a variable
3333
builder = builder.add_dimension("x", 100, long_name="X Dimension")
@@ -55,7 +55,7 @@ def test_dimension_builder_state():
5555

5656
def test_dimension_with_metadata():
5757
"""Test adding dimensions with custom metadata."""
58-
builder = TemplateBuilder("test_dataset")
58+
builder = MDIODatasetBuilder("test_dataset")
5959

6060
# Add dimension with custom metadata
6161
builder = builder.add_dimension(
@@ -74,7 +74,7 @@ def test_dimension_with_metadata():
7474

7575
def test_coordinate_builder_state():
7676
"""Test coordinate builder state transitions and functionality."""
77-
builder = TemplateBuilder("test_dataset")
77+
builder = MDIODatasetBuilder("test_dataset")
7878

7979
# Should not be able to add coordinates before dimensions
8080
with pytest.raises(
@@ -106,7 +106,7 @@ def test_coordinate_builder_state():
106106

107107
def test_variable_builder_state():
108108
"""Test variable builder state transitions and functionality."""
109-
builder = TemplateBuilder("test_dataset")
109+
builder = MDIODatasetBuilder("test_dataset")
110110

111111
# Should not be able to add variables before dimensions
112112
with pytest.raises(
@@ -136,7 +136,7 @@ def test_variable_builder_state():
136136
def test_build_dataset():
137137
"""Test building a complete dataset."""
138138
dataset = (
139-
TemplateBuilder("test_dataset")
139+
MDIODatasetBuilder("test_dataset")
140140
.add_dimension("x", 100)
141141
.add_dimension("y", 200)
142142
.add_coordinate("x_coord", dimensions=["x"])
@@ -159,7 +159,7 @@ def test_build_dataset():
159159
def test_auto_naming():
160160
"""Test automatic naming of coordinates and variables."""
161161
dataset = (
162-
TemplateBuilder("test_dataset")
162+
MDIODatasetBuilder("test_dataset")
163163
.add_dimension("x", 100)
164164
.add_coordinate() # Should be named "coord_0"
165165
.add_coordinate() # Should be named "coord_1"
@@ -176,7 +176,7 @@ def test_auto_naming():
176176
def test_default_dimensions():
177177
"""Test that coordinates and variables use all dimensions by default."""
178178
dataset = (
179-
TemplateBuilder("test_dataset")
179+
MDIODatasetBuilder("test_dataset")
180180
.add_dimension("x", 100)
181181
.add_dimension("y", 200)
182182
.add_coordinate() # Should use both x and y dimensions
@@ -194,7 +194,7 @@ def test_default_dimensions():
194194

195195
def test_build_order_enforcement():
196196
"""Test that the builder enforces the correct build order."""
197-
builder = TemplateBuilder("test_dataset")
197+
builder = MDIODatasetBuilder("test_dataset")
198198

199199
# Should not be able to add coordinates before dimensions
200200
with pytest.raises(
@@ -218,7 +218,7 @@ def test_build_order_enforcement():
218218
def test_toy_example(tmp_path):
219219
"""Test building a toy dataset with multiple variables and attributes."""
220220
dataset = (
221-
TemplateBuilder(
221+
MDIODatasetBuilder(
222222
"campos_3d",
223223
attributes={
224224
"textHeader": [

tests/unit/test_template_factory.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Unit tests for MDIO v1 factory."""
22

3+
# TODO(BrianMichell): Update this to use canonical factory functions.
4+
35
from datetime import datetime
46
from datetime import timezone
57

0 commit comments

Comments
 (0)