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


Python errors.PerformanceWarning方法代码示例

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


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

示例1: test_concat_different_fill

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

        for kind in ['integer', 'block']:
            sparse1 = pd.SparseSeries(val1, name='x', kind=kind)
            sparse2 = pd.SparseSeries(val2, name='y', kind=kind, 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=kind)
            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=kind, fill_value=0)
            tm.assert_sp_series_equal(res, exp) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:21,代码来源:test_series.py

示例2: test_concat_different_kind

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import PerformanceWarning [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 import errors [as 别名]
# 或者: from pandas.errors import PerformanceWarning [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_unsortedindex_doc_examples

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import PerformanceWarning [as 别名]
def test_unsortedindex_doc_examples():
    # http://pandas.pydata.org/pandas-docs/stable/advanced.html#sorting-a-multiindex  # noqa
    dfm = DataFrame({'jim': [0, 0, 1, 1],
                     'joe': ['x', 'x', 'z', 'y'],
                     'jolie': np.random.rand(4)})

    dfm = dfm.set_index(['jim', 'joe'])
    with tm.assert_produces_warning(PerformanceWarning):
        dfm.loc[(1, 'z')]

    with pytest.raises(UnsortedIndexError):
        dfm.loc[(0, 'y'):(1, 'z')]

    assert not dfm.index.is_lexsorted()
    assert dfm.index.lexsort_depth == 1

    # sort it
    dfm = dfm.sort_index()
    dfm.loc[(1, 'z')]
    dfm.loc[(0, 'y'):(1, 'z')]

    assert dfm.index.is_lexsorted()
    assert dfm.index.lexsort_depth == 2 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:25,代码来源:test_sorting.py

示例5: test_ix_general

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import PerformanceWarning [as 别名]
def test_ix_general(self):

        # ix general issues

        # GH 2817
        data = {'amount': {0: 700, 1: 600, 2: 222, 3: 333, 4: 444},
                'col': {0: 3.5, 1: 3.5, 2: 4.0, 3: 4.0, 4: 4.0},
                'year': {0: 2012, 1: 2011, 2: 2012, 3: 2012, 4: 2012}}
        df = DataFrame(data).set_index(keys=['col', 'year'])
        key = 4.0, 2012

        # emits a PerformanceWarning, ok
        with tm.assert_produces_warning(PerformanceWarning):
            tm.assert_frame_equal(df.loc[key], df.iloc[2:])

        # this is ok
        df.sort_index(inplace=True)
        res = df.loc[key]

        # col has float dtype, result should be Float64Index
        index = MultiIndex.from_arrays([[4.] * 3, [2012] * 3],
                                       names=['col', 'year'])
        expected = DataFrame({'amount': [222, 333, 444]}, index=index)
        tm.assert_frame_equal(res, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:26,代码来源:test_ix.py

示例6: test_sparse_series_fillna_limit

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import PerformanceWarning [as 别名]
def test_sparse_series_fillna_limit(self):
        index = np.arange(10)
        s = Series(np.random.randn(10), index=index)

        ss = s[:2].reindex(index).to_sparse()
        # TODO: what is this test doing? why are result an expected
        # the same call to fillna?
        with tm.assert_produces_warning(PerformanceWarning):
            # TODO: release-note fillna performance warning
            result = ss.fillna(method='pad', limit=5)
            expected = ss.fillna(method='pad', limit=5)
        expected = expected.to_dense()
        expected[-3:] = np.nan
        expected = expected.to_sparse()
        assert_series_equal(result, expected)

        ss = s[-2:].reindex(index).to_sparse()
        with tm.assert_produces_warning(PerformanceWarning):
            result = ss.fillna(method='backfill', limit=5)
            expected = ss.fillna(method='backfill')
        expected = expected.to_dense()
        expected[:3] = np.nan
        expected = expected.to_sparse()
        assert_series_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:26,代码来源:test_missing.py

示例7: test_sparse_series_pad_backfill_limit

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import PerformanceWarning [as 别名]
def test_sparse_series_pad_backfill_limit(self):
        index = np.arange(10)
        s = Series(np.random.randn(10), index=index)
        s = s.to_sparse()

        result = s[:2].reindex(index, method='pad', limit=5)
        with tm.assert_produces_warning(PerformanceWarning):
            expected = s[:2].reindex(index).fillna(method='pad')
        expected = expected.to_dense()
        expected[-3:] = np.nan
        expected = expected.to_sparse()
        assert_series_equal(result, expected)

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

示例8: test_td64arr_add_offset_array

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import PerformanceWarning [as 别名]
def test_td64arr_add_offset_array(self, box):
        # GH#18849
        tdi = TimedeltaIndex(['1 days 00:00:00', '3 days 04:00:00'])
        other = np.array([pd.offsets.Hour(n=1), pd.offsets.Minute(n=-2)])

        expected = TimedeltaIndex([tdi[n] + other[n] for n in range(len(tdi))],
                                  freq='infer')

        tdi = tm.box_expected(tdi, box)
        expected = tm.box_expected(expected, box)

        # The DataFrame operation is transposed and so operates as separate
        #  scalar operations, which do not issue a PerformanceWarning
        warn = PerformanceWarning if box is not pd.DataFrame else None
        with tm.assert_produces_warning(warn):
            res = tdi + other
        tm.assert_equal(res, expected)

        with tm.assert_produces_warning(warn):
            res2 = other + tdi
        tm.assert_equal(res2, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:23,代码来源:test_timedelta64.py

示例9: test_td64arr_sub_offset_array

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import PerformanceWarning [as 别名]
def test_td64arr_sub_offset_array(self, box_with_array):
        # GH#18824
        tdi = TimedeltaIndex(['1 days 00:00:00', '3 days 04:00:00'])
        other = np.array([pd.offsets.Hour(n=1), pd.offsets.Minute(n=-2)])

        expected = TimedeltaIndex([tdi[n] - other[n] for n in range(len(tdi))],
                                  freq='infer')

        tdi = tm.box_expected(tdi, box_with_array)
        expected = tm.box_expected(expected, box_with_array)

        # The DataFrame operation is transposed and so operates as separate
        #  scalar operations, which do not issue a PerformanceWarning
        warn = None if box_with_array is pd.DataFrame else PerformanceWarning
        with tm.assert_produces_warning(warn):
            res = tdi - other
        tm.assert_equal(res, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_timedelta64.py

示例10: test_td64arr_addsub_anchored_offset_arraylike

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import PerformanceWarning [as 别名]
def test_td64arr_addsub_anchored_offset_arraylike(self, obox,
                                                      box_with_array):
        # GH#18824
        tdi = TimedeltaIndex(['1 days 00:00:00', '3 days 04:00:00'])
        tdi = tm.box_expected(tdi, box_with_array)

        anchored = obox([pd.offsets.MonthEnd(), pd.offsets.Day(n=2)])

        # addition/subtraction ops with anchored offsets should issue
        # a PerformanceWarning and _then_ raise a TypeError.
        with pytest.raises(TypeError):
            with tm.assert_produces_warning(PerformanceWarning):
                tdi + anchored
        with pytest.raises(TypeError):
            with tm.assert_produces_warning(PerformanceWarning):
                anchored + tdi
        with pytest.raises(TypeError):
            with tm.assert_produces_warning(PerformanceWarning):
                tdi - anchored
        with pytest.raises(TypeError):
            with tm.assert_produces_warning(PerformanceWarning):
                anchored - tdi 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:test_timedelta64.py

示例11: test_dti_add_intarray_non_tick

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import PerformanceWarning [as 别名]
def test_dti_add_intarray_non_tick(self, int_holder, freq):
        # GH#19959
        dti = pd.date_range('2016-01-01', periods=2, freq=freq)
        other = int_holder([4, -1])

        with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
            expected = DatetimeIndex([dti[n] + other[n]
                                      for n in range(len(dti))])

        # tm.assert_produces_warning does not handle cases where we expect
        # two warnings, in this case PerformanceWarning and FutureWarning.
        # Until that is fixed, we don't catch either
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            result = dti + other
        tm.assert_index_equal(result, expected)

        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            result = other + dti
        tm.assert_index_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:23,代码来源:test_datetime64.py

示例12: test_dti_add_offset_index

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import PerformanceWarning [as 别名]
def test_dti_add_offset_index(self, tz_naive_fixture, names):
        # GH#18849, GH#19744
        tz = tz_naive_fixture
        dti = pd.date_range('2017-01-01', periods=2, tz=tz, name=names[0])
        other = pd.Index([pd.offsets.MonthEnd(), pd.offsets.Day(n=2)],
                         name=names[1])

        with tm.assert_produces_warning(PerformanceWarning,
                                        clear=[pd.core.arrays.datetimelike]):
            res = dti + other
        expected = DatetimeIndex([dti[n] + other[n] for n in range(len(dti))],
                                 name=names[2], freq='infer')
        tm.assert_index_equal(res, expected)

        with tm.assert_produces_warning(PerformanceWarning,
                                        clear=[pd.core.arrays.datetimelike]):
            res2 = other + dti
        tm.assert_index_equal(res2, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:test_datetime64.py

示例13: test_pi_add_offset_array

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import PerformanceWarning [as 别名]
def test_pi_add_offset_array(self, box):
        # GH#18849
        pi = pd.PeriodIndex([pd.Period('2015Q1'), pd.Period('2016Q2')])
        offs = box([pd.offsets.QuarterEnd(n=1, startingMonth=12),
                    pd.offsets.QuarterEnd(n=-2, startingMonth=12)])
        expected = pd.PeriodIndex([pd.Period('2015Q2'), pd.Period('2015Q4')])

        with tm.assert_produces_warning(PerformanceWarning):
            res = pi + offs
        tm.assert_index_equal(res, expected)

        with tm.assert_produces_warning(PerformanceWarning):
            res2 = offs + pi
        tm.assert_index_equal(res2, expected)

        unanchored = np.array([pd.offsets.Hour(n=1),
                               pd.offsets.Minute(n=-2)])
        # addition/subtraction ops with incompatible offsets should issue
        # a PerformanceWarning and _then_ raise a TypeError.
        with pytest.raises(IncompatibleFrequency):
            with tm.assert_produces_warning(PerformanceWarning):
                pi + unanchored
        with pytest.raises(IncompatibleFrequency):
            with tm.assert_produces_warning(PerformanceWarning):
                unanchored + pi 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:27,代码来源:test_period.py

示例14: _add_offset

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import PerformanceWarning [as 别名]
def _add_offset(self, offset):
        assert not isinstance(offset, Tick)
        try:
            if self.tz is not None:
                values = self.tz_localize(None)
            else:
                values = self
            result = offset.apply_index(values)
            if self.tz is not None:
                result = result.tz_localize(self.tz)

        except NotImplementedError:
            warnings.warn("Non-vectorized DateOffset being applied to Series "
                          "or DatetimeIndex", PerformanceWarning)
            result = self.astype('O') + offset

        return type(self)._from_sequence(result, freq='infer') 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:datetimes.py

示例15: test_tdi_add_offset_index

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import PerformanceWarning [as 别名]
def test_tdi_add_offset_index(self, names):
        # GH#18849, GH#19744
        tdi = TimedeltaIndex(['1 days 00:00:00', '3 days 04:00:00'],
                             name=names[0])
        other = pd.Index([pd.offsets.Hour(n=1), pd.offsets.Minute(n=-2)],
                         name=names[1])

        expected = TimedeltaIndex([tdi[n] + other[n] for n in range(len(tdi))],
                                  freq='infer', name=names[2])

        with tm.assert_produces_warning(PerformanceWarning):
            res = tdi + other
        tm.assert_index_equal(res, expected)

        with tm.assert_produces_warning(PerformanceWarning):
            res2 = other + tdi
        tm.assert_index_equal(res2, expected) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:19,代码来源:test_arithmetic.py


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