Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C408 fix #38260

Merged
merged 5 commits into from
Dec 4, 2020
Merged

C408 fix #38260

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pandas/tests/io/json/test_normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,21 +521,25 @@ def test_meta_non_iterable(self):

class TestNestedToRecord:
def test_flat_stays_flat(self):
recs = [dict(flat1=1, flat2=2), dict(flat1=3, flat2=4)]
recs = [{"flat1": 1, "flat2": 2}, {"flat3": 3, "flat2": 4}]
result = nested_to_record(recs)
expected = recs
assert result == expected

def test_one_level_deep_flattens(self):
data = dict(flat1=1, dict1=dict(c=1, d=2))
data = {"flat1": 1, "dict1": {"c": 1, "d": 2}}

result = nested_to_record(data)
expected = {"dict1.c": 1, "dict1.d": 2, "flat1": 1}

assert result == expected

def test_nested_flattens(self):
data = dict(flat1=1, dict1=dict(c=1, d=2), nested=dict(e=dict(c=1, d=2), d=2))
data = {
"flat1": 1,
"dict1": {"c": 1, "d": 2},
"nested": {"e": {"c": 1, "d": 2}, "d": 2},
}

result = nested_to_record(data)
expected = {
Expand Down
28 changes: 14 additions & 14 deletions pandas/tests/io/json/test_ujson.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,10 +757,10 @@ def test_array_reshaped(self, shape):
def test_array_list(self):
arr_list = [
"a",
list(),
dict(),
dict(),
list(),
[],
{},
{},
[],
42,
97.8,
["a", "b"],
Expand Down Expand Up @@ -797,9 +797,9 @@ def test_0d_array(self):
([42, {}, "a"], TypeError, {}),
([42, ["a"], 42], ValueError, {}),
(["a", "b", [], "c"], ValueError, {}),
([{"a": "b"}], ValueError, dict(labelled=True)),
({"a": {"b": {"c": 42}}}, ValueError, dict(labelled=True)),
([{"a": 42, "b": 23}, {"c": 17}], ValueError, dict(labelled=True)),
([{"a": "b"}], ValueError, {"labelled": True}),
({"a": {"b": {"c": 42}}}, ValueError, {"labelled": True}),
([{"a": 42, "b": 23}, {"c": 17}], ValueError, {"labelled": True}),
],
)
def test_array_numpy_except(self, bad_input, exc_type, kwargs):
Expand Down Expand Up @@ -852,8 +852,8 @@ def test_dataframe(self, orient, numpy):
columns=["x", "y", "z"],
dtype=dtype,
)
encode_kwargs = {} if orient is None else dict(orient=orient)
decode_kwargs = {} if numpy is None else dict(numpy=numpy)
encode_kwargs = {} if orient is None else {"orient": orient}
decode_kwargs = {} if numpy is None else {"numpy": numpy}
assert (df.dtypes == dtype).all()

output = ujson.decode(ujson.encode(df, **encode_kwargs), **decode_kwargs)
Expand Down Expand Up @@ -884,7 +884,7 @@ def test_dataframe_nested(self, orient):
)

nested = {"df1": df, "df2": df.copy()}
kwargs = {} if orient is None else dict(orient=orient)
kwargs = {} if orient is None else {"orient": orient}

exp = {
"df1": ujson.decode(ujson.encode(df, **kwargs)),
Expand All @@ -902,7 +902,7 @@ def test_dataframe_numpy_labelled(self, orient):
columns=["x", "y", "z"],
dtype=int,
)
kwargs = {} if orient is None else dict(orient=orient)
kwargs = {} if orient is None else {"orient": orient}

output = DataFrame(
*ujson.decode(ujson.encode(df, **kwargs), numpy=True, labelled=True)
Expand All @@ -925,8 +925,8 @@ def test_series(self, orient, numpy):
).sort_values()
assert s.dtype == dtype

encode_kwargs = {} if orient is None else dict(orient=orient)
decode_kwargs = {} if numpy is None else dict(numpy=numpy)
encode_kwargs = {} if orient is None else {"orient": orient}
decode_kwargs = {} if numpy is None else {"numpy": numpy}

output = ujson.decode(ujson.encode(s, **encode_kwargs), **decode_kwargs)
assert s.dtype == dtype
Expand All @@ -953,7 +953,7 @@ def test_series_nested(self, orient):
[10, 20, 30, 40, 50, 60], name="series", index=[6, 7, 8, 9, 10, 15]
).sort_values()
nested = {"s1": s, "s2": s.copy()}
kwargs = {} if orient is None else dict(orient=orient)
kwargs = {} if orient is None else {"orient": orient}

exp = {
"s1": ujson.decode(ujson.encode(s, **kwargs)),
Expand Down