Skip to content

Commit

Permalink
CLN: fix and move using_copy_on_write() helper out of internals (#50675)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche authored Jan 11, 2023
1 parent 2797b84 commit 710b83b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
7 changes: 7 additions & 0 deletions pandas/_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
"describe_option",
"option_context",
"options",
"using_copy_on_write",
]
from pandas._config import config
from pandas._config import dates # pyright: ignore # noqa:F401
from pandas._config.config import (
_global_config,
describe_option,
get_option,
option_context,
Expand All @@ -26,3 +28,8 @@
set_option,
)
from pandas._config.display import detect_console_encoding


def using_copy_on_write():
_mode_options = _global_config["mode"]
return _mode_options["copy_on_write"] and _mode_options["data_manager"] == "block"
11 changes: 5 additions & 6 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@

import numpy as np

from pandas._config import config
from pandas._config import (
config,
using_copy_on_write,
)

from pandas._libs import lib
from pandas._libs.tslibs import (
Expand Down Expand Up @@ -158,7 +161,6 @@
SingleArrayManager,
)
from pandas.core.internals.construction import mgr_to_mgr
from pandas.core.internals.managers import using_copy_on_write
from pandas.core.methods.describe import describe_ndframe
from pandas.core.missing import (
clean_fill_method,
Expand Down Expand Up @@ -4023,10 +4025,7 @@ def _check_setitem_copy(self, t: str = "setting", force: bool_t = False):
df.iloc[0:5]['group'] = 'a'
"""
if (
config.get_option("mode.copy_on_write")
and config.get_option("mode.data_manager") == "block"
):
if using_copy_on_write():
return

# return early if the check is not needed
Expand Down
9 changes: 1 addition & 8 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import numpy as np

from pandas._config import config
from pandas._config import using_copy_on_write

from pandas._libs import (
algos as libalgos,
Expand Down Expand Up @@ -2362,10 +2362,3 @@ def _preprocess_slice_or_indexer(
if not allow_fill:
indexer = maybe_convert_indices(indexer, length)
return "fancy", indexer, len(indexer)


_mode_options = config._global_config["mode"]


def using_copy_on_write():
return _mode_options["copy_on_write"]
10 changes: 5 additions & 5 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@

import numpy as np

from pandas._config import get_option
from pandas._config import (
get_option,
using_copy_on_write,
)

from pandas._libs import (
lib,
Expand Down Expand Up @@ -1263,10 +1266,7 @@ def _maybe_update_cacher(
# for CoW, we never want to update the parent DataFrame cache
# if the Series changed, and always pop the cached item
elif (
not (
get_option("mode.copy_on_write")
and get_option("mode.data_manager") == "block"
)
not using_copy_on_write()
and len(self) == len(ref)
and self.name in ref.columns
):
Expand Down
1 change: 1 addition & 0 deletions scripts/validate_unwanted_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"_test_decorators",
"__version__", # check np.__version__ in compat.numpy.function
"_arrow_dtype_mapping",
"_global_config",
}


Expand Down

0 comments on commit 710b83b

Please sign in to comment.