Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ def render(pieces, style):
}


def get_versions():
def get_versions() -> dict:
"""Get version information or return default if unable to do so."""
# I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have
# __file__, we can work backwards from there to the root. Some
Expand Down
10 changes: 10 additions & 0 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
from typing import (
TYPE_CHECKING,
Literal,
TypeVar,
cast,
overload,
)
import warnings

Expand Down Expand Up @@ -104,6 +106,8 @@
ExtensionArray,
)

T = TypeVar("T", bound=Index | Categorical | ExtensionArray)


# --------------- #
# dtype access #
Expand Down Expand Up @@ -314,6 +318,12 @@ def _check_object_for_strings(values: np.ndarray) -> str:
# --------------- #


@overload
def unique(values: T) -> T: ...
@overload
def unique(values: np.ndarray | Series) -> np.ndarray: ...


def unique(values):
"""
Return unique values based on a hash table.
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ def unique(self):
# i.e. ExtensionArray
result = values.unique()
else:
result = algorithms.unique1d(values)
result = algorithms.unique1d(values) # type: ignore[assignment]
return result

@final
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/groupby/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def recode_for_groupby(c: Categorical, sort: bool, observed: bool) -> Categorica
# In cases with c.ordered, this is equivalent to
# return c.remove_unused_categories(), c

take_codes = unique1d(c.codes[c.codes != -1]) # type: ignore[no-untyped-call]
take_codes = unique1d(c.codes[c.codes != -1])

if sort:
take_codes = np.sort(take_codes)
Expand All @@ -68,7 +68,7 @@ def recode_for_groupby(c: Categorical, sort: bool, observed: bool) -> Categorica

# GH:46909: Re-ordering codes faster than using (set|add|reorder)_categories
# GH 38140: exclude nan from indexer for categories
unique_notnan_codes = unique1d(c.codes[c.codes != -1]) # type: ignore[no-untyped-call]
unique_notnan_codes = unique1d(c.codes[c.codes != -1])
if sort:
unique_notnan_codes = np.sort(unique_notnan_codes)
if (num_cat := len(c.categories)) > len(unique_notnan_codes):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3304,7 +3304,7 @@ def _intersection(self, other: Index, sort: bool = False):
res = algos.unique1d(res_indexer)
else:
result = self.take(indexer)
res = result.drop_duplicates()
res = result.drop_duplicates() # type: ignore[assignment]
return ensure_wrapped_if_datetimelike(res)

res_values = self._intersection_via_get_indexer(other, sort=sort)
Expand Down
2 changes: 1 addition & 1 deletion pandas/util/_print_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _get_commit_hash() -> str | None:
except ImportError:
from pandas._version import get_versions

versions = get_versions() # type: ignore[no-untyped-call]
versions = get_versions()
return versions["full-revisionid"]


Expand Down
Loading