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

[MAINTENANCE] Replace black formatter with ruff format #9536

Merged
merged 30 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
cd3312d
swap black for `ruff-format` and update version
Kilo59 Feb 26, 2024
c6df05c
update ruff verion
Kilo59 Feb 26, 2024
4787436
`black` -> `ruff format`
Kilo59 Feb 26, 2024
4c6aa98
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 26, 2024
c2bd11b
Merge branch 'develop' into m/_/ruff-fmt
Kilo59 Feb 26, 2024
6ff8597
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 26, 2024
5174f64
formatting ignores
Kilo59 Feb 26, 2024
36edb35
manual fmt fixes
Kilo59 Feb 26, 2024
40aa57f
adjust packaging pins
Kilo59 Feb 26, 2024
7f875b2
remove isort config
Kilo59 Mar 1, 2024
835fc58
remove from packaging
Kilo59 Mar 1, 2024
1df89e0
Merge branch 'develop' into m/_/ruff-fmt
Kilo59 Mar 4, 2024
5b0772d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 4, 2024
aca4a3d
remove black import
Kilo59 Mar 4, 2024
2007279
`ruff` 0.3.0
Kilo59 Mar 4, 2024
05823f6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 4, 2024
6ebc2f6
Merge branch 'develop' into m/_/ruff-fmt
Kilo59 Mar 4, 2024
4486e84
revert fmt
Kilo59 Mar 4, 2024
997512b
adjust fmt comments
Kilo59 Mar 4, 2024
8432bc0
use `ruff check` for linting
Kilo59 Mar 4, 2024
da03678
update PR template
Kilo59 Mar 4, 2024
0b4220f
remove `lint_code` and related tests
Kilo59 Mar 4, 2024
5953295
merge conflicts
Kilo59 Mar 5, 2024
a873023
more merge conflicts
Kilo59 Mar 5, 2024
59c0f26
Merge branch 'develop' into m/_/ruff-fmt
Kilo59 Mar 5, 2024
87faca7
add back noqas
Kilo59 Mar 5, 2024
d48301e
adjust type-ignore comments
Kilo59 Mar 5, 2024
f31f177
final type-ignores
Kilo59 Mar 5, 2024
4f67833
source file adjustments
Kilo59 Mar 5, 2024
68f9e9b
use `ruff check`
Kilo59 Mar 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ repos:
args: [--branch, develop, --branch, main]
- id: detect-private-key
exclude: tests/test_fixtures/database_key_test*
- repo: https://github.com/psf/black
rev: 23.11.0
hooks:
- id: black-jupyter
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.2.2"
hooks:
- id: ruff
files: ^(great_expectations|assets|contrib|scripts|tasks\.py|tests) # TODO: add docs/ etc.
args: ["--fix"]
- id: ruff-format
# Github Actions Linter
# Need to be able to inline ignore errors
# https://github.com/rhysd/actionlint/issues/237
Expand Down
4 changes: 3 additions & 1 deletion assets/scripts/build_package_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ def write_results_to_disk(path: str, package_manifests: List[dict]) -> None:
if __name__ == "__main__":
pwd = os.path.abspath(os.getcwd()) # noqa: PTH100, PTH109
root = os.path.join( # noqa: PTH118
os.path.dirname(os.path.abspath(__file__)), "..", ".." # noqa: PTH100, PTH120
os.path.dirname(os.path.abspath(__file__)),
"..",
"..",
)
try:
os.chdir(root)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,5 @@ class ExpectColumnValuesConfidenceForDataLabelToBeGreaterThanOrEqualToThreshold(


if __name__ == "__main__":
diagnostics_report = (
ExpectColumnValuesConfidenceForDataLabelToBeGreaterThanOrEqualToThreshold().run_diagnostics()
)
diagnostics_report = ExpectColumnValuesConfidenceForDataLabelToBeGreaterThanOrEqualToThreshold().run_diagnostics()
print(diagnostics_report.generate_checklist())
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,5 @@ class ExpectColumnValuesConfidenceForDataLabelToBeLessThanOrEqualToThreshold(


if __name__ == "__main__":
diagnostics_report = (
ExpectColumnValuesConfidenceForDataLabelToBeLessThanOrEqualToThreshold().run_diagnostics()
)
diagnostics_report = ExpectColumnValuesConfidenceForDataLabelToBeLessThanOrEqualToThreshold().run_diagnostics()
print(diagnostics_report.generate_checklist())
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,5 @@ class ExpectColumnValuesToBeProbabilisticallyGreaterThanOrEqualToThreshold(


if __name__ == "__main__":
diagnostics_report = (
ExpectColumnValuesToBeProbabilisticallyGreaterThanOrEqualToThreshold().run_diagnostics()
)
diagnostics_report = ExpectColumnValuesToBeProbabilisticallyGreaterThanOrEqualToThreshold().run_diagnostics()
print(diagnostics_report.generate_checklist())
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,5 @@ class ExpectProfileNumericColumnsDiffBetweenExclusiveThresholdRange(


if __name__ == "__main__":
diagnostics_report = (
ExpectProfileNumericColumnsDiffBetweenExclusiveThresholdRange().run_diagnostics()
)
diagnostics_report = ExpectProfileNumericColumnsDiffBetweenExclusiveThresholdRange().run_diagnostics()
print(diagnostics_report.generate_checklist())
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,5 @@ class ExpectProfileNumericColumnsDiffBetweenInclusiveThresholdRange(


if __name__ == "__main__":
diagnostics_report = (
ExpectProfileNumericColumnsDiffBetweenInclusiveThresholdRange().run_diagnostics()
)
diagnostics_report = ExpectProfileNumericColumnsDiffBetweenInclusiveThresholdRange().run_diagnostics()
print(diagnostics_report.generate_checklist())
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,5 @@ class ExpectProfileNumericColumnsPercentDiffBetweenExclusiveThresholdRange(


if __name__ == "__main__":
diagnostics_report = (
ExpectProfileNumericColumnsPercentDiffBetweenExclusiveThresholdRange().run_diagnostics()
)
diagnostics_report = ExpectProfileNumericColumnsPercentDiffBetweenExclusiveThresholdRange().run_diagnostics()
print(diagnostics_report.generate_checklist())
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,5 @@ class ExpectProfileNumericColumnsPercentDiffBetweenInclusiveThresholdRange(


if __name__ == "__main__":
diagnostics_report = (
ExpectProfileNumericColumnsPercentDiffBetweenInclusiveThresholdRange().run_diagnostics()
)
diagnostics_report = ExpectProfileNumericColumnsPercentDiffBetweenInclusiveThresholdRange().run_diagnostics()
print(diagnostics_report.generate_checklist())
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,5 @@ class ExpectProfileNumericColumnsPercentDiffGreaterThanOrEqualToThreshold(


if __name__ == "__main__":
diagnostics_report = (
ExpectProfileNumericColumnsPercentDiffGreaterThanOrEqualToThreshold().run_diagnostics()
)
diagnostics_report = ExpectProfileNumericColumnsPercentDiffGreaterThanOrEqualToThreshold().run_diagnostics()
print(diagnostics_report.generate_checklist())
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,5 @@ class ExpectProfileNumericColumnsPercentDiffLessThanOrEqualToThreshold(


if __name__ == "__main__":
diagnostics_report = (
ExpectProfileNumericColumnsPercentDiffLessThanOrEqualToThreshold().run_diagnostics()
)
diagnostics_report = ExpectProfileNumericColumnsPercentDiffLessThanOrEqualToThreshold().run_diagnostics()
print(diagnostics_report.generate_checklist())
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ def bobby_columnar_table_multi_batch_deterministic_data_context(
project_path: str = str(tmp_path_factory.mktemp("taxi_data_context"))
context_path: str = os.path.join(project_path, "great_expectations") # noqa: PTH118
os.makedirs( # noqa: PTH103
os.path.join(context_path, "expectations"), exist_ok=True # noqa: PTH118
os.path.join(context_path, "expectations"),
exist_ok=True,
)
data_path: str = os.path.join(context_path, "..", "data") # noqa: PTH118
os.makedirs(os.path.join(data_path), exist_ok=True) # noqa: PTH118, PTH103
Expand Down Expand Up @@ -262,7 +263,8 @@ def bobby_columnar_table_multi_batch_probabilistic_data_context(
project_path: str = str(tmp_path_factory.mktemp("taxi_data_context"))
context_path: str = os.path.join(project_path, "great_expectations") # noqa: PTH118
os.makedirs( # noqa: PTH103
os.path.join(context_path, "expectations"), exist_ok=True # noqa: PTH118
os.path.join(context_path, "expectations"),
exist_ok=True,
)
data_path: str = os.path.join(context_path, "..", "data") # noqa: PTH118
os.makedirs(os.path.join(data_path), exist_ok=True) # noqa: PTH118, PTH103
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ def test_profile_data_profiler_structured_data_assistant_metrics_count(
for (
domain,
parameter_values_for_fully_qualified_parameter_names,
) in (
bobby_profile_data_profiler_structured_data_assistant_result.metrics_by_domain.items()
):
) in bobby_profile_data_profiler_structured_data_assistant_result.metrics_by_domain.items():
if domain.is_superset(other=domain_key):
num_metrics += len(parameter_values_for_fully_qualified_parameter_names)

Expand All @@ -180,9 +178,7 @@ def test_profile_data_profiler_structured_data_assistant_metrics_count(
for (
domain,
parameter_values_for_fully_qualified_parameter_names,
) in (
bobby_profile_data_profiler_structured_data_assistant_result.metrics_by_domain.items()
):
) in bobby_profile_data_profiler_structured_data_assistant_result.metrics_by_domain.items():
num_metrics += len(parameter_values_for_fully_qualified_parameter_names)
assert (
num_metrics == 50
Expand Down
3 changes: 2 additions & 1 deletion contrib/cli/great_expectations_contrib/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
# The following link points to the repo where the Cookiecutter template is hosted
URL = "https://github.com/great-expectations/great-expectations-contrib-cookiecutter"
PACKAGE_PATH = os.path.join( # noqa: PTH118
os.getcwd(), ".great_expectations_package.json" # noqa: PTH109
os.getcwd(),
".great_expectations_package.json",
)


Expand Down
6 changes: 3 additions & 3 deletions contrib/cli/great_expectations_contrib/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ def publish_cmd() -> None:
def perform_check(suppress_output: bool) -> bool:
commands = [
Command(
"black",
"black --check .",
"Please ensure that your files are linted properly with `black .`",
"ruff format",
"ruff format --check .",
"Please ensure that your files are linted properly with `ruff format .`",
),
# TODO: update this (or don't)
Command(
Expand Down
4 changes: 1 addition & 3 deletions contrib/cli/great_expectations_contrib/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ def update_package_state(self) -> None:
"""
Parses diagnostic reports from package Expectations and uses them to update JSON state
"""
diagnostics = (
GreatExpectationsContribPackageManifest.retrieve_package_expectations_diagnostics()
)
diagnostics = GreatExpectationsContribPackageManifest.retrieve_package_expectations_diagnostics()
self._update_attrs_with_diagnostics(diagnostics)

def _update_attrs_with_diagnostics(
Expand Down
3 changes: 1 addition & 2 deletions contrib/cli/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
black[jupyter]==23.10.1 # Linting / code style
Click>=7.1.2 # CLI tooling
cookiecutter==2.1.1 # Project templating
mypy==1.7.1 # Type checker
pydantic>=1.0 # Needed for mypy plugin
pytest>=5.3.5 # Test framework
ruff==0.2.2 # Linting / code style
ruff==0.2.2 # Linting / code style / formatting
twine==3.7.1 # Packaging
wheel==0.38.1 # Packaging
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class ExpectMulticolumnProductToBeEqualToSingleColumn(MulticolumnMapExpectation)
A numeric value that is included in the calculation to equal the nth column. \
The calculation becomes col_a * col_b * ... * col_n-1 * additional_value == col_n
"""

# </snippet>

# These examples will be shown in the public gallery.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class ExpectMulticolumnSumValuesToBeEqualToSingleColumn(MulticolumnMapExpectatio
A numeric value that is included in the calculation to equal the nth column. \
The calculation becomes col_a + col_b + ... + col_n-1 + additional_value == col_n
"""

# </snippet>

additional_value: Optional[float] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@ def validate_configuration(

try:
assert value is not None, "'value' must be specified"
assert (isinstance(threshold, (int, float)) and 0 < threshold <= 1) or (
isinstance(threshold, list)
and all(isinstance(x, (int, float)) for x in threshold)
and all(0 < x <= 1 for x in threshold)
and 0 < sum(threshold) <= 1
assert (
(isinstance(threshold, (int, float)) and 0 < threshold <= 1)
or (
isinstance(threshold, list)
and all(isinstance(x, (int, float)) for x in threshold)
and all(0 < x <= 1 for x in threshold)
and 0 < sum(threshold) <= 1
)
), "'threshold' must be 1, a float between 0 and 1, or a list of floats whose sum is between 0 and 1"
if isinstance(threshold, list):
assert isinstance(value, list) and len(value) == len(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class ExpectValueAtIndex(ColumnMapExpectation):
],
"contributors": [
"@prem1835213",
"@YaosenLin"
"@YaosenLin",
# Github handles for all contributors to this Expectation.
# "@your_name_here", # Don't forget to add your github handle here!
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ def get_rules(self) -> Optional[List[Rule]]:
"""
table_rule: Rule = self._build_table_rule()

total_count_metric_multi_batch_parameter_builder_for_evaluations: ParameterBuilder = (
DataAssistant.commonly_used_parameter_builders.get_table_row_count_metric_multi_batch_parameter_builder()
)
total_count_metric_multi_batch_parameter_builder_for_evaluations: ParameterBuilder = DataAssistant.commonly_used_parameter_builders.get_table_row_count_metric_multi_batch_parameter_builder()
column_value_nonnullity_rule: Rule = build_map_metric_rule(
data_assistant_class_name=self.__class__.__name__,
rule_name="column_value_nonnullity_rule",
Expand Down Expand Up @@ -134,12 +132,8 @@ def _build_table_rule() -> Rule:

# Step-2: Declare "ParameterBuilder" for every metric of interest.

table_row_count_metric_multi_batch_parameter_builder_for_metrics: ParameterBuilder = (
DataAssistant.commonly_used_parameter_builders.get_table_row_count_metric_multi_batch_parameter_builder()
)
table_columns_metric_multi_batch_parameter_builder_for_metrics: ParameterBuilder = (
DataAssistant.commonly_used_parameter_builders.get_table_columns_metric_multi_batch_parameter_builder()
)
table_row_count_metric_multi_batch_parameter_builder_for_metrics: ParameterBuilder = DataAssistant.commonly_used_parameter_builders.get_table_row_count_metric_multi_batch_parameter_builder()
table_columns_metric_multi_batch_parameter_builder_for_metrics: ParameterBuilder = DataAssistant.commonly_used_parameter_builders.get_table_columns_metric_multi_batch_parameter_builder()

# Step-3: Declare "ParameterBuilder" for every "validation" need in "ExpectationConfigurationBuilder" objects.

Expand Down Expand Up @@ -267,24 +261,12 @@ def _build_numeric_columns_rule() -> Rule:
column_histogram_single_batch_parameter_builder_for_metrics: ParameterBuilder = DataAssistant.commonly_used_parameter_builders.build_histogram_single_batch_parameter_builder(
name="column_values.partition",
)
column_min_metric_multi_batch_parameter_builder_for_metrics: ParameterBuilder = (
DataAssistant.commonly_used_parameter_builders.get_column_min_metric_multi_batch_parameter_builder()
)
column_max_metric_multi_batch_parameter_builder_for_metrics: ParameterBuilder = (
DataAssistant.commonly_used_parameter_builders.get_column_max_metric_multi_batch_parameter_builder()
)
column_quantile_values_metric_multi_batch_parameter_builder_for_metrics: ParameterBuilder = (
DataAssistant.commonly_used_parameter_builders.get_column_quantile_values_metric_multi_batch_parameter_builder()
)
column_median_metric_multi_batch_parameter_builder_for_metrics: ParameterBuilder = (
DataAssistant.commonly_used_parameter_builders.get_column_median_metric_multi_batch_parameter_builder()
)
column_mean_metric_multi_batch_parameter_builder_for_metrics: ParameterBuilder = (
DataAssistant.commonly_used_parameter_builders.get_column_mean_metric_multi_batch_parameter_builder()
)
column_standard_deviation_metric_multi_batch_parameter_builder_for_metrics: ParameterBuilder = (
DataAssistant.commonly_used_parameter_builders.get_column_standard_deviation_metric_multi_batch_parameter_builder()
)
column_min_metric_multi_batch_parameter_builder_for_metrics: ParameterBuilder = DataAssistant.commonly_used_parameter_builders.get_column_min_metric_multi_batch_parameter_builder()
column_max_metric_multi_batch_parameter_builder_for_metrics: ParameterBuilder = DataAssistant.commonly_used_parameter_builders.get_column_max_metric_multi_batch_parameter_builder()
column_quantile_values_metric_multi_batch_parameter_builder_for_metrics: ParameterBuilder = DataAssistant.commonly_used_parameter_builders.get_column_quantile_values_metric_multi_batch_parameter_builder()
column_median_metric_multi_batch_parameter_builder_for_metrics: ParameterBuilder = DataAssistant.commonly_used_parameter_builders.get_column_median_metric_multi_batch_parameter_builder()
column_mean_metric_multi_batch_parameter_builder_for_metrics: ParameterBuilder = DataAssistant.commonly_used_parameter_builders.get_column_mean_metric_multi_batch_parameter_builder()
column_standard_deviation_metric_multi_batch_parameter_builder_for_metrics: ParameterBuilder = DataAssistant.commonly_used_parameter_builders.get_column_standard_deviation_metric_multi_batch_parameter_builder()

# Step-3: Declare "ParameterBuilder" for every "validation" need in "ExpectationConfigurationBuilder" objects.

Expand Down Expand Up @@ -579,9 +561,7 @@ def _build_categorical_columns_rule() -> Rule:

# Step-2: Declare "ParameterBuilder" for every metric of interest.

column_distinct_values_count_metric_multi_batch_parameter_builder_for_metrics: ParameterBuilder = (
DataAssistant.commonly_used_parameter_builders.get_column_distinct_values_count_metric_multi_batch_parameter_builder()
)
column_distinct_values_count_metric_multi_batch_parameter_builder_for_metrics: ParameterBuilder = DataAssistant.commonly_used_parameter_builders.get_column_distinct_values_count_metric_multi_batch_parameter_builder()

# Step-3: Declare "ParameterBuilder" for every "validation" need in "ExpectationConfigurationBuilder" objects.

Expand Down