|
3 | 3 |
|
4 | 4 | import pandas.util._test_decorators as td
|
5 | 5 |
|
| 6 | +import pandas as pd |
6 | 7 | from pandas import DataFrame
|
7 | 8 | from pandas.tests.copy_view.util import get_array
|
8 | 9 |
|
@@ -62,3 +63,32 @@ def test_clear_parent(using_copy_on_write):
|
62 | 63 | # when losing the last reference, also the parent should be reset
|
63 | 64 | subset["b"] = 0
|
64 | 65 | assert subset._mgr.parent is None
|
| 66 | + |
| 67 | + |
| 68 | +@td.skip_array_manager_invalid_test |
| 69 | +def test_switch_options(): |
| 70 | + # ensure we can switch the value of the option within one session |
| 71 | + # (assuming data is constructed after switching) |
| 72 | + |
| 73 | + # using the option_context to ensure we set back to global option value |
| 74 | + # after running the test |
| 75 | + with pd.option_context("mode.copy_on_write", False): |
| 76 | + df = DataFrame({"a": [1, 2, 3], "b": [0.1, 0.2, 0.3]}) |
| 77 | + subset = df[:] |
| 78 | + subset.iloc[0, 0] = 0 |
| 79 | + # df updated with CoW disabled |
| 80 | + assert df.iloc[0, 0] == 0 |
| 81 | + |
| 82 | + pd.options.mode.copy_on_write = True |
| 83 | + df = DataFrame({"a": [1, 2, 3], "b": [0.1, 0.2, 0.3]}) |
| 84 | + subset = df[:] |
| 85 | + subset.iloc[0, 0] = 0 |
| 86 | + # df not updated with CoW enabled |
| 87 | + assert df.iloc[0, 0] == 1 |
| 88 | + |
| 89 | + pd.options.mode.copy_on_write = False |
| 90 | + df = DataFrame({"a": [1, 2, 3], "b": [0.1, 0.2, 0.3]}) |
| 91 | + subset = df[:] |
| 92 | + subset.iloc[0, 0] = 0 |
| 93 | + # df updated with CoW disabled |
| 94 | + assert df.iloc[0, 0] == 0 |
0 commit comments