Skip to content

Commit 5f0d669

Browse files
authored
Merge pull request #97 from GeoscienceAustralia/NPI-NPI-4237-clean-up-deprecated-type-hinting_branch_from_NPI-4067
NPI-4237 Clean up of deprecated type hinting (PEP 585)
2 parents be77e02 + 62ef5b7 commit 5f0d669

File tree

9 files changed

+80
-83
lines changed

9 files changed

+80
-83
lines changed

gnssanalysis/filenames.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# The collections.abc (rather than typing) versions don't support subscripting until 3.9
99
# from collections import Iterable
10-
from typing import Iterable, Mapping, Any, Dict, Optional, Tuple, Union, overload
10+
from typing import Iterable, Mapping, Any, Optional, Union, overload
1111
import warnings
1212

1313
import click
@@ -99,8 +99,8 @@
9999
@click.option("--verbose", is_flag=True)
100100
def determine_file_name_main(
101101
files: Iterable[pathlib.Path],
102-
defaults: Iterable[Tuple[str, str]],
103-
overrides: Iterable[Tuple[str, str]],
102+
defaults: Iterable[tuple[str, str]],
103+
overrides: Iterable[tuple[str, str]],
104104
current_name: bool,
105105
delimiter: str,
106106
verbose: bool,
@@ -165,8 +165,8 @@ def determine_file_name(
165165
defined as a parameter to maintain syntactic simplicity when calling.
166166
167167
:param pathlib.Path file_path: Path to the file for which to determine name
168-
:param Dict[str, Any] defaults: Default name properties to use when properties can't be determined
169-
:param Dict[str, Any] overrides: Name properties that should override anything detected in the file
168+
:param dict[str, Any] defaults: Default name properties to use when properties can't be determined
169+
:param dict[str, Any] overrides: Name properties that should override anything detected in the file
170170
:raises NotImplementedError: For files that we should support but currently don't (bia, iox, obx, sum, tro)
171171
:return str: Proposed IGS long filename
172172
"""
@@ -182,7 +182,7 @@ def determine_properties_from_contents_and_filename(
182182
file_path: pathlib.Path,
183183
defaults: Optional[Mapping[str, Any]] = None,
184184
overrides: Optional[Mapping[str, Any]] = None,
185-
) -> Dict[str, Any]:
185+
) -> dict[str, Any]:
186186
"""Determine the properties of a file based on its contents
187187
188188
The function reads both the existing filename of the provided file as well as
@@ -204,8 +204,8 @@ def determine_properties_from_contents_and_filename(
204204
- project: str
205205
206206
:param pathlib.Path file_path: Path to the file for which to determine properties
207-
:param Dict[str, Any] defaults: Default name properties to use when properties can't be determined
208-
:param Dict[str, Any] overrides: Name properties that should override anything detected in the file
207+
:param dict[str, Any] defaults: Default name properties to use when properties can't be determined
208+
:param dict[str, Any] overrides: Name properties that should override anything detected in the file
209209
:raises NotImplementedError: For files that we should support but currently don't (bia, iox, obx, sum, tro)
210210
:return str: Dictionary of file properties
211211
"""
@@ -459,15 +459,15 @@ def convert_nominal_span(nominal_span: str) -> datetime.timedelta:
459459
return datetime.timedelta()
460460

461461

462-
def determine_clk_name_props(file_path: pathlib.Path) -> Dict[str, Any]:
462+
def determine_clk_name_props(file_path: pathlib.Path) -> dict[str, Any]:
463463
"""Determine the IGS filename properties for a CLK files
464464
465465
Like all functions in this series, the function reads both a filename and the files contents
466466
to determine properties that can be used to describe the expected IGS long filename. The
467467
function returns a dictionary with any properties it manages to successfully determine.
468468
469469
:param pathlib.Path file_path: file for which to determine name properties
470-
:return Dict[str, Any]: dictionary containing the extracted name properties
470+
:return dict[str, Any]: dictionary containing the extracted name properties
471471
"""
472472
name_props = {}
473473
try:
@@ -519,15 +519,15 @@ def determine_clk_name_props(file_path: pathlib.Path) -> Dict[str, Any]:
519519
return name_props
520520

521521

522-
def determine_erp_name_props(file_path: pathlib.Path) -> Dict[str, Any]:
522+
def determine_erp_name_props(file_path: pathlib.Path) -> dict[str, Any]:
523523
"""Determine the IGS filename properties for a ERP files
524524
525525
Like all functions in this series, the function reads both a filename and the files contents
526526
to determine properties that can be used to describe the expected IGS long filename. The
527527
function returns a dictionary with any properties it manages to successfully determine.
528528
529529
:param pathlib.Path file_path: file for which to determine name properties
530-
:return Dict[str, Any]: dictionary containing the extracted name properties
530+
:return dict[str, Any]: dictionary containing the extracted name properties
531531
"""
532532
name_props = {}
533533
try:
@@ -574,15 +574,15 @@ def determine_erp_name_props(file_path: pathlib.Path) -> Dict[str, Any]:
574574
return name_props
575575

576576

577-
def determine_snx_name_props(file_path: pathlib.Path) -> Dict[str, Any]:
577+
def determine_snx_name_props(file_path: pathlib.Path) -> dict[str, Any]:
578578
"""Determine the IGS filename properties for a SINEX files
579579
580580
Like all functions in this series, the function reads both a filename and the files contents
581581
to determine properties that can be used to describe the expected IGS long filename. The
582582
function returns a dictionary with any properties it manages to successfully determine.
583583
584584
:param pathlib.Path file_path: file for which to determine name properties
585-
:return Dict[str, Any]: dictionary containing the extracted name properties
585+
:return dict[str, Any]: dictionary containing the extracted name properties
586586
"""
587587
name_props = {}
588588
try:
@@ -668,7 +668,7 @@ def determine_snx_name_props(file_path: pathlib.Path) -> Dict[str, Any]:
668668

669669
def determine_sp3_name_props(
670670
file_path: pathlib.Path, strict_mode: type[StrictMode] = StrictModes.STRICT_WARN
671-
) -> Dict[str, Any]:
671+
) -> dict[str, Any]:
672672
"""Determine the IGS filename properties for a SP3 files
673673
674674
Like all functions in this series, the function reads both a filename and the files contents
@@ -678,7 +678,7 @@ def determine_sp3_name_props(
678678
:param pathlib.Path file_path: file for which to determine name properties
679679
:param type[StrictMode] strict_mode: indicates whether to raise, warn, or silently continue on errors such as
680680
failure to get properties from a filename.
681-
:return Dict[str, Any]: dictionary containing the extracted name properties. May be empty on some errors, if
681+
:return dict[str, Any]: dictionary containing the extracted name properties. May be empty on some errors, if
682682
strict_mode is not set to RAISE.
683683
:raises ValueError: if strict_mode set to RAISE, and unable to statically extract properties from a filename
684684
"""

gnssanalysis/gn_aux.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Auxiliary functions"""
22

33
import logging as _logging
4-
from typing import overload, Tuple, Union
4+
from typing import overload, Union
55
import numpy as _np
66
import pandas as _pd
77

@@ -183,7 +183,7 @@ def rms(
183183

184184
def get_std_bounds(
185185
a: _np.ndarray,
186-
axis: Union[None, int, Tuple[int, ...]] = None,
186+
axis: Union[None, int, tuple[int, ...]] = None,
187187
sigma_coeff: int = 3,
188188
):
189189
"""
@@ -287,7 +287,7 @@ def degminsec2deg(a: Union[_pd.Series, _pd.DataFrame, list, str]) -> Union[_pd.S
287287
assert isinstance(a_series, _pd.Series)
288288
return _series_str_degminsec2deg(a_series).unstack()
289289
else:
290-
raise TypeError("Unsupported input type. Please use either of _pd.Series, _pd.DataFrame, List or str")
290+
raise TypeError("Unsupported input type. Please use either of _pd.Series, _pd.DataFrame, list or str")
291291

292292

293293
def _deg2degminsec(a: _np.ndarray) -> _np.ndarray:

gnssanalysis/gn_download.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import ftplib as _ftplib
2929
from ftplib import FTP_TLS as _FTP_TLS
3030
from pathlib import Path as _Path
31-
from typing import Any, Generator, List, Literal, Optional, Tuple, Union
31+
from typing import Any, Generator, Literal, Optional, Union
3232
from urllib import request as _request
3333
from urllib.error import HTTPError as _HTTPError
3434

@@ -391,7 +391,7 @@ def generate_product_filename(
391391
version: str = "0",
392392
project: str = "OPS",
393393
content_type: str = None,
394-
) -> Tuple[str, GPSDate, _datetime.datetime]:
394+
) -> tuple[str, GPSDate, _datetime.datetime]:
395395
"""Given a reference datetime and extention of file, generate the IGS filename and GPSDate obj for use in download
396396
397397
:param _datetime.datetime reference_start: Datetime of the start period of interest
@@ -405,7 +405,7 @@ def generate_product_filename(
405405
:param str version: Version of the file, defaults to "0"
406406
:param str project: IGS project descriptor, defaults to "OPS"
407407
:param str content_type: IGS content specifier - if None set automatically based on file_ext, defaults to None
408-
:return _Tuple[str, GPSDate, _datetime.datetime]: Tuple of filename str, GPSDate and datetime obj (based on shift)
408+
:return tuple[str, GPSDate, _datetime.datetime]: Tuple of filename str, GPSDate and datetime obj (based on shift)
409409
"""
410410
reference_start += _datetime.timedelta(hours=shift)
411411
if type(reference_start == _datetime.date):
@@ -822,7 +822,7 @@ def download_product_from_cddis(
822822
project_type: str = "OPS",
823823
timespan: _datetime.timedelta = _datetime.timedelta(days=2),
824824
if_file_present: str = "prompt_user",
825-
) -> List[_Path]:
825+
) -> list[_Path]:
826826
"""Download the file/s from CDDIS based on start and end epoch, to the download directory (download_dir)
827827
828828
:param _Path download_dir: Where to download files (local directory)
@@ -838,7 +838,7 @@ def download_product_from_cddis(
838838
:param _datetime.timedelta timespan: Timespan of the file/s to download, defaults to _datetime.timedelta(days=2)
839839
:param str if_file_present: What to do if file already present: "replace", "dont_replace", defaults to "prompt_user"
840840
:raises FileNotFoundError: Raise error if the specified file cannot be found on CDDIS
841-
:return List[_Path]: Return list of paths of downloaded files
841+
:return list[_Path]: Return list of paths of downloaded files
842842
"""
843843
# Download the correct IGS FIN ERP files
844844
if file_ext == "ERP" and analysis_center == "IGS" and solution_type == "FIN": # get the correct start_epoch
@@ -1193,12 +1193,12 @@ def download_satellite_metadata_snx(download_dir: _Path, if_file_present: str =
11931193
return download_filepath
11941194

11951195

1196-
def download_yaw_files(download_dir: _Path, if_file_present: str = "prompt_user") -> List[_Path]:
1196+
def download_yaw_files(download_dir: _Path, if_file_present: str = "prompt_user") -> list[_Path]:
11971197
"""Download yaw rate / bias files needed to for Ginan's PEA
11981198
11991199
:param _Path download_dir: Where to download files (local directory)
12001200
:param str if_file_present: What to do if file already present: "replace", "dont_replace", defaults to "prompt_user"
1201-
:return List[_Path]: Return list paths of downloaded files
1201+
:return list[_Path]: Return list paths of downloaded files
12021202
"""
12031203
ensure_folders([download_dir])
12041204
download_filepaths = []

gnssanalysis/gn_io/erp.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# from collections.abc import Callable, Iterable
88
from typing import Callable, Iterable
99
from io import BytesIO as _BytesIO
10-
from typing import List, TextIO, Union
10+
from typing import TextIO, Union
1111
from urllib import request as _rqs
1212

1313
import numpy as _np
@@ -17,11 +17,11 @@
1717
from gnssanalysis import gn_io as _gn_io
1818

1919

20-
def normalise_headers(headers: Iterable[str]) -> List[str]:
20+
def normalise_headers(headers: Iterable[str]) -> list[str]:
2121
"""Apply :func: `gn_io.erp.normalise_headers` to all headers in an iterable
2222
2323
:param Iterable[str] headers: Iterable of header strings obtained from an ERP file
24-
:return List[str]: List of normalised headers as per :func: `gn_io.erp.normalise_headers`
24+
:return list[str]: List of normalised headers as per :func: `gn_io.erp.normalise_headers`
2525
"""
2626
return [normalise_header(h) for h in headers]
2727

@@ -44,15 +44,15 @@ def normalise_header(header: str) -> str:
4444
return get_canonical_header(header)
4545

4646

47-
def merge_hyphen_headers(raw_split_header: Iterable[str]) -> List[str]:
47+
def merge_hyphen_headers(raw_split_header: Iterable[str]) -> list[str]:
4848
"""Take a list of raw headers from an ERP file and merge hyphenated headers that got split
4949
5050
In some ERP files hyphenated headers, such as UTC-TAI, occasionally have spaces before or after
5151
the hyphen/minus sign. This breaks tokenisation as the header gets split into multiple parts.
5252
This function re-merges those header components.
5353
5454
:param Iterable[str] raw_split_header: ERP header line that has been split/tokenized
55-
:return List[str]: List of ERP headers with hyphen-separated headers merged
55+
:return list[str]: List of ERP headers with hyphen-separated headers merged
5656
"""
5757
# Copy to avoid mutating input list
5858
headers = list(raw_split_header)

gnssanalysis/gn_io/igslog.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import glob as _glob
55
import re as _re
66
from multiprocessing import Pool as _Pool
7-
from typing import Union, List, Tuple
7+
from typing import Union
88

99
import numpy as _np
1010
import pandas as _pd
@@ -169,7 +169,7 @@ def determine_log_version(data: bytes) -> str:
169169

170170
def extract_id_block(
171171
data: bytes, file_path: str, file_code: str, version: Union[str, None] = None
172-
) -> Union[List[str], _np.ndarray]:
172+
) -> Union[list[str], _np.ndarray]:
173173
"""Extract the site ID block given the bytes object read from an IGS site log file
174174
175175
:param bytes data: The bytes object returned from an open() call on a IGS site log in "rb" mode
@@ -229,12 +229,12 @@ def extract_location_block(data: bytes, file_path: str, version: Union[str, None
229229
return location_block
230230

231231

232-
def extract_receiver_block(data: bytes, file_path: str) -> Union[List[Tuple[bytes]], _np.ndarray]:
232+
def extract_receiver_block(data: bytes, file_path: str) -> Union[list[tuple[bytes]], _np.ndarray]:
233233
"""Extract the location block given the bytes object read from an IGS site log file
234234
235235
:param bytes data: The bytes object returned from an open() call on a IGS site log in "rb" mode
236236
:param str file_path: The path to the file from which the "data" bytes object was obtained
237-
:return List[Tuple[bytes]] or _np.ndarray: The receiver block of the data. Each list element specifies an receiver.
237+
:return list[tuple[bytes]] or _np.ndarray: The receiver block of the data. Each list element specifies an receiver.
238238
If regex doesn't match, an empty numpy NDArray is returned instead.
239239
"""
240240
receiver_block = _REGEX_REC.findall(data)
@@ -244,12 +244,12 @@ def extract_receiver_block(data: bytes, file_path: str) -> Union[List[Tuple[byte
244244
return receiver_block
245245

246246

247-
def extract_antenna_block(data: bytes, file_path: str) -> Union[List[Tuple[bytes]], _np.ndarray]:
247+
def extract_antenna_block(data: bytes, file_path: str) -> Union[list[tuple[bytes]], _np.ndarray]:
248248
"""Extract the antenna block given the bytes object read from an IGS site log file
249249
250250
:param bytes data: The bytes object returned from an open() call on a IGS site log in "rb" mode
251251
:param str file_path: The path to the file from which the "data" bytes object was obtained
252-
:return List[Tuple[bytes]] or _np.ndarray: The antenna block of the data. Each list element specifies an antenna.
252+
:return list[tuple[bytes]] or _np.ndarray: The antenna block of the data. Each list element specifies an antenna.
253253
If regex doesn't match, an empty numpy NDArray is returned instead.
254254
"""
255255
antenna_block = _REGEX_ANT.findall(data)
@@ -397,13 +397,13 @@ def translate_series(series: _pd.Series, translation: dict) -> _pd.Series:
397397

398398
def gather_metadata(
399399
logs_glob_path: str = "/data/station_logs/station_logs_IGS/*/*.log", rnx_glob_path: str = None, num_threads: int = 1
400-
) -> List[_pd.DataFrame]:
400+
) -> list[_pd.DataFrame]:
401401
"""Parses log files found with glob expressions into pd.DataFrames
402402
403403
:param str logs_glob_path: A glob expression for log files, defaults to "/data/station_logs_IGS/*/*.log"
404404
:param str rnx_glob_path: A glob expression for rnx files, e.g. /data/pea/exs/data/*.rnx, defaults to None
405405
:param int num_threads: Number of threads to run, defaults to 1
406-
:return List[_pd.DataFrame]: List of DataFrames with [ID, Receiver, Antenna] data
406+
:return list[_pd.DataFrame]: List of DataFrames with [ID, Receiver, Antenna] data
407407
"""
408408
parsed_filenames = find_recent_logs(logs_glob_path=logs_glob_path, rnx_glob_path=rnx_glob_path).values
409409

0 commit comments

Comments
 (0)