Skip to content

Commit 6d1499a

Browse files
committed
pre-commit adjustments
1 parent 0428534 commit 6d1499a

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

pandas/io/json/_json.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,18 @@ def to_json(
148148
raise ValueError("'lines' keyword only valid when 'orient' is records")
149149

150150
if mode not in ["a", "w"]:
151-
raise ValueError(
152-
f"mode={mode!r} is not a valid option. Only 'w' and 'a' are currently supported."
151+
msg = (
152+
f"mode={repr(mode)} is not a valid option."
153+
"Only 'w' and 'a' are currently supported."
153154
)
155+
raise ValueError(msg)
154156

155157
if mode == "a" and (not lines or orient != "records"):
156-
raise ValueError(
157-
"mode='a' (append) is only supported when lines is True and orient is 'records'"
158+
msg = (
159+
"mode='a' (append) is only supported when"
160+
"lines is True and orient is 'records'"
158161
)
162+
raise ValueError(msg)
159163

160164
if orient == "table" and isinstance(obj, Series):
161165
obj = obj.to_frame(name=obj.name or "values")

pandas/tests/io/json/test_readlines.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,10 @@ def test_to_json_append_orient(orient_):
304304
# GH 35849
305305
# Test ValueError when orient is not 'records'
306306
df = DataFrame({"col1": [1, 2], "col2": ["a", "b"]})
307-
msg = r"mode='a' \(append\) is only supported when lines is True and orient is 'records'"
307+
msg = (
308+
r"mode='a' \(append\) is only supported when"
309+
"lines is True and orient is 'records'"
310+
)
308311
with pytest.raises(ValueError, match=msg):
309312
df.to_json(mode="a", orient=orient_)
310313

@@ -313,17 +316,23 @@ def test_to_json_append_lines():
313316
# GH 35849
314317
# Test ValueError when lines is not True
315318
df = DataFrame({"col1": [1, 2], "col2": ["a", "b"]})
316-
msg = r"mode='a' \(append\) is only supported when lines is True and orient is 'records'"
319+
msg = (
320+
r"mode='a' \(append\) is only supported when"
321+
"lines is True and orient is 'records'"
322+
)
317323
with pytest.raises(ValueError, match=msg):
318324
df.to_json(mode="a", lines=False, orient="records")
319325

320326

321-
@pytest.mark.parametrize("mode_", ['r', 'x'])
322-
def test_to_json_append_lines(mode_):
327+
@pytest.mark.parametrize("mode_", ["r", "x"])
328+
def test_to_json_append_mode(mode_):
323329
# GH 35849
324330
# Test ValueError when mode is not supported option
325331
df = DataFrame({"col1": [1, 2], "col2": ["a", "b"]})
326-
msg = f"mode={mode_!r} is not a valid option. Only 'w' and 'a' are currently supported."
332+
msg = (
333+
f"mode={repr(mode_)} is not a valid option."
334+
"Only 'w' and 'a' are currently supported."
335+
)
327336
with pytest.raises(ValueError, match=msg):
328337
df.to_json(mode=mode_, lines=False, orient="records")
329338

@@ -344,10 +353,8 @@ def to_json_append_output():
344353
df2.to_json(path, mode="a", lines=True, orient="records")
345354

346355
# Read path file
347-
result_df = read_json(path, lines=True)
356+
result = read_json(path, lines=True)
348357
tm.assert_frame_equal(result, expected)
349-
del expected
350-
del result_df
351358

352359
# Test 2: df1, df2, df3, df4 (in that order)
353360
expected = DataFrame(
@@ -366,18 +373,16 @@ def to_json_append_output():
366373
df4.to_json(path, mode="a", lines=True, orient="records")
367374

368375
# Read path file
369-
result_df = read_json(path, lines=True)
376+
result = read_json(path, lines=True)
370377
tm.assert_frame_equal(result, expected)
371-
del expected
372-
del result_df
373378

374379
# Test 3: df4, df3, df2, df1 (in that order)
375380
expected = DataFrame(
376381
{
377382
"col4": [True, False, None, None, None, None, None, None],
378383
"col2": [None, None, "e", "f", "c", "d", "a", "b"],
379384
"col3": [None, None, "!", "#", None, None, None, None],
380-
"col4": [None, None, None, None, 3, 4, 1, 2],
385+
"col1": [None, None, None, None, 3, 4, 1, 2],
381386
}
382387
)
383388
with tm.ensure_clean("test.json") as path:
@@ -388,7 +393,5 @@ def to_json_append_output():
388393
df1.to_json(path, mode="a", lines=True, orient="records")
389394

390395
# Read path file
391-
result_df = read_json(path, lines=True)
396+
result = read_json(path, lines=True)
392397
tm.assert_frame_equal(result, expected)
393-
del expected
394-
del result_df

0 commit comments

Comments
 (0)