Skip to content

Commit 602e56a

Browse files
committed
More ruff updates
1 parent 694851d commit 602e56a

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

python/tests/generic.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# under the License.
1717

1818
import datetime
19+
from datetime import timezone
1920

2021
import numpy as np
2122
import pyarrow as pa
@@ -26,29 +27,29 @@
2627

2728

2829
def data():
29-
np.random.seed(1)
30+
rng = np.random.default_rng(1)
3031
data = np.concatenate(
3132
[
32-
np.random.normal(0, 0.01, size=50),
33-
np.random.normal(50, 0.01, size=50),
33+
rng.normal(0, 0.01, size=50),
34+
rng.normal(50, 0.01, size=50),
3435
]
3536
)
3637
return pa.array(data)
3738

3839

3940
def data_with_nans():
40-
np.random.seed(0)
41-
data = np.random.normal(0, 0.01, size=50)
42-
mask = np.random.randint(0, 2, size=50)
41+
rng = np.random.default_rng(0)
42+
data = rng.normal(0, 0.01, size=50)
43+
mask = rng.normal(0, 2, size=50)
4344
data[mask == 0] = np.nan
4445
return data
4546

4647

4748
def data_datetime(f):
4849
data = [
49-
datetime.datetime.now(),
50-
datetime.datetime.now() - datetime.timedelta(days=1),
51-
datetime.datetime.now() + datetime.timedelta(days=1),
50+
datetime.datetime.now(tz=timezone.utc),
51+
datetime.datetime.now(tz=timezone.utc) - datetime.timedelta(days=1),
52+
datetime.datetime.now(tz=timezone.utc) + datetime.timedelta(days=1),
5253
]
5354
return pa.array(data, type=pa.timestamp(f), mask=np.array([False, True, False]))
5455

python/tests/test_aggregation.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def df_aggregate_100():
6666

6767

6868
@pytest.mark.parametrize(
69-
"agg_expr, calc_expected",
69+
("agg_expr", "calc_expected"),
7070
[
7171
(f.avg(column("a")), lambda a, b, c, d: np.array(np.average(a))),
7272
(
@@ -88,7 +88,7 @@ def df_aggregate_100():
8888
f.covar_samp(column("b"), column("c")),
8989
lambda a, b, c, d: np.array(np.cov(b, c, ddof=1)[0][1]),
9090
),
91-
# f.grouping(col_a), # No physical plan implemented yet
91+
# f.grouping(col_a), # No physical plan implemented yet # noqa: ERA001
9292
(f.max(column("a")), lambda a, b, c, d: np.array(np.max(a))),
9393
(f.mean(column("b")), lambda a, b, c, d: np.array(np.mean(b))),
9494
(f.median(column("b")), lambda a, b, c, d: np.array(np.median(b))),
@@ -114,7 +114,7 @@ def test_aggregation_stats(df, agg_expr, calc_expected):
114114

115115

116116
@pytest.mark.parametrize(
117-
"agg_expr, expected, array_sort",
117+
("agg_expr", "expected", "array_sort"),
118118
[
119119
(f.approx_distinct(column("b")), pa.array([2], type=pa.uint64()), False),
120120
(
@@ -182,12 +182,11 @@ def test_aggregation(df, agg_expr, expected, array_sort):
182182
agg_df.show()
183183
result = agg_df.collect()[0]
184184

185-
print(result)
186185
assert result.column(0) == expected
187186

188187

189188
@pytest.mark.parametrize(
190-
"name,expr,expected",
189+
("name", "expr", "expected"),
191190
[
192191
(
193192
"approx_percentile_cont",
@@ -313,7 +312,7 @@ def test_bit_and_bool_fns(df, name, expr, result):
313312

314313

315314
@pytest.mark.parametrize(
316-
"name,expr,result",
315+
("name", "expr", "result"),
317316
[
318317
("first_value", f.first_value(column("a")), [0, 4]),
319318
(
@@ -363,7 +362,6 @@ def test_bit_and_bool_fns(df, name, expr, result):
363362
),
364363
[8, 9],
365364
),
366-
("first_value", f.first_value(column("a")), [0, 4]),
367365
(
368366
"nth_value_ordered",
369367
f.nth_value(column("a"), 2, order_by=[column("a").sort(ascending=False)]),
@@ -403,7 +401,7 @@ def test_first_last_value(df_partitioned, name, expr, result) -> None:
403401

404402

405403
@pytest.mark.parametrize(
406-
"name,expr,result",
404+
("name", "expr", "result"),
407405
[
408406
("string_agg", f.string_agg(column("a"), ","), "one,two,three,two"),
409407
("string_agg", f.string_agg(column("b"), ""), "03124"),

python/tests/test_catalog.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,20 @@
1919
import pytest
2020

2121

22+
# Note we take in `database` as a variable even though we don't use
23+
# it because that will cause the fixture to set up the context with
24+
# the tables we need.
2225
def test_basic(ctx, database):
2326
with pytest.raises(KeyError):
2427
ctx.catalog("non-existent")
2528

2629
default = ctx.catalog()
2730
assert default.names() == ["public"]
2831

29-
for database in [default.database("public"), default.database()]:
30-
assert database.names() == {"csv1", "csv", "csv2"}
32+
for db in [default.database("public"), default.database()]:
33+
assert db.names() == {"csv1", "csv", "csv2"}
3134

32-
table = database.table("csv")
35+
table = db.table("csv")
3336
assert table.kind == "physical"
3437
assert table.schema == pa.schema(
3538
[

0 commit comments

Comments
 (0)