Skip to content

Commit

Permalink
Merge pull request #113 from IndexSeek/linting-maintenance
Browse files Browse the repository at this point in the history
lint: update ruff and pre-commit config
  • Loading branch information
SemyonSinchenko authored Aug 31, 2023
2 parents 5cb5ded + 49a1943 commit b6b4f70
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ __pycache__/
# PyVenv
.env
.venv
venv

# Linters cache
.mypy_cache
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yml → .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.265'
rev: 'v0.0.286'
hooks:
- id: ruff
- repo: local
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mkdocs = "^1.4.2"
# Allow lines to be as long as 150 characters.
line-length = 150
ignore = ["D100"]
required-version = "0.0.265"
required-version = "0.0.286"

[build-system]
requires = ["poetry>=0.12"]
Expand Down
3 changes: 0 additions & 3 deletions quinn/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
""""""
from .dataframe_helpers import *

Check failure on line 2 in quinn/__init__.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F403)

quinn/__init__.py:2:1: F403 `from .dataframe_helpers import *` used; unable to detect undefined names
from .dataframe_validator import *

Check failure on line 3 in quinn/__init__.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F403)

quinn/__init__.py:3:1: F403 `from .dataframe_validator import *` used; unable to detect undefined names
from .schema_helpers import print_schema_as_code
from .functions import *

Check failure on line 4 in quinn/__init__.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F403)

quinn/__init__.py:4:1: F403 `from .functions import *` used; unable to detect undefined names
from .scala_to_pyspark import ScalaToPyspark
from .transformations import *

Check failure on line 5 in quinn/__init__.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F403)

quinn/__init__.py:5:1: F403 `from .transformations import *` used; unable to detect undefined names
from .append_if_schema_identical import append_if_schema_identical
4 changes: 2 additions & 2 deletions quinn/extensions/column_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def isFalse(self: Column) -> Column:
:return: Column
:rtype: Column
"""
return self == False
return self is False


def isTrue(self: Column) -> Column:
Expand All @@ -51,7 +51,7 @@ def isTrue(self: Column) -> Column:
:returns: Column object
:rtype: Column
"""
return self == True
return self is True


def isNullOrBlank(self: Column) -> Column:
Expand Down
14 changes: 7 additions & 7 deletions quinn/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,20 @@ def _raise_if_invalid_day(day: str) -> None:
raise ValueError(message)


def approx_equal(col1: Column, col2: Column, threshhold: Number) -> Column:
def approx_equal(col1: Column, col2: Column, threshold: Number) -> Column:
"""Compares two ``Column`` objects by checking if the difference between them
is less than a specified ``threshhold``.
is less than a specified ``threshold``.
:param col1: the first ``Column``
:type col1: Column
:param col2: the second ``Column``
:type col2: Column
:param threshhold: value to compare with
:type threshhold: Number
:param threshold: value to compare with
:type threshold: Number
:return: Boolean ``Column`` with ``True`` indicating that ``abs(col1 -
col2)`` is less than ``threshhold``
col2)`` is less than ``threshold``
"""
return F.abs(col1 - col2) < threshhold
return F.abs(col1 - col2) < threshold


def array_choice(col: Column) -> Column:
Expand All @@ -227,7 +227,7 @@ def regexp_extract_all(s: str, regexp: str) -> Optional[List[re.Match]]:
:param regexp: string `re` pattern
:return: List of matches
"""
return None if s == None else re.findall(regexp, s)
return None if s is None else re.findall(regexp, s)


def uuid5(col: Column, namespace: uuid.UUID = uuid.NAMESPACE_DNS, extra_string: str = "") -> Column:
Expand Down
2 changes: 0 additions & 2 deletions tests/extensions/test_dataframe_ext.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from functools import partial

import chispa
from chispa.schema_comparer import assert_basic_schema_equality
from pyspark.sql.dataframe import DataFrame
from pyspark.sql.functions import col

from tests.conftest import auto_inject_fixtures
Expand Down
4 changes: 2 additions & 2 deletions tests/test_append_if_schema_identical.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@auto_inject_fixtures("spark")
def test_append_if_schema_identical(spark):
source_data = [(1, "capetown", "Alice"), (2, "delhi", "Bob")]
source_data = [(1, "cape town", "Alice"), (2, "delhi", "Bob")]
target_data = [(3, "Charlie", "New York"), (4, "Dave", "Los Angeles")]

source_df = spark.createDataFrame(source_data, schema=StructType([
Expand All @@ -21,4 +21,4 @@ def test_append_if_schema_identical(spark):
]))

# Call the append_if_schema_identical function
appended_df = quinn.append_if_schema_identical(source_df, target_df)
quinn.append_if_schema_identical(source_df, target_df)
1 change: 0 additions & 1 deletion tests/test_dataframe_helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pyspark.sql.types import IntegerType, StringType

import quinn
from tests.conftest import auto_inject_fixtures
Expand Down
3 changes: 1 addition & 2 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest

import re

import pyspark.sql.functions as F
from pyspark.sql.types import *
Expand Down Expand Up @@ -305,7 +304,7 @@ def test_array_choice(spark):
[(["a", "b", "c"],), (["a", "b", "c", "d"],), (["x"],), ([None],)],
[("letters", ArrayType(StringType(), True), True)],
)
actual_df = df.withColumn("random_letter", quinn.array_choice(F.col("letters")))
df.withColumn("random_letter", quinn.array_choice(F.col("letters")))
# actual_df.show()
# chispa.assert_column_equality(actual_df, "are_nums_approx_equal", "expected")

Expand Down
2 changes: 0 additions & 2 deletions tests/test_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from tests.conftest import auto_inject_fixtures
import chispa

from functools import reduce


@auto_inject_fixtures("spark")
def describe_with_columns_renamed():
Expand Down

0 comments on commit b6b4f70

Please sign in to comment.