Skip to content

Commit 2af89ac

Browse files
Terji Petersentopper-123
Terji Petersen
authored andcommitted
fix various issues
1 parent 6f10026 commit 2af89ac

File tree

3 files changed

+9
-24
lines changed

3 files changed

+9
-24
lines changed

pandas/core/indexes/base.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
can_hold_element,
8080
common_dtype_categorical_compat,
8181
ensure_dtype_can_hold_na,
82-
find_common_type,
82+
find_result_type,
8383
infer_dtype_from,
8484
maybe_cast_pointwise_result,
8585
np_can_hold_element,
@@ -124,6 +124,7 @@
124124
ABCDatetimeIndex,
125125
ABCMultiIndex,
126126
ABCPeriodIndex,
127+
ABCRangeIndex,
127128
ABCSeries,
128129
ABCTimedeltaIndex,
129130
)
@@ -5858,7 +5859,7 @@ def _find_common_type_compat(self, target) -> DtypeObj:
58585859
):
58595860
return _dtype_obj
58605861

5861-
dtype = find_common_type([self.dtype, target_dtype])
5862+
dtype = find_result_type(self._values, target)
58625863
dtype = common_dtype_categorical_compat([self, target], dtype)
58635864
return dtype
58645865

pandas/tests/indexes/interval/test_constructors.py

-15
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
timedelta_range,
1919
)
2020
import pandas._testing as tm
21-
from pandas.api.types import is_unsigned_integer_dtype
2221
from pandas.core.api import NumericIndex
2322
from pandas.core.arrays import IntervalArray
2423
import pandas.core.common as com
@@ -321,12 +320,6 @@ def breaks_and_expected_subtype(self, request):
321320
class TestFromTuples(TuplesClassConstructorTests):
322321
"""Tests specific to IntervalIndex.from_tuples"""
323322

324-
def _skip_test_constructor(self, dtype):
325-
if is_unsigned_integer_dtype(dtype):
326-
return True, "tuples don't have a dtype"
327-
else:
328-
return False, ""
329-
330323
@pytest.fixture
331324
def constructor(self):
332325
return IntervalIndex.from_tuples
@@ -374,14 +367,6 @@ def test_na_tuples(self):
374367
class TestClassConstructors(TuplesClassConstructorTests):
375368
"""Tests specific to the IntervalIndex/Index constructors"""
376369

377-
def _skip_test_constructor(self, dtype):
378-
# get_kwargs_from_breaks in TestFromTuples and TestClassconstructors just return
379-
# tuples of ints, so IntervalIndex can't know the original dtype
380-
if is_unsigned_integer_dtype(dtype):
381-
return True, "tuples don't have a dtype"
382-
else:
383-
return False, ""
384-
385370
@pytest.fixture(
386371
params=[IntervalIndex, partial(Index, dtype="interval")],
387372
ids=["IntervalIndex", "Index"],

pandas/tests/series/indexing/test_setitem.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,8 @@ def test_index_where(self, obj, key, expected, val):
793793
mask[key] = True
794794

795795
res = Index(obj).where(~mask, val)
796-
tm.assert_index_equal(res, Index(expected, dtype=expected.dtype))
796+
expected_idx = Index(expected, dtype=expected.dtype)
797+
tm.assert_index_equal(res, expected_idx)
797798

798799
def test_index_putmask(self, obj, key, expected, val):
799800
mask = np.zeros(obj.shape, dtype=bool)
@@ -1153,7 +1154,7 @@ def expected(self, val):
11531154
return Series(res_values)
11541155

11551156

1156-
@pytest.mark.parametrize("val", [np.int16(512), np.int16(512)])
1157+
@pytest.mark.parametrize("val", [512, np.int16(512)])
11571158
class TestSetitemIntoIntegerSeriesNeedsUpcast(SetitemCastingEquivalents):
11581159
@pytest.fixture
11591160
def obj(self):
@@ -1168,7 +1169,7 @@ def expected(self):
11681169
return Series([1, 512, 3], dtype=np.int16)
11691170

11701171

1171-
@pytest.mark.parametrize("val", [2**30 + 1.0, 2**33 + 1.1, 2**62])
1172+
@pytest.mark.parametrize("val", [2**33 + 1.0, 2**33 + 1.1, 2**62])
11721173
class TestSmallIntegerSetitemUpcast(SetitemCastingEquivalents):
11731174
# https://github.com/pandas-dev/pandas/issues/39584#issuecomment-941212124
11741175
@pytest.fixture
@@ -1181,12 +1182,10 @@ def key(self):
11811182

11821183
@pytest.fixture
11831184
def expected(self, val):
1184-
if val > np.iinfo(np.int64).max:
1185+
if val % 1 != 0:
11851186
dtype = "f8"
1186-
elif val > np.iinfo(np.int32).max:
1187-
dtype = "i8"
11881187
else:
1189-
dtype = "i4"
1188+
dtype = "i8"
11901189
return Series([val, 2, 3], dtype=dtype)
11911190

11921191

0 commit comments

Comments
 (0)