Skip to content

Commit

Permalink
fixing typos, typing and other review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
heikoklein committed May 24, 2024
1 parent 2126f92 commit 54cfe1d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 32 deletions.
21 changes: 8 additions & 13 deletions src/pyaro/timeseries/AutoFilterReaderEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .Filter import VariableNameFilter, Filter, filters, FilterFactory


class UnkownFilterException(Exception):
class UnknownFilterException(Exception):
pass


Expand All @@ -26,20 +26,15 @@ class AutoFilterReader(Reader):
"""

@classmethod
def supported_filters(cls) -> [Filter]:
def supported_filters(cls) -> list[Filter]:
"""Get the default list of implemented filters.
:return: list of filters
"""
filts = []
for (
f
) in "variables,stations,countries,bounding_boxes,duplicates,time_bounds,flags,time_variable_station".split(
supported = "variables,stations,countries,bounding_boxes,duplicates,time_bounds,flags,time_variable_station".split(
","
):
filts.append(filters.get(f))

return filts
)
return [filters.get(name) for name in supported]

def _set_filters(self, filters):
supported = set()
Expand All @@ -53,12 +48,12 @@ def _set_filters(self, filters):
filters = filtlist
for filt in filters:
if filt.__class__ not in supported:
raise UnkownFilterException(
raise UnknownFilterException(
f"Filter {filt.__class__} not supported in {supported}."
)
self._filters = filters

def _get_filters(self) -> [Filter]:
def _get_filters(self) -> list[Filter]:
"""Get a list of filters actually set during initialization of this object.
:return: list of filters
Expand Down Expand Up @@ -116,7 +111,7 @@ def reader_class(self) -> Reader:
"""
pass

def supported_filters(self) -> [Filter]:
def supported_filters(self) -> list[Filter]:
"""The supported filters by this Engine. Maps to the Readers supported_filters.
:return: a list of filters
Expand Down
40 changes: 21 additions & 19 deletions src/pyaro/timeseries/Filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def name(self) -> str:
:return: a string to be used by FilterFactory
"""

def filter_data(self, data: Data, stations: [Station], variables: [str]) -> Data:
def filter_data(
self, data: Data, stations: list[Station], variables: list[str]
) -> Data:
"""Filtering of data
:param data: Data of e.g. a Reader.data(varname) call
Expand All @@ -61,7 +63,7 @@ def filter_stations(self, stations: dict[str, Station]) -> dict[str, Station]:
"""
return stations

def filter_variables(self, variables: [str]) -> [str]:
def filter_variables(self, variables: list[str]) -> list[str]:
"""Filtering of variables
:param variables: List of variables, e.g. from a Reader.variables() call
Expand Down Expand Up @@ -203,8 +205,8 @@ class VariableNameFilter(Filter):
def __init__(
self,
reader_to_new: dict[str, str] = {},
include: [str] = [],
exclude: [str] = [],
include: list[str] = [],
exclude: list[str] = [],
):
"""Create a new variable name filter.
Expand Down Expand Up @@ -251,7 +253,7 @@ def filter_data(self, data, stations, variables):
data._set_variable(self._reader_to_new.get(data.variable, data.variable))
return data

def filter_variables(self, variables: [str]) -> [str]:
def filter_variables(self, variables: list[str]) -> list[str]:
"""change variable name and reduce variables applying include and exclude parameters
:param variables: variable names as in the reader
Expand Down Expand Up @@ -308,7 +310,7 @@ def filter_data_idx(self, data: Data, stations: dict[str, Station], variables: s

@registered_filter
class StationFilter(StationReductionFilter):
def __init__(self, include: [str] = [], exclude: [str] = []):
def __init__(self, include: list[str] = [], exclude: list[str] = []):
self._include = set(include)
self._exclude = set(exclude)
return
Expand All @@ -333,7 +335,7 @@ def filter_stations(self, stations: dict[str, Station]) -> dict[str, Station]:

@registered_filter
class CountryFilter(StationReductionFilter):
def __init__(self, include: [str] = [], exclude: [str] = []):
def __init__(self, include: list[str] = [], exclude: list[str] = []):
"""Filter countries by ISO2 names (capitals!)
:param include: countries to include, defaults to [], meaning all countries
Expand Down Expand Up @@ -371,8 +373,8 @@ class BoundingBoxFilter(StationReductionFilter):

def __init__(
self,
include: [(float, float, float, float)] = [],
exclude: [(float, float, float, float)] = [],
include: list[(float, float, float, float)] = [],
exclude: list[(float, float, float, float)] = [],
):
"""Filter using geographical bounding-boxes. Coordinates should be given in the range
[-180,180] (degrees_east) for longitude and [-90,90] (degrees_north) for latitude.
Expand Down Expand Up @@ -460,7 +462,7 @@ def filter_stations(self, stations: dict[str, Station]) -> dict[str, Station]:

@registered_filter
class FlagFilter(DataIndexFilter):
def __init__(self, include: [Flag] = [], exclude: [Flag] = []):
def __init__(self, include: list[Flag] = [], exclude: list[Flag] = []):
"""Filter data by Flags
:param include: flags to include, defaults to [], meaning all flags
Expand Down Expand Up @@ -498,12 +500,12 @@ class TimeBoundsException(Exception):
class TimeBoundsFilter(DataIndexFilter):
def __init__(
self,
start_include: [(str, str)] = [],
start_exclude: [(str, str)] = [],
startend_include: [(str, str)] = [],
startend_exclude: [(str, str)] = [],
end_include: [(str, str)] = [],
end_exclude: [(str, str)] = [],
start_include: list[(str, str)] = [],
start_exclude: list[(str, str)] = [],
startend_include: list[(str, str)] = [],
startend_exclude: list[(str, str)] = [],
end_include: list[(str, str)] = [],
end_exclude: list[(str, str)] = [],
):
"""Filter data by start and/or end-times of the measurements. Each timebound consists
of a bound-start and bound-end (both included). Timestamps are given as YYYY-MM-DD HH:MM:SS
Expand All @@ -527,7 +529,7 @@ def __init__(
def name(self):
return "time_bounds"

def _str_list_to_datetime_list(self, tuple_list: [(str, str)]):
def _str_list_to_datetime_list(self, tuple_list: list[(str, str)]):
retlist = []
for start, end in tuple_list:
start_dt = datetime.strptime(start, self.time_format)
Expand All @@ -539,7 +541,7 @@ def _str_list_to_datetime_list(self, tuple_list: [(str, str)]):
retlist.append((start_dt, end_dt))
return retlist

def _datetime_list_to_str_list(self, tuple_list) -> [(str, str)]:
def _datetime_list_to_str_list(self, tuple_list) -> list[(str, str)]:
retlist = []
for start_dt, end_dt in tuple_list:
retlist.append(
Expand Down Expand Up @@ -579,7 +581,7 @@ def has_envelope(self):
or len(self._end_include)
)

def envelope(self) -> (datetime, datetime):
def envelope(self) -> tuple[datetime, datetime]:
"""Get the earliest and latest time possible for this filter.
:return: earliest start and end-time (approximately)
Expand Down

0 comments on commit 54cfe1d

Please sign in to comment.