Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 5 additions & 7 deletions pandas/tests/io/json/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
Loading