当前位置: 首页>>代码示例>>Python>>正文


Python testing.assert_produces_warning方法代码示例

本文整理汇总了Python中pandas.util.testing.assert_produces_warning方法的典型用法代码示例。如果您正苦于以下问题:Python testing.assert_produces_warning方法的具体用法?Python testing.assert_produces_warning怎么用?Python testing.assert_produces_warning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas.util.testing的用法示例。


在下文中一共展示了testing.assert_produces_warning方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_set_value

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_produces_warning [as 别名]
def test_set_value(self):
        for item in self.panel.items:
            for mjr in self.panel.major_axis[::2]:
                for mnr in self.panel.minor_axis:
                    with tm.assert_produces_warning(FutureWarning,
                                                    check_stacklevel=False):
                        self.panel.set_value(item, mjr, mnr, 1.)
                    tm.assert_almost_equal(self.panel[item][mnr][mjr], 1.)

        # resize
        with catch_warnings():
            simplefilter("ignore", FutureWarning)
            res = self.panel.set_value('ItemE', 'foo', 'bar', 1.5)
            assert isinstance(res, Panel)
            assert res is not self.panel
            assert res.get_value('ItemE', 'foo', 'bar') == 1.5

            res3 = self.panel.set_value('ItemE', 'foobar', 'baz', 5)
            assert is_float_dtype(res3['ItemE'].values)

            msg = ("There must be an argument for each "
                   "axis plus the value provided")
            with pytest.raises(TypeError, match=msg):
                self.panel.set_value('a') 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:26,代码来源:test_panel.py

示例2: test_concat_different_kind

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_produces_warning [as 别名]
def test_concat_different_kind(self):
        val1 = np.array([1, 2, np.nan, np.nan, 0, np.nan])
        val2 = np.array([3, np.nan, 4, 0, 0])

        sparse1 = pd.SparseSeries(val1, name='x', kind='integer')
        sparse2 = pd.SparseSeries(val2, name='y', kind='block', fill_value=0)

        with tm.assert_produces_warning(PerformanceWarning):
            res = pd.concat([sparse1, sparse2])
        exp = pd.concat([pd.Series(val1), pd.Series(val2)])
        exp = pd.SparseSeries(exp, kind='integer')
        tm.assert_sp_series_equal(res, exp)

        with tm.assert_produces_warning(PerformanceWarning):
            res = pd.concat([sparse2, sparse1])
        exp = pd.concat([pd.Series(val2), pd.Series(val1)])
        exp = pd.SparseSeries(exp, kind='block', fill_value=0)
        tm.assert_sp_series_equal(res, exp) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:test_series.py

示例3: test_sparse_frame_pad_backfill_limit

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_produces_warning [as 别名]
def test_sparse_frame_pad_backfill_limit(self):
        index = np.arange(10)
        df = DataFrame(np.random.randn(10, 4), index=index)
        sdf = df.to_sparse()

        result = sdf[:2].reindex(index, method='pad', limit=5)

        with tm.assert_produces_warning(PerformanceWarning):
            expected = sdf[:2].reindex(index).fillna(method='pad')
        expected = expected.to_dense()
        expected.values[-3:] = np.nan
        expected = expected.to_sparse()
        tm.assert_frame_equal(result, expected)

        result = sdf[-2:].reindex(index, method='backfill', limit=5)

        with tm.assert_produces_warning(PerformanceWarning):
            expected = sdf[-2:].reindex(index).fillna(method='backfill')
        expected = expected.to_dense()
        expected.values[:3] = np.nan
        expected = expected.to_sparse()
        tm.assert_frame_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:test_frame.py

示例4: test_apply

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_produces_warning [as 别名]
def test_apply(frame):
    applied = frame.apply(np.sqrt)
    assert isinstance(applied, SparseDataFrame)
    tm.assert_almost_equal(applied.values, np.sqrt(frame.values))

    # agg / broadcast
    with tm.assert_produces_warning(FutureWarning):
        broadcasted = frame.apply(np.sum, broadcast=True)
    assert isinstance(broadcasted, SparseDataFrame)

    with tm.assert_produces_warning(FutureWarning):
        exp = frame.to_dense().apply(np.sum, broadcast=True)
    tm.assert_frame_equal(broadcasted.to_dense(), exp)

    applied = frame.apply(np.sum)
    tm.assert_series_equal(applied,
                           frame.to_dense().apply(nanops.nansum).to_sparse()) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_apply.py

示例5: test_from_codes_with_float

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_produces_warning [as 别名]
def test_from_codes_with_float(self):
        # GH21767
        codes = [1.0, 2.0, 0]  # integer, but in float dtype
        dtype = CategoricalDtype(categories=['a', 'b', 'c'])

        with tm.assert_produces_warning(FutureWarning):
            cat = Categorical.from_codes(codes, dtype.categories)
        tm.assert_numpy_array_equal(cat.codes, np.array([1, 2, 0], dtype='i1'))

        with tm.assert_produces_warning(FutureWarning):
            cat = Categorical.from_codes(codes, dtype=dtype)
        tm.assert_numpy_array_equal(cat.codes, np.array([1, 2, 0], dtype='i1'))

        codes = [1.1, 2.0, 0]  # non-integer
        with pytest.raises(ValueError,
                           match="codes need to be array-like integers"):
            Categorical.from_codes(codes, dtype.categories)
        with pytest.raises(ValueError,
                           match="codes need to be array-like integers"):
            Categorical.from_codes(codes, dtype=dtype) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:test_constructors.py

示例6: test_union_sort_other_incomparable

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_produces_warning [as 别名]
def test_union_sort_other_incomparable(self):
        # https://github.com/pandas-dev/pandas/issues/24959
        idx = pd.Index([1, pd.Timestamp('2000')])
        # default (sort=None)
        with tm.assert_produces_warning(RuntimeWarning):
            result = idx.union(idx[:1])

        tm.assert_index_equal(result, idx)

        # sort=None
        with tm.assert_produces_warning(RuntimeWarning):
            result = idx.union(idx[:1], sort=None)
        tm.assert_index_equal(result, idx)

        # sort=False
        result = idx.union(idx[:1], sort=False)
        tm.assert_index_equal(result, idx) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_base.py

示例7: test_construction_with_alt_tz_localize

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_produces_warning [as 别名]
def test_construction_with_alt_tz_localize(self, kwargs, tz_aware_fixture):
        tz = tz_aware_fixture
        i = pd.date_range('20130101', periods=5, freq='H', tz=tz)
        kwargs = {key: attrgetter(val)(i) for key, val in kwargs.items()}

        if str(tz) in ('UTC', 'tzutc()'):
            warn = None
        else:
            warn = FutureWarning

        with tm.assert_produces_warning(warn, check_stacklevel=False):
            result = DatetimeIndex(i.tz_localize(None).asi8, **kwargs)
        expected = DatetimeIndex(i, **kwargs)
        tm.assert_index_equal(result, expected)

        # localize into the provided tz
        i2 = DatetimeIndex(i.tz_localize(None).asi8, tz='UTC')
        expected = i.tz_localize(None).tz_localize('UTC')
        tm.assert_index_equal(i2, expected)

        # incompat tz/dtype
        pytest.raises(ValueError, lambda: DatetimeIndex(
            i.tz_localize(None).asi8, dtype=i.dtype, tz='US/Pacific')) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:25,代码来源:test_construction.py

示例8: test_dti_tz_localize_nonexistent_raise_coerce

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_produces_warning [as 别名]
def test_dti_tz_localize_nonexistent_raise_coerce(self):
        # GH#13057
        times = ['2015-03-08 01:00', '2015-03-08 02:00', '2015-03-08 03:00']
        index = DatetimeIndex(times)
        tz = 'US/Eastern'
        with pytest.raises(pytz.NonExistentTimeError):
            index.tz_localize(tz=tz)

        with pytest.raises(pytz.NonExistentTimeError):
            with tm.assert_produces_warning(FutureWarning):
                index.tz_localize(tz=tz, errors='raise')

        with tm.assert_produces_warning(FutureWarning,
                                        clear=FutureWarning,
                                        check_stacklevel=False):
            result = index.tz_localize(tz=tz, errors='coerce')
        test_times = ['2015-03-08 01:00-05:00', 'NaT',
                      '2015-03-08 03:00-04:00']
        dti = to_datetime(test_times, utc=True)
        expected = dti.tz_convert('US/Eastern')
        tm.assert_index_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:23,代码来源:test_timezones.py

示例9: test_to_period_tz

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_produces_warning [as 别名]
def test_to_period_tz(self, tz):
        ts = date_range('1/1/2000', '2/1/2000', tz=tz)

        with tm.assert_produces_warning(UserWarning):
            # GH#21333 warning that timezone info will be lost
            result = ts.to_period()[0]
            expected = ts[0].to_period()

        assert result == expected

        expected = date_range('1/1/2000', '2/1/2000').to_period()

        with tm.assert_produces_warning(UserWarning):
            # GH#21333 warning that timezone info will be lost
            result = ts.to_period()

        tm.assert_index_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_astype.py

示例10: test_asarray_tz_naive

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_produces_warning [as 别名]
def test_asarray_tz_naive(self):
        # This shouldn't produce a warning.
        idx = pd.date_range('2000', periods=2)
        # M8[ns] by default
        with tm.assert_produces_warning(None):
            result = np.asarray(idx)

        expected = np.array(['2000-01-01', '2000-01-02'], dtype='M8[ns]')
        tm.assert_numpy_array_equal(result, expected)

        # optionally, object
        with tm.assert_produces_warning(None):
            result = np.asarray(idx, dtype=object)

        expected = np.array([pd.Timestamp('2000-01-01'),
                             pd.Timestamp('2000-01-02')])
        tm.assert_numpy_array_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_datetime.py

示例11: test_asarray_tz_aware

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_produces_warning [as 别名]
def test_asarray_tz_aware(self):
        tz = 'US/Central'
        idx = pd.date_range('2000', periods=2, tz=tz)
        expected = np.array(['2000-01-01T06', '2000-01-02T06'], dtype='M8[ns]')
        # We warn by default and return an ndarray[M8[ns]]
        with tm.assert_produces_warning(FutureWarning):
            result = np.asarray(idx)

        tm.assert_numpy_array_equal(result, expected)

        # Old behavior with no warning
        with tm.assert_produces_warning(None):
            result = np.asarray(idx, dtype="M8[ns]")

        tm.assert_numpy_array_equal(result, expected)

        # Future behavior with no warning
        expected = np.array([pd.Timestamp("2000-01-01", tz=tz),
                             pd.Timestamp("2000-01-02", tz=tz)])
        with tm.assert_produces_warning(None):
            result = np.asarray(idx, dtype=object)

        tm.assert_numpy_array_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:25,代码来源:test_datetime.py

示例12: test_dti_shift_int

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_produces_warning [as 别名]
def test_dti_shift_int(self):
        rng = date_range('1/1/2000', periods=20)

        with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
            # GH#22535
            result = rng + 5

        expected = rng.shift(5)
        tm.assert_index_equal(result, expected)

        with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
            # GH#22535
            result = rng - 5

        expected = rng.shift(-5)
        tm.assert_index_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:test_arithmetic.py

示例13: test_pindex_multiples

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_produces_warning [as 别名]
def test_pindex_multiples(self):
        with tm.assert_produces_warning(FutureWarning):
            pi = PeriodIndex(start='1/1/11', end='12/31/11', freq='2M')
        expected = PeriodIndex(['2011-01', '2011-03', '2011-05', '2011-07',
                                '2011-09', '2011-11'], freq='2M')
        tm.assert_index_equal(pi, expected)
        assert pi.freq == offsets.MonthEnd(2)
        assert pi.freqstr == '2M'

        pi = period_range(start='1/1/11', end='12/31/11', freq='2M')
        tm.assert_index_equal(pi, expected)
        assert pi.freq == offsets.MonthEnd(2)
        assert pi.freqstr == '2M'

        pi = period_range(start='1/1/11', periods=6, freq='2M')
        tm.assert_index_equal(pi, expected)
        assert pi.freq == offsets.MonthEnd(2)
        assert pi.freqstr == '2M' 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:test_period.py

示例14: test_fillna_limit_pad

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_produces_warning [as 别名]
def test_fillna_limit_pad(self, data_missing):
        with tm.assert_produces_warning(PerformanceWarning):
            super(TestMissing, self).test_fillna_limit_pad(data_missing) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:5,代码来源:test_sparse.py

示例15: test_fillna_limit_backfill

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_produces_warning [as 别名]
def test_fillna_limit_backfill(self, data_missing):
        with tm.assert_produces_warning(PerformanceWarning):
            super(TestMissing, self).test_fillna_limit_backfill(data_missing) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:5,代码来源:test_sparse.py


注:本文中的pandas.util.testing.assert_produces_warning方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。