Skip to content

Commit 4e6cde7

Browse files
committed
Merge remote-tracking branch 'upstream/main' into read-csv-from-directory
2 parents d85b997 + 7817cb2 commit 4e6cde7

File tree

22 files changed

+106
-57
lines changed

22 files changed

+106
-57
lines changed

ci/deps/actions-311-downstream_compat.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ dependencies:
5050
- pytz>=2023.4
5151
- pyxlsb>=1.0.10
5252
- s3fs>=2023.12.2
53-
- scipy>=1.12.0
53+
# TEMP upper pin for scipy (https://github.com/statsmodels/statsmodels/issues/9584)
54+
- scipy>=1.12.0,<1.16
5455
- sqlalchemy>=2.0.0
5556
- tabulate>=0.9.0
5657
- xarray>=2024.1.1

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,7 @@ Indexing
752752
- Bug in :meth:`DataFrame.loc` with inconsistent behavior of loc-set with 2 given indexes to Series (:issue:`59933`)
753753
- Bug in :meth:`Index.get_indexer` and similar methods when ``NaN`` is located at or after position 128 (:issue:`58924`)
754754
- Bug in :meth:`MultiIndex.insert` when a new value inserted to a datetime-like level gets cast to ``NaT`` and fails indexing (:issue:`60388`)
755+
- Bug in :meth:`Series.__setitem__` when assigning boolean series with boolean indexer will raise ``LossySetitemError`` (:issue:`57338`)
755756
- Bug in printing :attr:`Index.names` and :attr:`MultiIndex.levels` would not escape single quotes (:issue:`60190`)
756757
- Bug in reindexing of :class:`DataFrame` with :class:`PeriodDtype` columns in case of consolidated block (:issue:`60980`, :issue:`60273`)
757758

pandas/core/apply.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
TYPE_CHECKING,
1111
Any,
1212
Literal,
13+
TypeAlias,
1314
cast,
1415
)
1516

@@ -71,7 +72,7 @@
7172
from pandas.core.resample import Resampler
7273
from pandas.core.window.rolling import BaseWindow
7374

74-
ResType = dict[int, Any]
75+
ResType: TypeAlias = dict[int, Any]
7576

7677

7778
class BaseExecutionEngine(abc.ABC):

pandas/core/arrays/datetimelike.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
TYPE_CHECKING,
1111
Any,
1212
Literal,
13+
TypeAlias,
1314
Union,
1415
cast,
1516
final,
@@ -161,7 +162,7 @@
161162
TimedeltaArray,
162163
)
163164

164-
DTScalarOrNaT = Union[DatetimeLikeScalar, NaTType]
165+
DTScalarOrNaT: TypeAlias = DatetimeLikeScalar | NaTType
165166

166167

167168
def _make_unpacked_invalid_op(op_name: str):
@@ -386,7 +387,7 @@ def __getitem__(self, key: PositionalIndexer2D) -> Self | DTScalarOrNaT:
386387
# Use cast as we know we will get back a DatetimeLikeArray or DTScalar,
387388
# but skip evaluating the Union at runtime for performance
388389
# (see https://github.com/pandas-dev/pandas/pull/44624)
389-
result = cast("Union[Self, DTScalarOrNaT]", super().__getitem__(key))
390+
result = cast(Union[Self, DTScalarOrNaT], super().__getitem__(key))
390391
if lib.is_scalar(result):
391392
return result
392393
else:

pandas/core/arrays/interval.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing import (
1010
TYPE_CHECKING,
1111
Literal,
12-
Union,
12+
TypeAlias,
1313
overload,
1414
)
1515

@@ -109,8 +109,8 @@
109109
)
110110

111111

112-
IntervalSide = Union[TimeArrayLike, np.ndarray]
113-
IntervalOrNA = Union[Interval, float]
112+
IntervalSide: TypeAlias = TimeArrayLike | np.ndarray
113+
IntervalOrNA: TypeAlias = Interval | float
114114

115115
_interval_shared_docs: dict[str, str] = {}
116116

pandas/core/arrays/string_arrow.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import re
55
from typing import (
66
TYPE_CHECKING,
7-
Union,
87
)
98
import warnings
109

@@ -63,9 +62,6 @@
6362
from pandas import Series
6463

6564

66-
ArrowStringScalarOrNAT = Union[str, libmissing.NAType]
67-
68-
6965
def _chk_pyarrow_available() -> None:
7066
if pa_version_under10p1:
7167
msg = "pyarrow>=10.0.1 is required for PyArrow backed ArrowExtensionArray."

pandas/core/dtypes/cast.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,10 @@ def np_can_hold_element(dtype: np.dtype, element: Any) -> Any:
19261926
# i.e. there are pd.NA elements
19271927
raise LossySetitemError
19281928
return element
1929+
# GH 57338 check boolean array set as object type
1930+
if tipo.kind == "O" and isinstance(element, np.ndarray):
1931+
if lib.is_bool_array(element):
1932+
return element.astype("bool")
19291933
raise LossySetitemError
19301934
if lib.is_bool(element):
19311935
return element

pandas/core/groupby/generic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
Any,
1818
Literal,
1919
NamedTuple,
20+
TypeAlias,
2021
TypeVar,
21-
Union,
2222
cast,
2323
)
2424
import warnings
@@ -102,7 +102,7 @@
102102
from pandas.core.generic import NDFrame
103103

104104
# TODO(typing) the return value on this callable should be any *scalar*.
105-
AggScalar = Union[str, Callable[..., Any]]
105+
AggScalar: TypeAlias = str | Callable[..., Any]
106106
# TODO: validate types on ScalarResult and move to _typing
107107
# Blocked from using by https://github.com/python/mypy/issues/1484
108108
# See note at _mangle_lambda_list

pandas/core/groupby/groupby.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class providing the base-class of operations.
2626
from typing import (
2727
TYPE_CHECKING,
2828
Literal,
29+
TypeAlias,
2930
TypeVar,
3031
Union,
3132
cast,
@@ -449,13 +450,13 @@ def f(self):
449450
return attr
450451

451452

452-
_KeysArgType = Union[
453-
Hashable,
454-
list[Hashable],
455-
Callable[[Hashable], Hashable],
456-
list[Callable[[Hashable], Hashable]],
457-
Mapping[Hashable, Hashable],
458-
]
453+
_KeysArgType: TypeAlias = (
454+
Hashable
455+
| list[Hashable]
456+
| Callable[[Hashable], Hashable]
457+
| list[Callable[[Hashable], Hashable]]
458+
| Mapping[Hashable, Hashable]
459+
)
459460

460461

461462
class BaseGroupBy(PandasObject, SelectionMixin[NDFrameT], GroupByIndexingMixin):
@@ -957,9 +958,8 @@ def __iter__(self) -> Iterator[tuple[Hashable, NDFrameT]]:
957958
level = self.level
958959
result = self._grouper.get_iterator(self._selected_obj)
959960
# mypy: Argument 1 to "len" has incompatible type "Hashable"; expected "Sized"
960-
if (
961-
(is_list_like(level) and len(level) == 1) # type: ignore[arg-type]
962-
or (isinstance(keys, list) and len(keys) == 1)
961+
if (is_list_like(level) and len(level) == 1) or ( # type: ignore[arg-type]
962+
isinstance(keys, list) and len(keys) == 1
963963
):
964964
# GH#42795 - when keys is a list, return tuples even when length is 1
965965
result = (((key,), group) for key, group in result)

pandas/core/indexes/base.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7026,6 +7026,23 @@ def infer_objects(self, copy: bool = True) -> Index:
70267026
----------
70277027
copy : bool, default True
70287028
Whether to make a copy in cases where no inference occurs.
7029+
7030+
Returns
7031+
-------
7032+
Index
7033+
An Index with a new dtype if the dtype was inferred
7034+
or a shallow copy if the dtype could not be inferred.
7035+
7036+
See Also
7037+
--------
7038+
Index.inferred_type: Return a string of the type inferred from the values.
7039+
7040+
Examples
7041+
--------
7042+
>>> pd.Index(["a", 1]).infer_objects()
7043+
Index(['a', '1'], dtype='object')
7044+
>>> pd.Index([1, 2], dtype="object").infer_objects()
7045+
Index([1, 2], dtype='int64')
70297046
"""
70307047
if self._is_multi:
70317048
raise NotImplementedError(

0 commit comments

Comments
 (0)