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 adc2ff8 commit 6adf501
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
30 changes: 15 additions & 15 deletions pandas/tests/io/parser/test_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
@pytest.fixture
def custom_dialect():
dialect_name = "weird"
dialect_kwargs = dict(
doublequote=False,
escapechar="~",
delimiter=":",
skipinitialspace=False,
quotechar="~",
quoting=3,
)
dialect_kwargs = {
"doublequote": False,
"escapechar": "~",
"delimiter": ":",
"skipinitialspace": False,
"quotechar": "~",
"quoting": 3,
}
return dialect_name, dialect_kwargs


Expand Down Expand Up @@ -91,7 +91,7 @@ def test_dialect_conflict_except_delimiter(all_parsers, custom_dialect, arg, val
data = "a:b\n1:2"

warning_klass = None
kwds = dict()
kwds = {}

# arg=None tests when we pass in the dialect without any other arguments.
if arg is not None:
Expand All @@ -114,12 +114,12 @@ def test_dialect_conflict_except_delimiter(all_parsers, custom_dialect, arg, val
@pytest.mark.parametrize(
"kwargs,warning_klass",
[
(dict(sep=","), None), # sep is default --> sep_override=True
(dict(sep="."), ParserWarning), # sep isn't default --> sep_override=False
(dict(delimiter=":"), None), # No conflict
(dict(delimiter=None), None), # Default arguments --> sep_override=True
(dict(delimiter=","), ParserWarning), # Conflict
(dict(delimiter="."), ParserWarning), # Conflict
({"sep": ","}, None), # sep is default --> sep_override=True
({"sep": "."}, ParserWarning), # sep isn't default --> sep_override=False
({"delimiter": ":"}, None), # No conflict
({"delimiter": None}, None), # Default arguments --> sep_override=True
({"delimiter": ","}, ParserWarning), # Conflict
({"delimiter": "."}, ParserWarning), # Conflict
],
ids=[
"sep-override-true",
Expand Down
12 changes: 6 additions & 6 deletions pandas/tests/io/parser/test_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_utf16_bom_skiprows(all_parsers, sep, encoding):
",", sep
)
path = f"__{tm.rands(10)}__.csv"
kwargs = dict(sep=sep, skiprows=2)
kwargs = {"sep": sep, "skiprows": 2}
utf8 = "utf-8"

with tm.ensure_clean(path) as path:
Expand Down Expand Up @@ -91,17 +91,17 @@ def test_unicode_encoding(all_parsers, csv_dir_path):
"data,kwargs,expected",
[
# Basic test
("a\n1", dict(), DataFrame({"a": [1]})),
("a\n1", {}, DataFrame({"a": [1]})),
# "Regular" quoting
('"a"\n1', dict(quotechar='"'), DataFrame({"a": [1]})),
('"a"\n1', {"quotechar": '"'}, DataFrame({"a": [1]})),
# Test in a data row instead of header
("b\n1", dict(names=["a"]), DataFrame({"a": ["b", "1"]})),
("b\n1", {"names": ["a"]}, DataFrame({"a": ["b", "1"]})),
# Test in empty data row with skipping
("\n1", dict(names=["a"], skip_blank_lines=True), DataFrame({"a": [1]})),
("\n1", {"names": ["a"], "skip_blank_lines": True}, DataFrame({"a": [1]})),
# Test in empty data row without skipping
(
"\n1",
dict(names=["a"], skip_blank_lines=False),
{"names": ["a"], "skip_blank_lines": False},
DataFrame({"a": [np.nan, 1]}),
),
],
Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/io/parser/test_skiprows.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ def test_skip_rows_blank(all_parsers):
2,"line 21
line 22",2
3,"line 31",1""",
dict(skiprows=[1]),
{"skiprows": [1]},
DataFrame(
[[2, "line 21\nline 22", 2], [3, "line 31", 1]],
columns=["id", "text", "num_lines"],
),
),
(
"a,b,c\n~a\n b~,~e\n d~,~f\n f~\n1,2,~12\n 13\n 14~",
dict(quotechar="~", skiprows=[2]),
{"quotechar": "~", "skiprows": [2]},
DataFrame([["a\n b", "e\n d", "f\n f"]], columns=["a", "b", "c"]),
),
(
Expand All @@ -111,7 +111,7 @@ def test_skip_rows_blank(all_parsers):
"example\n sentence\n two~,url2\n~"
"example\n sentence\n three~,url3"
),
dict(quotechar="~", skiprows=[1, 3]),
{"quotechar": "~", "skiprows": [1, 3]},
DataFrame([["example\n sentence\n two", "url2"]], columns=["Text", "url"]),
),
],
Expand Down Expand Up @@ -222,8 +222,8 @@ def test_skiprows_infield_quote(all_parsers):
@pytest.mark.parametrize(
"kwargs,expected",
[
(dict(), DataFrame({"1": [3, 5]})),
(dict(header=0, names=["foo"]), DataFrame({"foo": [3, 5]})),
({}, DataFrame({"1": [3, 5]})),
({"header": 0, "names": ["foo"]}, DataFrame({"foo": [3, 5]})),
],
)
def test_skip_rows_callable(all_parsers, kwargs, expected):
Expand Down

0 comments on commit 6adf501

Please sign in to comment.