Skip to content

Commit 9d9b2c6

Browse files
committed
Use built-in list,tuple,set,dict for type hints
1 parent d503705 commit 9d9b2c6

26 files changed

+229
-241
lines changed

mikeio/_interpolation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import annotations
2-
from typing import Tuple, TYPE_CHECKING, overload
2+
from typing import TYPE_CHECKING, overload
33
import numpy as np
44

55
if TYPE_CHECKING:
@@ -49,7 +49,7 @@ def interp2d(
4949
data: np.ndarray | DataArray,
5050
elem_ids: np.ndarray,
5151
weights: np.ndarray | None = None,
52-
shape: Tuple[int, ...] | None = None,
52+
shape: tuple[int, ...] | None = None,
5353
) -> np.ndarray: ...
5454

5555

@@ -58,15 +58,15 @@ def interp2d(
5858
data: Dataset,
5959
elem_ids: np.ndarray,
6060
weights: np.ndarray | None = None,
61-
shape: Tuple[int, ...] | None = None,
61+
shape: tuple[int, ...] | None = None,
6262
) -> Dataset: ...
6363

6464

6565
def interp2d(
6666
data: Dataset | DataArray | np.ndarray,
6767
elem_ids: np.ndarray,
6868
weights: np.ndarray | None = None,
69-
shape: Tuple[int, ...] | None = None,
69+
shape: tuple[int, ...] | None = None,
7070
) -> Dataset | np.ndarray:
7171
"""interp spatially in data (2d only)
7272

mikeio/_spectral.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22
from collections.abc import Sequence
3-
from typing import Literal, Tuple
3+
from typing import Literal
44
import numpy as np
55
from matplotlib.axes import Axes
66
from matplotlib.projections.polar import PolarAxes
@@ -20,7 +20,7 @@ def plot_2dspectrum(
2020
rmin: float | None = None,
2121
rmax: float | None = None,
2222
levels: int | Sequence[float] | None = None,
23-
figsize: Tuple[float, float] = (7, 7),
23+
figsize: tuple[float, float] = (7, 7),
2424
add_colorbar: bool = True,
2525
) -> Axes:
2626
"""

mikeio/_time.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22
from datetime import datetime
33
from dataclasses import dataclass
4-
from typing import List
54
from collections.abc import Iterable
65

76
import pandas as pd
@@ -18,7 +17,7 @@ def isel(
1817
x: (
1918
int | Iterable[int] | str | datetime | pd.DatetimeIndex | slice | None
2019
) = None,
21-
) -> List[int]:
20+
) -> list[int]:
2221
"""Select time steps from a pandas DatetimeIndex
2322
2423
Parameters
@@ -28,7 +27,7 @@ def isel(
2827
2928
Returns
3029
-------
31-
List[int]
30+
list[int]
3231
List of indices in the range (0, len(index)
3332
Examples
3433
--------

mikeio/_track.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22
from pathlib import Path
33
from collections.abc import Sequence
4-
from typing import Any, Callable, Tuple
4+
from typing import Any, Callable
55

66
import numpy as np
77
import pandas as pd
@@ -26,7 +26,7 @@ def _extract_track(
2626
n_elements: int,
2727
method: str,
2828
dtype: Any, # TODO DTypeLike?
29-
data_read_func: Callable[[int, int], Tuple[np.ndarray, float]],
29+
data_read_func: Callable[[int, int], tuple[np.ndarray, float]],
3030
) -> Dataset:
3131

3232
if not isinstance(geometry, GeometryFM2D):

mikeio/dataset/_data_plot.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import annotations
2-
from typing import Any, Tuple, TYPE_CHECKING
2+
from typing import Any, TYPE_CHECKING
33

44
from matplotlib.figure import Figure
55
import numpy as np
@@ -23,7 +23,7 @@ def __init__(self, da: "DataArray") -> None:
2323
def __call__(
2424
self,
2525
ax: Axes | None = None,
26-
figsize: Tuple[float, float] | None = None,
26+
figsize: tuple[float, float] | None = None,
2727
**kwargs: Any,
2828
) -> Axes:
2929
"""Plot DataArray according to geometry
@@ -57,7 +57,7 @@ def __call__(
5757

5858
@staticmethod
5959
def _get_ax(
60-
ax: Axes | None = None, figsize: Tuple[float, float] | None = None
60+
ax: Axes | None = None, figsize: tuple[float, float] | None = None
6161
) -> Axes:
6262

6363
if ax is None:
@@ -66,8 +66,8 @@ def _get_ax(
6666

6767
@staticmethod
6868
def _get_fig_ax(
69-
ax: Axes | None = None, figsize: Tuple[float, float] | None = None
70-
) -> Tuple[Figure, Axes]:
69+
ax: Axes | None = None, figsize: tuple[float, float] | None = None
70+
) -> tuple[Figure, Axes]:
7171

7272
if ax is None:
7373
fig, ax = plt.subplots(figsize=figsize)
@@ -78,7 +78,7 @@ def _get_fig_ax(
7878
def hist(
7979
self,
8080
ax: Axes | None = None,
81-
figsize: Tuple[float, float] | None = None,
81+
figsize: tuple[float, float] | None = None,
8282
title: str | None = None,
8383
**kwargs: Any,
8484
) -> Axes:
@@ -121,7 +121,7 @@ def _hist(self, ax: Axes, **kwargs: Any) -> Any:
121121
def line(
122122
self,
123123
ax: Axes | None = None,
124-
figsize: Tuple[float, float] | None = None,
124+
figsize: tuple[float, float] | None = None,
125125
**kwargs: Any,
126126
) -> Axes:
127127
"""Plot data as lines (timeseries if time is present)"""
@@ -178,7 +178,7 @@ class _DataArrayPlotterGrid1D(_DataArrayPlotter):
178178
def __call__(
179179
self,
180180
ax: Axes | None = None,
181-
figsize: Tuple[float, float] | None = None,
181+
figsize: tuple[float, float] | None = None,
182182
**kwargs: Any,
183183
) -> Axes:
184184
_, ax = self._get_fig_ax(ax, figsize)
@@ -190,7 +190,7 @@ def __call__(
190190
def line(
191191
self,
192192
ax: Axes | None = None,
193-
figsize: Tuple[float, float] | None = None,
193+
figsize: tuple[float, float] | None = None,
194194
**kwargs: Any,
195195
) -> Axes:
196196
"""Plot as spatial lines"""
@@ -200,7 +200,7 @@ def line(
200200
def timeseries(
201201
self,
202202
ax: Axes | None = None,
203-
figsize: Tuple[float, float] | None = None,
203+
figsize: tuple[float, float] | None = None,
204204
**kwargs: Any,
205205
) -> Axes:
206206
"""Plot as timeseries"""
@@ -212,7 +212,7 @@ def timeseries(
212212
def imshow(
213213
self,
214214
ax: Axes | None = None,
215-
figsize: Tuple[float, float] | None = None,
215+
figsize: tuple[float, float] | None = None,
216216
**kwargs: Any,
217217
) -> Axes:
218218
"""Plot as 2d"""
@@ -228,7 +228,7 @@ def imshow(
228228
def pcolormesh(
229229
self,
230230
ax: Axes | None = None,
231-
figsize: Tuple[float, float] | None = None,
231+
figsize: tuple[float, float] | None = None,
232232
title: str | None = None,
233233
**kwargs: Any,
234234
) -> Axes:
@@ -281,15 +281,15 @@ class _DataArrayPlotterGrid2D(_DataArrayPlotter):
281281
def __call__(
282282
self,
283283
ax: Axes | None = None,
284-
figsize: Tuple[float, float] | None = None,
284+
figsize: tuple[float, float] | None = None,
285285
**kwargs: Any,
286286
) -> Axes:
287287
return self.pcolormesh(ax, figsize, **kwargs)
288288

289289
def contour(
290290
self,
291291
ax: Axes | None = None,
292-
figsize: Tuple[float, float] | None = None,
292+
figsize: tuple[float, float] | None = None,
293293
title: str | None = None,
294294
**kwargs: Any,
295295
) -> Axes:
@@ -318,7 +318,7 @@ def contour(
318318
def contourf(
319319
self,
320320
ax: Axes | None = None,
321-
figsize: Tuple[float, float] | None = None,
321+
figsize: tuple[float, float] | None = None,
322322
title: str | None = None,
323323
label: str | None = None,
324324
**kwargs: Any,
@@ -349,7 +349,7 @@ def contourf(
349349
def pcolormesh(
350350
self,
351351
ax: Axes | None = None,
352-
figsize: Tuple[float, float] | None = None,
352+
figsize: tuple[float, float] | None = None,
353353
title: str | None = None,
354354
label: str | None = None,
355355
**kwargs: Any,
@@ -377,12 +377,12 @@ def pcolormesh(
377377
ax.set_title(title)
378378
return ax
379379

380-
def _get_x_y(self) -> Tuple[np.ndarray, np.ndarray]:
380+
def _get_x_y(self) -> tuple[np.ndarray, np.ndarray]:
381381
x = self.da.geometry.x
382382
y = self.da.geometry.y
383383
return x, y
384384

385-
def _get_xn_yn(self) -> Tuple[np.ndarray, np.ndarray]:
385+
def _get_xn_yn(self) -> tuple[np.ndarray, np.ndarray]:
386386
xn = self.da.geometry._centers_to_nodes(self.da.geometry.x)
387387
yn = self.da.geometry._centers_to_nodes(self.da.geometry.y)
388388
return xn, yn
@@ -429,7 +429,7 @@ class _DataArrayPlotterFM(_DataArrayPlotter):
429429
def __call__(
430430
self,
431431
ax: Axes | None = None,
432-
figsize: Tuple[float, float] | None = None,
432+
figsize: tuple[float, float] | None = None,
433433
**kwargs: Any,
434434
) -> Axes:
435435
"""Plot data as coloured patches"""
@@ -439,7 +439,7 @@ def __call__(
439439
def patch(
440440
self,
441441
ax: Axes | None = None,
442-
figsize: Tuple[float, float] | None = None,
442+
figsize: tuple[float, float] | None = None,
443443
**kwargs: Any,
444444
) -> Axes:
445445
"""Plot data as coloured patches
@@ -458,7 +458,7 @@ def patch(
458458
def contour(
459459
self,
460460
ax: Axes | None = None,
461-
figsize: Tuple[float, float] | None = None,
461+
figsize: tuple[float, float] | None = None,
462462
**kwargs: Any,
463463
) -> Axes:
464464
"""Plot data as contour lines
@@ -477,7 +477,7 @@ def contour(
477477
def contourf(
478478
self,
479479
ax: Axes | None = None,
480-
figsize: Tuple[float, float] | None = None,
480+
figsize: tuple[float, float] | None = None,
481481
**kwargs: Any,
482482
) -> Axes:
483483
"""Plot data as filled contours
@@ -496,7 +496,7 @@ def contourf(
496496
def mesh(
497497
self,
498498
ax: Axes | None = None,
499-
figsize: Tuple[float, float] | None = None,
499+
figsize: tuple[float, float] | None = None,
500500
**kwargs: Any,
501501
) -> Axes:
502502
"""Plot mesh only
@@ -513,7 +513,7 @@ def mesh(
513513
def outline(
514514
self,
515515
ax: Axes | None = None,
516-
figsize: Tuple[float, float] | None = None,
516+
figsize: tuple[float, float] | None = None,
517517
**kwargs: Any,
518518
) -> Axes:
519519
"""Plot domain outline (using the boundary_polylines property)
@@ -584,7 +584,7 @@ class _DataArrayPlotterFMVerticalColumn(_DataArrayPlotter):
584584
def __call__(
585585
self,
586586
ax: Axes | None = None,
587-
figsize: Tuple[float, float] | None = None,
587+
figsize: tuple[float, float] | None = None,
588588
**kwargs: Any,
589589
) -> Axes:
590590
ax = self._get_ax(ax, figsize)
@@ -593,7 +593,7 @@ def __call__(
593593
def line(
594594
self,
595595
ax: Axes | None = None,
596-
figsize: Tuple[float, float] | None = None,
596+
figsize: tuple[float, float] | None = None,
597597
extrapolate: bool = True,
598598
**kwargs: Any,
599599
) -> Axes:
@@ -638,7 +638,7 @@ def _line(
638638
def pcolormesh(
639639
self,
640640
ax: Axes | None = None,
641-
figsize: Tuple[float, float] | None = None,
641+
figsize: tuple[float, float] | None = None,
642642
title: str | None = None,
643643
**kwargs: Any,
644644
) -> Axes:
@@ -681,7 +681,7 @@ class _DataArrayPlotterFMVerticalProfile(_DataArrayPlotter):
681681
def __call__(
682682
self,
683683
ax: Axes | None = None,
684-
figsize: Tuple[float, float] | None = None,
684+
figsize: tuple[float, float] | None = None,
685685
**kwargs: Any,
686686
) -> Axes:
687687
ax = self._get_ax(ax, figsize)
@@ -714,7 +714,7 @@ class _DataArrayPlotterPointSpectrum(_DataArrayPlotter):
714714
def __call__(
715715
self,
716716
ax: Axes | None = None,
717-
figsize: Tuple[float, float] | None = None,
717+
figsize: tuple[float, float] | None = None,
718718
**kwargs: Any,
719719
) -> Axes:
720720
# ax = self._get_ax(ax, figsize)
@@ -742,7 +742,7 @@ def contourf(self, **kwargs: Any) -> Axes:
742742
def _plot_freqspectrum(
743743
self,
744744
ax: Axes | None = None,
745-
figsize: Tuple[float, float] | None = None,
745+
figsize: tuple[float, float] | None = None,
746746
**kwargs: Any,
747747
) -> Axes:
748748
ax = self._plot_1dspectrum(self.da.frequencies, ax, figsize, **kwargs) # type: ignore
@@ -753,7 +753,7 @@ def _plot_freqspectrum(
753753
def _plot_dirspectrum(
754754
self,
755755
ax: Axes | None = None,
756-
figsize: Tuple[float, float] | None = None,
756+
figsize: tuple[float, float] | None = None,
757757
**kwargs: Any,
758758
) -> Axes:
759759
ax = self._plot_1dspectrum(self.da.directions, ax, figsize, **kwargs) # type: ignore
@@ -766,7 +766,7 @@ def _plot_1dspectrum(
766766
self,
767767
x_values: np.ndarray,
768768
ax: Axes | None = None,
769-
figsize: Tuple[float, float] | None = None,
769+
figsize: tuple[float, float] | None = None,
770770
**kwargs: Any,
771771
) -> Axes:
772772
ax = self._get_ax(ax, figsize)
@@ -834,7 +834,7 @@ def __init__(self, ds: Dataset) -> None:
834834
self.ds = ds
835835

836836
def __call__(
837-
self, figsize: Tuple[float, float] | None = None, **kwargs: Any
837+
self, figsize: tuple[float, float] | None = None, **kwargs: Any
838838
) -> Axes:
839839
"""Plot multiple DataArrays as time series (only possible dfs0-type data)"""
840840
if self.ds.dims == ("time",):
@@ -847,8 +847,8 @@ def __call__(
847847

848848
@staticmethod
849849
def _get_fig_ax(
850-
ax: Axes | None = None, figsize: Tuple[float, float] | None = None
851-
) -> Tuple[Figure, Axes]:
850+
ax: Axes | None = None, figsize: tuple[float, float] | None = None
851+
) -> tuple[Figure, Axes]:
852852
import matplotlib.pyplot as plt
853853

854854
if ax is None:
@@ -862,7 +862,7 @@ def scatter(
862862
x: str | int,
863863
y: str | int,
864864
ax: Axes | None = None,
865-
figsize: Tuple[float, float] | None = None,
865+
figsize: tuple[float, float] | None = None,
866866
**kwargs: Any,
867867
) -> Axes:
868868
"""Plot data from two DataArrays against each other in a scatter plot

0 commit comments

Comments
 (0)