Skip to content
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

test refactor for floating point failures + mypy fix #1169

Merged
merged 3 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:
# Flake8: complexity and style checking
# https://flake8.pycqa.org/en/latest/user/using-hooks.html
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
rev: 5.0.4
hooks:
- id: flake8
additional_dependencies: [flake8-docstrings]
Expand Down
2 changes: 1 addition & 1 deletion dataprofiler/data_readers/parquet_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(
self._load_data(data)

@property
def file_encoding(self) -> None:
def file_encoding(self) -> Optional[str]:
"""Set file encoding to None since not detected for avro."""
return None

Expand Down
5 changes: 4 additions & 1 deletion dataprofiler/profilers/float_column_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,11 @@ def load_from_dict(cls, data, config: dict | None = None):

return profile

# TODO: refactor BaseColumnProfiler.profile to not be an @property
# NumericStatsMixin inherits from BaseColumnProfile and adding @property to
# NumericStatisMixin.profile() results in a breaking change - ignoring [override]
@property
def profile(self) -> dict:
def profile(self) -> dict: # type: ignore[override]
"""
Return the profile of the column.

Expand Down
5 changes: 4 additions & 1 deletion dataprofiler/profilers/int_column_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ def load_from_dict(cls, data, config: dict | None = None):
profile._reformat_numeric_stats_types_on_serialized_profiles()
return profile

# TODO: refactor BaseColumnProfiler.profile to not be an @property
# NumericStatsMixin inherits from BaseColumnProfile and adding @property to
# NumericStatisMixin.profile() results in a breaking change - ignoring [override]
@property
def profile(self) -> dict:
def profile(self) -> dict: # type: ignore[override]
"""
Return the profile of the column.

Expand Down
5 changes: 4 additions & 1 deletion dataprofiler/profilers/numerical_column_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,10 @@ def _add_helper(
other1._median_abs_dev_is_enabled and other2._median_abs_dev_is_enabled
)

def profile(self) -> dict:
# TODO: refactor BaseColumnProfiler.profile to not be an @property
# NumericStatsMixin inherits from BaseColumnProfile and adding @property to
# NumericStatisMixin.profile() results in a breaking change - ignoring [override]
def profile(self) -> dict: # type: ignore[override]
"""
Return profile of the column.

Expand Down
5 changes: 4 additions & 1 deletion dataprofiler/profilers/text_column_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ def report(self, remove_disabled_flag: bool = False) -> dict:

return profile

# TODO: refactor BaseColumnProfiler.profile to not be an @property
# NumericStatsMixin inherits from BaseColumnProfile and adding @property to
# NumericStatisMixin.profile() results in a breaking change - ignoring [override]
@property
def profile(self) -> dict:
def profile(self) -> dict: # type: ignore[override]
"""
Return the profile of the column.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import math
import os
import unittest
from collections import defaultdict
Expand Down Expand Up @@ -731,7 +732,44 @@ def test_categorical_diff(self):
},
}
actual_diff = profile.diff(profile2)
self.assertDictEqual(expected_diff, actual_diff)

assert expected_diff["categorical"] == actual_diff["categorical"]
assert (
expected_diff["statistics"]["unique_count"]
== actual_diff["statistics"]["unique_count"]
)
assert math.isclose(
expected_diff["statistics"]["unique_ratio"],
actual_diff["statistics"]["unique_ratio"],
)
assert (
expected_diff["statistics"]["categories"]
== actual_diff["statistics"]["categories"]
)
assert math.isclose(
expected_diff["statistics"]["gini_impurity"],
actual_diff["statistics"]["gini_impurity"],
)
assert math.isclose(
expected_diff["statistics"]["unalikeability"],
actual_diff["statistics"]["unalikeability"],
)
assert (
expected_diff["statistics"]["categorical_count"]
== actual_diff["statistics"]["categorical_count"]
)
assert math.isclose(
expected_diff["statistics"]["chi2-test"]["chi2-statistic"],
actual_diff["statistics"]["chi2-test"]["chi2-statistic"],
)
assert (
expected_diff["statistics"]["chi2-test"]["deg_of_free"]
== actual_diff["statistics"]["chi2-test"]["deg_of_free"]
)
assert math.isclose(
expected_diff["statistics"]["chi2-test"]["p-value"],
actual_diff["statistics"]["chi2-test"]["p-value"],
)

# Test with one categorical column matching
df_not_categorical = pd.Series(
Expand Down
15 changes: 13 additions & 2 deletions dataprofiler/tests/profilers/test_profile_builder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging
import math
import os
import random
import re
Expand Down Expand Up @@ -2162,8 +2163,18 @@ def test_diff_categorical_chi2_test(self, *mocks):
"deg_of_free": 2,
"p-value": 0.3099238764710244,
}
self.assertDictEqual(
expected_chi2_test_dict, diff["data_stats"][0]["statistics"]["chi2-test"]
actual_chi2_test_dict = diff["data_stats"][0]["statistics"]["chi2-test"]

assert math.isclose(
expected_chi2_test_dict["chi2-statistic"],
actual_chi2_test_dict["chi2-statistic"],
)
assert (
expected_chi2_test_dict["deg_of_free"]
== actual_chi2_test_dict["deg_of_free"]
)
assert math.isclose(
expected_chi2_test_dict["p-value"], actual_chi2_test_dict["p-value"]
)

@mock.patch(
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ warn_unused_configs = True
ignore_missing_imports = True
no_implicit_optional = False
exclude = ^dataprofiler/tests/|^resources/|^examples|venv*/
disable_error_code = override

[check-manifest]
ignore-default-rules=True
Expand Down