MCPcopy
hub / github.com/pandas-dev/pandas / test_update

Method test_update

pandas/tests/series/methods/test_update.py:17–35  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

15
16class TestUpdate:
17 def test_update(self):
18 s = Series([1.5, np.nan, 3.0, 4.0, np.nan])
19 s2 = Series([np.nan, 3.5, np.nan, 5.0])
20 s.update(s2)
21
22 expected = Series([1.5, 3.5, 3.0, 5.0, np.nan])
23 tm.assert_series_equal(s, expected)
24
25 # GH 3217
26 df = DataFrame([{"a": 1}, {"a": 3, "b": 2}])
27 df["c"] = np.nan
28 # Cast to object to avoid upcast when setting "foo"
29 df["c"] = df["c"].astype(object)
30 df_orig = df.copy()
31
32 with tm.raises_chained_assignment_error():
33 df["c"].update(Series(["foo"], index=[0]))
34 expected = df_orig
35 tm.assert_frame_equal(df, expected)
36
37 @pytest.mark.parametrize(
38 "other, dtype, expected, raises",

Callers

nothing calls this directly

Calls 5

updateMethod · 0.95
SeriesClass · 0.90
DataFrameClass · 0.90
astypeMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected