Skip to content

ENH: Support pd.col in .loc for Series #63277

@mattharrison

Description

@mattharrison

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

mport pandas as pd

cost = pd.Series([1.00, 2.25, 3.99, .99, 2.79], 
                 index=['Gum', 'Cookie', 'Melon', 'Roll', 'Carrots'],
                 name='s')
inflation = 1.10


# For Series, this fails:
(cost
    .mul(inflation)
    .loc[pd.col('s') > 3]  # Fails: pd.col not supported for Series
)

# I need to write it like this (with lambdas):
(cost
     .mul(inflation)
     .loc[lambda s_: s_ > 3]
)

Issue Description

Summary:
In pandas 3.x, the new pd.col API is supported for .loc indexing in DataFrames, but not in Series. This leads to inconsistent behavior and confusion for users expecting parity between DataFrame and Series indexing.

Expected Behavior:
pd.col should work for .loc on Series, just as it does for DataFrames.

Actual Behavior:
Raises an error: TypeError: 'Series' object is not subscriptable with pd.col.

Expected Behavior

I can refer to the series by the name of it with pd.col in .loc

Installed Versions

INSTALLED VERSIONS

commit : 1a3230d
python : 3.11.13
python-bits : 64
OS : Darwin
OS-release : 24.6.0
Version : Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:40 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6041
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : None
LOCALE : en_US.UTF-8

pandas : 3.0.0rc0
numpy : 2.4.0rc1
dateutil : 2.9.0.post0
pip : None
Cython : None
sphinx : None
IPython : 9.8.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.14.3
bottleneck : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.6
lxml.etree : None
matplotlib : 3.10.7
numba : None
numexpr : None
odfpy : None
openpyxl : None
psycopg2 : None
pymysql : None
pyarrow : 22.0.0
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementNeeds DiscussionRequires discussion from core team before further actionexpressionspd.eval, query, pd.col

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions