File tree 3 files changed +17
-6
lines changed
3 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -520,7 +520,7 @@ Indexing
520
520
521
521
Missing
522
522
^^^^^^^
523
- -
523
+ - Bug in :meth: ` DataFrame.update ` wasn't updating in-place for datetime64 dtypes ( :issue: ` 56227 `)
524
524
-
525
525
526
526
MultiIndex
Original file line number Diff line number Diff line change @@ -8862,8 +8862,6 @@ def update(
8862
8862
stacklevel = 2 ,
8863
8863
)
8864
8864
8865
- from pandas .core .computation import expressions
8866
-
8867
8865
# TODO: Support other joins
8868
8866
if join != "left" : # pragma: no cover
8869
8867
raise NotImplementedError ("Only left join is supported" )
@@ -8876,8 +8874,8 @@ def update(
8876
8874
other = other .reindex (self .index )
8877
8875
8878
8876
for col in self .columns .intersection (other .columns ):
8879
- this = self [col ]. _values
8880
- that = other [col ]. _values
8877
+ this = self [col ]
8878
+ that = other [col ]
8881
8879
8882
8880
if filter_func is not None :
8883
8881
mask = ~ filter_func (this ) | isna (that )
@@ -8897,7 +8895,7 @@ def update(
8897
8895
if mask .all ():
8898
8896
continue
8899
8897
8900
- self .loc [:, col ] = expressions .where (mask , this , that )
8898
+ self .loc [:, col ] = this .where (mask , that )
8901
8899
8902
8900
# ----------------------------------------------------------------------
8903
8901
# Data reshaping
Original file line number Diff line number Diff line change @@ -140,6 +140,19 @@ 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 ):
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
+ result .update (result + pd .Timedelta (days = 1 ))
149
+ expected = DataFrame ([pd .Timestamp ("2019-01-02" , tz = "UTC" )])
150
+ tm .assert_frame_equal (result , expected )
151
+ if not using_copy_on_write :
152
+ tm .assert_frame_equal (view , expected )
153
+ else :
154
+ tm .assert_frame_equal (view , orig )
155
+
143
156
def test_update_with_different_dtype (self , using_copy_on_write ):
144
157
# GH#3217
145
158
df = DataFrame ({"a" : [1 , 3 ], "b" : [np .nan , 2 ]})
You can’t perform that action at this time.
0 commit comments