Skip to content

Commit cba01ae

Browse files
committed
Whittle down failing tests
1 parent 7f3c46e commit cba01ae

File tree

16 files changed

+74
-16
lines changed

16 files changed

+74
-16
lines changed

pandas/_testing/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ def box_expected(expected, box_cls, transpose: bool = True):
307307
expected = pd.concat([expected] * 2, ignore_index=True)
308308
elif box_cls is np.ndarray or box_cls is np.array:
309309
expected = np.array(expected)
310+
if expected.dtype.kind in "iufb" and pd.get_option("mode.pdep16_data_types"):
311+
expected = pd.array(expected, copy=False)
310312
elif box_cls is to_array:
311313
expected = to_array(expected)
312314
else:

pandas/core/arrays/base.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
import numpy as np
2424

25+
from pandas._config import get_option
26+
2527
from pandas._libs import (
2628
algos as libalgos,
2729
lib,
@@ -2420,7 +2422,12 @@ def _where(self, mask: npt.NDArray[np.bool_], value) -> Self:
24202422
result = self.copy()
24212423

24222424
if is_list_like(value):
2423-
val = value[~mask]
2425+
if np.ndim(value) == 1 and len(value) == 1:
2426+
# test_where.test_broadcast if we change to use nullable...
2427+
# maybe this should be handled at a higher level?
2428+
val = value[0]
2429+
else:
2430+
val = value[~mask]
24242431
else:
24252432
val = value
24262433

@@ -2655,6 +2662,10 @@ def _groupby_op(
26552662
if op.how in op.cast_blocklist:
26562663
# i.e. how in ["rank"], since other cast_blocklist methods don't go
26572664
# through cython_operation
2665+
if get_option("mode.pdep16_data_types"):
2666+
from pandas import array as pd_array
2667+
2668+
return pd_array(res_values)
26582669
return res_values
26592670

26602671
if isinstance(self.dtype, StringDtype):

pandas/core/arrays/datetimelike.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,8 @@ def _groupby_op(
17011701
if op.how in op.cast_blocklist:
17021702
# i.e. how in ["rank"], since other cast_blocklist methods don't go
17031703
# through cython_operation
1704+
# if get_option("mode.pdep16_data_types"):
1705+
# return pd_array(res_values) # breaks bc they dont support 2D
17041706
return res_values
17051707

17061708
# We did a view to M8[ns] above, now we go the other direction

pandas/core/arrays/timedeltas.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,10 @@ def __mul__(self, other) -> Self:
507507
# numpy >= 2.1 may not raise a TypeError
508508
# and seems to dispatch to others.__rmul__?
509509
raise TypeError(f"Cannot multiply with {type(other).__name__}")
510+
if isinstance(result, type(self)):
511+
# e.g. if other is IntegerArray
512+
assert result.dtype == self.dtype
513+
return result
510514
return type(self)._simple_new(result, dtype=result.dtype)
511515

512516
__rmul__ = __mul__

pandas/core/frame.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
)
142142
from pandas.core.arrays.sparse import SparseFrameAccessor
143143
from pandas.core.construction import (
144+
array as pd_array,
144145
ensure_wrapped_if_datetimelike,
145146
sanitize_array,
146147
sanitize_masked_array,
@@ -4411,6 +4412,14 @@ def _iset_item_mgr(
44114412
def _set_item_mgr(
44124413
self, key, value: ArrayLike, refs: BlockValuesRefs | None = None
44134414
) -> None:
4415+
if get_option("mode.pdep16_data_types"):
4416+
# TODO: possibly handle this at a lower level?
4417+
if (
4418+
isinstance(value, np.ndarray)
4419+
and value.dtype.kind in "iufb"
4420+
and value.dtype != np.float16
4421+
):
4422+
value = pd_array(value, copy=False)
44144423
try:
44154424
loc = self._info_axis.get_loc(key)
44164425
except KeyError:

pandas/core/groupby/generic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2166,9 +2166,10 @@ def _cython_transform(
21662166
)
21672167

21682168
def arr_func(bvalues: ArrayLike) -> ArrayLike:
2169-
return self._grouper._cython_operation(
2169+
blk_res = self._grouper._cython_operation(
21702170
"transform", bvalues, how, 1, **kwargs
21712171
)
2172+
return blk_res
21722173

21732174
res_mgr = mgr.apply(arr_func)
21742175

pandas/core/indexes/base.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,11 @@ def __new__(
577577
raise ValueError("Index data must be 1-dimensional") from err
578578
raise
579579
arr = ensure_wrapped_if_datetimelike(arr)
580-
if arr.dtype.kind in "iufb" and get_option("mode.pdep16_data_types"):
580+
if (
581+
arr.dtype.kind in "iufb"
582+
and arr.dtype != np.float16
583+
and get_option("mode.pdep16_data_types")
584+
):
581585
arr = pd_array(arr, copy=False)
582586

583587
klass = cls._dtype_to_subclass(arr.dtype)
@@ -6937,7 +6941,8 @@ def insert(self, loc: int, item) -> Index:
69376941
return self.astype(dtype).insert(loc, item)
69386942

69396943
try:
6940-
if isinstance(arr, ExtensionArray):
6944+
if isinstance(arr, ExtensionArray) and not isinstance(self, ABCRangeIndex):
6945+
# RangeIndex's _simple_new expects a range object
69416946
res_values = arr.insert(loc, item)
69426947
return type(self)._simple_new(res_values, name=self.name)
69436948
else:

pandas/core/indexes/datetimelike.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ def _wrap_range_setop(self, other, res_i8) -> Self:
557557
# because test_setops_preserve_freq fails with _validate_frequency raising.
558558
# This raising is incorrect, as 'on_freq' is incorrect. This will
559559
# be fixed by GH#41493
560-
res_values = res_i8.values.view(self._data._ndarray.dtype)
560+
res_values = np.asarray(res_i8.values).view(self._data._ndarray.dtype)
561561
result = type(self._data)._simple_new(
562562
# error: Argument "dtype" to "_simple_new" of "DatetimeArray" has
563563
# incompatible type "Union[dtype[Any], ExtensionDtype]"; expected

pandas/core/indexes/range.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import numpy as np
2020

21+
from pandas._config import get_option
22+
2123
from pandas._libs import (
2224
index as libindex,
2325
lib,
@@ -44,7 +46,10 @@
4446

4547
from pandas.core import ops
4648
import pandas.core.common as com
47-
from pandas.core.construction import extract_array
49+
from pandas.core.construction import (
50+
array as pd_array,
51+
extract_array,
52+
)
4853
from pandas.core.indexers import check_array_indexer
4954
import pandas.core.indexes.base as ibase
5055
from pandas.core.indexes.base import (
@@ -278,7 +283,10 @@ def _data(self) -> np.ndarray: # type: ignore[override]
278283
279284
The constructed array is saved in ``_cache``.
280285
"""
281-
return np.arange(self.start, self.stop, self.step, dtype=np.int64)
286+
data = np.arange(self.start, self.stop, self.step, dtype=np.int64)
287+
if get_option("mode.pdep16_data_types"):
288+
return pd_array(data)
289+
return data
282290

283291
def _get_data_as_items(self) -> list[tuple[str, int]]:
284292
"""return a list of tuples of start, stop, step"""

pandas/core/internals/blocks.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ def reduce(self, func) -> list[Block]:
361361
else:
362362
res_values = result.reshape(-1, 1)
363363

364+
if self.values.dtype == object:
365+
if res_values.dtype.kind == "f":
366+
# TODO: this is kludgy; does it mean there is a problem
367+
# at a higher level?
368+
res_values = res_values.astype(object)
364369
nb = self.make_block(res_values)
365370
return [nb]
366371

@@ -2226,6 +2231,8 @@ def new_block_2d(
22262231
klass = get_block_type(values.dtype)
22272232

22282233
values = maybe_coerce_values(values)
2234+
if isinstance(values, np.ndarray):
2235+
assert values.dtype == np.float16 or values.dtype.kind not in "iufb"
22292236
return klass(values, ndim=2, placement=placement, refs=refs)
22302237

22312238

@@ -2241,6 +2248,8 @@ def new_block(
22412248
# - check_ndim/ensure_block_shape already checked
22422249
# - maybe_coerce_values already called/unnecessary
22432250
klass = get_block_type(values.dtype)
2251+
if isinstance(values, np.ndarray):
2252+
assert values.dtype == np.float16 or values.dtype.kind not in "iufb"
22442253
return klass(values, ndim=ndim, placement=placement, refs=refs)
22452254

22462255

0 commit comments

Comments
 (0)