diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index 2f7330d1e81fe..0c8d3072484ba 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -2342,6 +2342,9 @@ def _with_freq(self, freq) -> Self: def _values_for_json(self) -> np.ndarray: # Small performance bump vs the base class which calls np.asarray(self) + if self.unit != "ns": + # GH#55827 + return self.as_unit("ns")._values_for_json() if isinstance(self.dtype, np.dtype): return self._ndarray return super()._values_for_json() diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index 9c93be0937e91..3f508b2bb204a 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -132,12 +132,6 @@ def test_frame_non_unique_index_raises(self, orient): ], ) def test_frame_non_unique_columns(self, orient, data, request): - if isinstance(data[0][0], Timestamp) and orient == "split": - mark = pytest.mark.xfail( - reason="GH#55827 non-nanosecond dt64 fails to round-trip" - ) - request.applymarker(mark) - df = DataFrame(data, index=[1, 2], columns=["x", "x"]) expected_warning = None @@ -159,10 +153,14 @@ def test_frame_non_unique_columns(self, orient, data, request): # in milliseconds; these are internally stored in nanosecond, # so divide to get where we need # TODO: a to_epoch method would also solve; see GH 14772 - expected.isetitem(0, expected.iloc[:, 0].astype(np.int64) // 1000000) + dta = expected.iloc[:, 0]._values + dta = dta.as_unit("ns") # GH#55827 + expected.isetitem(0, dta.astype(np.int64) // 1_000_000) elif orient == "split": expected = df expected.columns = ["x", "x.1"] + if expected["x"].dtype.kind == "M": + expected["x"] = expected["x"].astype("M8[ns]") # GH#55827 tm.assert_frame_equal(result, expected)