Skip to content

Commit 8f430a0

Browse files
committed
Satisfy pre-commit
1 parent 60f0f76 commit 8f430a0

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

src/mdio/builder/dataset_builder.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from typing import Any
88

99
from mdio import __version__
10+
from mdio.builder.schemas.chunk_grid import RegularChunkGrid
11+
from mdio.builder.schemas.chunk_grid import RegularChunkShape
1012
from mdio.builder.schemas.compressors import ZFP
1113
from mdio.builder.schemas.compressors import Blosc
1214
from mdio.builder.schemas.dimension import NamedDimension
@@ -102,17 +104,22 @@ def add_dimension(self, name: str, size: int) -> "MDIODatasetBuilder":
102104
return self
103105

104106
def push_dimension(
105-
self, dimension: NamedDimension, position: int, new_dim_chunk_size: int = 1, new_dim_size: int = 1
107+
self, dimension: NamedDimension, position: int, new_dim_chunk_size: int = 1
106108
) -> "MDIODatasetBuilder":
107109
"""Pushes a dimension to all Coordiantes and Variables.
110+
108111
The position argument is the domain index of the dimension to push.
109-
If a Variable is within the position domain, it will be inserted at the position and all remaining dimensions will be shifted to the right.
112+
If a Variable is within the position domain, it will be inserted at the position
113+
and all remaining dimensions will be shifted to the right.
110114
111115
Args:
112116
dimension: The dimension to push
113117
position: The position to push the dimension to
114118
new_dim_chunk_size: The chunk size for only the new dimension
115119
120+
Raises:
121+
ValueError: If the position is invalid
122+
116123
Returns:
117124
self: Returns self for method chaining
118125
"""
@@ -123,7 +130,6 @@ def push_dimension(
123130
msg = "Position is greater than the number of dimensions"
124131
raise ValueError(msg)
125132
if new_dim_chunk_size <= 0:
126-
# TODO(BrianMichell): Do we actually need to check this, or does Pydantic handle when we call?
127133
msg = "New dimension chunk size must be greater than 0"
128134
raise ValueError(msg)
129135

@@ -132,9 +138,6 @@ def push_dimension(
132138

133139
def propogate_dimension(variable: Variable, position: int, new_dim_chunk_size: int) -> Variable:
134140
"""Propogates the dimension to the variable or coordinate."""
135-
from mdio.builder.schemas.chunk_grid import RegularChunkGrid
136-
from mdio.builder.schemas.chunk_grid import RegularChunkShape
137-
138141
if len(variable.dimensions) + 1 <= position:
139142
# Don't do anything if the new dimension is not within the Variable's domain
140143
return variable
@@ -154,12 +157,11 @@ def propogate_dimension(variable: Variable, position: int, new_dim_chunk_size: i
154157
# Update metadata with new chunk grid
155158
new_metadata = variable.metadata.model_copy() if variable.metadata else VariableMetadata()
156159
new_metadata.chunk_grid = new_chunk_grid
157-
ret = variable.model_copy(update={"dimensions": new_dimensions, "metadata": new_metadata})
158-
return ret
160+
return variable.model_copy(update={"dimensions": new_dimensions, "metadata": new_metadata})
159161

160162
to_ignore = []
161163
for v in self._dimensions:
162-
to_ignore.append(v.name)
164+
to_ignore.append(v.name) # noqa: PERF401
163165

164166
for i in range(len(self._variables)):
165167
var = self._variables[i]

src/mdio/builder/templates/abstract_dataset_template.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ def build_dataset(
8181
if header_dtype:
8282
self._add_trace_headers(header_dtype)
8383

84-
# This seems to be breaking the dataset, but adds the trace dimension.
8584
for transform in self._queued_transforms:
86-
logger.debug(f"Applying transform: {transform.__name__}")
85+
stmnt = f"Applying transform: {transform.__name__} to dataset"
86+
logger.debug(stmnt)
8787
transform(self._builder)
8888
self._queued_transforms = []
8989
return self._builder.build()

src/mdio/segy/geometry.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ def analyze_non_indexed_headers(
258258
Args:
259259
index_headers: numpy array with index headers
260260
dtype: numpy type for value of created trace header.
261+
index_names: list of index names to analyze
261262
262263
Returns:
263264
Dict container header name as key and numpy array of values as value
@@ -438,7 +439,7 @@ def transform(
438439
self,
439440
index_headers: HeaderArray,
440441
grid_overrides: dict[str, bool | int],
441-
index_names=None,
442+
index_names: Sequence[str] = None, # noqa: ARG002
442443
) -> NDArray:
443444
"""Perform the grid transform."""
444445
self.validate(index_headers, grid_overrides)
@@ -476,7 +477,7 @@ def transform(
476477
self,
477478
index_headers: HeaderArray,
478479
grid_overrides: dict[str, bool | int],
479-
index_names=None,
480+
index_names: Sequence[str] = None, # noqa: ARG002
480481
) -> NDArray:
481482
"""Perform the grid transform."""
482483
self.validate(index_headers, grid_overrides)

src/mdio/segy/utilities.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from dask.array.core import normalize_chunks
1212

1313
from mdio.builder.schemas.dimension import NamedDimension
14+
from mdio.builder.schemas.dtype import ScalarType
1415
from mdio.core import Dimension
1516
from mdio.segy.geometry import GridOverrider
1617
from mdio.segy.parsers import parse_headers
@@ -20,6 +21,7 @@
2021
from segy import SegyFile
2122
from segy.arrays import HeaderArray
2223

24+
from mdio.builder.dataset_builder import MDIODatasetBuilder
2325
from mdio.builder.templates.abstract_dataset_template import AbstractDatasetTemplate
2426

2527

@@ -41,15 +43,14 @@ def _create_delayed_trace_dimension_transform(headers_subset: HeaderArray, posit
4143
A callable that can be used as a transform function
4244
"""
4345

44-
def delayed_transform(builder):
45-
from mdio.builder.schemas.dtype import ScalarType
46-
46+
def delayed_transform(builder: MDIODatasetBuilder) -> MDIODatasetBuilder:
4747
# Calculate the trace dimension size at execution time
4848
if "trace" in headers_subset.dtype.names:
4949
trace_size = int(np.max(headers_subset["trace"]))
5050
else:
5151
# Fallback: if trace field doesn't exist, we need to determine size differently
52-
raise ValueError("Trace field not found in headers_subset when executing delayed transform")
52+
msg = "Trace field not found in headers_subset when executing delayed transform"
53+
raise ValueError(msg)
5354

5455
# Add the trace dimension
5556
trace_dimension = NamedDimension(name="trace", size=trace_size)
@@ -110,8 +111,7 @@ def get_grid_plan( # noqa: C901
110111
)
111112

112113
if grid_overrides.get("HasDuplicates", False):
113-
pos = len(template.dimension_names) - 1 # TODO: Implement the negative position case...
114-
# Use the delayed transform function instead of a simple lambda
114+
pos = len(template.dimension_names) - 1
115115
template._queue_transform(_create_delayed_trace_dimension_transform(headers_subset, pos))
116116
horizontal_dimensions = (*horizontal_dimensions, "trace")
117117

0 commit comments

Comments
 (0)