Skip to content

Commit bfcca21

Browse files
Merge branch 'main' into main
2 parents ead07af + cd0efe1 commit bfcca21

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

pandas/core/dtypes/astype.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ def _astype_float_to_int_nansafe(
144144
"""
145145
if not np.isfinite(values).all():
146146
raise IntCastingNaNError(
147-
"Cannot convert non-finite values (NA or inf) to integer"
147+
"Cannot convert non-finite values (NA or inf) to integer."
148+
"Replace or remove non-finite values or cast to an integer type"
149+
"that supports these values (e.g. 'Int64')"
148150
)
149151
if dtype.kind == "u":
150152
# GH#45151

pandas/tests/indexing/multiindex/test_setitem.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,24 @@ def test_setitem_enlargement_keep_index_names(self):
490490
)
491491
tm.assert_frame_equal(df, expected)
492492

493+
def test_setitem_enlargement_multiindex_with_none(self):
494+
# GH#59153
495+
# enlarging a DataFrame with a MultiIndex containing None values
496+
index = MultiIndex.from_tuples(
497+
[("A", "a1"), ("A", "a2"), ("B", "b1"), ("B", None)]
498+
)
499+
df = DataFrame([(0.0, 6.0), (1.0, 5.0), (2.0, 4.0), (3.0, 7.0)], index=index)
500+
df.loc[("A", None), :] = [12.0, 13.0]
501+
expected_index = MultiIndex.from_tuples(
502+
[("A", "a1"), ("A", "a2"), ("B", "b1"), ("B", None), ("A", None)]
503+
)
504+
expected = DataFrame(
505+
[[0.0, 6.0], [1.0, 5.0], [2.0, 4.0], [3.0, 7.0], [12.0, 13.0]],
506+
index=expected_index,
507+
columns=[0, 1],
508+
)
509+
tm.assert_frame_equal(df, expected, check_index_type=False)
510+
493511

494512
def test_frame_setitem_view_direct(multiindex_dataframe_random_data):
495513
# this works because we are modifying the underlying array

0 commit comments

Comments
 (0)