Skip to content

Commit ce9cf8a

Browse files
authored
chore: use walrus operator more (#3447)
more walrus
1 parent fc3b029 commit ce9cf8a

File tree

5 files changed

+5
-10
lines changed

5 files changed

+5
-10
lines changed

narwhals/_arrow/namespace.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ def _concat_horizontal(self, dfs: Sequence[pa.Table], /) -> pa.Table:
184184
def _concat_vertical(self, dfs: Sequence[pa.Table], /) -> pa.Table:
185185
cols_0 = dfs[0].column_names
186186
for i, df in enumerate(dfs[1:], start=1):
187-
cols_current = df.column_names
188-
if cols_current != cols_0:
187+
if (cols_current := df.column_names) != cols_0:
189188
msg = (
190189
"unable to vstack, column names don't match:\n"
191190
f" - dataframe 0: {cols_0}\n"

narwhals/_duckdb/expr_dt.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ def _offset_by(expr: Expression) -> Expression:
103103
def _no_op_time_zone(self, time_zone: str) -> DuckDBExpr:
104104
def func(df: DuckDBLazyFrame) -> Sequence[Expression]:
105105
native_series_list = self.compliant(df)
106-
conn_time_zone = fetch_rel_time_zone(df.native)
107-
if conn_time_zone != time_zone:
106+
if (conn_time_zone := fetch_rel_time_zone(df.native)) != time_zone:
108107
msg = (
109108
"DuckDB stores the time zone in the connection, rather than in the "
110109
f"data type, so changing the timezone to anything other than {conn_time_zone} "

narwhals/_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,8 +1254,7 @@ def generate_temporary_column_name(
12541254
"""
12551255
counter = 0
12561256
while True:
1257-
token = f"{prefix}{token_hex(n_bytes - 1)}"
1258-
if token not in columns:
1257+
if (token := f"{prefix}{token_hex(n_bytes - 1)}") not in columns:
12591258
return token
12601259

12611260
counter += 1

narwhals/testing/asserts/frame.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,13 @@ def _check_schema_equal(
268268
)
269269

270270
if check_dtypes:
271-
ldtypes = lschema.dtypes()
272271
rdtypes = (
273272
rschema.dtypes()
274273
if check_column_order
275274
else [rschema[col_name] for col_name in lnames]
276275
)
277276

278-
if ldtypes != rdtypes:
277+
if (ldtypes := lschema.dtypes()) != rdtypes:
279278
raise_frame_assertion_error(
280279
detail="dtypes do not match", left=ldtypes, right=rdtypes
281280
)

narwhals/translate.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,7 @@ def _from_native_impl( # noqa: C901, PLR0911, PLR0912, PLR0915
449449
return native_object
450450
return Version.V1.dataframe(InterchangeFrame(native_object), level="interchange")
451451

452-
compliant_object = plugins.from_native(native_object, version)
453-
if compliant_object is not None:
452+
if (compliant_object := plugins.from_native(native_object, version)) is not None:
454453
return _translate_if_compliant(
455454
compliant_object,
456455
pass_through=pass_through,

0 commit comments

Comments
 (0)