Skip to content

Commit

Permalink
last dict fixings
Browse files Browse the repository at this point in the history
  • Loading branch information
UrielMaD committed Dec 9, 2020
1 parent 6adf501 commit 492f01f
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 65 deletions.
68 changes: 34 additions & 34 deletions pandas/tests/io/parser/test_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,19 @@ def test_header_multi_index(all_parsers):
"kwargs,msg",
[
(
dict(index_col=["foo", "bar"]),
{"index_col": ["foo", "bar"]},
(
"index_col must only contain "
"row numbers when specifying "
"a multi-index header"
),
),
(
dict(index_col=[0, 1], names=["foo", "bar"]),
{"index_col": [0, 1], "names": ["foo", "bar"]},
("cannot specify names when specifying a multi-index header"),
),
(
dict(index_col=[0, 1], usecols=["foo", "bar"]),
{"index_col": [0, 1], "usecols": ["foo", "bar"]},
("cannot specify usecols when specifying a multi-index header"),
),
],
Expand Down Expand Up @@ -187,29 +187,29 @@ def test_header_multi_index_invalid(all_parsers, kwargs, msg):
@pytest.mark.parametrize(
"kwargs",
[
dict(header=[0, 1]),
dict(
skiprows=3,
names=[
{"header": [0, 1]},
{
"skiprows": 3,
"names": [
("a", "q"),
("a", "r"),
("a", "s"),
("b", "t"),
("c", "u"),
("c", "v"),
],
),
dict(
skiprows=3,
names=[
},
{
"skiprows": 3,
"names": [
_TestTuple("a", "q"),
_TestTuple("a", "r"),
_TestTuple("a", "s"),
_TestTuple("b", "t"),
_TestTuple("c", "u"),
_TestTuple("c", "v"),
],
),
},
],
)
def test_header_multi_index_common_format1(all_parsers, kwargs):
Expand All @@ -234,29 +234,29 @@ def test_header_multi_index_common_format1(all_parsers, kwargs):
@pytest.mark.parametrize(
"kwargs",
[
dict(header=[0, 1]),
dict(
skiprows=2,
names=[
{"header": [0, 1]},
{
"skiprows": 2,
"names": [
("a", "q"),
("a", "r"),
("a", "s"),
("b", "t"),
("c", "u"),
("c", "v"),
],
),
dict(
skiprows=2,
names=[
},
{
"skiprows": 2,
"names": [
_TestTuple("a", "q"),
_TestTuple("a", "r"),
_TestTuple("a", "s"),
_TestTuple("b", "t"),
_TestTuple("c", "u"),
_TestTuple("c", "v"),
],
),
},
],
)
def test_header_multi_index_common_format2(all_parsers, kwargs):
Expand All @@ -280,29 +280,29 @@ def test_header_multi_index_common_format2(all_parsers, kwargs):
@pytest.mark.parametrize(
"kwargs",
[
dict(header=[0, 1]),
dict(
skiprows=2,
names=[
{"header": [0, 1]},
{
"skiprows": 2,
"names": [
("a", "q"),
("a", "r"),
("a", "s"),
("b", "t"),
("c", "u"),
("c", "v"),
],
),
dict(
skiprows=2,
names=[
},
{
"skiprows": 2,
"names": [
_TestTuple("a", "q"),
_TestTuple("a", "r"),
_TestTuple("a", "s"),
_TestTuple("b", "t"),
_TestTuple("c", "u"),
_TestTuple("c", "v"),
],
),
},
],
)
def test_header_multi_index_common_format3(all_parsers, kwargs):
Expand Down Expand Up @@ -397,7 +397,7 @@ def test_header_names_backward_compat(all_parsers, data, header):
tm.assert_frame_equal(result, expected)


@pytest.mark.parametrize("kwargs", [dict(), dict(index_col=False)])
@pytest.mark.parametrize("kwargs", [{}, {"index_col": False}])
def test_read_only_header_no_rows(all_parsers, kwargs):
# See gh-7773
parser = all_parsers
Expand All @@ -410,10 +410,10 @@ def test_read_only_header_no_rows(all_parsers, kwargs):
@pytest.mark.parametrize(
"kwargs,names",
[
(dict(), [0, 1, 2, 3, 4]),
(dict(prefix="X"), ["X0", "X1", "X2", "X3", "X4"]),
({}, [0, 1, 2, 3, 4]),
({"prefix": "X"}, ["X0", "X1", "X2", "X3", "X4"]),
(
dict(names=["foo", "bar", "baz", "quux", "panda"]),
{"names": ["foo", "bar", "baz", "quux", "panda"]},
["foo", "bar", "baz", "quux", "panda"],
),
],
Expand Down
40 changes: 22 additions & 18 deletions pandas/tests/io/parser/test_index_col.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,35 +86,39 @@ def test_infer_index_col(all_parsers):
@pytest.mark.parametrize(
"index_col,kwargs",
[
(None, dict(columns=["x", "y", "z"])),
(False, dict(columns=["x", "y", "z"])),
(0, dict(columns=["y", "z"], index=Index([], name="x"))),
(1, dict(columns=["x", "z"], index=Index([], name="y"))),
("x", dict(columns=["y", "z"], index=Index([], name="x"))),
("y", dict(columns=["x", "z"], index=Index([], name="y"))),
(None, {"columns": ["x", "y", "z"]}),
(False, {"columns": ["x", "y", "z"]}),
(0, {"columns": ["y", "z"], "index": Index([], name="x")}),
(1, {"columns": ["x", "z"], "index": Index([], name="y")}),
("x", {"columns": ["y", "z"], "index": Index([], name="x")}),
("y", {"columns": ["x", "z"], "index": Index([], name="y")}),
(
[0, 1],
dict(
columns=["z"], index=MultiIndex.from_arrays([[]] * 2, names=["x", "y"])
),
{
"columns": ["z"],
"index": MultiIndex.from_arrays([[]] * 2, names=["x", "y"]),
},
),
(
["x", "y"],
dict(
columns=["z"], index=MultiIndex.from_arrays([[]] * 2, names=["x", "y"])
),
{
"columns": ["z"],
"index": MultiIndex.from_arrays([[]] * 2, names=["x", "y"]),
},
),
(
[1, 0],
dict(
columns=["z"], index=MultiIndex.from_arrays([[]] * 2, names=["y", "x"])
),
{
"columns": ["z"],
"index": MultiIndex.from_arrays([[]] * 2, names=["y", "x"]),
},
),
(
["y", "x"],
dict(
columns=["z"], index=MultiIndex.from_arrays([[]] * 2, names=["y", "x"])
),
{
"columns": ["z"],
"index": MultiIndex.from_arrays([[]] * 2, names=["y", "x"]),
},
),
],
)
Expand Down
14 changes: 7 additions & 7 deletions pandas/tests/io/parser/test_na_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def test_na_value_dict_multi_index(all_parsers, index_col, expected):
"kwargs,expected",
[
(
dict(),
{},
DataFrame(
{
"A": ["a", "b", np.nan, "d", "e", np.nan, "g"],
Expand All @@ -224,7 +224,7 @@ def test_na_value_dict_multi_index(all_parsers, index_col, expected):
),
),
(
dict(na_values={"A": [], "C": []}, keep_default_na=False),
{"na_values": {"A": [], "C": []}, "keep_default_na": False},
DataFrame(
{
"A": ["a", "b", "", "d", "e", "nan", "g"],
Expand All @@ -234,7 +234,7 @@ def test_na_value_dict_multi_index(all_parsers, index_col, expected):
),
),
(
dict(na_values=["a"], keep_default_na=False),
{"na_values": ["a"], "keep_default_na": False},
DataFrame(
{
"A": [np.nan, "b", "", "d", "e", "nan", "g"],
Expand All @@ -244,7 +244,7 @@ def test_na_value_dict_multi_index(all_parsers, index_col, expected):
),
),
(
dict(na_values={"A": [], "C": []}),
{"na_values": {"A": [], "C": []}},
DataFrame(
{
"A": ["a", "b", np.nan, "d", "e", np.nan, "g"],
Expand Down Expand Up @@ -445,11 +445,11 @@ def test_na_values_dict_col_index(all_parsers):
[
(
str(2 ** 63) + "\n" + str(2 ** 63 + 1),
dict(na_values=[2 ** 63]),
{"na_values": [2 ** 63]},
DataFrame([str(2 ** 63), str(2 ** 63 + 1)]),
),
(str(2 ** 63) + ",1" + "\n,2", dict(), DataFrame([[str(2 ** 63), 1], ["", 2]])),
(str(2 ** 63) + "\n1", dict(na_values=[2 ** 63]), DataFrame([np.nan, 1])),
(str(2 ** 63) + ",1" + "\n,2", {}, DataFrame([[str(2 ** 63), 1], ["", 2]])),
(str(2 ** 63) + "\n1", {"na_values": [2 ** 63]}, DataFrame([np.nan, 1])),
],
)
def test_na_values_uint64(all_parsers, data, kwargs, expected):
Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/io/parser/test_python_parser_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_invalid_skipfooter_negative(python_parser_only):
parser.read_csv(StringIO(data), skipfooter=-1)


@pytest.mark.parametrize("kwargs", [dict(sep=None), dict(delimiter="|")])
@pytest.mark.parametrize("kwargs", [{"sep": None}, {"delimiter": "|"}])
def test_sniff_delimiter(python_parser_only, kwargs):
data = """index|A|B|C
foo|1|2|3
Expand Down Expand Up @@ -122,7 +122,7 @@ def test_single_line(python_parser_only):
tm.assert_frame_equal(result, expected)


@pytest.mark.parametrize("kwargs", [dict(skipfooter=2), dict(nrows=3)])
@pytest.mark.parametrize("kwargs", [{"skipfooter": 2}, {"nrows": 3}])
def test_skipfooter(python_parser_only, kwargs):
# see gh-6607
data = """A,B,C
Expand Down Expand Up @@ -213,10 +213,10 @@ def test_skipfooter_with_decimal(python_parser_only, add_footer):
if add_footer:
# The stray footer line should not mess with the
# casting of the first two lines if we skip it.
kwargs = dict(skipfooter=1)
kwargs = {"skipfooter": 1}
data += "\nFooter"
else:
kwargs = dict()
kwargs = {}

result = parser.read_csv(StringIO(data), names=["a"], decimal="#", **kwargs)
tm.assert_frame_equal(result, expected)
Expand Down Expand Up @@ -245,7 +245,7 @@ def test_encoding_non_utf8_multichar_sep(python_parser_only, sep, encoding):
@pytest.mark.parametrize("quoting", [csv.QUOTE_MINIMAL, csv.QUOTE_NONE])
def test_multi_char_sep_quotes(python_parser_only, quoting):
# see gh-13374
kwargs = dict(sep=",,")
kwargs = {"sep": ",,"}
parser = python_parser_only

data = 'a,,b\n1,,a\n2,,"2,,b"'
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ ignore =
W504, # line break after binary operator
E402, # module level import not at top of file
E731, # do not assign a lambda expression, use a def
C408, # Unnecessary dict call - rewrite as a literal.
S001 # found modulo formatter (incorrect picks up mod operations)
exclude =
doc/sphinxext/*.py,
Expand Down

0 comments on commit 492f01f

Please sign in to comment.