-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tolerance to row count match #73
Changes from all commits
e1332c8
1cf08dd
d620478
a7affae
74ac39c
b69d26d
c8e5727
53fc018
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from __future__ import annotations | ||
from dataclasses import dataclass | ||
|
||
from typing import Any | ||
from typing import Any, TYPE_CHECKING | ||
|
||
import narwhals as nw | ||
from narwhals.typing import FrameT | ||
|
@@ -18,6 +18,8 @@ | |
from pointblank.column import Column, ColumnLiteral | ||
from pointblank.schema import Schema | ||
|
||
if TYPE_CHECKING: | ||
from pointblank._typing import AbsoluteTolBounds | ||
|
||
@dataclass | ||
class Interrogator: | ||
|
@@ -1893,16 +1895,23 @@ class RowCountMatch: | |
count: int | ||
inverse: bool | ||
threshold: int | ||
abs_tol_bounds : AbsoluteTolBounds | ||
tbl_type: str = "local" | ||
|
||
def __post_init__(self): | ||
|
||
from pointblank.validate import get_row_count | ||
|
||
if not self.inverse: | ||
res = get_row_count(data=self.data_tbl) == self.count | ||
row_count :int = get_row_count(data=self.data_tbl) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it common/better to declare types for variables? I'm honestly not sure what the norm is on this one. I only ask because if it is a preferred approach, we should probably be doing this everywhere (which is what I'm leaning toward). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "best practice" says to type hint everything but it's not necessary. Implementing type checking on a codebase of this size is a giant task, worth it in the long run but not trivial. I'd be happy to do so if you're on board though. I will say because of how dynamic this code base is, it would probably be even hard than usual, but not at all impossible. The most bang-for-buck would be to type check function signatures, it's 10% of the work for 90% gain. In my experience, so take it with a grain of salt, most things are caught at the signature level and not the individual variable level. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for weighing in on this. I think we ought to add types to variable declarations! We can both chip away at this, and I think it'll be worth it. |
||
|
||
lower_abs_limit, upper_abs_limit = self.abs_tol_bounds | ||
min_val: int = self.count - lower_abs_limit | ||
max_val: int = self.count + upper_abs_limit | ||
|
||
if self.inverse: | ||
res : bool = not (row_count >= min_val and row_count <= max_val) | ||
else: | ||
res = get_row_count(data=self.data_tbl) != self.count | ||
res : bool = row_count >= min_val and row_count <= max_val | ||
|
||
self.test_unit_res = res | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
from __future__ import annotations | ||
|
||
## Absolute bounds, ie. plus or minus | ||
type AbsoluteBounds = tuple[int, int] | ||
|
||
## Relative bounds, ie. plus or minus some percent | ||
type RelativeBounds = tuple[float, float] | ||
|
||
## Tolerance afforded to some check | ||
type Tolerance = int | float | AbsoluteBounds | RelativeBounds |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,3 +122,8 @@ testpaths = [ | |
|
||
[tool.black] | ||
line-length = 100 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this coverage exclusion. Hope it's alright! |
||
[tool.coverage.report] | ||
exclude_also = [ | ||
"if TYPE_CHECKING:" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't know about this! But it's a great improvement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I accidentally left that in the pr 😂