@@ -27,7 +27,7 @@ def random_text(nobs=100):
27
27
28
28
29
29
class TestCaching :
30
- def test_slice_consolidate_invalidate_item_cache (self , using_copy_on_write ):
30
+ def test_slice_consolidate_invalidate_item_cache (self ):
31
31
# this is chained assignment, but will 'work'
32
32
with option_context ("chained_assignment" , None ):
33
33
# #3970
@@ -61,7 +61,7 @@ def test_setitem_cache_updating(self, do_ref):
61
61
assert df .loc [0 , "c" ] == 0.0
62
62
assert df .loc [7 , "c" ] == 1.0
63
63
64
- def test_setitem_cache_updating_slices (self , using_copy_on_write ):
64
+ def test_setitem_cache_updating_slices (self ):
65
65
# GH 7084
66
66
# not updating cache on series setting with slices
67
67
expected = DataFrame (
@@ -85,15 +85,11 @@ def test_setitem_cache_updating_slices(self, using_copy_on_write):
85
85
out_original = out .copy ()
86
86
for ix , row in df .iterrows ():
87
87
v = out [row ["C" ]][six :eix ] + row ["D" ]
88
- with tm .raises_chained_assignment_error (( ix == 0 ) or using_copy_on_write ):
88
+ with tm .raises_chained_assignment_error ():
89
89
out [row ["C" ]][six :eix ] = v
90
90
91
- if not using_copy_on_write :
92
- tm .assert_frame_equal (out , expected )
93
- tm .assert_series_equal (out ["A" ], expected ["A" ])
94
- else :
95
- tm .assert_frame_equal (out , out_original )
96
- tm .assert_series_equal (out ["A" ], out_original ["A" ])
91
+ tm .assert_frame_equal (out , out_original )
92
+ tm .assert_series_equal (out ["A" ], out_original ["A" ])
97
93
98
94
out = DataFrame ({"A" : [0 , 0 , 0 ]}, index = date_range ("5/7/2014" , "5/9/2014" ))
99
95
for ix , row in df .iterrows ():
@@ -102,7 +98,7 @@ def test_setitem_cache_updating_slices(self, using_copy_on_write):
102
98
tm .assert_frame_equal (out , expected )
103
99
tm .assert_series_equal (out ["A" ], expected ["A" ])
104
100
105
- def test_altering_series_clears_parent_cache (self , using_copy_on_write ):
101
+ def test_altering_series_clears_parent_cache (self ):
106
102
# GH #33675
107
103
df = DataFrame ([[1 , 2 ], [3 , 4 ]], index = ["a" , "b" ], columns = ["A" , "B" ])
108
104
ser = df ["A" ]
@@ -116,49 +112,36 @@ def test_altering_series_clears_parent_cache(self, using_copy_on_write):
116
112
117
113
118
114
class TestChaining :
119
- def test_setitem_chained_setfault (self , using_copy_on_write ):
115
+ def test_setitem_chained_setfault (self ):
120
116
# GH6026
121
117
data = ["right" , "left" , "left" , "left" , "right" , "left" , "timeout" ]
122
- mdata = ["right" , "left" , "left" , "left" , "right" , "left" , "none" ]
123
118
124
119
df = DataFrame ({"response" : np .array (data )})
125
120
mask = df .response == "timeout"
126
121
with tm .raises_chained_assignment_error ():
127
122
df .response [mask ] = "none"
128
- if using_copy_on_write :
129
- tm .assert_frame_equal (df , DataFrame ({"response" : data }))
130
- else :
131
- tm .assert_frame_equal (df , DataFrame ({"response" : mdata }))
123
+ tm .assert_frame_equal (df , DataFrame ({"response" : data }))
132
124
133
125
recarray = np .rec .fromarrays ([data ], names = ["response" ])
134
126
df = DataFrame (recarray )
135
127
mask = df .response == "timeout"
136
128
with tm .raises_chained_assignment_error ():
137
129
df .response [mask ] = "none"
138
- if using_copy_on_write :
139
- tm .assert_frame_equal (df , DataFrame ({"response" : data }))
140
- else :
141
- tm .assert_frame_equal (df , DataFrame ({"response" : mdata }))
130
+ tm .assert_frame_equal (df , DataFrame ({"response" : data }))
142
131
143
132
df = DataFrame ({"response" : data , "response1" : data })
144
133
df_original = df .copy ()
145
134
mask = df .response == "timeout"
146
135
with tm .raises_chained_assignment_error ():
147
136
df .response [mask ] = "none"
148
- if using_copy_on_write :
149
- tm .assert_frame_equal (df , df_original )
150
- else :
151
- tm .assert_frame_equal (df , DataFrame ({"response" : mdata , "response1" : data }))
137
+ tm .assert_frame_equal (df , df_original )
152
138
153
139
# GH 6056
154
140
expected = DataFrame ({"A" : [np .nan , "bar" , "bah" , "foo" , "bar" ]})
155
141
df = DataFrame ({"A" : np .array (["foo" , "bar" , "bah" , "foo" , "bar" ])})
156
142
with tm .raises_chained_assignment_error ():
157
143
df ["A" ].iloc [0 ] = np .nan
158
- if using_copy_on_write :
159
- expected = DataFrame ({"A" : ["foo" , "bar" , "bah" , "foo" , "bar" ]})
160
- else :
161
- expected = DataFrame ({"A" : [np .nan , "bar" , "bah" , "foo" , "bar" ]})
144
+ expected = DataFrame ({"A" : ["foo" , "bar" , "bah" , "foo" , "bar" ]})
162
145
result = df .head ()
163
146
tm .assert_frame_equal (result , expected )
164
147
@@ -169,10 +152,9 @@ def test_setitem_chained_setfault(self, using_copy_on_write):
169
152
tm .assert_frame_equal (result , expected )
170
153
171
154
@pytest .mark .arm_slow
172
- def test_detect_chained_assignment (self , using_copy_on_write ):
155
+ def test_detect_chained_assignment (self ):
173
156
with option_context ("chained_assignment" , "raise" ):
174
157
# work with the chain
175
- expected = DataFrame ([[- 5 , 1 ], [- 6 , 3 ]], columns = list ("AB" ))
176
158
df = DataFrame (
177
159
np .arange (4 ).reshape (2 , 2 ), columns = list ("AB" ), dtype = "int64"
178
160
)
@@ -182,10 +164,7 @@ def test_detect_chained_assignment(self, using_copy_on_write):
182
164
df ["A" ][0 ] = - 5
183
165
with tm .raises_chained_assignment_error ():
184
166
df ["A" ][1 ] = - 6
185
- if using_copy_on_write :
186
- tm .assert_frame_equal (df , df_original )
187
- else :
188
- tm .assert_frame_equal (df , expected )
167
+ tm .assert_frame_equal (df , df_original )
189
168
190
169
@pytest .mark .arm_slow
191
170
def test_detect_chained_assignment_raises (self ):
@@ -340,9 +319,7 @@ def test_detect_chained_assignment_warnings_errors(self):
340
319
df .loc [0 ]["A" ] = 111
341
320
342
321
@pytest .mark .parametrize ("rhs" , [3 , DataFrame ({0 : [1 , 2 , 3 , 4 ]})])
343
- def test_detect_chained_assignment_warning_stacklevel (
344
- self , rhs , using_copy_on_write
345
- ):
322
+ def test_detect_chained_assignment_warning_stacklevel (self , rhs ):
346
323
# GH#42570
347
324
df = DataFrame (np .arange (25 ).reshape (5 , 5 ))
348
325
df_original = df .copy ()
@@ -379,7 +356,7 @@ def test_cache_updating(self):
379
356
assert "Hello Friend" in df ["A" ].index
380
357
assert "Hello Friend" in df ["B" ].index
381
358
382
- def test_cache_updating2 (self , using_copy_on_write ):
359
+ def test_cache_updating2 (self ):
383
360
# 10264
384
361
df = DataFrame (
385
362
np .zeros ((5 , 5 ), dtype = "int64" ),
@@ -388,26 +365,11 @@ def test_cache_updating2(self, using_copy_on_write):
388
365
)
389
366
df ["f" ] = 0
390
367
df_orig = df .copy ()
391
- if using_copy_on_write :
392
- with pytest .raises (ValueError , match = "read-only" ):
393
- df .f .values [3 ] = 1
394
- tm .assert_frame_equal (df , df_orig )
395
- return
396
-
397
- df .f .values [3 ] = 1
398
-
399
- df .f .values [3 ] = 2
400
- expected = DataFrame (
401
- np .zeros ((5 , 6 ), dtype = "int64" ),
402
- columns = ["a" , "b" , "c" , "d" , "e" , "f" ],
403
- index = range (5 ),
404
- )
405
- expected .at [3 , "f" ] = 2
406
- tm .assert_frame_equal (df , expected )
407
- expected = Series ([0 , 0 , 0 , 2 , 0 ], name = "f" )
408
- tm .assert_series_equal (df .f , expected )
368
+ with pytest .raises (ValueError , match = "read-only" ):
369
+ df .f .values [3 ] = 1
370
+ tm .assert_frame_equal (df , df_orig )
409
371
410
- def test_iloc_setitem_chained_assignment (self , using_copy_on_write ):
372
+ def test_iloc_setitem_chained_assignment (self ):
411
373
# GH#3970
412
374
with option_context ("chained_assignment" , None ):
413
375
df = DataFrame ({"aa" : range (5 ), "bb" : [2.2 ] * 5 })
@@ -424,10 +386,7 @@ def test_iloc_setitem_chained_assignment(self, using_copy_on_write):
424
386
with tm .raises_chained_assignment_error ():
425
387
df ["bb" ].iloc [0 ] = 0.15
426
388
427
- if not using_copy_on_write :
428
- assert df ["bb" ].iloc [0 ] == 0.15
429
- else :
430
- assert df ["bb" ].iloc [0 ] == 2.2
389
+ assert df ["bb" ].iloc [0 ] == 2.2
431
390
432
391
def test_getitem_loc_assignment_slice_state (self ):
433
392
# GH 13569
0 commit comments