Skip to content

Commit

Permalink
chore: enable ruff I (isort) (#125)
Browse files Browse the repository at this point in the history
* enable ruff isort
  • Loading branch information
fpgmaas authored Jul 17, 2024
1 parent ddf4d2c commit 3f6d88a
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 42 deletions.
17 changes: 9 additions & 8 deletions chispa/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
import os
import sys
from glob import glob

# Add PySpark to the library path based on the value of SPARK_HOME if pyspark is not already in our path
Expand All @@ -25,18 +25,19 @@
print("Can't find Apache Spark. Please set environment variable SPARK_HOME to root of installation!")
exit(-1)

from .dataframe_comparer import (
DataFramesNotEqualError,
assert_df_equality,
assert_approx_df_equality,
)
from chispa.default_formats import DefaultFormats

from .column_comparer import (
ColumnsNotEqualError,
assert_column_equality,
assert_approx_column_equality,
assert_column_equality,
)
from .dataframe_comparer import (
DataFramesNotEqualError,
assert_approx_df_equality,
assert_df_equality,
)
from .rows_comparer import assert_basic_rows_equality
from chispa.default_formats import DefaultFormats


class Chispa:
Expand Down
3 changes: 2 additions & 1 deletion chispa/column_comparer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from chispa.bcolors import bcolors
from prettytable import PrettyTable

from chispa.bcolors import bcolors


class ColumnsNotEqualError(Exception):
"""The columns are not equal"""
Expand Down
7 changes: 4 additions & 3 deletions chispa/dataframe_comparer.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from chispa.schema_comparer import assert_schema_equality
from functools import reduce

from chispa.default_formats import DefaultFormats
from chispa.row_comparer import are_rows_approx_equal, are_rows_equal_enhanced
from chispa.rows_comparer import (
assert_basic_rows_equality,
assert_generic_rows_equality,
)
from chispa.row_comparer import are_rows_equal_enhanced, are_rows_approx_equal
from functools import reduce
from chispa.schema_comparer import assert_schema_equality


class DataFramesNotEqualError(Exception):
Expand Down
6 changes: 4 additions & 2 deletions chispa/row_comparer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from pyspark.sql import Row
from chispa.number_helpers import nan_safe_equality, nan_safe_approx_equality
import math

from pyspark.sql import Row

from chispa.number_helpers import nan_safe_approx_equality, nan_safe_equality


def are_rows_equal(r1: Row, r2: Row) -> bool:
return r1 == r2
Expand Down
4 changes: 3 additions & 1 deletion chispa/rows_comparer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from itertools import zip_longest

from prettytable import PrettyTable

import chispa
from chispa.terminal_str_formatter import format_string
from chispa.default_formats import DefaultFormats
from chispa.terminal_str_formatter import format_string


def assert_basic_rows_equality(rows1, rows2, underline_cells=False, formats=DefaultFormats()):
Expand Down
4 changes: 3 additions & 1 deletion chispa/schema_comparer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from itertools import zip_longest

from prettytable import PrettyTable

from chispa.bcolors import blue
from itertools import zip_longest


class SchemasNotEqualError(Exception):
Expand Down
8 changes: 3 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,14 @@ fix = true
preview = true

[tool.ruff.lint]
select = ["E", "F", "I"]
ignore = [
"E501", # Line too long
"F405", # X may be undefined, or defined from star imports
# Line too long
"E501",
]

[tool.ruff.lint.flake8-type-checking]
strict = true

[tool.ruff.lint.isort]
required-imports = ["from __future__ import annotations"]

[tool.ruff.lint.per-file-ignores]
"tests/*" = ["S101", "S603"]
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest
from dataclasses import dataclass

import pytest

from chispa import Chispa


Expand Down
3 changes: 2 additions & 1 deletion tests/test_column_comparer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pytest

from chispa import ColumnsNotEqualError, assert_approx_column_equality, assert_column_equality

from .spark import spark
from chispa import assert_column_equality, ColumnsNotEqualError, assert_approx_column_equality


def describe_assert_column_equality():
Expand Down
10 changes: 6 additions & 4 deletions tests/test_dataframe_comparer.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import math

import pytest
from pyspark.sql.types import IntegerType, StringType, StructField, StructType

from .spark import spark
from chispa import assert_df_equality, DataFramesNotEqualError, assert_approx_df_equality
from chispa import DataFramesNotEqualError, assert_approx_df_equality, assert_df_equality
from chispa.dataframe_comparer import are_dfs_equal
from chispa.schema_comparer import SchemasNotEqualError
import math
from pyspark.sql.types import StringType, IntegerType, StructType, StructField

from .spark import spark


def describe_assert_df_equality():
Expand Down
14 changes: 6 additions & 8 deletions tests/test_readme_examples.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import pyspark.sql.functions as F
import pytest
from pyspark.sql import SparkSession
from pyspark.sql.types import ArrayType, DoubleType, IntegerType, StringType, StructField, StructType

from chispa import (
assert_column_equality,
ColumnsNotEqualError,
assert_df_equality,
DataFramesNotEqualError,
assert_approx_df_equality,
assert_approx_column_equality,
assert_approx_df_equality,
assert_basic_rows_equality,
assert_column_equality,
assert_df_equality,
)
import pyspark.sql.functions as F
from chispa.schema_comparer import SchemasNotEqualError
from pyspark.sql.types import StringType, IntegerType, DoubleType, StructField, StructType, ArrayType


from pyspark.sql import SparkSession


def remove_non_word_characters(col):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_row_comparer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from chispa.row_comparer import are_rows_equal_enhanced, are_rows_equal, are_rows_approx_equal
from pyspark.sql import Row

from chispa.row_comparer import are_rows_approx_equal, are_rows_equal, are_rows_equal_enhanced


def test_are_rows_equal():
assert are_rows_equal(Row("bob", "jose"), Row("li", "li")) is False
Expand Down
4 changes: 2 additions & 2 deletions tests/test_rows_comparer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest

from chispa import DataFramesNotEqualError, assert_basic_rows_equality

from .spark import spark
from chispa import assert_basic_rows_equality
from chispa import DataFramesNotEqualError


def describe_assert_basic_rows_equality():
Expand Down
6 changes: 3 additions & 3 deletions tests/test_schema_comparer.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import pytest
from pyspark.sql.types import ArrayType, DoubleType, IntegerType, StringType, StructField, StructType

from pyspark.sql.types import StringType, IntegerType, DoubleType, StructField, StructType, ArrayType
from chispa.schema_comparer import (
assert_schema_equality,
SchemasNotEqualError,
assert_schema_equality_ignore_nullable,
are_schemas_equal_ignore_nullable,
are_structfields_equal,
assert_schema_equality,
assert_schema_equality_ignore_nullable,
)


Expand Down
3 changes: 2 additions & 1 deletion tests/test_structfield_comparer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pyspark.sql.types import DoubleType, IntegerType, StructField, StructType

from chispa.structfield_comparer import are_structfields_equal
from pyspark.sql.types import StructField, IntegerType, StructType, DoubleType


def describe_are_structfields_equal():
Expand Down

0 comments on commit 3f6d88a

Please sign in to comment.