Skip to content

Commit 710b83b

Browse files
CLN: fix and move using_copy_on_write() helper out of internals (#50675)
1 parent 2797b84 commit 710b83b

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

pandas/_config/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
"describe_option",
1515
"option_context",
1616
"options",
17+
"using_copy_on_write",
1718
]
1819
from pandas._config import config
1920
from pandas._config import dates # pyright: ignore # noqa:F401
2021
from pandas._config.config import (
22+
_global_config,
2123
describe_option,
2224
get_option,
2325
option_context,
@@ -26,3 +28,8 @@
2628
set_option,
2729
)
2830
from pandas._config.display import detect_console_encoding
31+
32+
33+
def using_copy_on_write():
34+
_mode_options = _global_config["mode"]
35+
return _mode_options["copy_on_write"] and _mode_options["data_manager"] == "block"

pandas/core/generic.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929

3030
import numpy as np
3131

32-
from pandas._config import config
32+
from pandas._config import (
33+
config,
34+
using_copy_on_write,
35+
)
3336

3437
from pandas._libs import lib
3538
from pandas._libs.tslibs import (
@@ -158,7 +161,6 @@
158161
SingleArrayManager,
159162
)
160163
from pandas.core.internals.construction import mgr_to_mgr
161-
from pandas.core.internals.managers import using_copy_on_write
162164
from pandas.core.methods.describe import describe_ndframe
163165
from pandas.core.missing import (
164166
clean_fill_method,
@@ -4023,10 +4025,7 @@ def _check_setitem_copy(self, t: str = "setting", force: bool_t = False):
40234025
df.iloc[0:5]['group'] = 'a'
40244026
40254027
"""
4026-
if (
4027-
config.get_option("mode.copy_on_write")
4028-
and config.get_option("mode.data_manager") == "block"
4029-
):
4028+
if using_copy_on_write():
40304029
return
40314030

40324031
# return early if the check is not needed

pandas/core/internals/managers.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import numpy as np
1717

18-
from pandas._config import config
18+
from pandas._config import using_copy_on_write
1919

2020
from pandas._libs import (
2121
algos as libalgos,
@@ -2362,10 +2362,3 @@ def _preprocess_slice_or_indexer(
23622362
if not allow_fill:
23632363
indexer = maybe_convert_indices(indexer, length)
23642364
return "fancy", indexer, len(indexer)
2365-
2366-
2367-
_mode_options = config._global_config["mode"]
2368-
2369-
2370-
def using_copy_on_write():
2371-
return _mode_options["copy_on_write"]

pandas/core/series.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222

2323
import numpy as np
2424

25-
from pandas._config import get_option
25+
from pandas._config import (
26+
get_option,
27+
using_copy_on_write,
28+
)
2629

2730
from pandas._libs import (
2831
lib,
@@ -1263,10 +1266,7 @@ def _maybe_update_cacher(
12631266
# for CoW, we never want to update the parent DataFrame cache
12641267
# if the Series changed, and always pop the cached item
12651268
elif (
1266-
not (
1267-
get_option("mode.copy_on_write")
1268-
and get_option("mode.data_manager") == "block"
1269-
)
1269+
not using_copy_on_write()
12701270
and len(self) == len(ref)
12711271
and self.name in ref.columns
12721272
):

scripts/validate_unwanted_patterns.py

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"_test_decorators",
5353
"__version__", # check np.__version__ in compat.numpy.function
5454
"_arrow_dtype_mapping",
55+
"_global_config",
5556
}
5657

5758

0 commit comments

Comments
 (0)