Skip to content

Commit 6b5357a

Browse files
authored
CLN: fix C408 #38138 (#38385)
Co-authored-by: VirosaLi <2EkF8qUgpNkj>
1 parent 3aa8447 commit 6b5357a

File tree

2 files changed

+45
-44
lines changed

2 files changed

+45
-44
lines changed

pandas/tests/io/parser/test_common.py

+45-43
Original file line numberDiff line numberDiff line change
@@ -378,25 +378,25 @@ def test_read_duplicate_index_implicit(all_parsers):
378378
[
379379
(
380380
"A,B\nTrue,1\nFalse,2\nTrue,3",
381-
dict(),
381+
{},
382382
DataFrame([[True, 1], [False, 2], [True, 3]], columns=["A", "B"]),
383383
),
384384
(
385385
"A,B\nYES,1\nno,2\nyes,3\nNo,3\nYes,3",
386-
dict(true_values=["yes", "Yes", "YES"], false_values=["no", "NO", "No"]),
386+
{"true_values": ["yes", "Yes", "YES"], "false_values": ["no", "NO", "No"]},
387387
DataFrame(
388388
[[True, 1], [False, 2], [True, 3], [False, 3], [True, 3]],
389389
columns=["A", "B"],
390390
),
391391
),
392392
(
393393
"A,B\nTRUE,1\nFALSE,2\nTRUE,3",
394-
dict(),
394+
{},
395395
DataFrame([[True, 1], [False, 2], [True, 3]], columns=["A", "B"]),
396396
),
397397
(
398398
"A,B\nfoo,bar\nbar,foo",
399-
dict(true_values=["foo"], false_values=["bar"]),
399+
{"true_values": ["foo"], "false_values": ["bar"]},
400400
DataFrame([[True, False], [False, True]], columns=["A", "B"]),
401401
),
402402
],
@@ -520,7 +520,7 @@ def test_read_chunksize_and_nrows(all_parsers, chunksize):
520520
bar2,12,13,14,15
521521
"""
522522
parser = all_parsers
523-
kwargs = dict(index_col=0, nrows=5)
523+
kwargs = {"index_col": 0, "nrows": 5}
524524

525525
expected = parser.read_csv(StringIO(data), **kwargs)
526526
with parser.read_csv(StringIO(data), chunksize=chunksize, **kwargs) as reader:
@@ -537,7 +537,7 @@ def test_read_chunksize_and_nrows_changing_size(all_parsers):
537537
bar2,12,13,14,15
538538
"""
539539
parser = all_parsers
540-
kwargs = dict(index_col=0, nrows=5)
540+
kwargs = {"index_col": 0, "nrows": 5}
541541

542542
expected = parser.read_csv(StringIO(data), **kwargs)
543543
with parser.read_csv(StringIO(data), chunksize=8, **kwargs) as reader:
@@ -563,7 +563,7 @@ def test_get_chunk_passed_chunksize(all_parsers):
563563
tm.assert_frame_equal(result, expected)
564564

565565

566-
@pytest.mark.parametrize("kwargs", [dict(), dict(index_col=0)])
566+
@pytest.mark.parametrize("kwargs", [{}, {"index_col": 0}])
567567
def test_read_chunksize_compat(all_parsers, kwargs):
568568
# see gh-12185
569569
data = """index,A,B,C,D
@@ -593,7 +593,7 @@ def test_read_chunksize_jagged_names(all_parsers):
593593

594594
def test_read_data_list(all_parsers):
595595
parser = all_parsers
596-
kwargs = dict(index_col=0)
596+
kwargs = {"index_col": 0}
597597
data = "A,B,C\nfoo,1,2,3\nbar,4,5,6"
598598

599599
data_list = [["A", "B", "C"], ["foo", "1", "2", "3"], ["bar", "4", "5", "6"]]
@@ -616,7 +616,7 @@ def test_iterator(all_parsers):
616616
bar2,12,13,14,15
617617
"""
618618
parser = all_parsers
619-
kwargs = dict(index_col=0)
619+
kwargs = {"index_col": 0}
620620

621621
expected = parser.read_csv(StringIO(data), **kwargs)
622622
with parser.read_csv(StringIO(data), iterator=True, **kwargs) as reader:
@@ -657,7 +657,7 @@ def test_reader_list(all_parsers):
657657
bar2,12,13,14,15
658658
"""
659659
parser = all_parsers
660-
kwargs = dict(index_col=0)
660+
kwargs = {"index_col": 0}
661661

662662
lines = list(csv.reader(StringIO(data)))
663663
with TextParser(lines, chunksize=2, **kwargs) as reader:
@@ -680,7 +680,7 @@ def test_reader_list_skiprows(all_parsers):
680680
bar2,12,13,14,15
681681
"""
682682
parser = all_parsers
683-
kwargs = dict(index_col=0)
683+
kwargs = {"index_col": 0}
684684

685685
lines = list(csv.reader(StringIO(data)))
686686
with TextParser(lines, chunksize=2, skiprows=[1], **kwargs) as reader:
@@ -713,7 +713,7 @@ def test_iterator_stop_on_chunksize(all_parsers):
713713

714714

715715
@pytest.mark.parametrize(
716-
"kwargs", [dict(iterator=True, chunksize=1), dict(iterator=True), dict(chunksize=1)]
716+
"kwargs", [{"iterator": True, "chunksize": 1}, {"iterator": True}, {"chunksize": 1}]
717717
)
718718
def test_iterator_skipfooter_errors(all_parsers, kwargs):
719719
msg = "'skipfooter' not supported for iteration"
@@ -745,7 +745,7 @@ def test_nrows_skipfooter_errors(all_parsers):
745745
foo2,12,13,14,15
746746
bar2,12,13,14,15
747747
""",
748-
dict(index_col=0, names=["index", "A", "B", "C", "D"]),
748+
{"index_col": 0, "names": ["index", "A", "B", "C", "D"]},
749749
DataFrame(
750750
[
751751
[2, 3, 4, 5],
@@ -766,7 +766,7 @@ def test_nrows_skipfooter_errors(all_parsers):
766766
bar,one,12,13,14,15
767767
bar,two,12,13,14,15
768768
""",
769-
dict(index_col=[0, 1], names=["index1", "index2", "A", "B", "C", "D"]),
769+
{"index_col": [0, 1], "names": ["index1", "index2", "A", "B", "C", "D"]},
770770
DataFrame(
771771
[
772772
[2, 3, 4, 5],
@@ -906,7 +906,7 @@ def test_read_csv_parse_simple_list(all_parsers):
906906
def test_url(all_parsers, csv_dir_path):
907907
# TODO: FTP testing
908908
parser = all_parsers
909-
kwargs = dict(sep="\t")
909+
kwargs = {"sep": "\t"}
910910

911911
url = (
912912
"https://raw.github.com/pandas-dev/pandas/master/"
@@ -922,7 +922,7 @@ def test_url(all_parsers, csv_dir_path):
922922
@pytest.mark.slow
923923
def test_local_file(all_parsers, csv_dir_path):
924924
parser = all_parsers
925-
kwargs = dict(sep="\t")
925+
kwargs = {"sep": "\t"}
926926

927927
local_path = os.path.join(csv_dir_path, "salaries.csv")
928928
local_result = parser.read_csv(local_path, **kwargs)
@@ -1374,77 +1374,77 @@ def test_empty_with_nrows_chunksize(all_parsers, iterator):
13741374
# gh-10728: WHITESPACE_LINE
13751375
(
13761376
"a,b,c\n4,5,6\n ",
1377-
dict(),
1377+
{},
13781378
DataFrame([[4, 5, 6]], columns=["a", "b", "c"]),
13791379
None,
13801380
),
13811381
# gh-10548: EAT_LINE_COMMENT
13821382
(
13831383
"a,b,c\n4,5,6\n#comment",
1384-
dict(comment="#"),
1384+
{"comment": "#"},
13851385
DataFrame([[4, 5, 6]], columns=["a", "b", "c"]),
13861386
None,
13871387
),
13881388
# EAT_CRNL_NOP
13891389
(
13901390
"a,b,c\n4,5,6\n\r",
1391-
dict(),
1391+
{},
13921392
DataFrame([[4, 5, 6]], columns=["a", "b", "c"]),
13931393
None,
13941394
),
13951395
# EAT_COMMENT
13961396
(
13971397
"a,b,c\n4,5,6#comment",
1398-
dict(comment="#"),
1398+
{"comment": "#"},
13991399
DataFrame([[4, 5, 6]], columns=["a", "b", "c"]),
14001400
None,
14011401
),
14021402
# SKIP_LINE
14031403
(
14041404
"a,b,c\n4,5,6\nskipme",
1405-
dict(skiprows=[2]),
1405+
{"skiprows": [2]},
14061406
DataFrame([[4, 5, 6]], columns=["a", "b", "c"]),
14071407
None,
14081408
),
14091409
# EAT_LINE_COMMENT
14101410
(
14111411
"a,b,c\n4,5,6\n#comment",
1412-
dict(comment="#", skip_blank_lines=False),
1412+
{"comment": "#", "skip_blank_lines": False},
14131413
DataFrame([[4, 5, 6]], columns=["a", "b", "c"]),
14141414
None,
14151415
),
14161416
# IN_FIELD
14171417
(
14181418
"a,b,c\n4,5,6\n ",
1419-
dict(skip_blank_lines=False),
1419+
{"skip_blank_lines": False},
14201420
DataFrame([["4", 5, 6], [" ", None, None]], columns=["a", "b", "c"]),
14211421
None,
14221422
),
14231423
# EAT_CRNL
14241424
(
14251425
"a,b,c\n4,5,6\n\r",
1426-
dict(skip_blank_lines=False),
1426+
{"skip_blank_lines": False},
14271427
DataFrame([[4, 5, 6], [None, None, None]], columns=["a", "b", "c"]),
14281428
None,
14291429
),
14301430
# ESCAPED_CHAR
14311431
(
14321432
"a,b,c\n4,5,6\n\\",
1433-
dict(escapechar="\\"),
1433+
{"escapechar": "\\"},
14341434
None,
14351435
"(EOF following escape character)|(unexpected end of data)",
14361436
),
14371437
# ESCAPE_IN_QUOTED_FIELD
14381438
(
14391439
'a,b,c\n4,5,6\n"\\',
1440-
dict(escapechar="\\"),
1440+
{"escapechar": "\\"},
14411441
None,
14421442
"(EOF inside string starting at row 2)|(unexpected end of data)",
14431443
),
14441444
# IN_QUOTED_FIELD
14451445
(
14461446
'a,b,c\n4,5,6\n"',
1447-
dict(escapechar="\\"),
1447+
{"escapechar": "\\"},
14481448
None,
14491449
"(EOF inside string starting at row 2)|(unexpected end of data)",
14501450
),
@@ -1502,16 +1502,16 @@ def test_uneven_lines_with_usecols(all_parsers, usecols):
15021502
[
15031503
# First, check to see that the response of parser when faced with no
15041504
# provided columns raises the correct error, with or without usecols.
1505-
("", dict(), None),
1506-
("", dict(usecols=["X"]), None),
1505+
("", {}, None),
1506+
("", {"usecols": ["X"]}, None),
15071507
(
15081508
",,",
1509-
dict(names=["Dummy", "X", "Dummy_2"], usecols=["X"]),
1509+
{"names": ["Dummy", "X", "Dummy_2"], "usecols": ["X"]},
15101510
DataFrame(columns=["X"], index=[0], dtype=np.float64),
15111511
),
15121512
(
15131513
"",
1514-
dict(names=["Dummy", "X", "Dummy_2"], usecols=["X"]),
1514+
{"names": ["Dummy", "X", "Dummy_2"], "usecols": ["X"]},
15151515
DataFrame(columns=["X"]),
15161516
),
15171517
],
@@ -1535,19 +1535,21 @@ def test_read_empty_with_usecols(all_parsers, data, kwargs, expected):
15351535
# gh-8661, gh-8679: this should ignore six lines, including
15361536
# lines with trailing whitespace and blank lines.
15371537
(
1538-
dict(
1539-
header=None,
1540-
delim_whitespace=True,
1541-
skiprows=[0, 1, 2, 3, 5, 6],
1542-
skip_blank_lines=True,
1543-
),
1538+
{
1539+
"header": None,
1540+
"delim_whitespace": True,
1541+
"skiprows": [0, 1, 2, 3, 5, 6],
1542+
"skip_blank_lines": True,
1543+
},
15441544
DataFrame([[1.0, 2.0, 4.0], [5.1, np.nan, 10.0]]),
15451545
),
15461546
# gh-8983: test skipping set of rows after a row with trailing spaces.
15471547
(
1548-
dict(
1549-
delim_whitespace=True, skiprows=[1, 2, 3, 5, 6], skip_blank_lines=True
1550-
),
1548+
{
1549+
"delim_whitespace": True,
1550+
"skiprows": [1, 2, 3, 5, 6],
1551+
"skip_blank_lines": True,
1552+
},
15511553
DataFrame({"A": [1.0, 5.1], "B": [2.0, np.nan], "C": [4.0, 10]}),
15521554
),
15531555
],
@@ -1717,7 +1719,7 @@ def test_verbose_read2(all_parsers, capsys):
17171719

17181720
def test_iteration_open_handle(all_parsers):
17191721
parser = all_parsers
1720-
kwargs = dict(squeeze=True, header=None)
1722+
kwargs = {"squeeze": True, "header": None}
17211723

17221724
with tm.ensure_clean() as path:
17231725
with open(path, "w") as f:
@@ -1985,10 +1987,10 @@ def seek(self, pos, whence=0):
19851987

19861988
@pytest.mark.parametrize(
19871989
"kwargs",
1988-
[dict(), dict(error_bad_lines=True)], # Default is True. # Explicitly pass in.
1990+
[{}, {"error_bad_lines": True}], # Default is True. # Explicitly pass in.
19891991
)
19901992
@pytest.mark.parametrize(
1991-
"warn_kwargs", [dict(), dict(warn_bad_lines=True), dict(warn_bad_lines=False)]
1993+
"warn_kwargs", [{}, {"warn_bad_lines": True}, {"warn_bad_lines": False}]
19921994
)
19931995
def test_error_bad_lines(all_parsers, kwargs, warn_kwargs):
19941996
# see gh-15925

setup.cfg

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ ignore =
2222
W504, # line break after binary operator
2323
E402, # module level import not at top of file
2424
E731, # do not assign a lambda expression, use a def
25-
C408, # Unnecessary dict call - rewrite as a literal.
2625
S001 # found modulo formatter (incorrect picks up mod operations)
2726
exclude =
2827
doc/sphinxext/*.py,

0 commit comments

Comments
 (0)