Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1f8c628
init commit kendall spearman ordinal cats
pandeconscious Oct 23, 2025
906f1e4
Merge branch 'pandas-dev:main' into ordered_cat_corr
pandeconscious Oct 27, 2025
497dc7e
series test update and fixes
pandeconscious Oct 27, 2025
583aca6
cat desc longer in tests
pandeconscious Oct 27, 2025
e069810
testing frame corr
pandeconscious Oct 27, 2025
b90726f
pre commit fixes v2
pandeconscious Oct 27, 2025
65a506c
cleanup
pandeconscious Oct 27, 2025
ab3b8b9
Merge branch 'pandas-dev:main' into ordered_cat_corr
pandeconscious Nov 4, 2025
e93ed83
test import scipy fix
pandeconscious Nov 4, 2025
ec4d97e
rst sorting autofix
pandeconscious Nov 4, 2025
ebfc3b0
Merge branch 'pandas-dev:main' into ordered_cat_corr
pandeconscious Nov 4, 2025
8cfacef
Merge branch 'pandas-dev:main' into ordered_cat_corr
pandeconscious Nov 5, 2025
7ef7fb2
Merge branch 'pandas-dev:main' into ordered_cat_corr
pandeconscious Nov 12, 2025
588808a
refactor
pandeconscious Nov 12, 2025
c484552
fix dtype for duplicates
pandeconscious Nov 12, 2025
216475c
Merge branch 'pandas-dev:main' into ordered_cat_corr
pandeconscious Nov 16, 2025
e997747
clean up
pandeconscious Nov 16, 2025
4184167
Merge branch 'pandas-dev:main' into ordered_cat_corr
pandeconscious Nov 16, 2025
8bcd3dc
Merge branch 'pandas-dev:main' into ordered_cat_corr
pandeconscious Nov 18, 2025
2673281
clean up
pandeconscious Nov 18, 2025
ff48847
import fix
pandeconscious Nov 18, 2025
1c69e29
test tranform ordered cat func
pandeconscious Nov 18, 2025
8b26a7d
tests and mypy fixes
pandeconscious Nov 18, 2025
a625520
type check fix
pandeconscious Nov 18, 2025
259424e
addressing review comments
pandeconscious Nov 18, 2025
f141e6a
Merge branch 'main' into ordered_cat_corr
pandeconscious Nov 18, 2025
d2d0f71
type fix corr.py
pandeconscious Nov 19, 2025
858d0c2
ruff format
pandeconscious Nov 19, 2025
a8c88c7
mypy fix
pandeconscious Nov 19, 2025
1a472e3
Merge branch 'main' into ordered_cat_corr
pandeconscious Nov 19, 2025
71305aa
scipy unavailable fix in test
pandeconscious Nov 19, 2025
89e30cc
Merge branch 'pandas-dev:main' into ordered_cat_corr
pandeconscious Nov 28, 2025
9aa9ece
issue name before each test
pandeconscious Nov 28, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor
  • Loading branch information
pandeconscious committed Nov 12, 2025
commit 588808a6960a5cc2620cffc8902bcd47262713f4
27 changes: 21 additions & 6 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
from pandas.core.dtypes.dtypes import (
ArrowDtype,
BaseMaskedDtype,
CategoricalDtype,
ExtensionDtype,
)
from pandas.core.dtypes.generic import (
Expand Down Expand Up @@ -12015,15 +12016,29 @@ def _transform_ord_cat_cols_to_coded_cols(self) -> DataFrame:
if len(categ.columns) == 0:
return self

cols_convert = categ.loc[:, categ.agg(lambda x: x.cat.ordered)].columns
cols_convert = categ.loc[:, categ.agg(lambda x: x.cat.ordered)].columns.unique()
single_cols = [col for col in cols_convert if isinstance(categ[col], Series)]
duplicated_cols = [
col for col in cols_convert if isinstance(categ[col], DataFrame)
]

if len(cols_convert) > 0:
data = self.copy(deep=False)
data[cols_convert] = data[cols_convert].transform(
if not single_cols and not duplicated_cols:
return self

data = self.copy(deep=False)
if single_cols:
data[single_cols] = data[single_cols].transform(
lambda x: x.cat.codes.replace(-1, np.nan)
)
return data
return self

if duplicated_cols:
data[duplicated_cols] = data[duplicated_cols].apply(
lambda x: x.cat.codes.replace(-1, np.nan)
if isinstance(x, CategoricalDtype) and bool(x.ordered)
else x
)

return data

# ----------------------------------------------------------------------
# ndarray-like stats methods
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/methods/test_cov_corr.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,11 @@ def test_corr_numeric_only(self, meth, numeric_only):
df.corr(meth, numeric_only=numeric_only)

@pytest.mark.parametrize("method", ["kendall", "spearman"])
@td.skip_if_no("scipy")
def test_corr_rank_ordered_categorical(
self,
method,
):
pytest.importorskip("scipy")
df = DataFrame(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add # GH #60306 to the start of each test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

{
"ord_cat": Series(
Expand Down
Loading