8000 BUG: reindex with level specified does not expand data · Issue #59170 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content
BUG: reindex with level specified does not expand data #59170
Open
@seanv507

Description

@seanv507

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
z3 = pd.DataFrame({"a":[10], "b":[2], "c": [1]}).set_index(["a", "b"])
maturities = list(range(100))
z4 = z3.reindex(maturities,level=1)

Issue Description

I create a 1 row dataframe with multiindex
I reindex on a single level, and I expect all values in the new index to be in the new dataframe.
instead, the same dataframe is returned.

the same happens with more than a single row.

If I use a 1d index, or apply to the columns, I get a 100 row/column dataframe as expected

Expected Behavior

expected_output = pd.DataFrame({"a":10, "b": range(100), "c": np.nan}).set_index(["a", "b"])
expected_output.loc[(10,2), "c"]=1

expected_output.head()
#          c
# a  b     
# 10 0  NaN
#    1  NaN
#    2  1.0
#    3  NaN
#    4  NaN

Installed Versions

INSTALLED VERSIONS ------------------ commit : e86ed37 python : 3.11.5.final.0 python-bits : 64 OS : Darwin OS-release : 23.5.0 Version : Darwin Kernel Version 23.5.0: Wed May 1 20:19:05 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T8112 machine : arm64 processor : arm byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8

pandas : 2.1.1
numpy : 1.26.0
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.2.2
pip : 23.2.1
Cython : None
pytest : None
hypothesis : None
sphinx : 7.2.6
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.15.0
pandas_datareader : None
bs4 : None
bottleneck : None
dataframe-api-compat: None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.0
numba : None
numexpr : None
odfpy 5BBF : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.11.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0