Skip to content

Commit 47fc9b6

Browse files
GH1037 Remove na_sentinel from factorize methods (#1038)
* GH1037 Remove na_sentinel from factorize methods * GH1037 PR feedback * GH1037 PR feedback * GH1037 PR feedback
1 parent 70ee340 commit 47fc9b6

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

pandas-stubs/core/algorithms.pyi

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,13 @@ def factorize(
5252
def factorize(
5353
values: Index | Series,
5454
sort: bool = ...,
55-
# Not actually positional-only, used to handle deprecations in 1.5.0
56-
*,
5755
use_na_sentinel: bool = ...,
5856
size_hint: int | None = ...,
5957
) -> tuple[np.ndarray, Index]: ...
6058
@overload
6159
def factorize(
6260
values: Categorical,
6361
sort: bool = ...,
64-
# Not actually positional-only, used to handle deprecations in 1.5.0
65-
*,
6662
use_na_sentinel: bool = ...,
6763
size_hint: int | None = ...,
6864
) -> tuple[np.ndarray, Categorical]: ...

pandas-stubs/core/arrays/base.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ class ExtensionArray:
4242
def shift(self, periods: int = ..., fill_value: object = ...) -> Self: ...
4343
def unique(self): ...
4444
def searchsorted(self, value, side: str = ..., sorter=...): ...
45-
# TODO: remove keyword-only when pandas removed na_sentinel
46-
def factorize(self, *, use_na_sentinel: bool = ...) -> tuple[np.ndarray, Self]: ...
45+
def factorize(self, use_na_sentinel: bool = ...) -> tuple[np.ndarray, Self]: ...
4746
def repeat(self, repeats, axis=...): ...
4847
def take(
4948
self,

pandas-stubs/core/base.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class IndexOpsMixin(OpsMixin, Generic[S1]):
106106
@property
107107
def is_monotonic_increasing(self) -> bool: ...
108108
def factorize(
109-
self, sort: bool = ...
109+
self, sort: bool = ..., use_na_sentinel: bool = ...
110110
) -> tuple[np.ndarray, np.ndarray | Index | Categorical]: ...
111111
def searchsorted(
112112
self, value, side: Literal["left", "right"] = ..., sorter=...

tests/test_indexes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import numpy as np
77
from numpy import typing as npt
88
import pandas as pd
9+
from pandas.core.arrays.categorical import Categorical
10+
from pandas.core.indexes.base import Index
911
from typing_extensions import (
1012
Never,
1113
assert_type,
@@ -1160,3 +1162,16 @@ def test_value_counts() -> None:
11601162
pd.Series,
11611163
float,
11621164
)
1165+
1166+
1167+
def test_index_factorize() -> None:
1168+
"""Test Index.factorize method."""
1169+
codes, idx_uniques = pd.Index(["b", "b", "a", "c", "b"]).factorize()
1170+
check(assert_type(codes, np.ndarray), np.ndarray)
1171+
check(assert_type(idx_uniques, np.ndarray | Index | Categorical), pd.Index)
1172+
1173+
codes, idx_uniques = pd.Index(["b", "b", "a", "c", "b"]).factorize(
1174+
use_na_sentinel=False
1175+
)
1176+
check(assert_type(codes, np.ndarray), np.ndarray)
1177+
check(assert_type(idx_uniques, np.ndarray | Index | Categorical), pd.Index)

0 commit comments

Comments
 (0)