Skip to content

Commit 2b28454

Browse files
authored
Cleaned up DTA test (#28502)
1 parent c94eaee commit 2b28454

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

pandas/tests/io/json/test_pandas.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -813,20 +813,11 @@ def test_series_roundtrip_simple(self, orient, numpy):
813813
@pytest.mark.parametrize("dtype", [False, None])
814814
@pytest.mark.parametrize("numpy", [True, False])
815815
def test_series_roundtrip_object(self, orient, numpy, dtype):
816-
# TODO: see why tm.makeObjectSeries provides back DTA
817-
dtSeries = Series(
818-
[str(d) for d in self.objSeries],
819-
index=self.objSeries.index,
820-
name=self.objSeries.name,
821-
)
822-
data = dtSeries.to_json(orient=orient)
816+
data = self.objSeries.to_json(orient=orient)
823817
result = pd.read_json(
824818
data, typ="series", orient=orient, numpy=numpy, dtype=dtype
825819
)
826-
if dtype is False:
827-
expected = dtSeries.copy()
828-
else:
829-
expected = self.objSeries.copy()
820+
expected = self.objSeries.copy()
830821

831822
if not numpy and PY35 and orient in ("index", "columns"):
832823
expected = expected.sort_index()
@@ -897,6 +888,19 @@ def test_series_with_dtype(self):
897888
expected = Series([4] * 3)
898889
assert_series_equal(result, expected)
899890

891+
@pytest.mark.parametrize(
892+
"dtype,expected",
893+
[
894+
(True, Series(["2000-01-01"], dtype="datetime64[ns]")),
895+
(False, Series([946684800000])),
896+
],
897+
)
898+
def test_series_with_dtype_datetime(self, dtype, expected):
899+
s = Series(["2000-01-01"], dtype="datetime64[ns]")
900+
data = s.to_json()
901+
result = pd.read_json(data, typ="series", dtype=dtype)
902+
assert_series_equal(result, expected)
903+
900904
def test_frame_from_json_precise_float(self):
901905
df = DataFrame([[4.56, 4.56, 4.56], [4.56, 4.56, 4.56]])
902906
result = read_json(df.to_json(), precise_float=True)

0 commit comments

Comments
 (0)