Skip to content

Commit

Permalink
chore: Expand mypy rules further
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisjared committed Aug 22, 2023
1 parent b51918a commit 05364ff
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 69 deletions.
18 changes: 17 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,20 @@ build-backend = "setuptools.build_meta"

[tool.black]
line-length = 88
target-version = ['py39']
target-version = ['py39']


[tool.mypy]
strict = true
# show error codes on failure with context
show_error_codes = true
show_error_context = true
# warn if code can't be reached
warn_unreachable = true
# importing following uses default settings
follow_imports = "normal"

# Opt outs
# We don't currently have 100% type coverage so the settings below are temporarily added
disallow_untyped_calls = false
disallow_untyped_defs = false
9 changes: 0 additions & 9 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,6 @@ line_length = 88
multi_line_output = 3
skip = src/scmdata/__init__.py

[mypy]
disallow_incomplete_defs = true
disallow_subclassing_any = true
ignore_missing_imports = true
no_implicit_optional = true
warn_redundant_casts = true
warn_return_any = true
warn_unused_configs = true
warn_unused_ignores = true

[pydocstyle]
# D213 - Multi-line docstring summary should start at the second line
Expand Down
3 changes: 3 additions & 0 deletions src/scmdata/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
from os import PathLike # noqa
from typing import Callable, Dict, Union

import numpy as np
import pandas as pd
from numpy.typing import NDArray

FilePath = Union[str, "PathLike[str]"]
MetadataValue = Union[str, int, float]
MetadataType = Dict[str, MetadataValue]
ApplyCallable = Callable[[pd.DataFrame], Union[pd.DataFrame, pd.Series, float]]
FloatArray = NDArray[np.float_]
16 changes: 8 additions & 8 deletions src/scmdata/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import datetime
import re
import time
from typing import Iterable, List, Optional, Union, Any
from typing import Any, Iterable, List, Optional, Union

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -42,7 +42,7 @@ def find_depth(
s: str,
level: Union[int, str],
separator: str = HIERARCHY_SEPARATOR,
) -> list[Any]:
) -> List[Any]:
"""
Find all values which match given depth from a filter keyword.
Expand Down Expand Up @@ -105,7 +105,7 @@ def apply_test(val):


def pattern_match( # pylint: disable=too-many-arguments,too-many-locals
meta_col: pd.Series,
meta_col: pd.Index,
values: Union[Iterable[str], str],
level: Optional[Union[str, int]] = None,
regexp: bool = False,
Expand Down Expand Up @@ -259,7 +259,9 @@ def month_match(
return time_match(data, months, ["%b", "%B"], "tm_mon", "month")


def day_match(data: List, days: Union[List[str], List[int], int, str]) -> np.ndarray:
def day_match(
data: Iterable[Any], days: Union[List[str], List[int], int, str]
) -> np.ndarray:
"""
Match days in time columns for data filtering.
Expand All @@ -279,9 +281,7 @@ def day_match(data: List, days: Union[List[str], List[int], int, str]) -> np.nda
return time_match(data, days, ["%a", "%A"], "tm_wday", "day")


def hour_match(
data: Iterable[Any], hours: Union[np.ndarray, Iterable[int], int]
) -> np.ndarray:
def hour_match(data: Iterable[Any], hours: Union[Iterable[int], int]) -> np.ndarray:
"""
Match hours in time columns for data filtering.
Expand Down Expand Up @@ -395,7 +395,7 @@ def conv_strs(strs_to_convert, conv_codes, name):


def datetime_match(
data: Iterable[Any], dts: Union[Iterable[datetime.datetime], datetime.datetime]
data: Iterable[Any], dts: Union[Iterable[datetime.datetime], datetime.datetime, str]
) -> np.ndarray:
"""
Match datetimes in time columns for data filtering.
Expand Down
3 changes: 3 additions & 0 deletions src/scmdata/offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ def generate_range(
)

return [date_cls(*dt.timetuple()[:6]) for dt in res]


__all__ = ["to_offset", "generate_range"]
3 changes: 3 additions & 0 deletions src/scmdata/pyam_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ def convert_str_to_datetime(inp):
# mypy can't work out try-except block sets typing
IamDataFrame = None
LongDatetimeIamDataFrame = None # type: ignore


__all__ = ["IamDataFrame", "LongDatetimeIamDataFrame"]
Loading

0 comments on commit 05364ff

Please sign in to comment.