Skip to content

Commit 01521dd

Browse files
committed
Merge branch 'main' into tst-string-xfails
2 parents b98d48a + 7817cb2 commit 01521dd

File tree

7 files changed

+54
-2
lines changed

7 files changed

+54
-2
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/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/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(

pandas/tests/dtypes/cast/test_can_hold_element.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,22 @@ def test_can_hold_element_int8_int():
7777
assert not can_hold_element(arr, np.uint32(element))
7878
assert not can_hold_element(arr, np.int64(element))
7979
assert not can_hold_element(arr, np.uint64(element))
80+
81+
82+
def test_can_hold_element_bool():
83+
arr = np.array([], dtype=bool)
84+
85+
element = True
86+
assert can_hold_element(arr, element)
87+
assert can_hold_element(arr, np.array([element]))
88+
assert can_hold_element(arr, np.array([element], dtype=object))
89+
90+
element = 1
91+
assert not can_hold_element(arr, element)
92+
assert not can_hold_element(arr, np.array([element]))
93+
assert not can_hold_element(arr, np.array([element], dtype=object))
94+
95+
element = np.nan
96+
assert not can_hold_element(arr, element)
97+
assert not can_hold_element(arr, np.array([element]))
98+
assert not can_hold_element(arr, np.array([element], dtype=object))

pandas/tests/extension/test_arrow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3295,7 +3295,7 @@ def test_decimal_parse_raises():
32953295
# GH 56984
32963296
ser = pd.Series(["1.2345"], dtype=ArrowDtype(pa.string()))
32973297
with pytest.raises(
3298-
pa.lib.ArrowInvalid, match="Rescaling Decimal128 value would cause data loss"
3298+
pa.lib.ArrowInvalid, match="Rescaling Decimal(128)? value would cause data loss"
32993299
):
33003300
ser.astype(ArrowDtype(pa.decimal128(1, 0)))
33013301

pandas/tests/series/indexing/test_setitem.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,3 +1838,13 @@ def test_setitem_empty_mask_dont_upcast_dt64():
18381838
ser.mask(mask, "foo", inplace=True)
18391839
assert ser.dtype == dti.dtype # no-op -> dont upcast
18401840
tm.assert_series_equal(ser, orig)
1841+
1842+
1843+
def test_setitem_bool_dtype_with_boolean_indexer():
1844+
# GH 57338
1845+
s1 = Series([True, True, True], dtype=bool)
1846+
s2 = Series([False, False, False], dtype=bool)
1847+
condition = [False, True, False]
1848+
s1[condition] = s2[condition]
1849+
expected = Series([True, False, True], dtype=bool)
1850+
tm.assert_series_equal(s1, expected)

0 commit comments

Comments
 (0)