Skip to content

Commit 93ea131

Browse files
TST: add a test for preserving dtype while calling frame.update (#55509)
1 parent f7419d8 commit 93ea131

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

pandas/tests/frame/methods/test_update.py

+29
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,32 @@ def test_update_dt_column_with_NaT_create_column(self):
184184
{"A": [1.0, 3.0], "B": [pd.NaT, pd.to_datetime("2016-01-01")]}
185185
)
186186
tm.assert_frame_equal(df, expected)
187+
188+
@pytest.mark.parametrize(
189+
"value_df, value_other, dtype",
190+
[
191+
(True, False, bool),
192+
(1, 2, int),
193+
(np.uint64(1), np.uint(2), np.dtype("uint64")),
194+
(1.0, 2.0, float),
195+
(1.0 + 1j, 2.0 + 2j, complex),
196+
("a", "b", pd.StringDtype()),
197+
(
198+
pd.to_timedelta("1 ms"),
199+
pd.to_timedelta("2 ms"),
200+
np.dtype("timedelta64[ns]"),
201+
),
202+
(
203+
np.datetime64("2000-01-01T00:00:00"),
204+
np.datetime64("2000-01-02T00:00:00"),
205+
np.dtype("datetime64[ns]"),
206+
),
207+
],
208+
)
209+
def test_update_preserve_dtype(self, value_df, value_other, dtype):
210+
# GH#55509
211+
df = DataFrame({"a": [value_df] * 2}, index=[1, 2])
212+
other = DataFrame({"a": [value_other]}, index=[1])
213+
expected = DataFrame({"a": [value_other, value_df]}, index=[1, 2])
214+
df.update(other)
215+
tm.assert_frame_equal(df, expected)

0 commit comments

Comments
 (0)