Skip to content

Commit efc6ff3

Browse files
committed
appease mypy
1 parent 5423882 commit efc6ff3

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

flopy4/mf6/converter/structure.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,12 @@ def _validate_duck_array(
179179
# Check for structured→flat conversion
180180
needs_reshape, target_shape = _detect_grid_reshape(value.shape, expected_dims, dim_dict)
181181
if needs_reshape:
182-
return _reshape_grid(value, target_shape, list(value.dims), expected_dims)
182+
assert (
183+
target_shape is not None
184+
) # target_shape is always set when needs_reshape is True
185+
return _reshape_grid(
186+
value, target_shape, [str(d) for d in value.dims], expected_dims
187+
)
183188
raise ValueError(f"Dimension mismatch: {value.dims} vs {expected_dims}")
184189
return value
185190

@@ -189,12 +194,13 @@ def _validate_duck_array(
189194
# Try structured→flat reshape
190195
needs_reshape, target_shape = _detect_grid_reshape(value.shape, expected_dims, dim_dict)
191196
if needs_reshape:
197+
assert (
198+
target_shape is not None
199+
) # target_shape is always set when needs_reshape is True
192200
return _reshape_grid(value, target_shape)
193201
raise ValueError(f"Shape mismatch: {value.shape} vs {expected_shape}")
194202
return value
195203

196-
return value
197-
198204

199205
def _fill_forward_time(
200206
data: np.ndarray | xr.DataArray, dims: list[str], nper: int
@@ -234,8 +240,6 @@ def _fill_forward_time(
234240
return data_broadcast
235241
return data
236242

237-
return data
238-
239243

240244
def _parse_list_format(
241245
value: list, expected_dims: list[str], expected_shape: tuple, field
@@ -339,7 +343,7 @@ def _parse_dict_format(
339343
return {0: value["data"]}
340344
return {0: value}
341345

342-
parsed = {}
346+
parsed: dict[int, Any] = {}
343347

344348
for key, val in value.items():
345349
# Handle special '*' key (means period/layer 0, don't fill forward)
@@ -436,7 +440,7 @@ def structure_array(
436440
# Handle different input types
437441
if isinstance(value, dict):
438442
# Parse dict format with fill-forward logic
439-
parsed_dict = _parse_dict_format(value, dims, shape, dim_dict, field, self_)
443+
parsed_dict = _parse_dict_format(value, dims, tuple(shape), dim_dict, field, self_)
440444

441445
# Build array using sparse or dense approach
442446
if np.prod(shape) > threshold:
@@ -515,7 +519,7 @@ def structure_array(
515519
)
516520
kper_range = range(key, next_key)
517521
else:
518-
kper_range = [key]
522+
kper_range = range(key, key + 1)
519523

520524
for kper in kper_range:
521525
if isinstance(val, (int, float)):
@@ -564,7 +568,7 @@ def structure_array(
564568

565569
elif isinstance(value, list):
566570
# List format
567-
result = _parse_list_format(value, dims, shape, field)
571+
result = _parse_list_format(value, dims, tuple(shape), field)
568572

569573
elif isinstance(value, (xr.DataArray, np.ndarray)):
570574
# Duck array - validate and reshape if needed
@@ -585,11 +589,11 @@ def structure_array(
585589
# Wrap in xarray if requested
586590
if return_xarray and not isinstance(result, xr.DataArray):
587591
# Build coordinates
588-
coords = {}
592+
xr_coords: dict[str, Any] = {}
589593
for dim in dims:
590594
if dim in dim_dict:
591-
coords[dim] = np.arange(dim_dict[dim])
595+
xr_coords[dim] = np.arange(dim_dict[dim])
592596

593-
result = _to_xarray(result, dims, coords)
597+
result = _to_xarray(result, dims, xr_coords)
594598

595599
return result

0 commit comments

Comments
 (0)