#37528 BUG: isin incorrectly casting ints to datetimes

Merged jbrockmendel Pseudo commit used to compare (f823a85...fb379d8)
Missing base report.

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

Changes found in between f823a85...fb379d8 (pseudo...base) which prevent comparing this pull request.


@@ -491,12 +491,40 @@
Loading
491 491
        if level is not None:
492 492
            self._validate_index_level(level)
493 493
494 +
        if not hasattr(values, "dtype"):
495 +
            values = np.asarray(values)
496 +
497 +
        if values.dtype.kind in ["f", "i", "u", "c"]:
498 +
            # TODO: de-duplicate with equals, validate_comparison_value
499 +
            return np.zeros(self.shape, dtype=bool)
500 +
494 501
        if not isinstance(values, type(self)):
502 +
            inferrable = [
503 +
                "timedelta",
504 +
                "timedelta64",
505 +
                "datetime",
506 +
                "datetime64",
507 +
                "date",
508 +
                "period",
509 +
            ]
510 +
            if values.dtype == object:
511 +
                inferred = lib.infer_dtype(values, skipna=False)
512 +
                if inferred not in inferrable:
513 +
                    if "mixed" in inferred:
514 +
                        return self.astype(object).isin(values)
515 +
                    return np.zeros(self.shape, dtype=bool)
516 +
495 517
            try:
496 518
                values = type(self)(values)
497 519
            except ValueError:
498 520
                return self.astype(object).isin(values)
499 521
522 +
        try:
523 +
            self._data._check_compatible_with(values)
524 +
        except (TypeError, ValueError):
525 +
            # Includes tzawareness mismatch and IncompatibleFrequencyError
526 +
            return np.zeros(self.shape, dtype=bool)
527 +
500 528
        return algorithms.isin(self.asi8, values.asi8)
501 529
502 530
    @Appender(Index.where.__doc__)

@@ -1359,7 +1359,6 @@
Loading
1359 1359
        self.bar_width = kwargs.pop("width", 0.5)
1360 1360
        pos = kwargs.pop("position", 0.5)
1361 1361
        kwargs.setdefault("align", "center")
1362 -
        self.tick_pos = np.arange(len(data))
1363 1362
1364 1363
        self.bottom = kwargs.pop("bottom", 0)
1365 1364
        self.left = kwargs.pop("left", 0)
@@ -1382,7 +1381,16 @@
Loading
1382 1381
                self.tickoffset = self.bar_width * pos
1383 1382
                self.lim_offset = 0
1384 1383
1385 -
        self.ax_pos = self.tick_pos - self.tickoffset
1384 +
        if isinstance(self.data.index, ABCMultiIndex):
1385 +
            if kwargs["ax"] is not None and kwargs["ax"].has_data():
1386 +
                warnings.warn(
1387 +
                    "Redrawing a bar plot with a MultiIndex is not supported "
1388 +
                    + "and may lead to inconsistent label positions.",
1389 +
                    UserWarning,
1390 +
                )
1391 +
            self.ax_index = np.arange(len(data))
1392 +
        else:
1393 +
            self.ax_index = self.data.index
1386 1394
1387 1395
    def _args_adjust(self):
1388 1396
        if is_list_like(self.bottom):
@@ -1409,6 +1417,15 @@
Loading
1409 1417
1410 1418
        for i, (label, y) in enumerate(self._iter_data(fillna=0)):
1411 1419
            ax = self._get_ax(i)
1420 +
1421 +
            if self.orientation == "vertical":
1422 +
                ax.xaxis.update_units(self.ax_index)
1423 +
                self.tick_pos = ax.convert_xunits(self.ax_index).astype(np.int)
1424 +
            elif self.orientation == "horizontal":
1425 +
                ax.yaxis.update_units(self.ax_index)
1426 +
                self.tick_pos = ax.convert_yunits(self.ax_index).astype(np.int)
1427 +
            self.ax_pos = self.tick_pos - self.tickoffset
1428 +
1412 1429
            kwds = self.kwds.copy()
1413 1430
            if self._is_series:
1414 1431
                kwds["color"] = colors
@@ -1480,8 +1497,8 @@
Loading
1480 1497
            str_index = [pprint_thing(key) for key in range(data.shape[0])]
1481 1498
        name = self._get_index_name()
1482 1499
1483 -
        s_edge = self.ax_pos[0] - 0.25 + self.lim_offset
1484 -
        e_edge = self.ax_pos[-1] + 0.25 + self.bar_width + self.lim_offset
1500 +
        s_edge = self.ax_pos.min() - 0.25 + self.lim_offset
1501 +
        e_edge = self.ax_pos.max() + 0.25 + self.bar_width + self.lim_offset
1485 1502
1486 1503
        self._decorate_ticks(ax, name, str_index, s_edge, e_edge)
1487 1504

@@ -430,6 +430,12 @@
Loading
430 430
        # handle categoricals
431 431
        return cast("Categorical", comps).isin(values)
432 432
433 +
    if needs_i8_conversion(comps):
434 +
        # Dispatch to DatetimeLikeIndexMixin.isin
435 +
        from pandas import Index
436 +
437 +
        return Index(comps).isin(values)
438 +
433 439
    comps, dtype = _ensure_data(comps)
434 440
    values, _ = _ensure_data(values, dtype=dtype)
435 441

Unable to process changes.

No base report to compare against.

Files Coverage
pandas 94.21%
Project Totals (215 files) 94.21%
Loading