Skip to content

Commit 85a107e

Browse files
TST: test that update preserve dtype (pandas-dev#55509)
1 parent 4fd4102 commit 85a107e

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

pandas/tests/frame/methods/test_update.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,31 @@ def test_update_dt_column_with_NaT_create_column(self):
178178
)
179179
tm.assert_frame_equal(df, expected)
180180

181-
def test_update_preserve_column_dtype_bool(self):
181+
@pytest.mark.parametrize(
182+
"value_df, value_other, dtype",
183+
[
184+
(True, False, bool),
185+
(1, 2, int),
186+
(np.uint64(1), np.uint(2), np.dtype("uint64")),
187+
(1.0, 2.0, float),
188+
(1.0 + 1j, 2.0 + 2j, complex),
189+
("a", "b", pd.StringDtype()),
190+
(
191+
pd.to_timedelta("1 ms"),
192+
pd.to_timedelta("2 ms"),
193+
np.dtype("timedelta64[ns]"),
194+
),
195+
(
196+
np.datetime64("2000-01-01T00:00:00"),
197+
np.datetime64("2000-01-02T00:00:00"),
198+
np.dtype("datetime64[ns]"),
199+
),
200+
],
201+
)
202+
def test_update_preserve_dtype(self, value_df, value_other, dtype):
182203
# GH#55509
183-
df = DataFrame({"A": [True, True]}, index=[1, 2])
184-
other = DataFrame({"A": [False]}, index=[1])
185-
expected = DataFrame({"A": [False, True]}, index=[1, 2])
204+
df = DataFrame({"a": [value_df] * 2}, index=[1, 2])
205+
other = DataFrame({"a": [value_other]}, index=[1])
206+
expected = DataFrame({"a": [value_other, value_df]}, index=[1, 2])
186207
df.update(other)
187-
188208
tm.assert_frame_equal(df, expected)

0 commit comments

Comments
 (0)