From 1ce8af0048ed0cae0304353346bba36da642e1d2 Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Sun, 4 Feb 2024 08:26:23 -0500 Subject: [PATCH] chore: address lints --- .../clickhouse/tests/test_operators.py | 2 +- ibis/backends/pandas/execution/temporal.py | 8 +++--- ibis/backends/postgres/datatypes.py | 2 +- ibis/backends/risingwave/datatypes.py | 2 +- ibis/backends/tests/test_map.py | 2 +- ibis/common/patterns.py | 2 +- ibis/common/tests/test_patterns.py | 26 +++++++++---------- ibis/common/typing.py | 2 +- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/ibis/backends/clickhouse/tests/test_operators.py b/ibis/backends/clickhouse/tests/test_operators.py index f4e27fbdc361f..4db313f76a93d 100644 --- a/ibis/backends/clickhouse/tests/test_operators.py +++ b/ibis/backends/clickhouse/tests/test_operators.py @@ -260,7 +260,7 @@ def test_array_index(con, arr, gen_idx): ) def test_array_concat(con, arrays): expr = L([]).cast("!array") - expected = sum(arrays, []) + expected = sum(arrays, []) # noqa: RUF017 for arr in arrays: expr += L(arr, type="!array") diff --git a/ibis/backends/pandas/execution/temporal.py b/ibis/backends/pandas/execution/temporal.py index a2f2b5d8b5ec8..c294c373211d9 100644 --- a/ibis/backends/pandas/execution/temporal.py +++ b/ibis/backends/pandas/execution/temporal.py @@ -130,7 +130,7 @@ def execute_timestamp_truncate(op, data, **kwargs): def execute_interval_from_integer_series(op, data, **kwargs): unit = op.unit.short resolution = op.unit.plural - cls = OFFSET_CLASS.get(unit, None) + cls = OFFSET_CLASS.get(unit) # fast path for timedelta conversion if cls is None: @@ -142,7 +142,7 @@ def execute_interval_from_integer_series(op, data, **kwargs): def execute_interval_from_integer_integer_types(op, data, **kwargs): unit = op.unit.short resolution = op.unit.plural - cls = OFFSET_CLASS.get(unit, None) + cls = OFFSET_CLASS.get(unit) if cls is None: return pd.Timedelta(data, unit=unit) @@ -154,7 +154,7 @@ def execute_cast_integer_to_interval_series(op, data, type, **kwargs): to = op.to unit = to.unit.short resolution = to.unit.plural - cls = OFFSET_CLASS.get(unit, None) + cls = OFFSET_CLASS.get(unit) if cls is None: return data.astype(f"timedelta64[{unit}]") @@ -166,7 +166,7 @@ def execute_cast_integer_to_interval_integer_types(op, data, type, **kwargs): to = op.to unit = to.unit.short resolution = to.unit.plural - cls = OFFSET_CLASS.get(unit, None) + cls = OFFSET_CLASS.get(unit) if cls is None: return pd.Timedelta(data, unit=unit) diff --git a/ibis/backends/postgres/datatypes.py b/ibis/backends/postgres/datatypes.py index 4a2bd2c1f71fc..095df636a0f6f 100644 --- a/ibis/backends/postgres/datatypes.py +++ b/ibis/backends/postgres/datatypes.py @@ -73,7 +73,7 @@ def to_ibis(cls, typ: sat.TypeEngine, nullable: bool = True) -> dt.DataType: return dt.Map(dt.string, dt.string, nullable=nullable) elif isinstance(typ, psql.INTERVAL): field = typ.fields.upper() - if (unit := _postgres_interval_fields.get(field, None)) is None: + if (unit := _postgres_interval_fields.get(field)) is None: raise ValueError(f"Unknown PostgreSQL interval field {field!r}") elif unit in {"Y", "M"}: raise ValueError( diff --git a/ibis/backends/risingwave/datatypes.py b/ibis/backends/risingwave/datatypes.py index 389210486a6f8..8ff106306f0b7 100644 --- a/ibis/backends/risingwave/datatypes.py +++ b/ibis/backends/risingwave/datatypes.py @@ -68,7 +68,7 @@ def to_ibis(cls, typ: sat.TypeEngine, nullable: bool = True) -> dt.DataType: return dt.Map(dt.string, dt.string, nullable=nullable) elif isinstance(typ, psql.INTERVAL): field = typ.fields.upper() - if (unit := _postgres_interval_fields.get(field, None)) is None: + if (unit := _postgres_interval_fields.get(field)) is None: raise ValueError(f"Unknown Risingwave interval field {field!r}") elif unit in {"Y", "M"}: raise ValueError( diff --git a/ibis/backends/tests/test_map.py b/ibis/backends/tests/test_map.py index 10cc901419d55..67eccf7918f86 100644 --- a/ibis/backends/tests/test_map.py +++ b/ibis/backends/tests/test_map.py @@ -225,7 +225,7 @@ def test_literal_map_getitem_broadcast(backend, alltypes, df): expr = lookup_table[alltypes.string_col] result = expr.name("tmp").execute() - expected = df.string_col.apply(lambda x: value.get(x, None)).rename("tmp") + expected = df.string_col.apply(value.get).rename("tmp") backend.assert_series_equal(result, expected) diff --git a/ibis/common/patterns.py b/ibis/common/patterns.py index 2e48c697d5f19..224e997a45751 100644 --- a/ibis/common/patterns.py +++ b/ibis/common/patterns.py @@ -1410,7 +1410,7 @@ def match(self, values, context): if result is NoMatch: return NoMatch else: - return sum(result, []) + return [el for lst in result for el in lst] def _maybe_unwrap_capture(obj): diff --git a/ibis/common/tests/test_patterns.py b/ibis/common/tests/test_patterns.py index aa770da9e79c4..29bfe0430efe6 100644 --- a/ibis/common/tests/test_patterns.py +++ b/ibis/common/tests/test_patterns.py @@ -263,10 +263,10 @@ def test_generic_instance_of_with_covariant_typevar(): assert p.match(My(1, 2, "3"), context={}) == My(1, 2, "3") assert p.describe() == "a My[int, Any]" - assert match(My[int, AnyType], v := My(1, 2, "3")) == v - assert match(My[int, int], v := My(1, 2, "3")) == v + assert match(My[int, AnyType], v := My(1, 2, "3")) == v # noqa: RUF018 + assert match(My[int, int], v := My(1, 2, "3")) == v # noqa: RUF018 assert match(My[int, float], My(1, 2, "3")) is NoMatch - assert match(My[int, float], v := My(1, 2.0, "3")) == v + assert match(My[int, float], v := My(1, 2.0, "3")) == v # noqa: RUF018 def test_generic_instance_of_disallow_nested_coercion(): @@ -777,12 +777,12 @@ def test_matching(): assert Capture("pi", InstanceOf(float)) == "pi" @ InstanceOf(float) assert Capture("pi", InstanceOf(float)) == "pi" @ InstanceOf(float) - assert match(Capture("pi", InstanceOf(float)), 3.14, ctx := {}) == 3.14 + assert match(Capture("pi", InstanceOf(float)), 3.14, ctx := {}) == 3.14 # noqa: RUF018 assert ctx == {"pi": 3.14} - assert match("pi" @ InstanceOf(float), 3.14, ctx := {}) == 3.14 + assert match("pi" @ InstanceOf(float), 3.14, ctx := {}) == 3.14 # noqa: RUF018 assert ctx == {"pi": 3.14} - assert match("pi" @ InstanceOf(float), 3.14, ctx := {}) == 3.14 + assert match("pi" @ InstanceOf(float), 3.14, ctx := {}) == 3.14 # noqa: RUF018 assert ctx == {"pi": 3.14} assert match(InstanceOf(int) | InstanceOf(float), 3) == 3 @@ -894,13 +894,13 @@ def test_matching_sequence_pattern_keeps_original_type(): def test_matching_sequence_with_captures(): v = list(range(1, 9)) assert match([1, 2, 3, 4, Some(...)], v) == v - assert match([1, 2, 3, 4, "rest" @ Some(...)], v, ctx := {}) == v + assert match([1, 2, 3, 4, "rest" @ Some(...)], v, ctx := {}) == v # noqa: RUF018 assert ctx == {"rest": [5, 6, 7, 8]} v = list(range(5)) - assert match([0, 1, x @ Some(...), 4], v, ctx := {}) == v + assert match([0, 1, x @ Some(...), 4], v, ctx := {}) == v # noqa: RUF018 assert ctx == {"x": [2, 3]} - assert match([0, 1, "var" @ Some(...), 4], v, ctx := {}) == v + assert match([0, 1, "var" @ Some(...), 4], v, ctx := {}) == v # noqa: RUF018 assert ctx == {"var": [2, 3]} p = [ @@ -911,7 +911,7 @@ def test_matching_sequence_with_captures(): 6, ] v = [0, 1, 2, 3, 4.0, 5.0, 6] - assert match(p, v, ctx := {}) == v + assert match(p, v, ctx := {}) == v # noqa: RUF018 assert ctx == {"ints": [2, 3], "last_float": 5.0} @@ -927,7 +927,7 @@ def test_matching_sequence_remaining(): assert match([1, 2, 3, Some(InstanceOf(int) & Between(0, 10))], five) == five assert match([1, 2, 3, Some(InstanceOf(int) & Between(0, 4))], five) is NoMatch assert match([1, 2, 3, Some(int, at_least=2)], four) is NoMatch - assert match([1, 2, 3, "res" @ Some(int, at_least=2)], five, ctx := {}) == five + assert match([1, 2, 3, "res" @ Some(int, at_least=2)], five, ctx := {}) == five # noqa: RUF018 assert ctx == {"res": [4, 5]} @@ -944,12 +944,12 @@ def test_matching_sequence_complicated(): "a": [2, 3], "b": [5, 6, 7], } - assert match(pat, range(1, 10), ctx := {}) == list(range(1, 10)) + assert match(pat, range(1, 10), ctx := {}) == list(range(1, 10)) # noqa: RUF018 assert ctx == expected pat = [1, 2, Capture("remaining", Some(...))] expected = {"remaining": [3, 4, 5, 6, 7, 8, 9]} - assert match(pat, range(1, 10), ctx := {}) == list(range(1, 10)) + assert match(pat, range(1, 10), ctx := {}) == list(range(1, 10)) # noqa: RUF018 assert ctx == expected v = [0, [1, 2, "3"], [1, 2, "4"], 3] diff --git a/ibis/common/typing.py b/ibis/common/typing.py index 170ca2bd2b403..7bcc7d62d6855 100644 --- a/ibis/common/typing.py +++ b/ibis/common/typing.py @@ -203,7 +203,7 @@ def evaluate_annotations( else: localns = dict(Self=f"{module_name}.{class_name}") return { - k: eval(v, globalns, localns) if isinstance(v, str) else v # noqa: PGH001 + k: eval(v, globalns, localns) if isinstance(v, str) else v for k, v in annots.items() }