Skip to content

FIX-#7723: Keep column labels in DataFrame.cov when min_periods exceeds the row count - #7724

Open
Amorth wants to merge 1 commit into
modin-project:mainfrom
Amorth:fix-cov-min-periods-labels
Open

Amorth wants to merge 1 commit into
modin-project:mainfrom
Amorth:fix-cov-min-periods-labels

Conversation

@Amorth

@Amorth Amorth commented Nov 27, 2026

Copy link
Copy Markdown

What do these changes do?

DataFrame.cov(min_periods=n) with n larger than the number of rows returns an all-NaN matrix labelled 0..k-1 on both axes instead of the column labels, unlike pandas.

import modin.pandas as pd
import pandas

data = {"a": [1, 2, 3], "b": [3, 2, 5]}
print(pandas.DataFrame(data).cov(min_periods=4))
print(pd.DataFrame(data).cov(min_periods=4))
pandas:
     a   b
a NaN NaN
b NaN NaN
modin:
     0   1
0 NaN NaN
1 NaN NaN

The early-return branch in DataFrame.cov (modin/pandas/dataframe.py) builds the NaN result from a bare NumPy array, so the frame gets a default RangeIndex on both axes. The change passes cov_df.columns as both index and columns, which matches pandas.

Added test_cov_min_periods_greater_than_length in modin/tests/pandas/dataframe/test_default.py (compares with pandas through eval_general). It fails without the change and passes with it (MODIN_ENGINE=python). The existing cov tests pass, and black --check, flake8 and isort --check pass on the touched files.

…periods exceeds the row count

Signed-off-by: yangpei <19790187+Amorth@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: DataFrame.cov loses column labels when min_periods exceeds the number of rows

1 participant