Skip to content

Commit 7f3104b

Browse files
committed
Ruff SIM: fixed all remaining simplify linting issues
1 parent 13d2e08 commit 7f3104b

26 files changed

Lines changed: 48 additions & 106 deletions

duckdb/experimental/spark/sql/column.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,7 @@ def otherwise(self, value: Union["Column", str]) -> "Column": # noqa: D102
223223
return Column(expr)
224224

225225
def cast(self, dataType: Union[DataType, str]) -> "Column": # noqa: D102
226-
if isinstance(dataType, str):
227-
# Try to construct a default DuckDBPyType from it
228-
internal_type = DuckDBPyType(dataType)
229-
else:
230-
internal_type = dataType.duckdb_type
226+
internal_type = DuckDBPyType(dataType) if isinstance(dataType, str) else dataType.duckdb_type
231227
return Column(self.expr.cast(internal_type))
232228

233229
def isin(self, *cols: Union[Iterable[Union["Column", str]], Union["Column", str]]) -> "Column": # noqa: D102

duckdb/experimental/spark/sql/dataframe.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -972,10 +972,7 @@ def groupBy(self, *cols: "ColumnOrName") -> "GroupedData": # type: ignore[misc]
972972
""" # noqa: D205
973973
from .group import GroupedData, Grouping
974974

975-
if len(cols) == 1 and isinstance(cols[0], list):
976-
columns = cols[0]
977-
else:
978-
columns = cols
975+
columns = cols[0] if len(cols) == 1 and isinstance(cols[0], list) else cols
979976
return GroupedData(Grouping(*columns), self)
980977

981978
groupby = groupBy

duckdb/experimental/spark/sql/functions.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -742,10 +742,7 @@ def like(str: "ColumnOrName", pattern: "ColumnOrName", escapeChar: Optional["Col
742742
>>> df.select(like(df.a, df.b, lit("/")).alias("r")).collect()
743743
[Row(r=True)]
744744
""" # noqa: D205
745-
if escapeChar is None:
746-
escapeChar = ConstantExpression("\\")
747-
else:
748-
escapeChar = _to_column_expr(escapeChar)
745+
escapeChar = ConstantExpression("\\") if escapeChar is None else _to_column_expr(escapeChar)
749746
return _invoke_function("like_escape", _to_column_expr(str), _to_column_expr(pattern), escapeChar)
750747

751748

@@ -779,10 +776,7 @@ def ilike(str: "ColumnOrName", pattern: "ColumnOrName", escapeChar: Optional["Co
779776
>>> df.select(ilike(df.a, df.b, lit("/")).alias("r")).collect()
780777
[Row(r=True)]
781778
""" # noqa: D205
782-
if escapeChar is None:
783-
escapeChar = ConstantExpression("\\")
784-
else:
785-
escapeChar = _to_column_expr(escapeChar)
779+
escapeChar = ConstantExpression("\\") if escapeChar is None else _to_column_expr(escapeChar)
786780
return _invoke_function("ilike_escape", _to_column_expr(str), _to_column_expr(pattern), escapeChar)
787781

788782

duckdb/experimental/spark/sql/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ def __init__(self, startField: Optional[int] = None, endField: Optional[int] = N
531531
endField = startField
532532

533533
fields = DayTimeIntervalType._fields
534-
if startField not in fields.keys() or endField not in fields.keys():
534+
if startField not in fields or endField not in fields:
535535
raise RuntimeError(f"interval {startField} to {endField} is invalid")
536536
self.startField = cast("int", startField)
537537
self.endField = cast("int", endField)

duckdb/query_graph/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def get_phases(self) -> list[NodeTiming]: # noqa: D102
116116

117117
def get_sum_of_all_timings(self) -> float: # noqa: D102
118118
total_timing_sum = 0
119-
for phase in self.phase_to_timings.keys():
119+
for phase in self.phase_to_timings:
120120
total_timing_sum += self.get_summary_phase_timings(phase).time
121121
return total_timing_sum
122122

scripts/generate_connection_methods.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ def is_py_args(method):
2323
args = method["args"]
2424
if len(args) == 0:
2525
return False
26-
if args[0]["name"] != "*args":
27-
return False
28-
return True
26+
return args[0]["name"] == "*args"
2927

3028

3129
def generate():
@@ -110,10 +108,7 @@ def create_definition(name, method) -> str:
110108

111109
body = []
112110
for method in connection_methods:
113-
if isinstance(method["name"], list):
114-
names = method["name"]
115-
else:
116-
names = [method["name"]]
111+
names = method["name"] if isinstance(method["name"], list) else [method["name"]]
117112
for name in names:
118113
body.append(create_definition(name, method))
119114

scripts/generate_connection_stubs.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ def create_overloaded_definition(name, method) -> str:
7575
overloaded_methods: set[str] = {m for m in connection_methods if isinstance(m["name"], list)}
7676

7777
for method in connection_methods:
78-
if isinstance(method["name"], list):
79-
names = method["name"]
80-
else:
81-
names = [method["name"]]
78+
names = method["name"] if isinstance(method["name"], list) else [method["name"]]
8279
for name in names:
8380
if name in overloaded_methods:
8481
body.append(create_overloaded_definition(name, method))

scripts/generate_connection_wrapper_methods.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ def is_py_args(method):
6060
args = method["args"]
6161
if len(args) == 0:
6262
return False
63-
if args[0]["name"] != "*args":
64-
return False
65-
return True
63+
return args[0]["name"] == "*args"
6664

6765

6866
def is_py_kwargs(method):
@@ -196,10 +194,7 @@ def create_definition(name, method, lambda_def) -> str:
196194
body = []
197195
all_names = []
198196
for method in connection_methods:
199-
if isinstance(method["name"], list):
200-
names = method["name"]
201-
else:
202-
names = [method["name"]]
197+
names = method["name"] if isinstance(method["name"], list) else [method["name"]]
203198
if "kwargs" not in method:
204199
method["kwargs"] = []
205200
method["kwargs"].append({"name": "connection", "type": "Optional[DuckDBPyConnection]", "default": "None"})
@@ -211,10 +206,7 @@ def create_definition(name, method, lambda_def) -> str:
211206
all_names.append(name)
212207

213208
for method in wrapper_methods:
214-
if isinstance(method["name"], list):
215-
names = method["name"]
216-
else:
217-
names = [method["name"]]
209+
names = method["name"] if isinstance(method["name"], list) else [method["name"]]
218210
if "kwargs" not in method:
219211
method["kwargs"] = []
220212
method["kwargs"].append({"name": "connection", "type": "Optional[DuckDBPyConnection]", "default": "None"})

scripts/generate_connection_wrapper_stubs.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,7 @@ def create_overloaded_definition(name, method) -> str:
9191

9292
body = []
9393
for method in methods:
94-
if isinstance(method["name"], list):
95-
names = method["name"]
96-
else:
97-
names = [method["name"]]
94+
names = method["name"] if isinstance(method["name"], list) else [method["name"]]
9895

9996
# Artificially add 'connection' keyword argument
10097
if "kwargs" not in method:

scripts/generate_import_cache_cpp.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ def get_variables(self):
7070
item = self.items[key]
7171
name = item["name"]
7272
var_name = get_variable_name(name)
73-
if item["children"] == []:
74-
class_name = "PythonImportCacheItem"
75-
else:
76-
class_name = get_class_name(item["full_path"])
73+
class_name = "PythonImportCacheItem" if item["children"] == [] else get_class_name(item["full_path"])
7774
variables.append(f"\t{class_name} {var_name};")
7875
return "\n".join(variables)
7976

@@ -87,10 +84,7 @@ def get_initializer(self):
8784
initialization = f'{var_name}("{name}", this)'
8885
variables.append(initialization)
8986
else:
90-
if item["type"] == "module":
91-
arguments = ""
92-
else:
93-
arguments = "this"
87+
arguments = "" if item["type"] == "module" else "this"
9488
initialization = f"{var_name}({arguments})"
9589
variables.append(initialization)
9690
if self.module["type"] != "module":

0 commit comments

Comments
 (0)