File tree 3 files changed +23
-9
lines changed
3 files changed +23
-9
lines changed Original file line number Diff line number Diff line change @@ -521,7 +521,7 @@ Indexing
521
521
522
522
Missing
523
523
^^^^^^^
524
- -
524
+ - Bug in :meth: ` DataFrame.update ` wasn't updating in-place for tz-aware datetime64 dtypes ( :issue: ` 56227 `)
525
525
-
526
526
527
527
MultiIndex
Original file line number Diff line number Diff line change @@ -8852,14 +8852,14 @@ def update(
8852
8852
in the original dataframe.
8853
8853
8854
8854
>>> df = pd.DataFrame({'A': [1, 2, 3],
8855
- ... 'B': [400, 500, 600]})
8855
+ ... 'B': [400. , 500. , 600. ]})
8856
8856
>>> new_df = pd.DataFrame({'B': [4, np.nan, 6]})
8857
8857
>>> df.update(new_df)
8858
8858
>>> df
8859
- A B
8860
- 0 1 4
8861
- 1 2 500
8862
- 2 3 6
8859
+ A B
8860
+ 0 1 4.0
8861
+ 1 2 500.0
8862
+ 2 3 6.0
8863
8863
"""
8864
8864
if not PYPY and using_copy_on_write ():
8865
8865
if sys .getrefcount (self ) <= REF_COUNT :
@@ -8876,8 +8876,6 @@ def update(
8876
8876
stacklevel = 2 ,
8877
8877
)
8878
8878
8879
- from pandas .core .computation import expressions
8880
-
8881
8879
# TODO: Support other joins
8882
8880
if join != "left" : # pragma: no cover
8883
8881
raise NotImplementedError ("Only left join is supported" )
@@ -8911,7 +8909,7 @@ def update(
8911
8909
if mask .all ():
8912
8910
continue
8913
8911
8914
- self .loc [:, col ] = expressions .where (mask , this , that )
8912
+ self .loc [:, col ] = self [ col ] .where (mask , that )
8915
8913
8916
8914
# ----------------------------------------------------------------------
8917
8915
# Data reshaping
Original file line number Diff line number Diff line change @@ -140,6 +140,22 @@ def test_update_datetime_tz(self):
140
140
expected = DataFrame ([pd .Timestamp ("2019" , tz = "UTC" )])
141
141
tm .assert_frame_equal (result , expected )
142
142
143
+ def test_update_datetime_tz_in_place (self , using_copy_on_write , warn_copy_on_write ):
144
+ # https://github.com/pandas-dev/pandas/issues/56227
145
+ result = DataFrame ([pd .Timestamp ("2019" , tz = "UTC" )])
146
+ orig = result .copy ()
147
+ view = result [:]
148
+ with tm .assert_produces_warning (
149
+ FutureWarning if warn_copy_on_write else None , match = "Setting a value"
150
+ ):
151
+ result .update (result + pd .Timedelta (days = 1 ))
152
+ expected = DataFrame ([pd .Timestamp ("2019-01-02" , tz = "UTC" )])
153
+ tm .assert_frame_equal (result , expected )
154
+ if not using_copy_on_write :
155
+ tm .assert_frame_equal (view , expected )
156
+ else :
157
+ tm .assert_frame_equal (view , orig )
158
+
143
159
def test_update_with_different_dtype (self , using_copy_on_write ):
144
160
# GH#3217
145
161
df = DataFrame ({"a" : [1 , 3 ], "b" : [np .nan , 2 ]})
You can’t perform that action at this time.
0 commit comments