Skip to content

Commit c6c23be

Browse files
added test for to_json method using all orients to check if a column with int type is preserved
1 parent b0923d4 commit c6c23be

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pandas/tests/io/json/test_pandas.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,3 +2283,21 @@ def test_large_number():
22832283
)
22842284
expected = Series([9999999999999999])
22852285
tm.assert_series_equal(result, expected)
2286+
2287+
2288+
@pytest.mark.parametrize(
2289+
"orient", ["records", "index", "columns", "split", "values", "table"]
2290+
)
2291+
def test_to_json_read_json_numeric_columns_all_orients(orient):
2292+
df = DataFrame([[1, 2, 3, 4]], columns=[5, 6, 7, 8])
2293+
2294+
with tm.ensure_clean("tmp.json") as path:
2295+
df.to_json(path, orient=orient)
2296+
result = read_json(path, orient=orient)
2297+
2298+
# Column types must be int in all cases
2299+
assert all(isinstance(col, int) for col in result.columns)
2300+
2301+
# Content check (relaxed for "values")
2302+
if orient != "values":
2303+
tm.assert_frame_equal(result, df, check_column_type=False)

0 commit comments

Comments
 (0)