Skip to content

BUG: DataFrame.loc assignment with boolean column indexer raises NotImplementedError for single-column DataFrame #66527

Description

@kanade-ao

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd

left = pd.DataFrame(
    {"A": [f"x{i}" for i in range(60)]},
)

# left.loc[:, [True]] = left.loc[:, [True]]
left.loc[:, left.columns.isin(["A"])] = left.loc[:, left.columns.isin(["A"])]
Traceback (most recent call last):
  File "/Users/user/PycharmProjects/pythonProject/test.py", line 7, in <module>
    left.iloc[:, [True]] = left.iloc[:, [True]]
    ~~~~~~~~~^^^^^^^^^^^
  File "/Users/user/PycharmProjects/pythonProject/.venv/lib/python3.14/site-packages/pandas/core/indexing.py", line 938, in __setitem__
    iloc._setitem_with_indexer(indexer, value, self.name)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/PycharmProjects/pythonProject/.venv/lib/python3.14/site-packages/pandas/core/indexing.py", line 1955, in _setitem_with_indexer
    self._setitem_single_block(indexer, value, name)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/PycharmProjects/pythonProject/.venv/lib/python3.14/site-packages/pandas/core/indexing.py", line 2219, in _setitem_single_block
    self.obj._mgr = self.obj._mgr.setitem(indexer=indexer, value=value)
                    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/PycharmProjects/pythonProject/.venv/lib/python3.14/site-packages/pandas/core/internals/managers.py", line 620, in setitem
    return self.apply("setitem", indexer=indexer, value=value)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/PycharmProjects/pythonProject/.venv/lib/python3.14/site-packages/pandas/core/internals/managers.py", line 445, in apply
    applied = getattr(b, f)(**kwargs)
  File "/Users/user/PycharmProjects/pythonProject/.venv/lib/python3.14/site-packages/pandas/core/internals/blocks.py", line 1658, in setitem
    indexer = self._unwrap_setitem_indexer(indexer)
  File "/Users/user/PycharmProjects/pythonProject/.venv/lib/python3.14/site-packages/pandas/core/internals/blocks.py", line 2027, in _unwrap_setitem_indexer
    raise NotImplementedError(
    ...<2 lines>...
    )
NotImplementedError: This should not be reached. Please report a bug at github.com/pandas-dev/pandas/

Issue Description

After upgrading to pandas 3.0.x, I encountered a NotImplementedError when assigning a DataFrame selected by a boolean column indexer back to itself using .loc.

The issue only occurs when the DataFrame contains a single column. If an additional column is added, or if an explicit column label is used instead of a boolean column indexer, the assignment succeeds.

This appears to be an inconsistency in the internal assignment implementation rather than an invalid user operation.

Additional Information

The issue seems to occur only for a single-column DataFrame.

The following examples work correctly:

import pandas as pd

left = pd.DataFrame(
    {
        "A": [f"x{i}" for i in range(60)],
        "B": [f"y{i}" for i in range(60)],
    }
)

left.loc[:, [True, False]] = left.loc[:, [True, False]]

Expected Behavior

The assignment should succeed without raising an exception.

This is equivalent to assigning the selected DataFrame back to itself.

Installed Versions

Details

INSTALLED VERSIONS

commit : e68db09
python : 3.14.0
python-bits : 64
OS : Darwin
OS-release : 24.6.0
Version : Darwin Kernel Version 24.6.0: Tue Apr 21 20:16:56 PDT 2026; root:xnu-11417.140.69.710.16~1/RELEASE_ARM64_T6030
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : None
LOCALE : en_US.UTF-8

pandas : 3.0.5
numpy : 2.5.1
dateutil : 2.9.0.post0
pip : None
Cython : None
sphinx : None
IPython : 9.15.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.15.0
bottleneck : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.6
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
psycopg2 : None
pymysql : None
pyarrow : None
pyiceberg : None
pyreadstat : None
pytest : None
python-calamine : None
pytz : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
qtpy : None
pyqt5 : None
None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions