Skip to content

Commit 54b9d12

Browse files
kkleinpavelzw
andcommitted
Type-check package (#229)
* Draft usage of mypy. * Apply pchs. * Draft usage of pixi. * Adapt more integration tests. * Adapt bigquery integration test task. * Migrate docs deployment to pixi. * Update build and publish. * Run postinstall for readthedocs. * Adapt liniting to rely on pixi. * Add pytest as dependency. * Adapt readthedocs configuration. * Update development instructions. * Switch to pixi in helper script. * Minor adadptations. * Introduce mypy CI step. * Add changelog entry. * Fix usage of condarc file. * Adapt development.rst. * Use pixi for mypy job. * Fix yml syntax. * Create pixi environment for mypy. * Remove impala step for debugging. * Add type packages. * Comment out impala run for debugging. * Move flit to host-dependencies. * Remove redundant dependency. * Update .github/workflows/ci.yaml Co-authored-by: Pavel Zwerschke <[email protected]> * Add color to ci tests. * Update .github/workflows/ci.yaml Co-authored-by: Pavel Zwerschke <[email protected]> * Update .github/workflows/ci.yaml Co-authored-by: Pavel Zwerschke <[email protected]> * Remove configurations which were erroneously added. * Remove configurations which were erroneously added. * Consistently use ubuntu-latest. * Update .github/workflows/ci.yaml Co-authored-by: Pavel Zwerschke <[email protected]> * Also run unit tests on macos and windows. * Fix impala test syntax. * Downgrade sqlalchemy version for impala tests. * Downgrade sqlalchemy version for impala tests. * Disable BigQuery tests for now. --------- Co-authored-by: Pavel Zwerschke <[email protected]>
1 parent 7fced1f commit 54b9d12

File tree

24 files changed

+963
-497
lines changed

24 files changed

+963
-497
lines changed

.github/workflows/ci.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ jobs:
2929
- name: pre-commit
3030
run: pixi run pre-commit-run --color=always --show-diff-on-failure
3131

32+
mypy-type-checks:
33+
name: Mypy Type Checks
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: Checkout branch
37+
uses: actions/checkout@v4
38+
- name: Set up pixi
39+
uses: prefix-dev/[email protected]
40+
with:
41+
environments: default lint
42+
- name: mypy
43+
run: |
44+
pixi run -e mypy postinstall
45+
pixi run -e mypy mypy .
46+
3247
unit-tests:
3348
name: "unit tests"
3449
strategy:

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ Changelog
1111
------------------
1212

1313
**New features**
14+
1415
- Added styling for assertion messages. See :ref:`assertion-message-styling` for more information.
1516

17+
**Other changes**
18+
19+
- Provide a ``py.typed`` file.
20+
21+
1622
1.8.0 - 2023.06.16
1723
------------------
1824

pixi.lock

Lines changed: 621 additions & 236 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pixi.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ sqlalchemy = "2.*"
8888
pytest-cov = "*"
8989
pytest-xdist = "*"
9090

91+
[feature.mypy.dependencies]
92+
mypy = "*"
93+
types-setuptools = "*"
94+
types-colorama = "*"
95+
pandas-stubs = "*"
96+
types-jinja2 = "*"
97+
9198
[feature.lint.dependencies]
9299
pre-commit = "*"
93100
black = "*"
@@ -150,3 +157,5 @@ impala-py38 = ["impala", "py38", "sa1", "test"]
150157
impala-sa1 = ["impala", "sa1", "test"]
151158

152159
lint = { features = ["lint"], no-default-feature = true }
160+
161+
mypy = ["mypy"]

pyproject.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ skip_glob = '\.eggs/*,\.git/*,\.venv/*,build/*,dist/*'
4646
default_section = 'THIRDPARTY'
4747

4848
[tool.mypy]
49-
# Temporary fix.
50-
no_implicit_optional = false
49+
no_implicit_optional = true
5150
allow_empty_bodies = true
51+
check_untyped_defs = true
52+
53+
[[tool.mypy.overrides]]
54+
module = ["scipy.*", "impala.*", "pytest_html"]
55+
ignore_missing_imports = true

src/datajudge/constraints/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ def __init__(
117117
self,
118118
ref: DataReference,
119119
*,
120-
ref2=None,
121-
ref_value: Any = None,
122-
name: str = None,
120+
ref2: Optional[DataReference] = None,
121+
ref_value: Optional[Any] = None,
122+
name: Optional[str] = None,
123123
output_processors: Optional[
124124
Union[OutputProcessor, List[OutputProcessor]]
125125
] = output_processor_limit,

src/datajudge/constraints/column.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ def retrieve(
2121

2222

2323
class ColumnExistence(Column):
24-
def __init__(self, ref: DataReference, columns: List[str], name: str = None):
24+
def __init__(
25+
self, ref: DataReference, columns: List[str], name: Optional[str] = None
26+
):
2527
super().__init__(ref, ref_value=columns, name=name)
2628

2729
def compare(

src/datajudge/constraints/date.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ def __init__(
3838
ref: DataReference,
3939
use_lower_bound_reference: bool,
4040
column_type: str,
41-
name: str = None,
41+
name: Optional[str] = None,
4242
*,
43-
ref2: DataReference = None,
44-
min_value: str = None,
43+
ref2: Optional[DataReference] = None,
44+
min_value: Optional[str] = None,
4545
):
4646
self.format = get_format_from_column_type(column_type)
4747
self.use_lower_bound_reference = use_lower_bound_reference
@@ -84,10 +84,10 @@ def __init__(
8484
ref: DataReference,
8585
use_upper_bound_reference: bool,
8686
column_type: str,
87-
name: str = None,
87+
name: Optional[str] = None,
8888
*,
89-
ref2: DataReference = None,
90-
max_value: str = None,
89+
ref2: Optional[DataReference] = None,
90+
max_value: Optional[str] = None,
9191
):
9292
self.format = get_format_from_column_type(column_type)
9393
self.use_upper_bound_reference = use_upper_bound_reference
@@ -132,7 +132,7 @@ def __init__(
132132
min_fraction: float,
133133
lower_bound: str,
134134
upper_bound: str,
135-
name: str = None,
135+
name: Optional[str] = None,
136136
):
137137
super().__init__(ref, ref_value=min_fraction, name=name)
138138
self.lower_bound = lower_bound

src/datajudge/constraints/groupby.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ def __init__(
1313
ref: DataReference,
1414
aggregation_column: str,
1515
start_value: int = 0,
16-
name: str = None,
16+
name: Optional[str] = None,
1717
*,
1818
tolerance: float = 0,
19-
ref2: DataReference = None,
19+
ref2: Optional[DataReference] = None,
2020
):
2121
super().__init__(ref, ref2=ref2, ref_value=object(), name=name)
2222
self.aggregation_column = aggregation_column

src/datajudge/constraints/interval.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(
1818
start_columns: List[str],
1919
end_columns: List[str],
2020
max_relative_n_violations: float,
21-
name: str = None,
21+
name: Optional[str] = None,
2222
):
2323
super().__init__(ref, ref_value=object(), name=name)
2424
self.key_columns = key_columns
@@ -56,7 +56,9 @@ def retrieve(
5656
sample_selection, n_violations_selection = self.select(engine, ref)
5757
with engine.connect() as connection:
5858
self.sample = connection.execute(sample_selection).first()
59-
n_violation_keys = connection.execute(n_violations_selection).scalar()
59+
n_violation_keys = int(
60+
str(connection.execute(n_violations_selection).scalar())
61+
)
6062

6163
selections = [*n_keys_selections, sample_selection, n_violations_selection]
6264
return (n_violation_keys, n_distinct_key_values), selections
@@ -97,7 +99,7 @@ def select(self, engine: sa.engine.Engine, ref: DataReference):
9799
return sample_selection, n_violations_selection
98100

99101
@abc.abstractmethod
100-
def compare(self, engine: sa.engine.Engine, ref: DataReference):
102+
def compare(self, factual: Any, target: Any):
101103
pass
102104

103105

0 commit comments

Comments
 (0)