#37547 ENH: Improve error reporting for wrong merge cols

Merged patrick phofl Pseudo commit used to compare (4aa0783...8b05fe3)
Missing base report.

Unable to compare commits because the base of the pull request did not upload a coverage report.

Changes found in between 4aa0783...8b05fe3 (pseudo...base) which prevent comparing this pull request.

Showing 11 of 34 files from the diff.

@@ -45,7 +45,7 @@
Loading
45 45
        """
46 46
        return x
47 47
48 -
    def _validate_insert_value(self, value):
48 +
    def _validate_scalar(self, value):
49 49
        # used by NDArrayBackedExtensionIndex.insert
50 50
        raise AbstractMethodError(self)
51 51

@@ -1177,9 +1177,6 @@
Loading
1177 1177
    # -------------------------------------------------------------
1178 1178
    # Validators; ideally these can be de-duplicated
1179 1179
1180 -
    def _validate_insert_value(self, value) -> int:
1181 -
        return self._validate_fill_value(value)
1182 -
1183 1180
    def _validate_searchsorted_value(self, value):
1184 1181
        # searchsorted is very performance sensitive. By converting codes
1185 1182
        # to same dtype as self.codes, we get much faster performance.
@@ -1219,6 +1216,8 @@
Loading
1219 1216
            )
1220 1217
        return fill_value
1221 1218
1219 +
    _validate_scalar = _validate_fill_value
1220 +
1222 1221
    # -------------------------------------------------------------
1223 1222
1224 1223
    def __array__(self, dtype=None) -> np.ndarray:

@@ -335,7 +335,7 @@
Loading
335 335
        ValueError if the item is not valid for this dtype.
336 336
        """
337 337
        arr = self._data
338 -
        code = arr._validate_insert_value(item)
338 +
        code = arr._validate_scalar(item)
339 339
340 340
        new_vals = np.concatenate((arr._ndarray[:loc], [code], arr._ndarray[loc:]))
341 341
        new_arr = arr._from_backing_data(new_vals)

@@ -479,10 +479,12 @@
Loading
479 479
            f"Got '{str(fill_value)}'."
480 480
        )
481 481
        try:
482 -
            fill_value = self._validate_scalar(fill_value)
482 +
            return self._validate_scalar(fill_value)
483 483
        except TypeError as err:
484 +
            if "Cannot compare tz-naive and tz-aware" in str(err):
485 +
                # tzawareness-compat
486 +
                raise
484 487
            raise ValueError(msg) from err
485 -
        return self._unbox(fill_value, setitem=True)
486 488
487 489
    def _validate_shift_value(self, fill_value):
488 490
        # TODO(2.0): once this deprecation is enforced, use _validate_fill_value
@@ -511,7 +513,14 @@
Loading
511 513
512 514
        return self._unbox(fill_value, setitem=True)
513 515
514 -
    def _validate_scalar(self, value, allow_listlike: bool = False):
516 +
    def _validate_scalar(
517 +
        self,
518 +
        value,
519 +
        *,
520 +
        allow_listlike: bool = False,
521 +
        setitem: bool = True,
522 +
        unbox: bool = True,
523 +
    ):
515 524
        """
516 525
        Validate that the input value can be cast to our scalar_type.
517 526
@@ -521,6 +530,11 @@
Loading
521 530
        allow_listlike: bool, default False
522 531
            When raising an exception, whether the message should say
523 532
            listlike inputs are allowed.
533 +
        setitem : bool, default True
534 +
            Whether to check compatibility with setitem strictness.
535 +
        unbox : bool, default True
536 +
            Whether to unbox the result before returning.  Note: unbox=False
537 +
            skips the setitem compatibility check.
524 538
525 539
        Returns
526 540
        -------
@@ -546,7 +560,12 @@
Loading
546 560
            msg = self._validation_error_message(value, allow_listlike)
547 561
            raise TypeError(msg)
548 562
549 -
        return value
563 +
        if not unbox:
564 +
            # NB: In general NDArrayBackedExtensionArray will unbox here;
565 +
            #  this option exists to prevent a performance hit in
566 +
            #  TimedeltaIndex.get_loc
567 +
            return value
568 +
        return self._unbox_scalar(value, setitem=setitem)
550 569
551 570
    def _validation_error_message(self, value, allow_listlike: bool = False) -> str:
552 571
        """
@@ -611,7 +630,7 @@
Loading
611 630
612 631
    def _validate_searchsorted_value(self, value):
613 632
        if not is_list_like(value):
614 -
            value = self._validate_scalar(value, True)
633 +
            return self._validate_scalar(value, allow_listlike=True, setitem=False)
615 634
        else:
616 635
            value = self._validate_listlike(value)
617 636
@@ -621,12 +640,7 @@
Loading
621 640
        if is_list_like(value):
622 641
            value = self._validate_listlike(value)
623 642
        else:
624 -
            value = self._validate_scalar(value, True)
625 -
626 -
        return self._unbox(value, setitem=True)
627 -
628 -
    def _validate_insert_value(self, value):
629 -
        value = self._validate_scalar(value)
643 +
            return self._validate_scalar(value, allow_listlike=True)
630 644
631 645
        return self._unbox(value, setitem=True)
632 646

@@ -581,7 +581,7 @@
Loading
581 581
        """
582 582
        Find the `freq` for self.insert(loc, item).
583 583
        """
584 -
        value = self._data._validate_insert_value(item)
584 +
        value = self._data._validate_scalar(item)
585 585
        item = self._data._box_func(value)
586 586
587 587
        freq = None

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Unable to process changes.

No base report to compare against.

Files Coverage
pandas 94.20%
Project Totals (214 files) 94.20%
Loading