Skip to content

Commit 4cacdd1

Browse files
author
Chris Bertinato
committed
Fixed tests
1 parent 045b9b3 commit 4cacdd1

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

pandas/tests/io/json/test_pandas.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -814,38 +814,37 @@ def test_reconstruction_index(self):
814814
assert_frame_equal(result, df)
815815

816816
@pytest.mark.parametrize(
817-
"date_format,delta,formatted",
817+
"date_format,expected",
818818
[
819-
("iso", ["1D", "2D"], ["P1DT0H0M0S", "P2DT0H0M0S"]),
820-
("epoch", ["1D", "2D"], [86400000, 172800000]),
819+
("iso", '{"0":"P1DT0H0M0S","1":"P2DT0H0M0S"}'),
820+
("epoch", '{"0":86400000,"1":172800000}'),
821821
],
822822
)
823-
def test_series_timedelta_to_json(self, date_format, delta, formatted):
823+
def test_series_timedelta_to_json(self, date_format, expected):
824824
# GH28156: to_json not correctly formatting Timedelta
825-
s = Series([pd.Timedelta(d) for d in delta])
826-
s.index = ["one", "two"]
825+
s = Series(pd.timedelta_range(start="1D", periods=2))
827826

828-
result = json.loads(s.to_json(date_format=date_format))
829-
expected = {k: v for k, v in zip(s.index, formatted)}
827+
result = s.to_json(date_format=date_format)
828+
assert result == expected
830829

830+
result = s.astype(object).to_json(date_format=date_format)
831831
assert result == expected
832832

833833
@pytest.mark.parametrize(
834-
"date_format,delta,formatted",
834+
"date_format,expected",
835835
[
836-
("iso", ["1D", "2D"], ["P1DT0H0M0S", "P2DT0H0M0S"]),
837-
("epoch", ["1D", "2D"], [86400000, 172800000]),
836+
("iso", '{"0":{"0":"P1DT0H0M0S","1":"P2DT0H0M0S"}}'),
837+
("epoch", '{"0":{"0":86400000,"1":172800000}}'),
838838
],
839839
)
840-
def test_dataframe_timedelta_to_json(self, date_format, delta, formatted):
840+
def test_dataframe_timedelta_to_json(self, date_format, expected):
841841
# GH28156: to_json not correctly formatting Timedelta
842-
df = DataFrame([pd.Timedelta(d) for d in delta])
843-
df.index = ["one", "two"]
844-
df.columns = ["A"]
842+
df = DataFrame(pd.timedelta_range(start="1D", periods=2))
845843

846-
result = json.loads(df.to_json(date_format=date_format))
847-
expected = {"A": {k: v for k, v in zip(df.index, formatted)}}
844+
result = df.to_json(date_format=date_format)
845+
assert result == expected
848846

847+
result = df.astype(object).to_json(date_format=date_format)
849848
assert result == expected
850849

851850
def test_path(self):

0 commit comments

Comments
 (0)