Skip to content

Commit c9ccde2

Browse files
committed
Refactor key retrieval in various modules for consistency and clarity
1 parent e814885 commit c9ccde2

File tree

12 files changed

+17
-19
lines changed

12 files changed

+17
-19
lines changed

pde/fields/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def from_file(cls, filename: str) -> FieldBase:
244244

245245
elif len(fp) == 1:
246246
# a single field is stored in the data
247-
dataset = fp[list(fp.keys())[0]] # retrieve only dataset
247+
dataset = fp[list(fp)[0]] # retrieve only dataset
248248
obj = cls._from_hdf_dataset(dataset) # type: ignore
249249

250250
else:

pde/grids/boundaries/axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
BoundaryPairData, Sequence[BoundaryPairData], Callable, "BoundariesBase"
3737
]
3838

39-
BC_LOCAL_KEYS = ["type", "value"] + list(BCBase._conditions.keys())
39+
BC_LOCAL_KEYS = ["type", "value"] + list(BCBase._conditions)
4040

4141

4242
def _is_local_bc_data(data: dict[str, Any]) -> bool:
@@ -215,7 +215,7 @@ def _parse_from_dict(
215215

216216
# warn if some keys were left over
217217
if data:
218-
_logger.warning("Didn't use BC data from %s", list(data.keys()))
218+
_logger.warning("Didn't use BC data from %s", list(data))
219219
# find boundary conditions that have not been specified
220220
bcs_unspecified = []
221221
for ax, bc_ax in enumerate(bc_data):

pde/grids/boundaries/axis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def from_data(cls, grid: GridBase, axis: int, data, rank: int = 0) -> BoundaryPa
283283
d_high = data_copy.pop("high")
284284
high = BCBase.from_data(grid, axis, upper=True, data=d_high, rank=rank)
285285
if data_copy:
286-
raise BCDataError(f"Data items {data_copy.keys()} were not used.")
286+
raise BCDataError(f"Data items {list(data_copy)} were not used.")
287287
else:
288288
# one condition for both sides
289289
low = BCBase.from_data(grid, axis, upper=False, data=data, rank=rank)

pde/grids/boundaries/local.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,7 @@ def from_dict(
474474
)
475475

476476
else:
477-
raise BCDataError(
478-
f"Boundary conditions `{str(list(data.keys()))}` are not supported."
479-
)
477+
raise BCDataError(f"Boundary conditions `{list(data)}` are not supported.")
480478

481479
@classmethod
482480
def from_data(

pde/grids/cartesian.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def from_state(cls, state: dict[str, Any]) -> CartesianGrid: # type: ignore
161161
periodic=state_copy.pop("periodic"),
162162
)
163163
if state_copy:
164-
raise ValueError(f"State items {state_copy.keys()} were not used")
164+
raise ValueError(f"State items {list(state_copy)} were not used")
165165
return obj
166166

167167
@classmethod
@@ -504,7 +504,7 @@ def from_state(cls, state: dict[str, Any]) -> UnitGrid: # type: ignore
504504
state_copy = state.copy()
505505
obj = cls(shape=state_copy.pop("shape"), periodic=state_copy.pop("periodic"))
506506
if state_copy:
507-
raise ValueError(f"State items {state_copy.keys()} were not used")
507+
raise ValueError(f"State items {list(state_copy)} were not used")
508508
return obj
509509

510510
def to_cartesian(self) -> CartesianGrid:

pde/grids/cylindrical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def from_state(cls, state: dict[str, Any]) -> CylindricalSymGrid: # type: ignor
156156
periodic_z=state_copy.pop("periodic_z"),
157157
)
158158
if state_copy:
159-
raise ValueError(f"State items {state_copy.keys()} were not used")
159+
raise ValueError(f"State items {list(state_copy)} were not used")
160160
return obj
161161

162162
@classmethod

pde/grids/spherical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def from_state(cls, state: dict[str, Any]) -> SphericalSymGridBase: # type: ign
116116
state_copy = state.copy()
117117
obj = cls(radius=state_copy.pop("radius"), shape=state_copy.pop("shape"))
118118
if state_copy:
119-
raise ValueError(f"State items {state_copy.keys()} were not used")
119+
raise ValueError(f"State items {list(state_copy)} were not used")
120120
return obj
121121

122122
@classmethod

pde/solvers/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def from_name(cls, name: str, pde: PDEBase, **kwargs) -> SolverBase:
111111
# solver was not registered
112112
solvers = (
113113
f"'{solver}'"
114-
for solver in sorted(cls._subclasses.keys())
114+
for solver in sorted(cls._subclasses)
115115
if not solver.endswith("Solver")
116116
)
117117
raise ValueError(
@@ -124,7 +124,7 @@ def from_name(cls, name: str, pde: PDEBase, **kwargs) -> SolverBase:
124124
@classproperty
125125
def registered_solvers(cls) -> list[str]:
126126
"""list of str: the names of the registered solvers"""
127-
return sorted(cls._subclasses.keys())
127+
return sorted(cls._subclasses)
128128

129129
@property
130130
def _compiled(self) -> bool:

pde/storage/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def grid(self) -> GridBase | None:
187187
else:
188188
self._logger.warning(
189189
"`grid` attribute was not stored. Available attributes: %s",
190-
", ".join(sorted(attrs.keys())),
190+
", ".join(sorted(attrs)),
191191
)
192192

193193
else:

pde/tools/spectral.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def noise_corr() -> NumericArray:
9696
return noise_corr
9797

9898

99-
CorrelationType = Literal["none", "gaussian", "power law", "cosine"]
99+
CorrelationType = Literal["none", "delta", "gaussian", "power law", "cosine"]
100100

101101

102102
def make_correlated_noise(
@@ -164,7 +164,7 @@ def make_correlated_noise(
164164
"""
165165
rng = np.random.default_rng(rng)
166166

167-
if correlation == "none":
167+
if correlation == "none" or correlation == "delta":
168168
# no correlation
169169
corr_spectrum = None
170170

@@ -204,7 +204,7 @@ def corr_spectrum(k2s):
204204
raise ValueError(f"Unknown correlation `{correlation}`")
205205

206206
if kwargs:
207-
_logger.warning("Unused arguments: %s", kwargs.keys())
207+
_logger.warning("Unused arguments: %s", list(kwargs))
208208

209209
if corr_spectrum is None:
210210
# fast case of uncorrelated white noise

0 commit comments

Comments
 (0)