Skip to content

Commit 1fc040f

Browse files
author
Kashif Khan
committed
Merge remote-tracking branch 'upstream/master' into fix_mypy_err_reshape.py
2 parents 58b4f63 + 9512393 commit 1fc040f

File tree

8 files changed

+189
-111
lines changed

8 files changed

+189
-111
lines changed

.github/workflows/code-checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474

7575
- name: Install pyright
7676
# note: keep version in sync with .pre-commit-config.yaml
77-
run: npm install -g pyright@1.1.200
77+
run: npm install -g pyright@1.1.202
7878

7979
- name: Build Pandas
8080
id: build

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ repos:
7878
types: [python]
7979
stages: [manual]
8080
# note: keep version in sync with .github/workflows/ci.yml
81-
additional_dependencies: ['pyright@1.1.200']
81+
additional_dependencies: ['pyright@1.1.202']
8282
- repo: local
8383
hooks:
8484
- id: flake8-rst

pandas/_typing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
DatetimeLikeScalar = Union["Period", "Timestamp", "Timedelta"]
8585
PandasScalar = Union["Period", "Timestamp", "Timedelta", "Interval"]
8686
Scalar = Union[PythonScalar, PandasScalar]
87+
IntStrT = TypeVar("IntStrT", int, str)
8788

8889

8990
# timestamp and timedelta convertible types

pandas/core/algorithms.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def _get_values_for_rank(values: ArrayLike) -> np.ndarray:
298298
return values
299299

300300

301-
def get_data_algo(values: ArrayLike):
301+
def _get_data_algo(values: ArrayLike):
302302
values = _get_values_for_rank(values)
303303

304304
ndtype = _check_object_for_strings(values)
@@ -555,7 +555,7 @@ def factorize_array(
555555
codes : ndarray[np.intp]
556556
uniques : ndarray
557557
"""
558-
hash_klass, values = get_data_algo(values)
558+
hash_klass, values = _get_data_algo(values)
559559

560560
table = hash_klass(size_hint or len(values))
561561
uniques, codes = table.factorize(
@@ -1747,7 +1747,7 @@ def safe_sort(
17471747

17481748
if sorter is None:
17491749
# mixed types
1750-
hash_klass, values = get_data_algo(values)
1750+
hash_klass, values = _get_data_algo(values)
17511751
t = hash_klass(len(values))
17521752
t.map_locations(values)
17531753
sorter = ensure_platform_int(t.lookup(ordered))

pandas/core/arrays/categorical.py

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
)
5656
from pandas.core.dtypes.common import (
5757
ensure_int64,
58-
ensure_object,
5958
ensure_platform_int,
6059
is_categorical_dtype,
6160
is_datetime64_dtype,
@@ -96,7 +95,6 @@
9695
import pandas.core.algorithms as algorithms
9796
from pandas.core.algorithms import (
9897
factorize,
99-
get_data_algo,
10098
take_nd,
10199
unique1d,
102100
)
@@ -2760,8 +2758,6 @@ def _get_codes_for_values(values, categories: Index) -> np.ndarray:
27602758
27612759
If `values` is known to be a Categorical, use recode_for_categories instead.
27622760
"""
2763-
dtype_equal = is_dtype_equal(values.dtype, categories.dtype)
2764-
27652761
if values.ndim > 1:
27662762
flat = values.ravel()
27672763
codes = _get_codes_for_values(flat, categories)
@@ -2773,30 +2769,9 @@ def _get_codes_for_values(values, categories: Index) -> np.ndarray:
27732769
# Categorical(array[Period, Period], categories=PeriodIndex(...))
27742770
cls = categories.dtype.construct_array_type()
27752771
values = maybe_cast_to_extension_array(cls, values)
2776-
if not isinstance(values, cls):
2777-
# exception raised in _from_sequence
2778-
values = ensure_object(values)
2779-
# error: Incompatible types in assignment (expression has type
2780-
# "ndarray", variable has type "Index")
2781-
categories = ensure_object(categories) # type: ignore[assignment]
2782-
elif not dtype_equal:
2783-
values = ensure_object(values)
2784-
# error: Incompatible types in assignment (expression has type "ndarray",
2785-
# variable has type "Index")
2786-
categories = ensure_object(categories) # type: ignore[assignment]
2787-
2788-
if isinstance(categories, ABCIndex):
2789-
return coerce_indexer_dtype(categories.get_indexer_for(values), categories)
2790-
2791-
# Only hit here when we've already coerced to object dtypee.
2792-
2793-
hash_klass, vals = get_data_algo(values)
2794-
# pandas/core/arrays/categorical.py:2661: error: Argument 1 to "get_data_algo" has
2795-
# incompatible type "Index"; expected "Union[ExtensionArray, ndarray]" [arg-type]
2796-
_, cats = get_data_algo(categories) # type: ignore[arg-type]
2797-
t = hash_klass(len(cats))
2798-
t.map_locations(cats)
2799-
return coerce_indexer_dtype(t.lookup(vals), cats)
2772+
2773+
codes = categories.get_indexer_for(values)
2774+
return coerce_indexer_dtype(codes, categories)
28002775

28012776

28022777
def recode_for_categories(

0 commit comments

Comments
 (0)