Skip to content

Commit

Permalink
Apply linter guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
tools4origins committed Sep 26, 2021
1 parent 6d60eb2 commit 507f4f7
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 16 deletions.
1 change: 1 addition & 0 deletions pysparkling/sql/column.py
Expand Up @@ -688,6 +688,7 @@ def data_type(self, schema):
try:
return schema[self.expr].dataType
except KeyError:
# pylint: disable=raise-missing-from
raise AnalysisException(
f"cannot resolve '`{self.expr}`' given input columns: {schema.fields};"
)
Expand Down
5 changes: 3 additions & 2 deletions pysparkling/sql/expressions/arrays.py
@@ -1,4 +1,5 @@
from ..types import BooleanType, ArrayType, NullType, MapType, IntegerType, StringType, StructType
from ..column import Column
from ..types import ArrayType, BooleanType, IntegerType, MapType, NullType, StringType, StructType
from ..utils import AnalysisException
from .expressions import BinaryOperation, Expression, UnaryExpression

Expand Down Expand Up @@ -337,7 +338,7 @@ def __init__(self, columns):

def eval(self, row, schema):
return [
{i: v for i, v in enumerate(combination)}
dict(enumerate(combination))
for combination in zip(
*(c.eval(row, schema) for c in self.columns)
)
Expand Down
4 changes: 3 additions & 1 deletion pysparkling/sql/expressions/dates.py
Expand Up @@ -5,7 +5,7 @@

from ...utils import parse_tz
from ..casts import get_time_formatter, get_unix_timestamp_parser
from ..types import DateType, FloatType, TimestampType, IntegerType, DoubleType, StringType, LongType
from ..types import DateType, DoubleType, FloatType, IntegerType, LongType, StringType, TimestampType
from .expressions import Expression, UnaryExpression
from .operators import Cast

Expand Down Expand Up @@ -35,6 +35,7 @@ def args(self):
def data_type(self, schema):
return DateType()


class DateAdd(Expression):
pretty_name = "date_add"

Expand All @@ -56,6 +57,7 @@ def args(self):
def data_type(self, schema):
return DateType()


class DateSub(Expression):
pretty_name = "date_sub"

Expand Down
2 changes: 1 addition & 1 deletion pysparkling/sql/expressions/explodes.py
@@ -1,4 +1,4 @@
from ..types import DataType, IntegerType, StructField, StructType
from ..types import IntegerType, StructField, StructType
from .expressions import UnaryExpression


Expand Down
2 changes: 1 addition & 1 deletion pysparkling/sql/expressions/jsons.py
@@ -1,9 +1,9 @@
import json

from ..types import StringType
from ...utils import get_json_encoder
from ..internal_utils.options import Options
from ..internal_utils.readers.jsonreader import JSONReader
from ..types import StringType
from .expressions import Expression


Expand Down
6 changes: 4 additions & 2 deletions pysparkling/sql/expressions/mappers.py
Expand Up @@ -6,8 +6,10 @@

from ...utils import half_even_round, half_up_round, MonotonicallyIncreasingIDGenerator, XORShiftRandom
from ..internal_utils.column import resolve_column
from ..types import create_row, StringType, NullType, BooleanType, DoubleType, LongType, IntegerType, ArrayType, \
StructType, StructField, MapType, BinaryType
from ..types import (
ArrayType, BinaryType, BooleanType, create_row, DoubleType, IntegerType, LongType, MapType, NullType, StringType,
StructField, StructType
)
from ..utils import AnalysisException
from .expressions import Expression, NullSafeColumnOperation, UnaryExpression
from .operators import Cast
Expand Down
2 changes: 1 addition & 1 deletion pysparkling/sql/expressions/operators.py
@@ -1,5 +1,5 @@
from ..casts import get_caster
from ..types import Row, StructType, DoubleType, BooleanType, StringType, largest_numeric_type
from ..types import BooleanType, DoubleType, largest_numeric_type, Row, StringType, StructType
from .expressions import BinaryOperation, Expression, NullSafeBinaryOperation, TypeSafeBinaryOperation, UnaryExpression


Expand Down
2 changes: 1 addition & 1 deletion pysparkling/sql/expressions/strings.py
@@ -1,7 +1,7 @@
import string

from ...utils import levenshtein_distance
from ..types import StringType, IntegerType
from ..types import IntegerType, StringType
from .expressions import Expression, UnaryExpression
from .operators import Cast

Expand Down
13 changes: 6 additions & 7 deletions pysparkling/sql/types.py
Expand Up @@ -26,7 +26,7 @@

from sqlparser.internalparser import SqlParsingError

from .utils import require_minimum_pandas_version, AnalysisException
from .utils import AnalysisException, require_minimum_pandas_version

__all__ = [
"DataType", "NullType", "StringType", "BinaryType", "BooleanType", "DateType",
Expand Down Expand Up @@ -1144,20 +1144,19 @@ def merge_decimal_types(p1, s1, p2, s2, operation):
if operation in ("add", "minus"):
result_scale = max(s1, s2)
return DecimalType.adjust_precision_scale(max(p1 - s1, p2 - s2) + result_scale + 1, result_scale)
elif operation == "multiply":
if operation == "multiply":
return DecimalType.adjust_precision_scale(p1 + p2 + 1, s1 + s2)
elif operation == "divide":
if operation == "divide":
result_scale = max(6, s1 + p2 + 1)
return DecimalType.adjust_precision_scale(p1 - s1 + s2 + result_scale, result_scale)
elif operation == "mod":
if operation == "mod":
result_scale = max(s1, s2)
return DecimalType.adjust_precision_scale(min(p1 - s1, p2 - s2) + result_scale, result_scale)
elif operation in ("bitwise_or", "bitwise_and", "bitwise_xor"):
if operation in ("bitwise_or", "bitwise_and", "bitwise_xor"):
if (p1, s1) != (p2, s2):
raise AnalysisException("data type mismatch: differing types")
return DecimalType.adjust_precision_scale(p1, s1)
else:
raise ValueError(f"Unknown operation {operation}")
raise ValueError(f"Unknown operation {operation}")


def _need_converter(dataType):
Expand Down

0 comments on commit 507f4f7

Please sign in to comment.