Skip to content

Commit c64020d

Browse files
authored
Rewrite dict literal for files in ./pandas/tests/tools/ and ./pandas/tests/resample/ (#38203)
1 parent 44f0e32 commit c64020d

7 files changed

+63
-61
lines changed

pandas/tests/io/test_parquet.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ def test_s3_roundtrip_explicit_fs(self, df_compat, s3_resource, pa, s3so):
645645
if LooseVersion(pyarrow.__version__) <= LooseVersion("0.17.0"):
646646
pytest.skip()
647647
s3 = s3fs.S3FileSystem(**s3so)
648-
kw = dict(filesystem=s3)
648+
kw = {"filesystem": s3}
649649
check_round_trip(
650650
df_compat,
651651
pa,
@@ -658,7 +658,7 @@ def test_s3_roundtrip(self, df_compat, s3_resource, pa, s3so):
658658
if LooseVersion(pyarrow.__version__) <= LooseVersion("0.17.0"):
659659
pytest.skip()
660660
# GH #19134
661-
s3so = dict(storage_options=s3so)
661+
s3so = {"storage_options": s3so}
662662
check_round_trip(
663663
df_compat,
664664
pa,
@@ -710,10 +710,12 @@ def test_s3_roundtrip_for_dir(
710710
pa,
711711
expected=expected_df,
712712
path="s3://pandas-test/parquet_dir",
713-
read_kwargs=dict(storage_options=s3so),
714-
write_kwargs=dict(
715-
partition_cols=partition_col, compression=None, storage_options=s3so
716-
),
713+
read_kwargs={"storage_options": s3so},
714+
write_kwargs={
715+
"partition_cols": partition_col,
716+
"compression": None,
717+
"storage_options": s3so,
718+
},
717719
check_like=True,
718720
repeat=1,
719721
)
@@ -946,8 +948,8 @@ def test_s3_roundtrip(self, df_compat, s3_resource, fp, s3so):
946948
df_compat,
947949
fp,
948950
path="s3://pandas-test/fastparquet.parquet",
949-
read_kwargs=dict(storage_options=s3so),
950-
write_kwargs=dict(compression=None, storage_options=s3so),
951+
read_kwargs={"storage_options": s3so},
952+
write_kwargs={"compression": None, "storage_options": s3so},
951953
)
952954

953955
def test_partition_cols_supported(self, fp, df_full):

pandas/tests/resample/test_time_grouper.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ def test_aggregate_normal(resample_method):
158158
@pytest.mark.parametrize(
159159
"method, method_args, unit",
160160
[
161-
("sum", dict(), 0),
162-
("sum", dict(min_count=0), 0),
163-
("sum", dict(min_count=1), np.nan),
164-
("prod", dict(), 1),
165-
("prod", dict(min_count=0), 1),
166-
("prod", dict(min_count=1), np.nan),
161+
("sum", {}, 0),
162+
("sum", {"min_count": 0}, 0),
163+
("sum", {"min_count": 1}, np.nan),
164+
("prod", {}, 1),
165+
("prod", {"min_count": 0}, 1),
166+
("prod", {"min_count": 1}, np.nan),
167167
],
168168
)
169169
def test_resample_entirely_nat_window(method, method_args, unit):
@@ -267,14 +267,14 @@ def test_repr():
267267
@pytest.mark.parametrize(
268268
"method, method_args, expected_values",
269269
[
270-
("sum", dict(), [1, 0, 1]),
271-
("sum", dict(min_count=0), [1, 0, 1]),
272-
("sum", dict(min_count=1), [1, np.nan, 1]),
273-
("sum", dict(min_count=2), [np.nan, np.nan, np.nan]),
274-
("prod", dict(), [1, 1, 1]),
275-
("prod", dict(min_count=0), [1, 1, 1]),
276-
("prod", dict(min_count=1), [1, np.nan, 1]),
277-
("prod", dict(min_count=2), [np.nan, np.nan, np.nan]),
270+
("sum", {}, [1, 0, 1]),
271+
("sum", {"min_count": 0}, [1, 0, 1]),
272+
("sum", {"min_count": 1}, [1, np.nan, 1]),
273+
("sum", {"min_count": 2}, [np.nan, np.nan, np.nan]),
274+
("prod", {}, [1, 1, 1]),
275+
("prod", {"min_count": 0}, [1, 1, 1]),
276+
("prod", {"min_count": 1}, [1, np.nan, 1]),
277+
("prod", {"min_count": 2}, [np.nan, np.nan, np.nan]),
278278
],
279279
)
280280
def test_upsample_sum(method, method_args, expected_values):

pandas/tests/tools/test_to_numeric.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def transform_assert_equal(request):
4848
@pytest.mark.parametrize(
4949
"input_kwargs,result_kwargs",
5050
[
51-
(dict(), dict(dtype=np.int64)),
52-
(dict(errors="coerce", downcast="integer"), dict(dtype=np.int8)),
51+
({}, {"dtype": np.int64}),
52+
({"errors": "coerce", "downcast": "integer"}, {"dtype": np.int8}),
5353
],
5454
)
5555
def test_empty(input_kwargs, result_kwargs):
@@ -147,10 +147,10 @@ def test_list():
147147
@pytest.mark.parametrize(
148148
"data,arr_kwargs",
149149
[
150-
([1, 3, 4, 5], dict(dtype=np.int64)),
151-
([1.0, 3.0, 4.0, 5.0], dict()),
150+
([1, 3, 4, 5], {"dtype": np.int64}),
151+
([1.0, 3.0, 4.0, 5.0], {}),
152152
# Boolean is regarded as numeric.
153-
([True, False, True, True], dict()),
153+
([True, False, True, True], {}),
154154
],
155155
)
156156
def test_list_numeric(data, arr_kwargs):
@@ -159,7 +159,7 @@ def test_list_numeric(data, arr_kwargs):
159159
tm.assert_numpy_array_equal(result, expected)
160160

161161

162-
@pytest.mark.parametrize("kwargs", [dict(dtype="O"), dict()])
162+
@pytest.mark.parametrize("kwargs", [{"dtype": "O"}, {}])
163163
def test_numeric(kwargs):
164164
data = [1, -3.14, 7]
165165

@@ -182,13 +182,13 @@ def test_numeric(kwargs):
182182
def test_numeric_df_columns(columns):
183183
# see gh-14827
184184
df = DataFrame(
185-
dict(
186-
a=[1.2, decimal.Decimal(3.14), decimal.Decimal("infinity"), "0.1"],
187-
b=[1.0, 2.0, 3.0, 4.0],
188-
)
185+
{
186+
"a": [1.2, decimal.Decimal(3.14), decimal.Decimal("infinity"), "0.1"],
187+
"b": [1.0, 2.0, 3.0, 4.0],
188+
}
189189
)
190190

191-
expected = DataFrame(dict(a=[1.2, 3.14, np.inf, 0.1], b=[1.0, 2.0, 3.0, 4.0]))
191+
expected = DataFrame({"a": [1.2, 3.14, np.inf, 0.1], "b": [1.0, 2.0, 3.0, 4.0]})
192192

193193
df_copy = df.copy()
194194
df_copy[columns] = df_copy[columns].apply(to_numeric)
@@ -208,10 +208,10 @@ def test_numeric_df_columns(columns):
208208
)
209209
def test_numeric_embedded_arr_likes(data, exp_data):
210210
# Test to_numeric with embedded lists and arrays
211-
df = DataFrame(dict(a=data))
211+
df = DataFrame({"a": data})
212212
df["a"] = df["a"].apply(to_numeric)
213213

214-
expected = DataFrame(dict(a=exp_data))
214+
expected = DataFrame({"a": exp_data})
215215
tm.assert_frame_equal(df, expected)
216216

217217

@@ -226,7 +226,7 @@ def test_all_nan():
226226
def test_type_check(errors):
227227
# see gh-11776
228228
df = DataFrame({"a": [1, -3.14, 7], "b": ["4", "5", "6"]})
229-
kwargs = dict(errors=errors) if errors is not None else dict()
229+
kwargs = {"errors": errors} if errors is not None else {}
230230
error_ctx = pytest.raises(TypeError, match="1-d array")
231231

232232
with error_ctx:
@@ -241,7 +241,7 @@ def test_scalar(val, signed, transform):
241241

242242
def test_really_large_scalar(large_val, signed, transform, errors):
243243
# see gh-24910
244-
kwargs = dict(errors=errors) if errors is not None else dict()
244+
kwargs = {"errors": errors} if errors is not None else {}
245245
val = -large_val if signed else large_val
246246

247247
val = transform(val)
@@ -258,7 +258,7 @@ def test_really_large_scalar(large_val, signed, transform, errors):
258258

259259
def test_really_large_in_arr(large_val, signed, transform, multiple_elts, errors):
260260
# see gh-24910
261-
kwargs = dict(errors=errors) if errors is not None else dict()
261+
kwargs = {"errors": errors} if errors is not None else {}
262262
val = -large_val if signed else large_val
263263
val = transform(val)
264264

@@ -300,7 +300,7 @@ def test_really_large_in_arr_consistent(large_val, signed, multiple_elts, errors
300300
#
301301
# Even if we discover that we have to hold float, does not mean
302302
# we should be lenient on subsequent elements that fail to be integer.
303-
kwargs = dict(errors=errors) if errors is not None else dict()
303+
kwargs = {"errors": errors} if errors is not None else {}
304304
arr = [str(-large_val if signed else large_val)]
305305

306306
if multiple_elts:
@@ -452,12 +452,12 @@ def test_errors_invalid_value():
452452
"kwargs,exp_dtype",
453453
[
454454
# Basic function tests.
455-
(dict(), np.int64),
456-
(dict(downcast=None), np.int64),
455+
({}, np.int64),
456+
({"downcast": None}, np.int64),
457457
# Support below np.float32 is rare and far between.
458-
(dict(downcast="float"), np.dtype(np.float32).char),
458+
({"downcast": "float"}, np.dtype(np.float32).char),
459459
# Basic dtype support.
460-
(dict(downcast="unsigned"), np.dtype(np.typecodes["UnsignedInteger"][0])),
460+
({"downcast": "unsigned"}, np.dtype(np.typecodes["UnsignedInteger"][0])),
461461
],
462462
)
463463
def test_downcast_basic(data, kwargs, exp_dtype):

pandas/tests/util/test_assert_extension_array_equal.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
@pytest.mark.parametrize(
1010
"kwargs",
1111
[
12-
dict(), # Default is check_exact=False
13-
dict(check_exact=False),
14-
dict(check_exact=True),
12+
{}, # Default is check_exact=False
13+
{"check_exact": False},
14+
{"check_exact": True},
1515
],
1616
)
1717
def test_assert_extension_array_equal_not_exact(kwargs):
@@ -55,7 +55,7 @@ def test_assert_extension_array_equal_less_precise(decimals):
5555

5656
def test_assert_extension_array_equal_dtype_mismatch(check_dtype):
5757
end = 5
58-
kwargs = dict(check_dtype=check_dtype)
58+
kwargs = {"check_dtype": check_dtype}
5959

6060
arr1 = SparseArray(np.arange(end, dtype="int64"))
6161
arr2 = SparseArray(np.arange(end, dtype="int32"))

pandas/tests/util/test_assert_index_equal.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def test_index_equal_values_close(check_exact):
8585
def test_index_equal_values_less_close(check_exact, rtol):
8686
idx1 = Index([1, 2, 3.0])
8787
idx2 = Index([1, 2, 3.0001])
88-
kwargs = dict(check_exact=check_exact, rtol=rtol)
88+
kwargs = {"check_exact": check_exact, "rtol": rtol}
8989

9090
if check_exact or rtol < 0.5e-3:
9191
msg = """Index are different
@@ -103,7 +103,7 @@ def test_index_equal_values_less_close(check_exact, rtol):
103103
def test_index_equal_values_too_far(check_exact, rtol):
104104
idx1 = Index([1, 2, 3])
105105
idx2 = Index([1, 2, 4])
106-
kwargs = dict(check_exact=check_exact, rtol=rtol)
106+
kwargs = {"check_exact": check_exact, "rtol": rtol}
107107

108108
msg = """Index are different
109109
@@ -140,7 +140,7 @@ def test_index_equal_value_oder_mismatch(check_exact, rtol, check_order):
140140
def test_index_equal_level_values_mismatch(check_exact, rtol):
141141
idx1 = MultiIndex.from_tuples([("A", 2), ("A", 2), ("B", 3), ("B", 4)])
142142
idx2 = MultiIndex.from_tuples([("A", 1), ("A", 2), ("B", 3), ("B", 4)])
143-
kwargs = dict(check_exact=check_exact, rtol=rtol)
143+
kwargs = {"check_exact": check_exact, "rtol": rtol}
144144

145145
msg = """MultiIndex level \\[1\\] are different
146146

pandas/tests/util/test_assert_interval_array_equal.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
@pytest.mark.parametrize(
88
"kwargs",
99
[
10-
dict(start=0, periods=4),
11-
dict(start=1, periods=5),
12-
dict(start=5, end=10, closed="left"),
10+
{"start": 0, "periods": 4},
11+
{"start": 1, "periods": 5},
12+
{"start": 5, "end": 10, "closed": "left"},
1313
],
1414
)
1515
def test_interval_array_equal(kwargs):
@@ -18,7 +18,7 @@ def test_interval_array_equal(kwargs):
1818

1919

2020
def test_interval_array_equal_closed_mismatch():
21-
kwargs = dict(start=0, periods=5)
21+
kwargs = {"start": 0, "periods": 5}
2222
arr1 = interval_range(closed="left", **kwargs).values
2323
arr2 = interval_range(closed="right", **kwargs).values
2424

@@ -34,7 +34,7 @@ def test_interval_array_equal_closed_mismatch():
3434

3535

3636
def test_interval_array_equal_periods_mismatch():
37-
kwargs = dict(start=0)
37+
kwargs = {"start": 0}
3838
arr1 = interval_range(periods=5, **kwargs).values
3939
arr2 = interval_range(periods=6, **kwargs).values
4040

@@ -50,7 +50,7 @@ def test_interval_array_equal_periods_mismatch():
5050

5151

5252
def test_interval_array_equal_end_mismatch():
53-
kwargs = dict(start=0, periods=5)
53+
kwargs = {"start": 0, "periods": 5}
5454
arr1 = interval_range(end=10, **kwargs).values
5555
arr2 = interval_range(end=20, **kwargs).values
5656

@@ -66,7 +66,7 @@ def test_interval_array_equal_end_mismatch():
6666

6767

6868
def test_interval_array_equal_start_mismatch():
69-
kwargs = dict(periods=4)
69+
kwargs = {"periods": 4}
7070
arr1 = interval_range(start=0, **kwargs).values
7171
arr2 = interval_range(start=1, **kwargs).values
7272

pandas/tests/util/test_assert_series_equal.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ def test_series_not_equal_value_mismatch(data1, data2):
8787
@pytest.mark.parametrize(
8888
"kwargs",
8989
[
90-
dict(dtype="float64"), # dtype mismatch
91-
dict(index=[1, 2, 4]), # index mismatch
92-
dict(name="foo"), # name mismatch
90+
{"dtype": "float64"}, # dtype mismatch
91+
{"index": [1, 2, 4]}, # index mismatch
92+
{"name": "foo"}, # name mismatch
9393
],
9494
)
9595
def test_series_not_equal_metadata_mismatch(kwargs):
@@ -140,7 +140,7 @@ def test_less_precise(data1, data2, dtype, decimals):
140140
],
141141
)
142142
def test_series_equal_index_dtype(s1, s2, msg, check_index_type):
143-
kwargs = dict(check_index_type=check_index_type)
143+
kwargs = {"check_index_type": check_index_type}
144144

145145
if check_index_type:
146146
with pytest.raises(AssertionError, match=msg):

0 commit comments

Comments
 (0)