Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion autotest/dfns/__snapshots__/v2.0.0.dev2/utl-ts.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
"fields": {
"names": {
"type": "keyword",
"description": "xxx"
"description": "xxx",
"aliases": [
"name"
]
},
"time_series_names": {
"type": "array",
Expand Down
3 changes: 3 additions & 0 deletions autotest/dfns/__snapshots__/v2.0.0.dev2/utl-ts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ description = "xxx"
[blocks.attributes.fields.time_series_namerecord.fields.names]
type = "keyword"
description = "xxx"
aliases = [
"name",
]

[blocks.attributes.fields.time_series_namerecord.fields.time_series_names]
type = "array"
Expand Down
2 changes: 2 additions & 0 deletions autotest/dfns/__snapshots__/v2.0.0.dev2/utl-ts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ blocks:
names:
type: keyword
description: xxx
aliases:
- name
time_series_names:
type: array
description: Name by which a package references a particular time-array series. The name must
Expand Down
5 changes: 4 additions & 1 deletion autotest/dfns/__snapshots__/v2.0.0.dev3/utl-ts.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
"fields": {
"names": {
"type": "keyword",
"description": "xxx"
"description": "xxx",
"aliases": [
"name"
]
},
"time_series_names": {
"type": "array",
Expand Down
3 changes: 3 additions & 0 deletions autotest/dfns/__snapshots__/v2.0.0.dev3/utl-ts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ description = "xxx"
[blocks.attributes.fields.time_series_namerecord.fields.names]
type = "keyword"
description = "xxx"
aliases = [
"name",
]

[blocks.attributes.fields.time_series_namerecord.fields.time_series_names]
type = "array"
Expand Down
2 changes: 2 additions & 0 deletions autotest/dfns/__snapshots__/v2.0.0.dev3/utl-ts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ blocks:
names:
type: keyword
description: xxx
aliases:
- name
time_series_names:
type: array
description: Name by which a package references a particular time-array series. The name must
Expand Down
6 changes: 6 additions & 0 deletions autotest/dfns/test_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,9 @@ def test_migrate_package_dims_are_component_scoped(dev3):
name for name in spec.components if name.split("-")[1].startswith("dis")
}
assert ("sim-tdis", "nper") in shared


def test_migrate_keyword_aliases(dfn_dir):
component = _migrate_dev3(dfn_dir, "utl-ts")
record = component.blocks["attributes"].fields["time_series_namerecord"]
assert record.fields["names"].aliases == ["name"]
6 changes: 6 additions & 0 deletions autotest/dfns/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,3 +1069,9 @@ def test_index_rejects_unknown_kind():
def test_signed_index_requires_integer_array():
with pytest.raises(ValueError, match="requires dtype='integer'"):
Array(name="ic", dtype="double", shape=["ncon"], index="signed")


def test_keyword_aliases_round_trip():
field = Keyword(name="names", aliases=["name"])
assert Keyword.model_validate(field.model_dump()).aliases == ["name"]
assert "aliases" not in Keyword(name="names").model_dump(exclude_defaults=True)
6 changes: 6 additions & 0 deletions docs/md/dfnspec.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,12 @@ Scalar fields define a single value.

Type `keyword`. Represents a boolean choice. In input files, the presence of a keyword indicates true, its absence false.

##### Type-specific attributes

###### `aliases`

`[string] (default: [])`. Other spellings MF6 accepts for the keyword.

#### String

Type `string`.
Expand Down
1 change: 1 addition & 0 deletions modflow_devtools/dfn/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Field(TypedDict):
preserve_case: NotRequired[bool]
numeric_index: NotRequired[bool]
support_negative_index: NotRequired[bool]
other_names: NotRequired[str]
# Whether MF6 requires this block's header to appear in the input file
# even when it has zero body lines (e.g. an empty required recarray
# block). Set explicitly on the block's aggregate field -- see
Expand Down
1 change: 1 addition & 0 deletions modflow_devtools/dfns/migrate_to_v2_0_0_dev2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,7 @@ def _to_scalar() -> v2.Scalar:
netcdf=netcdf,
removed=removed,
deprecated=deprecated,
aliases=(f.get("other_names") or "").lower().split(),
)
if _type == "string":
return v2.String(
Expand Down
8 changes: 8 additions & 0 deletions modflow_devtools/dfns/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,14 @@
"default": "keyword",
"title": "Type",
"type": "string"
},
"aliases": {
"default": [],
"items": {
"type": "string"
},
"title": "Aliases",
"type": "array"
}
},
"required": [
Expand Down
3 changes: 2 additions & 1 deletion modflow_devtools/dfns/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def render(self, *, inline: bool = False) -> str:

class Keyword(InputFieldBase):
type: Literal["keyword"] = PydanticField(default="keyword", frozen=True)
aliases: list[str] = []


class String(InputFieldBase):
Expand Down Expand Up @@ -221,7 +222,7 @@ def _leading_tags(field: "InputField", *, every_line: bool = False) -> list[str]
(a Union with an arm that begins with a value instead doesn't qualify)."""
match field:
case Keyword():
return [field.name]
return [field.name, *field.aliases]
case String() | Integer() | Double() | Array() | File():
return [field.name] if field.tagged else []
case Record():
Expand Down
Loading