Skip to content

Commit

Permalink
Merge pull request #121 from fpgmaas/chore/ruff-f841
Browse files Browse the repository at this point in the history
chore: enable ruff `F841`
  • Loading branch information
SemyonSinchenko authored Jul 17, 2024
2 parents 34b37b1 + efd6eb6 commit 0d2b5b6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 27 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ preview = true
ignore = [
"E501", # Line too long
"F405", # X may be undefined, or defined from star imports
"F841", # Local variable `e_info` is assigned to but never used
]

[tool.ruff.lint.flake8-type-checking]
Expand Down
8 changes: 4 additions & 4 deletions tests/test_column_comparer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def describe_assert_column_equality():
def it_throws_error_with_data_mismatch():
data = [("jose", "jose"), ("li", "li"), ("luisa", "laura")]
df = spark.createDataFrame(data, ["name", "expected_name"])
with pytest.raises(ColumnsNotEqualError) as e_info:
with pytest.raises(ColumnsNotEqualError):
assert_column_equality(df, "name", "expected_name")

def it_doesnt_throw_without_mismatch():
Expand All @@ -31,17 +31,17 @@ def it_works_with_no_mismatches():
def it_throws_when_difference_is_bigger_than_precision():
data = [(1.5, 1.1), (1.0004, 1.0005), (0.4, 0.45)]
df = spark.createDataFrame(data, ["num1", "num2"])
with pytest.raises(ColumnsNotEqualError) as e_info:
with pytest.raises(ColumnsNotEqualError):
assert_approx_column_equality(df, "num1", "num2", 0.1)

def it_throws_when_comparing_floats_with_none():
data = [(1.1, 1.1), (2.2, 2.2), (3.3, None)]
df = spark.createDataFrame(data, ["num1", "num2"])
with pytest.raises(ColumnsNotEqualError) as e_info:
with pytest.raises(ColumnsNotEqualError):
assert_approx_column_equality(df, "num1", "num2", 0.1)

def it_throws_when_comparing_none_with_floats():
data = [(1.1, 1.1), (2.2, 2.2), (None, 3.3)]
df = spark.createDataFrame(data, ["num1", "num2"])
with pytest.raises(ColumnsNotEqualError) as e_info:
with pytest.raises(ColumnsNotEqualError):
assert_approx_column_equality(df, "num1", "num2", 0.1)
18 changes: 9 additions & 9 deletions tests/test_dataframe_comparer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def it_throws_with_schema_mismatches():
df1 = spark.createDataFrame(data1, ["num", "expected_name"])
data2 = [("bob", "jose"), ("li", "li"), ("luisa", "laura")]
df2 = spark.createDataFrame(data2, ["name", "expected_name"])
with pytest.raises(SchemasNotEqualError) as e_info:
with pytest.raises(SchemasNotEqualError):
assert_df_equality(df1, df2)

def it_can_work_with_different_row_orders():
Expand Down Expand Up @@ -51,7 +51,7 @@ def it_throws_with_schema_column_order_mismatch():
df1 = spark.createDataFrame(data1, ["num", "name"])
data2 = [("jose", 1), ("li", 1)]
df2 = spark.createDataFrame(data2, ["name", "num"])
with pytest.raises(SchemasNotEqualError) as e_info:
with pytest.raises(SchemasNotEqualError):
assert_df_equality(df1, df2)

def it_does_not_throw_on_schema_column_order_mismatch_with_transforms():
Expand All @@ -66,23 +66,23 @@ def it_throws_with_schema_mismatch():
df1 = spark.createDataFrame(data1, ["num", "different_name"])
data2 = [("jose", 1), ("li", 2)]
df2 = spark.createDataFrame(data2, ["name", "num"])
with pytest.raises(SchemasNotEqualError) as e_info:
with pytest.raises(SchemasNotEqualError):
assert_df_equality(df1, df2, transforms=[lambda df: df.select(sorted(df.columns))])

def it_throws_with_content_mismatches():
data1 = [("jose", "jose"), ("li", "li"), ("luisa", "laura")]
df1 = spark.createDataFrame(data1, ["name", "expected_name"])
data2 = [("bob", "jose"), ("li", "li"), ("luisa", "laura")]
df2 = spark.createDataFrame(data2, ["name", "expected_name"])
with pytest.raises(DataFramesNotEqualError) as e_info:
with pytest.raises(DataFramesNotEqualError):
assert_df_equality(df1, df2)

def it_throws_with_length_mismatches():
data1 = [("jose", "jose"), ("li", "li"), ("laura", "laura")]
df1 = spark.createDataFrame(data1, ["name", "expected_name"])
data2 = [("jose", "jose"), ("li", "li")]
df2 = spark.createDataFrame(data2, ["name", "expected_name"])
with pytest.raises(DataFramesNotEqualError) as e_info:
with pytest.raises(DataFramesNotEqualError):
assert_df_equality(df1, df2)

def it_can_consider_nan_values_equal():
Expand All @@ -97,7 +97,7 @@ def it_does_not_consider_nan_values_equal_by_default():
df1 = spark.createDataFrame(data1, ["num", "name"])
data2 = [(float("nan"), "jose"), (2.0, "li")]
df2 = spark.createDataFrame(data2, ["num", "name"])
with pytest.raises(DataFramesNotEqualError) as e_info:
with pytest.raises(DataFramesNotEqualError):
assert_df_equality(df1, df2, allow_nan_equality=False)

def it_can_ignore_metadata():
Expand Down Expand Up @@ -126,7 +126,7 @@ def it_catches_mismatched_metadata():
])
df1 = spark.createDataFrame(rows_data, schema1)
df2 = spark.createDataFrame(rows_data, schema2)
with pytest.raises(SchemasNotEqualError) as e_info:
with pytest.raises(SchemasNotEqualError):
assert_df_equality(df1, df2)


Expand Down Expand Up @@ -159,15 +159,15 @@ def it_throws_with_content_mismatch():
df1 = spark.createDataFrame(data1, ["num", "expected_name"])
data2 = [(1.0, "jose"), (1.05, "li"), (1.0, "laura"), (None, "hi")]
df2 = spark.createDataFrame(data2, ["num", "expected_name"])
with pytest.raises(DataFramesNotEqualError) as e_info:
with pytest.raises(DataFramesNotEqualError):
assert_approx_df_equality(df1, df2, 0.1)

def it_throws_with_with_length_mismatch():
data1 = [(1.0, "jose"), (1.1, "li"), (1.2, "laura"), (None, None)]
df1 = spark.createDataFrame(data1, ["num", "expected_name"])
data2 = [(1.0, "jose"), (1.05, "li")]
df2 = spark.createDataFrame(data2, ["num", "expected_name"])
with pytest.raises(DataFramesNotEqualError) as e_info:
with pytest.raises(DataFramesNotEqualError):
assert_approx_df_equality(df1, df2, 0.1)

def it_does_not_throw_with_no_mismatch():
Expand Down
16 changes: 8 additions & 8 deletions tests/test_readme_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_remove_non_word_characters_nice_error():
"clean_name", remove_non_word_characters(F.col("name"))
)
# assert_column_equality(df, "clean_name", "expected_name")
with pytest.raises(ColumnsNotEqualError) as e_info:
with pytest.raises(ColumnsNotEqualError):
assert_column_equality(df, "clean_name", "expected_name")


Expand Down Expand Up @@ -78,7 +78,7 @@ def test_remove_non_word_characters_long_error():
]
expected_df = spark.createDataFrame(expected_data, ["name", "clean_name"])
# assert_df_equality(actual_df, expected_df)
with pytest.raises(DataFramesNotEqualError) as e_info:
with pytest.raises(DataFramesNotEqualError):
assert_df_equality(actual_df, expected_df)

def ignore_row_order():
Expand Down Expand Up @@ -141,7 +141,7 @@ def it_prints_underline_message():
("rick", 66),
]
df2 = spark.createDataFrame(data, ["firstname", "age"])
with pytest.raises(DataFramesNotEqualError) as e_info:
with pytest.raises(DataFramesNotEqualError):
assert_df_equality(df1, df2, underline_cells=True)

def it_shows_assert_basic_rows_equality(my_formats):
Expand All @@ -161,7 +161,7 @@ def it_shows_assert_basic_rows_equality(my_formats):
]
df2 = spark.createDataFrame(data, ["firstname", "age"])
# assert_basic_rows_equality(df1.collect(), df2.collect(), formats=my_formats)
with pytest.raises(DataFramesNotEqualError) as e_info:
with pytest.raises(DataFramesNotEqualError):
assert_basic_rows_equality(df1.collect(), df2.collect(), underline_cells=True)


Expand All @@ -174,7 +174,7 @@ def test_approx_col_equality_same():
def test_approx_col_equality_different():
data = [(1.1, 1.1), (2.2, 2.15), (3.3, 5.0), (None, None)]
df = spark.createDataFrame(data, ["num1", "num2"])
with pytest.raises(ColumnsNotEqualError) as e_info:
with pytest.raises(ColumnsNotEqualError):
assert_approx_column_equality(df, "num1", "num2", 0.1)

def test_approx_df_equality_same():
Expand All @@ -190,7 +190,7 @@ def test_approx_df_equality_different():
data2 = [(1.1, "a"), (5.0, "b"), (3.3, "z"), (None, None)]
df2 = spark.createDataFrame(data2, ["num", "letter"])
# assert_approx_df_equality(df1, df2, 0.1)
with pytest.raises(DataFramesNotEqualError) as e_info:
with pytest.raises(DataFramesNotEqualError):
assert_approx_df_equality(df1, df2, 0.1)


Expand All @@ -200,7 +200,7 @@ def test_schema_mismatch_message():
df1 = spark.createDataFrame(data1, ["num", "letter"])
data2 = [(1, 6), (2, 7), (3, 8), (None, None)]
df2 = spark.createDataFrame(data2, ["num", "num2"])
with pytest.raises(SchemasNotEqualError) as e_info:
with pytest.raises(SchemasNotEqualError):
assert_df_equality(df1, df2)


Expand All @@ -216,5 +216,5 @@ def test_remove_non_word_characters_long_error(my_chispa):
]
expected_df = spark.createDataFrame(expected_data, ["name", "clean_name"])
# my_chispa.assert_df_equality(actual_df, expected_df)
with pytest.raises(DataFramesNotEqualError) as e_info:
with pytest.raises(DataFramesNotEqualError):
assert_df_equality(actual_df, expected_df)
4 changes: 2 additions & 2 deletions tests/test_rows_comparer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ def it_throws_with_row_mismatches():
df1 = spark.createDataFrame(data1, ["num", "expected_name"])
data2 = [("bob", "jose"), ("li", "li"), ("luisa", "laura")]
df2 = spark.createDataFrame(data2, ["name", "expected_name"])
with pytest.raises(DataFramesNotEqualError) as e_info:
with pytest.raises(DataFramesNotEqualError):
assert_basic_rows_equality(df1.collect(), df2.collect())

def it_throws_when_rows_have_different_lengths():
data1 = [(1, "jose"), (2, "li"), (3, "laura"), (4, "bill")]
df1 = spark.createDataFrame(data1, ["num", "expected_name"])
data2 = [(1, "jose"), (2, "li"), (3, "laura")]
df2 = spark.createDataFrame(data2, ["name", "expected_name"])
with pytest.raises(DataFramesNotEqualError) as e_info:
with pytest.raises(DataFramesNotEqualError):
assert_basic_rows_equality(df1.collect(), df2.collect())

def it_works_when_rows_are_the_same():
Expand Down
6 changes: 3 additions & 3 deletions tests/test_schema_comparer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def it_throws_when_column_names_differ():
StructField("name", StringType(), True),
StructField("age", IntegerType(), True),
])
with pytest.raises(SchemasNotEqualError) as e_info:
with pytest.raises(SchemasNotEqualError):
assert_schema_equality(s1, s2)

def it_throws_when_schema_lengths_differ():
Expand All @@ -44,7 +44,7 @@ def it_throws_when_schema_lengths_differ():
StructField("age", IntegerType(), True),
StructField("fav_number", IntegerType(), True),
])
with pytest.raises(SchemasNotEqualError) as e_info:
with pytest.raises(SchemasNotEqualError):
assert_schema_equality(s1, s2)


Expand All @@ -60,7 +60,7 @@ def it_has_good_error_messages_for_different_sized_schemas():
StructField("something", IntegerType(), True),
StructField("else", IntegerType(), True),
])
with pytest.raises(SchemasNotEqualError) as e_info:
with pytest.raises(SchemasNotEqualError):
assert_schema_equality_ignore_nullable(s1, s2)

def it_does_nothing_when_equal():
Expand Down

0 comments on commit 0d2b5b6

Please sign in to comment.