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 22 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

- [ ] Description of PR changes above includes a link to [an existing GitHub issue](https://github.com/great-expectations/great_expectations/issues)
- [ ] PR title is prefixed with one of: [BUGFIX], [FEATURE], [DOCS], [MAINTENANCE], [CONTRIB]
- [ ] Code is linted - run `invoke lint` (uses `black` + `ruff`)
- [ ] Code is linted - run `invoke lint` (uses `ruff format` + `ruff check`)
- [ ] Appropriate tests and docs have been updated

For more information about contributing, see [Contribute](https://docs.greatexpectations.io/docs/contributing/contributing_checklist).
Expand Down
7 changes: 2 additions & 5 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"
rev: "v0.3.0"
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
24 changes: 12 additions & 12 deletions assets/scripts/build_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,19 +439,19 @@ def combine_backend_results(
tests=diagnostic_object.tests,
backend_test_result_counts=backend_test_result_counts_object,
)
expectations_info[expectation_name][
"maturity_checklist"
] = maturity_checklist_object.to_dict()
expectations_info[expectation_name][
"coverage_score"
] = Expectation._get_coverage_score(
backend_test_result_counts=backend_test_result_counts_object,
execution_engines=diagnostic_object.execution_engines,
expectations_info[expectation_name]["maturity_checklist"] = (
maturity_checklist_object.to_dict()
)
expectations_info[expectation_name]["coverage_score"] = (
Expectation._get_coverage_score(
backend_test_result_counts=backend_test_result_counts_object,
execution_engines=diagnostic_object.execution_engines,
)
)
expectations_info[expectation_name]["library_metadata"][
"maturity"
] = Expectation._get_final_maturity_level(
maturity_checklist=maturity_checklist_object
expectations_info[expectation_name]["library_metadata"]["maturity"] = (
Expectation._get_final_maturity_level(
maturity_checklist=maturity_checklist_object
)
)

for bad_key_name in bad_key_names:
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
1 change: 1 addition & 0 deletions ci/checks/check_no_line_number_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Purpose: To ensure that no docs snippets use the file and line number convention,
only the named snippets convention.
"""

import pathlib
import re
import shutil
Expand Down
1 change: 1 addition & 0 deletions ci/checks/validate_docs_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

In short, this script creates a temporary Docusaurus build and utilizes grep to parse for stray tags.
"""

from __future__ import annotations

import shutil
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 @@ -3,6 +3,7 @@
For detailed instructions on how to use it, please see:
https://docs.greatexpectations.io/docs/guides/expectations/creating_custom_expectations/how_to_create_custom_column_map_expectations
"""

from typing import Any

import dataprofiler as dp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
For detailed instructions on how to use it, please see:
https://docs.greatexpectations.io/docs/guides/expectations/creating_custom_expectations/how_to_create_custom_column_map_expectations
"""

from typing import Any

import dataprofiler as dp
Expand Down
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 All @@ -193,9 +189,9 @@ def test_profile_data_profiler_structured_data_assistant_metrics_count(
def test_profile_data_profiler_structured_data_assistant_result_batch_id_to_batch_identifier_display_name_map_coverage(
bobby_profile_data_profiler_structured_data_assistant_result: DataProfilerStructuredDataAssistantResult,
):
metrics_by_domain: Optional[
Dict[Domain, Dict[str, ParameterNode]]
] = bobby_profile_data_profiler_structured_data_assistant_result.metrics_by_domain
metrics_by_domain: Optional[Dict[Domain, Dict[str, ParameterNode]]] = (
bobby_profile_data_profiler_structured_data_assistant_result.metrics_by_domain
)

parameter_values_for_fully_qualified_parameter_names: Dict[str, ParameterNode]
parameter_node: ParameterNode
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.3.0 # 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 @@ -4,7 +4,6 @@
https://docs.greatexpectations.io/docs/guides/expectations/creating_custom_expectations/how_to_create_custom_column_map_expectations
"""


from great_expectations.execution_engine import PandasExecutionEngine
from great_expectations.expectations.expectation import ColumnMapExpectation
from great_expectations.expectations.metrics import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
For detailed instructions on how to use it, please see:
https://docs.greatexpectations.io/docs/guides/expectations/creating_custom_expectations/how_to_create_custom_column_map_expectations
"""

from datetime import date

from dateutil.parser import parse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
https://docs.greatexpectations.io/docs/guides/expectations/creating_custom_expectations/how_to_create_custom_regex_based_column_map_expectations
"""


from great_expectations.expectations.regex_based_column_map_expectation import (
RegexBasedColumnMapExpectation,
)
Expand All @@ -21,7 +20,7 @@ class ExpectColumnValuesToMatchThai(RegexBasedColumnMapExpectation):

# These values will be used to configure the metric created by your expectation
regex_camel_name = "RegexName"
regex = "[\u0E00-\u0E7F]+"
regex = "[\u0e00-\u0e7f]+"
semantic_type_name_plural = None

# These examples will be shown in the public gallery.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def date_diff_in_months(row):

# This class defines the Expectation itself
class ExpectMulticolumnDatetimeDifferenceInMonths(MulticolumnMapExpectation):

"""Expect the difference of 2 datetime columns is equal to another column in month.

This means that for each row, we expect end_datetime - start_datetime = gap (in months)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def date_diff_in_months(row):
class ExpectMulticolumnDatetimeDifferenceToBeLessThanTwoMonths(
MulticolumnMapExpectation
):

"""Expect the difference of 2 datetime columns to be less than or equal to 2 months.

This means that for each row, we expect end_datetime - start_datetime <= 2 (in months)
Expand Down
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 @@ -3,6 +3,7 @@
For detailed instructions on how to use it, please see:
https://docs.greatexpectations.io/docs/guides/expectations/creating_custom_expectations/how_to_create_custom_multicolumn_map_expectations
"""

import functools
import operator

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 @@ -4,7 +4,6 @@
https://docs.greatexpectations.io/docs/guides/expectations/creating_custom_expectations/how_to_create_custom_query_expectations
"""


from typing import Union

from great_expectations.execution_engine import ExecutionEngine
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