Skip to content

Commit e058e05

Browse files
authored
Merge branch 'main' into issue_61917
2 parents faf5962 + fcffde9 commit e058e05

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

pandas/_libs/internals.pyx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,8 +1006,12 @@ cdef class BlockValuesRefs:
10061006

10071007
cdef extern from "Python.h":
10081008
"""
1009+
// python version < 3.14
10091010
#if PY_VERSION_HEX < 0x030E0000
1010-
int __Pyx_PyUnstable_Object_IsUniqueReferencedTemporary(PyObject *ref);
1011+
// This function is unused and is declared to avoid a build warning
1012+
int __Pyx_PyUnstable_Object_IsUniqueReferencedTemporary(PyObject *ref) {
1013+
return Py_REFCNT(ref) == 1;
1014+
}
10111015
#else
10121016
#define __Pyx_PyUnstable_Object_IsUniqueReferencedTemporary \
10131017
PyUnstable_Object_IsUniqueReferencedTemporary

pandas/core/arrays/datetimelike.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,6 +2342,9 @@ def _with_freq(self, freq) -> Self:
23422342

23432343
def _values_for_json(self) -> np.ndarray:
23442344
# Small performance bump vs the base class which calls np.asarray(self)
2345+
if self.unit != "ns":
2346+
# GH#55827
2347+
return self.as_unit("ns")._values_for_json()
23452348
if isinstance(self.dtype, np.dtype):
23462349
return self._ndarray
23472350
return super()._values_for_json()

pandas/tests/frame/methods/test_update.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ def test_update_dt_column_with_NaT_create_column(self):
197197
np.datetime64("2000-01-02T00:00:00"),
198198
np.dtype("datetime64[ns]"),
199199
),
200+
(1, 2, pd.Int64Dtype()),
200201
],
201202
)
202203
def test_update_preserve_dtype(self, value_df, value_other, dtype):
@@ -228,3 +229,19 @@ def test_update_on_duplicate_frame_unique_argument_index(self):
228229
expected = DataFrame({"a": [2, 2, 3]}, index=[1, 1, 2], dtype=np.dtype("intc"))
229230
df.update(other)
230231
tm.assert_frame_equal(df, expected)
232+
233+
def test_update_preserve_mixed_dtypes(self):
234+
# GH#44104
235+
dtype1 = pd.Int64Dtype()
236+
dtype2 = pd.StringDtype()
237+
df = DataFrame({"a": [1, 2, 3], "b": ["x", "y", "z"]})
238+
df = df.astype({"a": dtype1, "b": dtype2})
239+
240+
other = DataFrame({"a": [4, 5], "b": ["a", "b"]})
241+
other = other.astype({"a": dtype1, "b": dtype2})
242+
243+
expected = DataFrame({"a": [4, 5, 3], "b": ["a", "b", "z"]})
244+
expected = expected.astype({"a": dtype1, "b": dtype2})
245+
246+
df.update(other)
247+
tm.assert_frame_equal(df, expected)

pandas/tests/io/json/test_pandas.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,6 @@ def test_frame_non_unique_index_raises(self, orient):
135135
],
136136
)
137137
def test_frame_non_unique_columns(self, orient, data, request):
138-
if isinstance(data[0][0], Timestamp) and orient == "split":
139-
mark = pytest.mark.xfail(
140-
reason="GH#55827 non-nanosecond dt64 fails to round-trip"
141-
)
142-
request.applymarker(mark)
143-
144138
df = DataFrame(data, index=[1, 2], columns=["x", "x"])
145139

146140
expected_warning = None
@@ -162,10 +156,14 @@ def test_frame_non_unique_columns(self, orient, data, request):
162156
# in milliseconds; these are internally stored in nanosecond,
163157
# so divide to get where we need
164158
# TODO: a to_epoch method would also solve; see GH 14772
165-
expected.isetitem(0, expected.iloc[:, 0].astype(np.int64) // 1000000)
159+
dta = expected.iloc[:, 0]._values
160+
dta = dta.as_unit("ns") # GH#55827
161+
expected.isetitem(0, dta.astype(np.int64) // 1_000_000)
166162
elif orient == "split":
167163
expected = df
168164
expected.columns = ["x", "x.1"]
165+
if expected["x"].dtype.kind == "M":
166+
expected["x"] = expected["x"].astype("M8[ns]") # GH#55827
169167

170168
tm.assert_frame_equal(result, expected)
171169

0 commit comments

Comments
 (0)