code: import numpy as np
  import pytest
  
  import pandas as pd
  from pandas import Series
  import pandas._testing as tm
  
  
  def test_get():
      # GH 6383
      s = Series(
          np.array(
              [
                  43,
                  48,
                  60,
                  48,
                  50,
                  51,
                  50,
                  45,
                  57,
                  48,
                  56,
                  45,
                  51,
                  39,
                  55,
                  43,
                  54,
                  52,
                  51,
                  54,
              ]
          )
      )
  
      result = s.get(25, 0)
      expected = 0
      assert result == expected
  
      s = Series(
          np.array(
              [
                  43,
                  48,
                  60,
                  48,
                  50,
                  51,
                  50,
                  45,
                  57,
                  48,
                  56,
                  45,
                  51,
                  39,
                  55,
                  43,
                  54,
                  52,
                  51,
                  54,
              ]
          ),
          index=pd.Float64Index(
              [
                  25.0,
                  36.0,
                  49.0,
                  64.0,
                  81.0,
                  100.0,
                  121.0,
                  144.0,
                  169.0,
                  196.0,
                  1225.0,
                  1296.0,
                  1369.0,
                  1444.0,
                  1521.0,
                  1600.0,
                  1681.0,
                  1764.0,
                  1849.0,
                  1936.0,
              ]
          ),
      )
  
      result = s.get(25, 0)
      expected = 43
      assert result == expected
  
      # GH 7407
      # with a boolean accessor
      df = pd.DataFrame({"i": [0] * 3, "b": [False] * 3})
      vc = df.i.value_counts()
      result = vc.get(99, default="Missing")
      assert result == "Missing"
  
      vc = df.b.value_counts()
      result = vc.get(False, default="Missing")
      assert result == 3
  
      result = vc.get(True, default="Missing")
      assert result == "Missing"
  
  
  def test_get_nan():
      # GH 8569
      s = pd.Float64Index(range(10)).to_series()
      assert s.get(np.nan) is None
      assert s.get(np.nan, default="Missing") == "Missing"
  
  
  def test_get_nan_multiple():
      # GH 8569
      # ensure that fixing "test_get_nan" above hasn't broken get
      # with multiple elements
      s = pd.Float64Index(range(10)).to_series()
  
      idx = [2, 30]
      assert s.get(idx) is None
  
      idx = [2, np.nan]
      assert s.get(idx) is None
  
      # GH 17295 - all missing keys
      idx = [20, 30]
      assert s.get(idx) is None
  
      idx = [np.nan, np.nan]
      assert s.get(idx) is None
  
  
  def test_get_with_default():
      # GH#7725
      d0 = ["a", "b", "c", "d"]
      d1 = np.arange(4, dtype="int64")
      others = ["e", 10]
  
      for data, index in ((d0, d1), (d1, d0)):
          s = Series(data, index=index)
          for i, d in zip(index, data):
              assert s.get(i) == d
              assert s.get(i, d) == d
              assert s.get(i, "z") == d
              for other in others:
                  assert s.get(other, "z") == "z"
                  assert s.get(other, other) == other
  
  
  @pytest.mark.parametrize(
      "arr",
      [np.random.randn(10), tm.makeDateIndex(10, name="a").tz_localize(tz="US/Eastern")],
  )
  def test_get2(arr):
      # TODO: better name, possibly split
      # GH#21260
      ser = Series(arr, index=[2 * i for i in range(len(arr))])
      assert ser.get(4) == ser.iloc[2]
  
      result = ser.get([4, 6])
      expected = ser.iloc[[2, 3]]
      tm.assert_series_equal(result, expected)
  
      result = ser.get(slice(2))
      expected = ser.iloc[[0, 1]]
      tm.assert_series_equal(result, expected)
  
      assert ser.get(-1) is None
      assert ser.get(ser.index.max() + 1) is None
  
      ser = Series(arr[:6], index=list("abcdef"))
      assert ser.get("c") == ser.iloc[2]
  
      result = ser.get(slice("b", "d"))
      expected = ser.iloc[[1, 2, 3]]
      tm.assert_series_equal(result, expected)
  
      result = ser.get("Z")
      assert result is None
  
      assert ser.get(4) == ser.iloc[4]
      assert ser.get(-1) == ser.iloc[-1]
      assert ser.get(len(ser)) is None
  
      # GH#21257
      ser = Series(arr)
      ser2 = ser[::2]
      assert ser2.get(1) is None
  
  
  def test_getitem_get(string_series, object_series):
      for obj in [string_series, object_series]:
          idx = obj.index[5]
  
          assert obj[idx] == obj.get(idx)
          assert obj[idx] == obj[5]
  
      assert string_series.get(-1) == string_series.get(string_series.index[-1])
      assert string_series[5] == string_series.get(string_series.index[5])
  
  
  def test_get_none():
      # GH#5652
      s1 = Series(dtype=object)
      s2 = Series(dtype=object, index=list("abc"))
      for s in [s1, s2]:
          result = s.get(None)
          assert result is None
   from datetime import time
  
  import numpy as np
  import pytest
  import pytz
  
  from pandas._libs.tslibs import timezones
  
  from pandas import (
      DataFrame,
      date_range,
  )
  import pandas._testing as tm
  
  
  class TestAtTime:
      @pytest.mark.parametrize("tzstr", ["US/Eastern", "dateutil/US/Eastern"])
      def test_localized_at_time(self, tzstr, frame_or_series):
          tz = timezones.maybe_get_tz(tzstr)
  
          rng = date_range("4/16/2012", "5/1/2012", freq="H")
          ts = frame_or_series(np.random.randn(len(rng)), index=rng)
  
          ts_local = ts.tz_localize(tzstr)
  
          result = ts_local.at_time(time(10, 0))
          expected = ts.at_time(time(10, 0)).tz_localize(tzstr)
          tm.assert_equal(result, expected)
          assert timezones.tz_compare(result.index.tz, tz)
  
      def test_at_time(self, frame_or_series):
          rng = date_range("1/1/2000", "1/5/2000", freq="5min")
          ts = DataFrame(np.random.randn(len(rng), 2), index=rng)
          if frame_or_series is not DataFrame:
              ts = ts[0]
          rs = ts.at_time(rng[1])
          assert (rs.index.hour == rng[1].hour).all()
          assert (rs.index.minute == rng[1].minute).all()
          assert (rs.index.second == rng[1].second).all()
  
          result = ts.at_time("9:30")
          expected = ts.at_time(time(9, 30))
          tm.assert_equal(result, expected)
  
      def test_at_time_midnight(self, frame_or_series):
          # midnight, everything
          rng = date_range("1/1/2000", "1/31/2000")
          ts = DataFrame(np.random.randn(len(rng), 3), index=rng)
          if frame_or_series is not DataFrame:
              ts = ts[0]
  
          result = ts.at_time(time(0, 0))
          tm.assert_equal(result, ts)
  
      def test_at_time_nonexistent(self, frame_or_series):
          # time doesn't exist
          rng = date_range("1/1/2012", freq="23Min", periods=384)
          ts = DataFrame(np.random.randn(len(rng)), rng)
          if frame_or_series is not DataFrame:
              ts = ts[0]
          rs = ts.at_time("16:00")
          assert len(rs) == 0
  
      @pytest.mark.parametrize(
          "hour", ["1:00", "1:00AM", time(1), time(1, tzinfo=pytz.UTC)]
      )
      def test_at_time_errors(self, hour):
          # GH#24043
          dti = date_range("2018", periods=3, freq="H")
          df = DataFrame(list(range(len(dti))), index=dti)
          if getattr(hour, "tzinfo", None) is None:
              result = df.at_time(hour)
              expected = df.iloc[1:2]
              tm.assert_frame_equal(result, expected)
          else:
              with pytest.raises(ValueError, match="Index must be timezone"):
                  df.at_time(hour)
  
      def test_at_time_tz(self):
          # GH#24043
          dti = date_range("2018", periods=3, freq="H", tz="US/Pacific")
          df = DataFrame(list(range(len(dti))), index=dti)
          result = df.at_time(time(4, tzinfo=pytz.timezone("US/Eastern")))
          expected = df.iloc[1:2]
          tm.assert_frame_equal(result, expected)
  
      def test_at_time_raises(self, frame_or_series):
          # GH#20725
          obj = DataFrame([[1, 2, 3], [4, 5, 6]])
          if frame_or_series is not DataFrame:
              obj = obj[0]
          msg = "Index must be DatetimeIndex"
          with pytest.raises(TypeError, match=msg):  # index is not a DatetimeIndex
              obj.at_time("00:00")
  
      @pytest.mark.parametrize("axis", ["index", "columns", 0, 1])
      def test_at_time_axis(self, axis):
          # issue 8839
          rng = date_range("1/1/2000", "1/5/2000", freq="5min")
          ts = DataFrame(np.random.randn(len(rng), len(rng)))
          ts.index, ts.columns = rng, rng
  
          indices = rng[(rng.hour == 9) & (rng.minute == 30) & (rng.second == 0)]
  
          if axis in ["index", 0]:
              expected = ts.loc[indices, :]
          elif axis in ["columns", 1]:
              expected = ts.loc[:, indices]
  
          result = ts.at_time("9:30", axis=axis)
  
          # Without clearing freq, result has freq 1440T and expected 5T
          result.index = result.index._with_freq(None)
          expected.index = expected.index._with_freq(None)
          tm.assert_frame_equal(result, expected)
  
      def test_at_time_datetimeindex(self):
          index = date_range("2012-01-01", "2012-01-05", freq="30min")
          df = DataFrame(np.random.randn(len(index), 5), index=index)
          akey = time(12, 0, 0)
          ainds = [24, 72, 120, 168]
  
          result = df.at_time(akey)
          expected = df.loc[akey]
          expected2 = df.iloc[ainds]
          tm.assert_frame_equal(result, expected)
          tm.assert_frame_equal(result, expected2)
          assert len(result) == 4
   import operator
  import warnings
  
  import numpy as np
  import pytest
  
  import pandas as pd
  from pandas import (
      Categorical,
      DataFrame,
      Series,
      date_range,
  )
  import pandas._testing as tm
  from pandas.tests.arrays.categorical.common import TestCategorical
  
  
  class TestCategoricalOpsWithFactor(TestCategorical):
      def test_categories_none_comparisons(self):
          factor = Categorical(["a", "b", "b", "a", "a", "c", "c", "c"], ordered=True)
          tm.assert_categorical_equal(factor, self.factor)
  
      def test_comparisons(self):
          result = self.factor[self.factor == "a"]
          expected = self.factor[np.asarray(self.factor) == "a"]
          tm.assert_categorical_equal(result, expected)
  
          result = self.factor[self.factor != "a"]
          expected = self.factor[np.asarray(self.factor) != "a"]
          tm.assert_categorical_equal(result, expected)
  
          result = self.factor[self.factor < "c"]
          expected = self.factor[np.asarray(self.factor) < "c"]
          tm.assert_categorical_equal(result, expected)
  
          result = self.factor[self.factor > "a"]
          expected = self.factor[np.asarray(self.factor) > "a"]
          tm.assert_categorical_equal(result, expected)
  
          result = self.factor[self.factor >= "b"]
          expected = self.factor[np.asarray(self.factor) >= "b"]
          tm.assert_categorical_equal(result, expected)
  
          result = self.factor[self.factor <= "b"]
          expected = self.factor[np.asarray(self.factor) <= "b"]
          tm.assert_categorical_equal(result, expected)
  
          n = len(self.factor)
  
          other = self.factor[np.random.permutation(n)]
          result = self.factor == other
          expected = np.asarray(self.factor) == np.asarray(other)
          tm.assert_numpy_array_equal(result, expected)
  
          result = self.factor == "d"
          expected = np.zeros(len(self.factor), dtype=bool)
          tm.assert_numpy_array_equal(result, expected)
  
          # comparisons with categoricals
          cat_rev = Categorical(["a", "b", "c"], categories=["c", "b", "a"], ordered=True)
          cat_rev_base = Categorical(
              ["b", "b", "b"], categories=["c", "b", "a"], ordered=True
          )
          cat = Categorical(["a", "b", "c"], ordered=True)
          cat_base = Categorical(["b", "b", "b"], categories=cat.categories, ordered=True)
  
          # comparisons need to take categories ordering into account
          res_rev = cat_rev > cat_rev_base
          exp_rev = np.array([True, False, False])
          tm.assert_numpy_array_equal(res_rev, exp_rev)
  
          res_rev = cat_rev < cat_rev_base
          exp_rev = np.array([False, False, True])
          tm.assert_numpy_array_equal(res_rev, exp_rev)
  
          res = cat > cat_base
          exp = np.array([False, False, True])
          tm.assert_numpy_array_equal(res, exp)
  
          # Only categories with same categories can be compared
          msg = "Categoricals can only be compared if 'categories' are the same"
          with pytest.raises(TypeError, match=msg):
              cat > cat_rev
  
          cat_rev_base2 = Categorical(["b", "b", "b"], categories=["c", "b", "a", "d"])
  
          with pytest.raises(TypeError, match=msg):
              cat_rev > cat_rev_base2
  
          # Only categories with same ordering information can be compared
          cat_unorderd = cat.set_ordered(False)
          assert not (cat > cat).any()
  
          with pytest.raises(TypeError, match=msg):
              cat > cat_unorderd
  
          # comparison (in both directions) with Series will raise
          s = Series(["b", "b", "b"])
          msg = (
              "Cannot compare a Categorical for op __gt__ with type "
              r"<class 'numpy\.ndarray'>"
          )
          with pytest.raises(TypeError, match=msg):
              cat > s
          with pytest.raises(TypeError, match=msg):
              cat_rev > s
          with pytest.raises(TypeError, match=msg):
              s < cat
          with pytest.raises(TypeError, match=msg):
              s < cat_rev
  
          # comparison with numpy.array will raise in both direction, but only on
          # newer numpy versions
          a = np.array(["b", "b", "b"])
          with pytest.raises(TypeError, match=msg):
              cat > a
          with pytest.raises(TypeError, match=msg):
              cat_rev > a
  
          # Make sure that unequal comparison take the categories order in
          # account
          cat_rev = Categorical(list("abc"), categories=list("cba"), ordered=True)
          exp = np.array([True, False, False])
          res = cat_rev > "b"
          tm.assert_numpy_array_equal(res, exp)
  
          # check that zero-dim array gets unboxed
          res = cat_rev > np.array("b")
          tm.assert_numpy_array_equal(res, exp)
  
  
  class TestCategoricalOps:
      def test_compare_frame(self):
          # GH#24282 check that Categorical.__cmp__(DataFrame) defers to frame
          data = ["a", "b", 2, "a"]
          cat = Categorical(data)
  
          df = DataFrame(cat)
  
          result = cat == df.T
          expected = DataFrame([[True, True, True, True]])
          tm.assert_frame_equal(result, expected)
  
          result = cat[::-1] != df.T
          expected = DataFrame([[False, True, True, False]])
          tm.assert_frame_equal(result, expected)
  
      def test_compare_frame_raises(self, all_compare_operators):
          # alignment raises unless we transpose
          op = getattr(operator, all_compare_operators)
          cat = Categorical(["a", "b", 2, "a"])
          df = DataFrame(cat)
          msg = "Unable to coerce to Series, length must be 1: given 4"
          with pytest.raises(ValueError, match=msg):
              op(cat, df)
  
      def test_datetime_categorical_comparison(self):
          dt_cat = Categorical(date_range("2014-01-01", periods=3), ordered=True)
          tm.assert_numpy_array_equal(dt_cat > dt_cat[0], np.array([False, True, True]))
          tm.assert_numpy_array_equal(dt_cat[0] < dt_cat, np.array([False, True, True]))
  
      def test_reflected_comparison_with_scalars(self):
          # GH8658
          cat = Categorical([1, 2, 3], ordered=True)
          tm.assert_numpy_array_equal(cat > cat[0], np.array([False, True, True]))
          tm.assert_numpy_array_equal(cat[0] < cat, np.array([False, True, True]))
  
      def test_comparison_with_unknown_scalars(self):
          # https://github.com/pandas-dev/pandas/issues/9836#issuecomment-92123057
          # and following comparisons with scalars not in categories should raise
          # for unequal comps, but not for equal/not equal
          cat = Categorical([1, 2, 3], ordered=True)
  
          msg = "Invalid comparison between dtype=category and int"
          with pytest.raises(TypeError, match=msg):
              cat < 4
          with pytest.raises(TypeError, match=msg):
              cat > 4
          with pytest.raises(TypeError, match=msg):
              4 < cat
          with pytest.raises(TypeError, match=msg):
              4 > cat
  
          tm.assert_numpy_array_equal(cat == 4, np.array([False, False, False]))
          tm.assert_numpy_array_equal(cat != 4, np.array([True, True, True]))
  
      def test_comparison_with_tuple(self):
          cat = Categorical(np.array(["foo", (0, 1), 3, (0, 1)], dtype=object))
  
          result = cat == "foo"
          expected = np.array([True, False, False, False], dtype=bool)
          tm.assert_numpy_array_equal(result, expected)
  
          result = cat == (0, 1)
          expected = np.array([False, True, False, True], dtype=bool)
          tm.assert_numpy_array_equal(result, expected)
  
          result = cat != (0, 1)
          tm.assert_numpy_array_equal(result, ~expected)
  
      def test_comparison_of_ordered_categorical_with_nan_to_scalar(
          self, compare_operators_no_eq_ne
      ):
          # https://github.com/pandas-dev/pandas/issues/26504
          # BUG: fix ordered categorical comparison with missing values (#26504 )
          # and following comparisons with scalars in categories with missing
          # values should be evaluated as False
  
          cat = Categorical([1, 2, 3, None], categories=[1, 2, 3], ordered=True)
          scalar = 2
          with warnings.catch_warnings():
              warnings.simplefilter("ignore", RuntimeWarning)
              expected = getattr(np.array(cat), compare_operators_no_eq_ne)(scalar)
          actual = getattr(cat, compare_operators_no_eq_ne)(scalar)
          tm.assert_numpy_array_equal(actual, expected)
  
      def test_comparison_of_ordered_categorical_with_nan_to_listlike(
          self, compare_operators_no_eq_ne
      ):
          # https://github.com/pandas-dev/pandas/issues/26504
          # and following comparisons of missing values in ordered Categorical
          # with listlike should be evaluated as False
  
          cat = Categorical([1, 2, 3, None], categories=[1, 2, 3], ordered=True)
          other = Categorical([2, 2, 2, 2], categories=[1, 2, 3], ordered=True)
          with warnings.catch_warnings():
              warnings.simplefilter("ignore", RuntimeWarning)
              expected = getattr(np.array(cat), compare_operators_no_eq_ne)(2)
          actual = getattr(cat, compare_operators_no_eq_ne)(other)
          tm.assert_numpy_array_equal(actual, expected)
  
      @pytest.mark.parametrize(
          "data,reverse,base",
          [(list("abc"), list("cba"), list("bbb")), ([1, 2, 3], [3, 2, 1], [2, 2, 2])],
      )
      def test_comparisons(self, data, reverse, base):
          cat_rev = Series(Categorical(data, categories=reverse, ordered=True))
          cat_rev_base = Series(Categorical(base, categories=reverse, ordered=True))
          cat = Series(Categorical(data, ordered=True))
          cat_base = Series(
              Categorical(base, categories=cat.cat.categories, ordered=True)
          )
          s = Series(base)
          a = np.array(base)
  
          # comparisons need to take categories ordering into account
          res_rev = cat_rev > cat_rev_base
          exp_rev = Series([True, False, False])
          tm.assert_series_equal(res_rev, exp_rev)
  
          res_rev = cat_rev < cat_rev_base
          exp_rev = Series([False, False, True])
          tm.assert_series_equal(res_rev, exp_rev)
  
          res = cat > cat_base
          exp = Series([False, False, True])
          tm.assert_series_equal(res, exp)
  
          scalar = base[1]
          res = cat > scalar
          exp = Series([False, False, True])
          exp2 = cat.values > scalar
          tm.assert_series_equal(res, exp)
          tm.assert_numpy_array_equal(res.values, exp2)
          res_rev = cat_rev > scalar
          exp_rev = Series([True, False, False])
          exp_rev2 = cat_rev.values > scalar
          tm.assert_series_equal(res_rev, exp_rev)
          tm.assert_numpy_array_equal(res_rev.values, exp_rev2)
  
          # Only categories with same categories can be compared
          msg = "Categoricals can only be compared if 'categories' are the same"
          with pytest.raises(TypeError, match=msg):
              cat > cat_rev
  
          # categorical cannot be compared to Series or numpy array, and also
          # not the other way around
          msg = (
              "Cannot compare a Categorical for op __gt__ with type "
              r"<class 'numpy\.ndarray'>"
          )
          with pytest.raises(TypeError, match=msg):
              cat > s
          with pytest.raises(TypeError, match=msg):
              cat_rev > s
          with pytest.raises(TypeError, match=msg):
              cat > a
          with pytest.raises(TypeError, match=msg):
              cat_rev > a
  
          with pytest.raises(TypeError, match=msg):
              s < cat
          with pytest.raises(TypeError, match=msg):
              s < cat_rev
  
          with pytest.raises(TypeError, match=msg):
              a < cat
          with pytest.raises(TypeError, match=msg):
              a < cat_rev
  
      @pytest.mark.parametrize(
          "ctor",
          [
              lambda *args, **kwargs: Categorical(*args, **kwargs),
              lambda *args, **kwargs: Series(Categorical(*args, **kwargs)),
          ],
      )
      def test_unordered_different_order_equal(self, ctor):
          # https://github.com/pandas-dev/pandas/issues/16014
          c1 = ctor(["a", "b"], categories=["a", "b"], ordered=False)
          c2 = ctor(["a", "b"], categories=["b", "a"], ordered=False)
          assert (c1 == c2).all()
  
          c1 = ctor(["a", "b"], categories=["a", "b"], ordered=False)
          c2 = ctor(["b", "a"], categories=["b", "a"], ordered=False)
          assert (c1 != c2).all()
  
          c1 = ctor(["a", "a"], categories=["a", "b"], ordered=False)
          c2 = ctor(["b", "b"], categories=["b", "a"], ordered=False)
          assert (c1 != c2).all()
  
          c1 = ctor(["a", "a"], categories=["a", "b"], ordered=False)
          c2 = ctor(["a", "b"], categories=["b", "a"], ordered=False)
          result = c1 == c2
          tm.assert_numpy_array_equal(np.array(result), np.array([True, False]))
  
      def test_unordered_different_categories_raises(self):
          c1 = Categorical(["a", "b"], categories=["a", "b"], ordered=False)
          c2 = Categorical(["a", "c"], categories=["c", "a"], ordered=False)
  
          with pytest.raises(TypeError, match=("Categoricals can only be compared")):
              c1 == c2
  
      def test_compare_different_lengths(self):
          c1 = Categorical([], categories=["a", "b"])
          c2 = Categorical([], categories=["a"])
  
          msg = "Categoricals can only be compared if 'categories' are the same."
          with pytest.raises(TypeError, match=msg):
              c1 == c2
  
      def test_compare_unordered_different_order(self):
          # https://github.com/pandas-dev/pandas/issues/16603#issuecomment-
          # 349290078
          a = Categorical(["a"], categories=["a", "b"])
          b = Categorical(["b"], categories=["b", "a"])
          assert not a.equals(b)
  
      def test_numeric_like_ops(self):
  
          df = DataFrame({"value": np.random.randint(0, 10000, 100)})
          labels = [f"{i} - {i + 499}" for i in range(0, 10000, 500)]
          cat_labels = Categorical(labels, labels)
  
          df = df.sort_values(by=["value"], ascending=True)
          df["value_group"] = pd.cut(
              df.value, range(0, 10500, 500), right=False, labels=cat_labels
          )
  
          # numeric ops should not succeed
          for op, str_rep in [
              ("__add__", r"\+"),
              ("__sub__", "-"),
              ("__mul__", r"\*"),
              ("__truediv__", "/"),
          ]:
              msg = f"Series cannot perform the operation {str_rep}|unsupported operand"
              with pytest.raises(TypeError, match=msg):
                  getattr(df, op)(df)
  
          # reduction ops should not succeed (unless specifically defined, e.g.
          # min/max)
          s = df["value_group"]
          for op in ["kurt", "skew", "var", "std", "mean", "sum", "median"]:
              msg = f"'Categorical' does not implement reduction '{op}'"
              with pytest.raises(TypeError, match=msg):
                  getattr(s, op)(numeric_only=False)
  
          # mad technically works because it takes always the numeric data
  
          # numpy ops
          s = Series(Categorical([1, 2, 3, 4]))
          with pytest.raises(
              TypeError, match="'Categorical' does not implement reduction 'sum'"
          ):
              np.sum(s)
  
          # numeric ops on a Series
          for op, str_rep in [
              ("__add__", r"\+"),
              ("__sub__", "-"),
              ("__mul__", r"\*"),
              ("__truediv__", "/"),
          ]:
              msg = f"Series cannot perform the operation {str_rep}|unsupported operand"
              with pytest.raises(TypeError, match=msg):
                  getattr(s, op)(2)
  
          # invalid ufunc
          msg = "Object with dtype category cannot perform the numpy op log"
          with pytest.raises(TypeError, match=msg):
              np.log(s)
   import numpy as np
  import pytest
  
  import pandas as pd
  from pandas import DataFrame
  import pandas._testing as tm
  
  
  class TestDataFrameFilter:
      def test_filter(self, float_frame, float_string_frame):
          # Items
          filtered = float_frame.filter(["A", "B", "E"])
          assert len(filtered.columns) == 2
          assert "E" not in filtered
  
          filtered = float_frame.filter(["A", "B", "E"], axis="columns")
          assert len(filtered.columns) == 2
          assert "E" not in filtered
  
          # Other axis
          idx = float_frame.index[0:4]
          filtered = float_frame.filter(idx, axis="index")
          expected = float_frame.reindex(index=idx)
          tm.assert_frame_equal(filtered, expected)
  
          # like
          fcopy = float_frame.copy()
          fcopy["AA"] = 1
  
          filtered = fcopy.filter(like="A")
          assert len(filtered.columns) == 2
          assert "AA" in filtered
  
          # like with ints in column names
          df = DataFrame(0.0, index=[0, 1, 2], columns=[0, 1, "_A", "_B"])
          filtered = df.filter(like="_")
          assert len(filtered.columns) == 2
  
          # regex with ints in column names
          # from PR #10384
          df = DataFrame(0.0, index=[0, 1, 2], columns=["A1", 1, "B", 2, "C"])
          expected = DataFrame(
              0.0, index=[0, 1, 2], columns=pd.Index([1, 2], dtype=object)
          )
          filtered = df.filter(regex="^[0-9]+$")
          tm.assert_frame_equal(filtered, expected)
  
          expected = DataFrame(0.0, index=[0, 1, 2], columns=[0, "0", 1, "1"])
          # shouldn't remove anything
          filtered = expected.filter(regex="^[0-9]+$")
          tm.assert_frame_equal(filtered, expected)
  
          # pass in None
          with pytest.raises(TypeError, match="Must pass"):
              float_frame.filter()
          with pytest.raises(TypeError, match="Must pass"):
              float_frame.filter(items=None)
          with pytest.raises(TypeError, match="Must pass"):
              float_frame.filter(axis=1)
  
          # test mutually exclusive arguments
          with pytest.raises(TypeError, match="mutually exclusive"):
              float_frame.filter(items=["one", "three"], regex="e$", like="bbi")
          with pytest.raises(TypeError, match="mutually exclusive"):
              float_frame.filter(items=["one", "three"], regex="e$", axis=1)
          with pytest.raises(TypeError, match="mutually exclusive"):
              float_frame.filter(items=["one", "three"], regex="e$")
          with pytest.raises(TypeError, match="mutually exclusive"):
              float_frame.filter(items=["one", "three"], like="bbi", axis=0)
          with pytest.raises(TypeError, match="mutually exclusive"):
              float_frame.filter(items=["one", "three"], like="bbi")
  
          # objects
          filtered = float_string_frame.filter(like="foo")
          assert "foo" in filtered
  
          # unicode columns, won't ascii-encode
          df = float_frame.rename(columns={"B": "\u2202"})
          filtered = df.filter(like="C")
          assert "C" in filtered
  
      def test_filter_regex_search(self, float_frame):
          fcopy = float_frame.copy()
          fcopy["AA"] = 1
  
          # regex
          filtered = fcopy.filter(regex="[A]+")
          assert len(filtered.columns) == 2
          assert "AA" in filtered
  
          # doesn't have to be at beginning
          df = DataFrame(
              {"aBBa": [1, 2], "BBaBB": [1, 2], "aCCa": [1, 2], "aCCaBB": [1, 2]}
          )
  
          result = df.filter(regex="BB")
          exp = df[[x for x in df.columns if "BB" in x]]
          tm.assert_frame_equal(result, exp)
  
      @pytest.mark.parametrize(
          "name,expected",
          [
              ("a", DataFrame({"a": [1, 2]})),
              ("a", DataFrame({"a": [1, 2]})),
              ("あ", DataFrame({"あ": [3, 4]})),
          ],
      )
      def test_filter_unicode(self, name, expected):
          # GH13101
          df = DataFrame({"a": [1, 2], "あ": [3, 4]})
  
          tm.assert_frame_equal(df.filter(like=name), expected)
          tm.assert_frame_equal(df.filter(regex=name), expected)
  
      @pytest.mark.parametrize("name", ["a", "a"])
      def test_filter_bytestring(self, name):
          # GH13101
          df = DataFrame({b"a": [1, 2], b"b": [3, 4]})
          expected = DataFrame({b"a": [1, 2]})
  
          tm.assert_frame_equal(df.filter(like=name), expected)
          tm.assert_frame_equal(df.filter(regex=name), expected)
  
      def test_filter_corner(self):
          empty = DataFrame()
  
          result = empty.filter([])
          tm.assert_frame_equal(result, empty)
  
          result = empty.filter(like="foo")
          tm.assert_frame_equal(result, empty)
  
      def test_filter_regex_non_string(self):
          # GH#5798 trying to filter on non-string columns should drop,
          #  not raise
          df = DataFrame(np.random.random((3, 2)), columns=["STRING", 123])
          result = df.filter(regex="STRING")
          expected = df[["STRING"]]
          tm.assert_frame_equal(result, expected)
   """Base classes for all estimators."""
  
  # Author: Gael Varoquaux <gael.varoquaux@normalesup.org>
  # License: BSD 3 clause
  
  import copy
  import warnings
  from collections import defaultdict
  import platform
  import inspect
  import re
  
  import numpy as np
  
  from . import __version__
  from ._config import get_config
  from .utils import _IS_32BIT
  from .utils._tags import (
      _DEFAULT_TAGS,
      _safe_tags,
  )
  from .utils.validation import check_X_y
  from .utils.validation import check_array
  from .utils.validation import _check_y
  from .utils.validation import _num_features
  from .utils.validation import _check_feature_names_in
  from .utils._estimator_html_repr import estimator_html_repr
  from .utils.validation import _get_feature_names
  
  
  def clone(estimator, *, safe=True):
      """Constructs a new unfitted estimator with the same parameters.
  
      Clone does a deep copy of the model in an estimator
      without actually copying attached data. It yields a new estimator
      with the same parameters that has not been fitted on any data.
  
      If the estimator's `random_state` parameter is an integer (or if the
      estimator doesn't have a `random_state` parameter), an *exact clone* is
      returned: the clone and the original estimator will give the exact same
      results. Otherwise, *statistical clone* is returned: the clone might
      yield different results from the original estimator. More details can be
      found in :ref:`randomness`.
  
      Parameters
      ----------
      estimator : {list, tuple, set} of estimator instance or a single \
              estimator instance
          The estimator or group of estimators to be cloned.
  
      safe : bool, default=True
          If safe is False, clone will fall back to a deep copy on objects
          that are not estimators.
  
      """
      estimator_type = type(estimator)
      # XXX: not handling dictionaries
      if estimator_type in (list, tuple, set, frozenset):
          return estimator_type([clone(e, safe=safe) for e in estimator])
      elif not hasattr(estimator, "get_params") or isinstance(estimator, type):
          if not safe:
              return copy.deepcopy(estimator)
          else:
              if isinstance(estimator, type):
                  raise TypeError(
                      "Cannot clone object. "
                      + "You should provide an instance of "
                      + "scikit-learn estimator instead of a class."
                  )
              else:
                  raise TypeError(
                      "Cannot clone object '%s' (type %s): "
                      "it does not seem to be a scikit-learn "
                      "estimator as it does not implement a "
                      "'get_params' method." % (repr(estimator), type(estimator))
                  )
  
      klass = estimator.__class__
      new_object_params = estimator.get_params(deep=False)
      for name, param in new_object_params.items():
          new_object_params[name] = clone(param, safe=False)
      new_object = klass(**new_object_params)
      params_set = new_object.get_params(deep=False)
  
      # quick sanity check of the parameters of the clone
      for name in new_object_params:
          param1 = new_object_params[name]
          param2 = params_set[name]
          if param1 is not param2:
              raise RuntimeError(
                  "Cannot clone object %s, as the constructor "
                  "either does not set or modifies parameter %s" % (estimator, name)
              )
      return new_object
  
  
  def _pprint(params, offset=0, printer=repr):
      """Pretty print the dictionary 'params'
  
      Parameters
      ----------
      params : dict
          The dictionary to pretty print
  
      offset : int, default=0
          The offset in characters to add at the begin of each line.
  
      printer : callable, default=repr
          The function to convert entries to strings, typically
          the builtin str or repr
  
      """
      # Do a multi-line justified repr:
      options = np.get_printoptions()
      np.set_printoptions(precision=5, threshold=64, edgeitems=2)
      params_list = list()
      this_line_length = offset
      line_sep = ",\n" + (1 + offset // 2) * " "
      for i, (k, v) in enumerate(sorted(params.items())):
          if type(v) is float:
              # use str for representing floating point numbers
              # this way we get consistent representation across
              # architectures and versions.
              this_repr = "%s=%s" % (k, str(v))
          else:
              # use repr of the rest
              this_repr = "%s=%s" % (k, printer(v))
          if len(this_repr) > 500:
              this_repr = this_repr[:300] + "..." + this_repr[-100:]
          if i > 0:
              if this_line_length + len(this_repr) >= 75 or "\n" in this_repr:
                  params_list.append(line_sep)
                  this_line_length = len(line_sep)
              else:
                  params_list.append(", ")
                  this_line_length += 2
          params_list.append(this_repr)
          this_line_length += len(this_repr)
  
      np.set_printoptions(**options)
      lines = "".join(params_list)
      # Strip trailing space to avoid nightmare in doctests
      lines = "\n".join(l.rstrip(" ") for l in lines.split("\n"))
      return lines
  
  
  class BaseEstimator:
      """Base class for all estimators in scikit-learn.
  
      Notes
      -----
      All estimators should specify all the parameters that can be set
      at the class level in their ``__init__`` as explicit keyword
      arguments (no ``*args`` or ``**kwargs``).
      """
  
      @classmethod
      def _get_param_names(cls):
          """Get parameter names for the estimator"""
          # fetch the constructor or the original constructor before
          # deprecation wrapping if any
          init = getattr(cls.__init__, "deprecated_original", cls.__init__)
          if init is object.__init__:
              # No explicit constructor to introspect
              return []
  
          # introspect the constructor arguments to find the model parameters
          # to represent
          init_signature = inspect.signature(init)
          # Consider the constructor parameters excluding 'self'
          parameters = [
              p
              for p in init_signature.parameters.values()
              if p.name != "self" and p.kind != p.VAR_KEYWORD
          ]
          for p in parameters:
              if p.kind == p.VAR_POSITIONAL:
                  raise RuntimeError(
                      "scikit-learn estimators should always "
                      "specify their parameters in the signature"
                      " of their __init__ (no varargs)."
                      " %s with constructor %s doesn't "
                      " follow this convention." % (cls, init_signature)
                  )
          # Extract and sort argument names excluding 'self'
          return sorted([p.name for p in parameters])
  
      def get_params(self, deep=True):
          """
          Get parameters for this estimator.
  
          Parameters
          ----------
          deep : bool, default=True
              If True, will return the parameters for this estimator and
              contained subobjects that are estimators.
  
          Returns
          -------
          params : dict
              Parameter names mapped to their values.
          """
          out = dict()
          for key in self._get_param_names():
              value = getattr(self, key)
              if deep and hasattr(value, "get_params"):
                  deep_items = value.get_params().items()
                  out.update((key + "__" + k, val) for k, val in deep_items)
              out[key] = value
          return out
  
      def set_params(self, **params):
          """
          Set the parameters of this estimator.
  
          The method works on simple estimators as well as on nested objects
          (such as :class:`~sklearn.pipeline.Pipeline`). The latter have
          parameters of the form ``<component>__<parameter>`` so that it's
          possible to update each component of a nested object.
  
          Parameters
          ----------
          **params : dict
              Estimator parameters.
  
          Returns
          -------
          self : estimator instance
              Estimator instance.
          """
          if not params:
              # Simple optimization to gain speed (inspect is slow)
              return self
          valid_params = self.get_params(deep=True)
  
          nested_params = defaultdict(dict)  # grouped by prefix
          for key, value in params.items():
              key, delim, sub_key = key.partition("__")
              if key not in valid_params:
                  raise ValueError(
                      "Invalid parameter %s for estimator %s. "
                      "Check the list of available parameters "
                      "with `estimator.get_params().keys()`." % (key, self)
                  )
  
              if delim:
                  nested_params[key][sub_key] = value
              else:
                  setattr(self, key, value)
                  valid_params[key] = value
  
          for key, sub_params in nested_params.items():
              valid_params[key].set_params(**sub_params)
  
          return self
  
      def __repr__(self, N_CHAR_MAX=700):
          # N_CHAR_MAX is the (approximate) maximum number of non-blank
          # characters to render. We pass it as an optional parameter to ease
          # the tests.
  
          from .utils._pprint import _EstimatorPrettyPrinter
  
          N_MAX_ELEMENTS_TO_SHOW = 30  # number of elements to show in sequences
  
          # use ellipsis for sequences with a lot of elements
          pp = _EstimatorPrettyPrinter(
              compact=True,
              indent=1,
              indent_at_name=True,
              n_max_elements_to_show=N_MAX_ELEMENTS_TO_SHOW,
          )
  
          repr_ = pp.pformat(self)
  
          # Use bruteforce ellipsis when there are a lot of non-blank characters
          n_nonblank = len("".join(repr_.split()))
          if n_nonblank > N_CHAR_MAX:
              lim = N_CHAR_MAX // 2  # apprx number of chars to keep on both ends
              regex = r"^(\s*\S){%d}" % lim
              # The regex '^(\s*\S){%d}' % n
              # matches from the start of the string until the nth non-blank
              # character:
              # - ^ matches the start of string
              # - (pattern){n} matches n repetitions of pattern
              # - \s*\S matches a non-blank char following zero or more blanks
              left_lim = re.match(regex, repr_).end()
              right_lim = re.match(regex, repr_[::-1]).end()
  
              if "\n" in repr_[left_lim:-right_lim]:
                  # The left side and right side aren't on the same line.
                  # To avoid weird cuts, e.g.:
                  # categoric...ore',
                  # we need to start the right side with an appropriate newline
                  # character so that it renders properly as:
                  # categoric...
                  # handle_unknown='ignore',
                  # so we add [^\n]*\n which matches until the next \n
                  regex += r"[^\n]*\n"
                  right_lim = re.match(regex, repr_[::-1]).end()
  
              ellipsis = "..."
              if left_lim + len(ellipsis) < len(repr_) - right_lim:
                  # Only add ellipsis if it results in a shorter repr
                  repr_ = repr_[:left_lim] + "..." + repr_[-right_lim:]
  
          return repr_
  
      def __getstate__(self):
          try:
              state = super().__getstate__()
          except AttributeError:
              state = self.__dict__.copy()
  
          if type(self).__module__.startswith("sklearn."):
              return dict(state.items(), _sklearn_version=__version__)
          else:
              return state
  
      def __setstate__(self, state):
          if type(self).__module__.startswith("sklearn."):
              pickle_version = state.pop("_sklearn_version", "pre-0.18")
              if pickle_version != __version__:
                  warnings.warn(
                      "Trying to unpickle estimator {0} from version {1} when "
                      "using version {2}. This might lead to breaking code or "
                      "invalid results. Use at your own risk. "
                      "For more info please refer to:\n"
                      "https://scikit-learn.org/stable/modules/model_persistence"
                      ".html#security-maintainability-limitations".format(
                          self.__class__.__name__, pickle_version, __version__
                      ),
                      UserWarning,
                  )
          try:
              super().__setstate__(state)
          except AttributeError:
              self.__dict__.update(state)
  
      def _more_tags(self):
          return _DEFAULT_TAGS
  
      def _get_tags(self):
          collected_tags = {}
          for base_class in reversed(inspect.getmro(self.__class__)):
              if hasattr(base_class, "_more_tags"):
                  # need the if because mixins might not have _more_tags
                  # but might do redundant work in estimators
                  # (i.e. calling more tags on BaseEstimator multiple times)
                  more_tags = base_class._more_tags(self)
                  collected_tags.update(more_tags)
          return collected_tags
  
      def _check_n_features(self, X, reset):
          """Set the `n_features_in_` attribute, or check against it.
  
          Parameters
          ----------
          X : {ndarray, sparse matrix} of shape (n_samples, n_features)
              The input samples.
          reset : bool
              If True, the `n_features_in_` attribute is set to `X.shape[1]`.
              If False and the attribute exists, then check that it is equal to
              `X.shape[1]`. If False and the attribute does *not* exist, then
              the check is skipped.
              .. note::
                 It is recommended to call reset=True in `fit` and in the first
                 call to `partial_fit`. All other methods that validate `X`
                 should set `reset=False`.
          """
          try:
              n_features = _num_features(X)
          except TypeError as e:
              if not reset and hasattr(self, "n_features_in_"):
                  raise ValueError(
                      "X does not contain any features, but "
                      f"{self.__class__.__name__} is expecting "
                      f"{self.n_features_in_} features"
                  ) from e
              # If the number of features is not defined and reset=True,
              # then we skip this check
              return
  
          if reset:
              self.n_features_in_ = n_features
              return
  
          if not hasattr(self, "n_features_in_"):
              # Skip this check if the expected number of expected input features
              # was not recorded by calling fit first. This is typically the case
              # for stateless transformers.
              return
  
          if n_features != self.n_features_in_:
              raise ValueError(
                  f"X has {n_features} features, but {self.__class__.__name__} "
                  f"is expecting {self.n_features_in_} features as input."
              )
  
      def _check_feature_names(self, X, *, reset):
          """Set or check the `feature_names_in_` attribute.
  
          .. versionadded:: 1.0
  
          Parameters
          ----------
          X : {ndarray, dataframe} of shape (n_samples, n_features)
              The input samples.
  
          reset : bool
              Whether to reset the `feature_names_in_` attribute.
              If False, the input will be checked for consistency with
              feature names of data provided when reset was last True.
              .. note::
                 It is recommended to call `reset=True` in `fit` and in the first
                 call to `partial_fit`. All other methods that validate `X`
                 should set `reset=False`.
          """
  
          if reset:
              feature_names_in = _get_feature_names(X)
              if feature_names_in is not None:
                  self.feature_names_in_ = feature_names_in
              elif hasattr(self, "feature_names_in_"):
                  # Delete the attribute when the estimator is fitted on a new dataset
                  # that has no feature names.
                  delattr(self, "feature_names_in_")
              return
  
          fitted_feature_names = getattr(self, "feature_names_in_", None)
          X_feature_names = _get_feature_names(X)
  
          if fitted_feature_names is None and X_feature_names is None:
              # no feature names seen in fit and in X
              return
  
          if X_feature_names is not None and fitted_feature_names is None:
              warnings.warn(
                  f"X has feature names, but {self.__class__.__name__} was fitted without"
                  " feature names"
              )
              return
  
          if X_feature_names is None and fitted_feature_names is not None:
              warnings.warn(
                  "X does not have valid feature names, but"
                  f" {self.__class__.__name__} was fitted with feature names"
              )
              return
  
          # validate the feature names against the `feature_names_in_` attribute
          if len(fitted_feature_names) != len(X_feature_names) or np.any(
              fitted_feature_names != X_feature_names
          ):
              message = (
                  "The feature names should match those that were "
                  "passed during fit. Starting version 1.2, an error will be raised.\n"
              )
              fitted_feature_names_set = set(fitted_feature_names)
              X_feature_names_set = set(X_feature_names)
  
              unexpected_names = sorted(X_feature_names_set - fitted_feature_names_set)
              missing_names = sorted(fitted_feature_names_set - X_feature_names_set)
  
              def add_names(names):
                  output = ""
                  max_n_names = 5
                  for i, name in enumerate(names):
                      if i >= max_n_names:
                          output += "- ...\n"
                          break
                      output += f"- {name}\n"
                  return output
  
              if unexpected_names:
                  message += "Feature names unseen at fit time:\n"
                  message += add_names(unexpected_names)
  
              if missing_names:
                  message += "Feature names seen at fit time, yet now missing:\n"
                  message += add_names(missing_names)
  
              if not missing_names and not missing_names:
                  message += (
                      "Feature names must be in the same order as they were in fit.\n"
                  )
  
              warnings.warn(message, FutureWarning)
  
      def _validate_data(
          self,
          X="no_validation",
          y="no_validation",
          reset=True,
          validate_separately=False,
          **check_params,
      ):
          """Validate input data and set or check the `n_features_in_` attribute.
  
          Parameters
          ----------
          X : {array-like, sparse matrix, dataframe} of shape \
                  (n_samples, n_features), default='no validation'
              The input samples.
              If `'no_validation'`, no validation is performed on `X`. This is
              useful for meta-estimator which can delegate input validation to
              their underlying estimator(s). In that case `y` must be passed and
              the only accepted `check_params` are `multi_output` and
              `y_numeric`.
  
          y : array-like of shape (n_samples,), default='no_validation'
              The targets.
  
              - If `None`, `check_array` is called on `X`. If the estimator's
                requires_y tag is True, then an error will be raised.
              - If `'no_validation'`, `check_array` is called on `X` and the
                estimator's requires_y tag is ignored. This is a default
                placeholder and is never meant to be explicitly set. In that case
                `X` must be passed.
              - Otherwise, only `y` with `_check_y` or both `X` and `y` are
                checked with either `check_array` or `check_X_y` depending on
                `validate_separately`.
  
          reset : bool, default=True
              Whether to reset the `n_features_in_` attribute.
              If False, the input will be checked for consistency with data
              provided when reset was last True.
              .. note::
                 It is recommended to call reset=True in `fit` and in the first
                 call to `partial_fit`. All other methods that validate `X`
                 should set `reset=False`.
          validate_separately : False or tuple of dicts, default=False
              Only used if y is not None.
              If False, call validate_X_y(). Else, it must be a tuple of kwargs
              to be used for calling check_array() on X and y respectively.
          **check_params : kwargs
              Parameters passed to :func:`sklearn.utils.check_array` or
              :func:`sklearn.utils.check_X_y`. Ignored if validate_separately
              is not False.
  
          Returns
          -------
          out : {ndarray, sparse matrix} or tuple of these
              The validated input. A tuple is returned if both `X` and `y` are
              validated.
          """
          self._check_feature_names(X, reset=reset)
  
          if y is None and self._get_tags()["requires_y"]:
              raise ValueError(
                  f"This {self.__class__.__name__} estimator "
                  "requires y to be passed, but the target y is None."
              )
  
          no_val_X = isinstance(X, str) and X == "no_validation"
          no_val_y = y is None or isinstance(y, str) and y == "no_validation"
  
          if no_val_X and no_val_y:
              raise ValueError("Validation should be done on X, y or both.")
          elif not no_val_X and no_val_y:
              X = check_array(X, **check_params)
              out = X
          elif no_val_X and not no_val_y:
              y = _check_y(y, **check_params)
              out = y
          else:
              if validate_separately:
                  # We need this because some estimators validate X and y
                  # separately, and in general, separately calling check_array()
                  # on X and y isn't equivalent to just calling check_X_y()
                  # :(
                  check_X_params, check_y_params = validate_separately
                  X = check_array(X, **check_X_params)
                  y = check_array(y, **check_y_params)
              else:
                  X, y = check_X_y(X, y, **check_params)
              out = X, y
  
          if not no_val_X and check_params.get("ensure_2d", True):
              self._check_n_features(X, reset=reset)
  
          return out
  
      @property
      def _repr_html_(self):
          """HTML representation of estimator.
  
          This is redundant with the logic of `_repr_mimebundle_`. The latter
          should be favorted in the long term, `_repr_html_` is only
          implemented for consumers who do not interpret `_repr_mimbundle_`.
          """
          if get_config()["display"] != "diagram":
              raise AttributeError(
                  "_repr_html_ is only defined when the "
                  "'display' configuration option is set to "
                  "'diagram'"
              )
          return self._repr_html_inner
  
      def _repr_html_inner(self):
          """This function is returned by the @property `_repr_html_` to make
          `hasattr(estimator, "_repr_html_") return `True` or `False` depending
          on `get_config()["display"]`.
          """
          return estimator_html_repr(self)
  
      def _repr_mimebundle_(self, **kwargs):
          """Mime bundle used by jupyter kernels to display estimator"""
          output = {"text/plain": repr(self)}
          if get_config()["display"] == "diagram":
              output["text/html"] = estimator_html_repr(self)
          return output
  
  
  class ClassifierMixin:
      """Mixin class for all classifiers in scikit-learn."""
  
      _estimator_type = "classifier"
  
      def score(self, X, y, sample_weight=None):
          """
          Return the mean accuracy on the given test data and labels.
  
          In multi-label classification, this is the subset accuracy
          which is a harsh metric since you require for each sample that
          each label set be correctly predicted.
  
          Parameters
          ----------
          X : array-like of shape (n_samples, n_features)
              Test samples.
  
          y : array-like of shape (n_samples,) or (n_samples, n_outputs)
              True labels for `X`.
  
          sample_weight : array-like of shape (n_samples,), default=None
              Sample weights.
  
          Returns
          -------
          score : float
              Mean accuracy of ``self.predict(X)`` wrt. `y`.
          """
          from .metrics import accuracy_score
  
          return accuracy_score(y, self.predict(X), sample_weight=sample_weight)
  
      def _more_tags(self):
          return {"requires_y": True}
  
  
  class RegressorMixin:
      """Mixin class for all regression estimators in scikit-learn."""
  
      _estimator_type = "regressor"
  
      def score(self, X, y, sample_weight=None):
          """Return the coefficient of determination of the prediction.
  
          The coefficient of determination :math:`R^2` is defined as
          :math:`(1 - \\frac{u}{v})`, where :math:`u` is the residual
          sum of squares ``((y_true - y_pred)** 2).sum()`` and :math:`v`
          is the total sum of squares ``((y_true - y_true.mean()) ** 2).sum()``.
          The best possible score is 1.0 and it can be negative (because the
          model can be arbitrarily worse). A constant model that always predicts
          the expected value of `y`, disregarding the input features, would get
          a :math:`R^2` score of 0.0.
  
          Parameters
          ----------
          X : array-like of shape (n_samples, n_features)
              Test samples. For some estimators this may be a precomputed
              kernel matrix or a list of generic objects instead with shape
              ``(n_samples, n_samples_fitted)``, where ``n_samples_fitted``
              is the number of samples used in the fitting for the estimator.
  
          y : array-like of shape (n_samples,) or (n_samples, n_outputs)
              True values for `X`.
  
          sample_weight : array-like of shape (n_samples,), default=None
              Sample weights.
  
          Returns
          -------
          score : float
              :math:`R^2` of ``self.predict(X)`` wrt. `y`.
  
          Notes
          -----
          The :math:`R^2` score used when calling ``score`` on a regressor uses
          ``multioutput='uniform_average'`` from version 0.23 to keep consistent
          with default value of :func:`~sklearn.metrics.r2_score`.
          This influences the ``score`` method of all the multioutput
          regressors (except for
          :class:`~sklearn.multioutput.MultiOutputRegressor`).
          """
  
          from .metrics import r2_score
  
          y_pred = self.predict(X)
          return r2_score(y, y_pred, sample_weight=sample_weight)
  
      def _more_tags(self):
          return {"requires_y": True}
  
  
  class ClusterMixin:
      """Mixin class for all cluster estimators in scikit-learn."""
  
      _estimator_type = "clusterer"
  
      def fit_predict(self, X, y=None):
          """
          Perform clustering on `X` and returns cluster labels.
  
          Parameters
          ----------
          X : array-like of shape (n_samples, n_features)
              Input data.
  
          y : Ignored
              Not used, present for API consistency by convention.
  
          Returns
          -------
          labels : ndarray of shape (n_samples,), dtype=np.int64
              Cluster labels.
          """
          # non-optimized default implementation; override when a better
          # method is possible for a given clustering algorithm
          self.fit(X)
          return self.labels_
  
      def _more_tags(self):
          return {"preserves_dtype": []}
  
  
  class BiclusterMixin:
      """Mixin class for all bicluster estimators in scikit-learn."""
  
      @property
      def biclusters_(self):
          """Convenient way to get row and column indicators together.
  
          Returns the ``rows_`` and ``columns_`` members.
          """
          return self.rows_, self.columns_
  
      def get_indices(self, i):
          """Row and column indices of the `i`'th bicluster.
  
          Only works if ``rows_`` and ``columns_`` attributes exist.
  
          Parameters
          ----------
          i : int
              The index of the cluster.
  
          Returns
          -------
          row_ind : ndarray, dtype=np.intp
              Indices of rows in the dataset that belong to the bicluster.
          col_ind : ndarray, dtype=np.intp
              Indices of columns in the dataset that belong to the bicluster.
          """
          rows = self.rows_[i]
          columns = self.columns_[i]
          return np.nonzero(rows)[0], np.nonzero(columns)[0]
  
      def get_shape(self, i):
          """Shape of the `i`'th bicluster.
  
          Parameters
          ----------
          i : int
              The index of the cluster.
  
          Returns
          -------
          n_rows : int
              Number of rows in the bicluster.
  
          n_cols : int
              Number of columns in the bicluster.
          """
          indices = self.get_indices(i)
          return tuple(len(i) for i in indices)
  
      def get_submatrix(self, i, data):
          """Return the submatrix corresponding to bicluster `i`.
  
          Parameters
          ----------
          i : int
              The index of the cluster.
          data : array-like of shape (n_samples, n_features)
              The data.
  
          Returns
          -------
          submatrix : ndarray of shape (n_rows, n_cols)
              The submatrix corresponding to bicluster `i`.
  
          Notes
          -----
          Works with sparse matrices. Only works if ``rows_`` and
          ``columns_`` attributes exist.
          """
          from .utils.validation import check_array
  
          data = check_array(data, accept_sparse="csr")
          row_ind, col_ind = self.get_indices(i)
          return data[row_ind[:, np.newaxis], col_ind]
  
  
  class TransformerMixin:
      """Mixin class for all transformers in scikit-learn."""
  
      def fit_transform(self, X, y=None, **fit_params):
          """
          Fit to data, then transform it.
  
          Fits transformer to `X` and `y` with optional parameters `fit_params`
          and returns a transformed version of `X`.
  
          Parameters
          ----------
          X : array-like of shape (n_samples, n_features)
              Input samples.
  
          y :  array-like of shape (n_samples,) or (n_samples, n_outputs), \
                  default=None
              Target values (None for unsupervised transformations).
  
          **fit_params : dict
              Additional fit parameters.
  
          Returns
          -------
          X_new : ndarray array of shape (n_samples, n_features_new)
              Transformed array.
          """
          # non-optimized default implementation; override when a better
          # method is possible for a given clustering algorithm
          if y is None:
              # fit method of arity 1 (unsupervised transformation)
              return self.fit(X, **fit_params).transform(X)
          else:
              # fit method of arity 2 (supervised transformation)
              return self.fit(X, y, **fit_params).transform(X)
  
  
  class _OneToOneFeatureMixin:
      """Provides `get_feature_names_out` for simple transformers.
  
      Assumes there's a 1-to-1 correspondence between input features
      and output features.
      """
  
      def get_feature_names_out(self, input_features=None):
          """Get output feature names for transformation.
  
          Parameters
          ----------
          input_features : array-like of str or None, default=None
              Input features.
  
              - If `input_features` is `None`, then `feature_names_in_` is
                used as feature names in. If `feature_names_in_` is not defined,
                then names are generated: `[x0, x1, ..., x(n_features_in_)]`.
              - If `input_features` is an array-like, then `input_features` must
                match `feature_names_in_` if `feature_names_in_` is defined.
  
          Returns
          -------
          feature_names_out : ndarray of str objects
              Same as input features.
          """
          return _check_feature_names_in(self, input_features)
  
  
  class DensityMixin:
      """Mixin class for all density estimators in scikit-learn."""
  
      _estimator_type = "DensityEstimator"
  
      def score(self, X, y=None):
          """Return the score of the model on the data `X`.
  
          Parameters
          ----------
          X : array-like of shape (n_samples, n_features)
              Test samples.
  
          y : Ignored
              Not used, present for API consistency by convention.
  
          Returns
          -------
          score : float
          """
          pass
  
  
  class OutlierMixin:
      """Mixin class for all outlier detection estimators in scikit-learn."""
  
      _estimator_type = "outlier_detector"
  
      def fit_predict(self, X, y=None):
          """Perform fit on X and returns labels for X.
  
          Returns -1 for outliers and 1 for inliers.
  
          Parameters
          ----------
          X : {array-like, sparse matrix} of shape (n_samples, n_features)
              The input samples.
  
          y : Ignored
              Not used, present for API consistency by convention.
  
          Returns
          -------
          y : ndarray of shape (n_samples,)
              1 for inliers, -1 for outliers.
          """
          # override for transductive outlier detectors like LocalOulierFactor
          return self.fit(X).predict(X)
  
  
  class MetaEstimatorMixin:
      _required_parameters = ["estimator"]
      """Mixin class for all meta estimators in scikit-learn."""
  
  
  class MultiOutputMixin:
      """Mixin to mark estimators that support multioutput."""
  
      def _more_tags(self):
          return {"multioutput": True}
  
  
  class _UnstableArchMixin:
      """Mark estimators that are non-determinstic on 32bit or PowerPC"""
  
      def _more_tags(self):
          return {
              "non_deterministic": (
                  _IS_32BIT or platform.machine().startswith(("ppc", "powerpc"))
              )
          }
  
  
  def is_classifier(estimator):
      """Return True if the given estimator is (probably) a classifier.
  
      Parameters
      ----------
      estimator : object
          Estimator object to test.
  
      Returns
      -------
      out : bool
          True if estimator is a classifier and False otherwise.
      """
      return getattr(estimator, "_estimator_type", None) == "classifier"
  
  
  def is_regressor(estimator):
      """Return True if the given estimator is (probably) a regressor.
  
      Parameters
      ----------
      estimator : estimator instance
          Estimator object to test.
  
      Returns
      -------
      out : bool
          True if estimator is a regressor and False otherwise.
      """
      return getattr(estimator, "_estimator_type", None) == "regressor"
  
  
  def is_outlier_detector(estimator):
      """Return True if the given estimator is (probably) an outlier detector.
  
      Parameters
      ----------
      estimator : estimator instance
          Estimator object to test.
  
      Returns
      -------
      out : bool
          True if estimator is an outlier detector and False otherwise.
      """
      return getattr(estimator, "_estimator_type", None) == "outlier_detector"
  
  
  def _is_pairwise(estimator):
      """Returns True if estimator is pairwise.
  
      - If the `_pairwise` attribute and the tag are present and consistent,
        then use the value and not issue a warning.
      - If the `_pairwise` attribute and the tag are present and not
        consistent, use the `_pairwise` value and issue a deprecation
        warning.
      - If only the `_pairwise` attribute is present and it is not False,
        issue a deprecation warning and use the `_pairwise` value.
  
      Parameters
      ----------
      estimator : object
          Estimator object to test.
  
      Returns
      -------
      out : bool
          True if the estimator is pairwise and False otherwise.
      """
      with warnings.catch_warnings():
          warnings.filterwarnings("ignore", category=FutureWarning)
          has_pairwise_attribute = hasattr(estimator, "_pairwise")
          pairwise_attribute = getattr(estimator, "_pairwise", False)
      pairwise_tag = _safe_tags(estimator, key="pairwise")
  
      if has_pairwise_attribute:
          if pairwise_attribute != pairwise_tag:
              warnings.warn(
                  "_pairwise was deprecated in 0.24 and will be removed in 1.1 "
                  "(renaming of 0.26). Set the estimator tags of your estimator "
                  "instead",
                  FutureWarning,
              )
          return pairwise_attribute
  
      # use pairwise tag when the attribute is not present
      return pairwise_tag
  
apis: pandas.Series pandas.DataFrame numpy.random.randn pandas.Float64Index numpy.arange pandas._testing.assert_series_equal numpy.array pandas._testing.makeDateIndex
apis: pandas.date_range pandas._libs.tslibs.timezones.tz_compare pandas.DataFrame pandas._testing.assert_frame_equal pandas._testing.assert_equal pandas._libs.tslibs.timezones.maybe_get_tz
apis: pandas._testing.assert_numpy_array_equal numpy.sum pandas.Series pandas.date_range pandas._testing.assert_categorical_equal numpy.random.permutation pandas.DataFrame pandas._testing.assert_frame_equal pandas.Categorical numpy.asarray pandas._testing.assert_series_equal numpy.log numpy.array numpy.random.randint
apis: numpy.random.random pandas.Index pandas.DataFrame pandas._testing.assert_frame_equal
apis: numpy.any numpy.get_printoptions numpy.set_printoptions numpy.nonzero