-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
Description
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
from pandas import DataFrame
df_e = DataFrame([["x", 10.0, 20.0], ["y", 30.0, 40.0]])
print(df_e.loc[0, slice(1, 3)])Issue Description
When selecting columns using slices from a DataFrame that contains mixed data types, the resulting columns always have the dtype object, even when all the selected elements share the same data type (for example, float64). This issue was previously reported and fixed for array-based column selection in Issue #60600, but it still occurs when selecting columns with slices.
Expected Behavior
# Current Output:
1 10.0
2 20.0
Name: 0, dtype: object
# Expected Output:
1 10.0
2 20.0
Name: 0, dtype: float64
Installed Versions
pandas : 2.3.3
numpy : 2.3.4
pytz : 2025.2
dateutil : 2.9.0.post0
pip : 25.2
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : 22.0.0
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : N/A
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2025.2
qtpy : None
pyqt5 : None
None