Skip to content

DEPR: Enforce deprecation of ArrayManager #57118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 31, 2024
2 changes: 0 additions & 2 deletions asv_bench/benchmarks/frame_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,6 @@ def setup(self):
N = 10000
# this is the worst case, where every column has NaNs.
arr = np.random.randn(N, 100)
# NB: we need to set values in array, not in df.values, otherwise
# the benchmark will be misleading for ArrayManager
arr[::2] = np.nan

self.df = DataFrame(arr)
Expand Down
5 changes: 1 addition & 4 deletions pandas/_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@

def using_copy_on_write() -> bool:
_mode_options = _global_config["mode"]
return (
_mode_options["copy_on_write"] is True
and _mode_options["data_manager"] == "block"
)
return _mode_options["copy_on_write"] is True


def warn_copy_on_write() -> bool:
Expand Down
11 changes: 4 additions & 7 deletions pandas/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
Optional,
Protocol,
Type as type_t,
TypeAlias,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not supported in python 3.9, so you should import it from typing_extensions

TypeVar,
Union,
overload,
Expand Down Expand Up @@ -61,9 +62,7 @@
)
from pandas.core.indexes.base import Index
from pandas.core.internals import (
ArrayManager,
BlockManager,
SingleArrayManager,
SingleBlockManager,
)
from pandas.core.resample import Resampler
Expand Down Expand Up @@ -382,11 +381,9 @@ def closed(self) -> bool:
]

# internals
Manager = Union[
"ArrayManager", "SingleArrayManager", "BlockManager", "SingleBlockManager"
]
SingleManager = Union["SingleArrayManager", "SingleBlockManager"]
Manager2D = Union["ArrayManager", "BlockManager"]
Manager = Union["BlockManager", "SingleBlockManager"]
SingleManager: TypeAlias = "SingleBlockManager"
Manager2D: TypeAlias = "BlockManager"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if these are still useful - can remove

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only useful if they are used elsewhere in the code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are used - but I'm not sure that makes them useful. We can replace any current usage of SingleManager with SingleBlockManager.

I tracked it down, this was added in #40152, so I think it makes sense to remove.


# indexing
# PositionalIndexer -> valid 1D positional indexer, e.g. can pass
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ def series_generator(self) -> Generator[Series, None, None]:
ser = self.obj._ixs(0, axis=0)
mgr = ser._mgr

is_view = mgr.blocks[0].refs.has_reference() # type: ignore[union-attr]
is_view = mgr.blocks[0].refs.has_reference()

if isinstance(ser.dtype, ExtensionDtype):
# values will be incorrect for this block
Expand All @@ -1278,7 +1278,7 @@ def series_generator(self) -> Generator[Series, None, None]:
# -> if that happened and `ser` is already a copy, then we reset
# the refs here to avoid triggering a unnecessary CoW inside the
# applied function (https://github.com/pandas-dev/pandas/pull/56212)
mgr.blocks[0].refs = BlockValuesRefs(mgr.blocks[0]) # type: ignore[union-attr]
mgr.blocks[0].refs = BlockValuesRefs(mgr.blocks[0])
yield ser

@staticmethod
Expand Down
7 changes: 2 additions & 5 deletions pandas/core/arraylike.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,7 @@ def array_ufunc(self, ufunc: np.ufunc, method: str, *inputs: Any, **kwargs: Any)
Series,
)
from pandas.core.generic import NDFrame
from pandas.core.internals import (
ArrayManager,
BlockManager,
)
from pandas.core.internals import BlockManager

cls = type(self)

Expand Down Expand Up @@ -350,7 +347,7 @@ def _reconstruct(result):
if method == "outer":
raise NotImplementedError
return result
if isinstance(result, (BlockManager, ArrayManager)):
if isinstance(result, (BlockManager)):
# we went through BlockManager.apply e.g. np.sqrt
result = self._constructor_from_mgr(result, axes=result.axes)
else:
Expand Down
26 changes: 0 additions & 26 deletions pandas/core/config_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,32 +436,6 @@ def use_inf_as_na_cb(key) -> None:
"version. Convert inf values to NaN before operating instead.",
)

data_manager_doc = """
: string
Internal data manager type; can be "block" or "array". Defaults to "block",
unless overridden by the 'PANDAS_DATA_MANAGER' environment variable (needs
to be set before pandas is imported).
"""


with cf.config_prefix("mode"):
cf.register_option(
"data_manager",
# Get the default from an environment variable, if set, otherwise defaults
# to "block". This environment variable can be set for testing.
os.environ.get("PANDAS_DATA_MANAGER", "block"),
data_manager_doc,
validator=is_one_of_factory(["block", "array"]),
)

cf.deprecate_option(
# GH#55043
"mode.data_manager",
"data_manager option is deprecated and will be removed in a future "
"version. Only the BlockManager will be available.",
)


# TODO better name?
copy_on_write_doc = """
: bool
Expand Down
Loading