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


Python testing.makeIntIndex方法代码示例

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


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

示例1: setup_method

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeIntIndex [as 别名]
def setup_method(self, method):
        self.indices = dict(unicodeIndex=tm.makeUnicodeIndex(100),
                            strIndex=tm.makeStringIndex(100),
                            dateIndex=tm.makeDateIndex(100),
                            periodIndex=tm.makePeriodIndex(100),
                            tdIndex=tm.makeTimedeltaIndex(100),
                            intIndex=tm.makeIntIndex(100),
                            uintIndex=tm.makeUIntIndex(100),
                            rangeIndex=tm.makeRangeIndex(100),
                            floatIndex=tm.makeFloatIndex(100),
                            boolIndex=Index([True, False]),
                            catIndex=tm.makeCategoricalIndex(100),
                            empty=Index([]),
                            tuples=MultiIndex.from_tuples(lzip(
                                ['foo', 'bar', 'baz'], [1, 2, 3])),
                            repeats=Index([0, 0, 1, 1, 2, 2]))
        self.setup_indices() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_base.py

示例2: test_map_dictlike

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeIntIndex [as 别名]
def test_map_dictlike(self, mapper):
        # GH 12756
        expected = Index(['foo', 'bar', 'baz'])
        index = tm.makeIntIndex(3)
        result = index.map(mapper(expected.values, index))
        tm.assert_index_equal(result, expected)

        # TODO: replace with fixture
        for name in self.indices.keys():
            if name == 'catIndex':
                # Tested in test_categorical
                continue
            elif name == 'repeats':
                # Cannot map duplicated index
                continue

            index = self.indices[name]
            expected = Index(np.arange(len(index), 0, -1))

            # to match proper result coercion for uints
            if name == 'empty':
                expected = Index([])

            result = index.map(mapper(expected, index))
            tm.assert_index_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:27,代码来源:test_base.py

示例3: setup_method

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeIntIndex [as 别名]
def setup_method(self, method):
        super(TestIndex, self).setup_method(method)

        self.d = {
            'string': tm.makeStringIndex(100),
            'date': tm.makeDateIndex(100),
            'int': tm.makeIntIndex(100),
            'rng': tm.makeRangeIndex(100),
            'float': tm.makeFloatIndex(100),
            'empty': Index([]),
            'tuple': Index(zip(['foo', 'bar', 'baz'], [1, 2, 3])),
            'period': Index(period_range('2012-1-1', freq='M', periods=3)),
            'date2': Index(date_range('2013-01-1', periods=10)),
            'bdate': Index(bdate_range('2013-01-02', periods=10)),
            'cat': tm.makeCategoricalIndex(100),
            'interval': tm.makeIntervalIndex(100),
            'timedelta': tm.makeTimedeltaIndex(100, 'H')
        }

        self.mi = {
            'reg': MultiIndex.from_tuples([('bar', 'one'), ('baz', 'two'),
                                           ('foo', 'two'),
                                           ('qux', 'one'), ('qux', 'two')],
                                          names=['first', 'second']),
        } 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:27,代码来源:test_packers.py

示例4: setUp

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeIntIndex [as 别名]
def setUp(self):
        super(TestIndex, self).setUp()

        self.d = {
            'string': tm.makeStringIndex(100),
            'date': tm.makeDateIndex(100),
            'int': tm.makeIntIndex(100),
            'float': tm.makeFloatIndex(100),
            'empty': Index([]),
            'tuple': Index(zip(['foo', 'bar', 'baz'], [1, 2, 3])),
            'period': Index(period_range('2012-1-1', freq='M', periods=3)),
            'date2': Index(date_range('2013-01-1', periods=10)),
            'bdate': Index(bdate_range('2013-01-02', periods=10)),
        }

        self.mi = {
            'reg': MultiIndex.from_tuples([('bar', 'one'), ('baz', 'two'), ('foo', 'two'),
                                           ('qux', 'one'), ('qux', 'two')], names=['first', 'second']),
        } 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:21,代码来源:test_packers.py

示例5: setup_method

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeIntIndex [as 别名]
def setup_method(self, method):
        self.indices = dict(unicodeIndex=tm.makeUnicodeIndex(100),
                            strIndex=tm.makeStringIndex(100),
                            dateIndex=tm.makeDateIndex(100),
                            periodIndex=tm.makePeriodIndex(100),
                            tdIndex=tm.makeTimedeltaIndex(100),
                            intIndex=tm.makeIntIndex(100),
                            uintIndex=tm.makeUIntIndex(100),
                            rangeIndex=tm.makeIntIndex(100),
                            floatIndex=tm.makeFloatIndex(100),
                            boolIndex=Index([True, False]),
                            catIndex=tm.makeCategoricalIndex(100),
                            empty=Index([]),
                            tuples=MultiIndex.from_tuples(lzip(
                                ['foo', 'bar', 'baz'], [1, 2, 3])),
                            repeats=Index([0, 0, 1, 1, 2, 2]))
        self.setup_indices() 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:19,代码来源:test_base.py

示例6: test_map_with_tuples

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeIntIndex [as 别名]
def test_map_with_tuples(self):
        # GH 12766

        # Test that returning a single tuple from an Index
        #   returns an Index.
        boolean_index = tm.makeIntIndex(3).map(lambda x: (x,))
        expected = Index([(0,), (1,), (2,)])
        tm.assert_index_equal(boolean_index, expected)

        # Test that returning a tuple from a map of a single index
        #   returns a MultiIndex object.
        boolean_index = tm.makeIntIndex(3).map(lambda x: (x, x == 1))
        expected = MultiIndex.from_tuples([(0, False), (1, True), (2, False)])
        tm.assert_index_equal(boolean_index, expected)

        # Test that returning a single object from a MultiIndex
        #   returns an Index.
        first_level = ['foo', 'bar', 'baz']
        multi_index = MultiIndex.from_tuples(lzip(first_level, [1, 2, 3]))
        reduced_index = multi_index.map(lambda x: x[0])
        tm.assert_index_equal(reduced_index, Index(first_level)) 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:23,代码来源:test_base.py

示例7: setup_method

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeIntIndex [as 别名]
def setup_method(self, method):
        self.bool_index = tm.makeBoolIndex(10, name='a')
        self.int_index = tm.makeIntIndex(10, name='a')
        self.float_index = tm.makeFloatIndex(10, name='a')
        self.dt_index = tm.makeDateIndex(10, name='a')
        self.dt_tz_index = tm.makeDateIndex(10, name='a').tz_localize(
            tz='US/Eastern')
        self.period_index = tm.makePeriodIndex(10, name='a')
        self.string_index = tm.makeStringIndex(10, name='a')
        self.unicode_index = tm.makeUnicodeIndex(10, name='a')

        arr = np.random.randn(10)
        self.int_series = Series(arr, index=self.int_index, name='a')
        self.float_series = Series(arr, index=self.float_index, name='a')
        self.dt_series = Series(arr, index=self.dt_index, name='a')
        self.dt_tz_series = self.dt_tz_index.to_series(keep_tz=True)
        self.period_series = Series(arr, index=self.period_index, name='a')
        self.string_series = Series(arr, index=self.string_index, name='a')

        types = ['bool', 'int', 'float', 'dt', 'dt_tz', 'period', 'string',
                 'unicode']
        fmts = ["{0}_{1}".format(t, f)
                for t in types for f in ['index', 'series']]
        self.objs = [getattr(self, f)
                     for f in fmts if getattr(self, f, None) is not None] 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:27,代码来源:test_base.py

示例8: setup_method

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeIntIndex [as 别名]
def setup_method(self, method):
        super(TestIndex, self).setup_method(method)

        self.d = {
            'string': tm.makeStringIndex(100),
            'date': tm.makeDateIndex(100),
            'int': tm.makeIntIndex(100),
            'rng': tm.makeRangeIndex(100),
            'float': tm.makeFloatIndex(100),
            'empty': Index([]),
            'tuple': Index(zip(['foo', 'bar', 'baz'], [1, 2, 3])),
            'period': Index(period_range('2012-1-1', freq='M', periods=3)),
            'date2': Index(date_range('2013-01-1', periods=10)),
            'bdate': Index(bdate_range('2013-01-02', periods=10)),
            'cat': tm.makeCategoricalIndex(100)
        }

        self.mi = {
            'reg': MultiIndex.from_tuples([('bar', 'one'), ('baz', 'two'),
                                           ('foo', 'two'),
                                           ('qux', 'one'), ('qux', 'two')],
                                          names=['first', 'second']),
        } 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:25,代码来源:test_packers.py

示例9: test_map_with_tuples

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeIntIndex [as 别名]
def test_map_with_tuples(self):
        # GH 12766

        # Test that returning a single tuple from an Index
        #   returns an Index.
        index = tm.makeIntIndex(3)
        result = tm.makeIntIndex(3).map(lambda x: (x,))
        expected = Index([(i,) for i in index])
        tm.assert_index_equal(result, expected)

        # Test that returning a tuple from a map of a single index
        #   returns a MultiIndex object.
        result = index.map(lambda x: (x, x == 1))
        expected = MultiIndex.from_tuples([(i, i == 1) for i in index])
        tm.assert_index_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:17,代码来源:test_base.py

示例10: test_invalid_index_types

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeIntIndex [as 别名]
def test_invalid_index_types(self):

        # test all index types
        for i in [tm.makeIntIndex(10), tm.makeFloatIndex(10),
                  tm.makePeriodIndex(10)]:
            pytest.raises(TypeError, lambda: frequencies.infer_freq(i))

        # GH 10822
        # odd error message on conversions to datetime for unicode
        if not is_platform_windows():
            for i in [tm.makeStringIndex(10), tm.makeUnicodeIndex(10)]:
                pytest.raises(ValueError, lambda: frequencies.infer_freq(i)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:14,代码来源:test_frequencies.py

示例11: setup_method

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeIntIndex [as 别名]
def setup_method(self, method):
        self.bool_index = tm.makeBoolIndex(10, name='a')
        self.int_index = tm.makeIntIndex(10, name='a')
        self.float_index = tm.makeFloatIndex(10, name='a')
        self.dt_index = tm.makeDateIndex(10, name='a')
        self.dt_tz_index = tm.makeDateIndex(10, name='a').tz_localize(
            tz='US/Eastern')
        self.period_index = tm.makePeriodIndex(10, name='a')
        self.string_index = tm.makeStringIndex(10, name='a')
        self.unicode_index = tm.makeUnicodeIndex(10, name='a')

        arr = np.random.randn(10)
        self.bool_series = Series(arr, index=self.bool_index, name='a')
        self.int_series = Series(arr, index=self.int_index, name='a')
        self.float_series = Series(arr, index=self.float_index, name='a')
        self.dt_series = Series(arr, index=self.dt_index, name='a')
        self.dt_tz_series = self.dt_tz_index.to_series(keep_tz=True)
        self.period_series = Series(arr, index=self.period_index, name='a')
        self.string_series = Series(arr, index=self.string_index, name='a')
        self.unicode_series = Series(arr, index=self.unicode_index, name='a')

        types = ['bool', 'int', 'float', 'dt', 'dt_tz', 'period', 'string',
                 'unicode']
        self.indexes = [getattr(self, '{}_index'.format(t)) for t in types]
        self.series = [getattr(self, '{}_series'.format(t)) for t in types]
        self.objs = self.indexes + self.series 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:28,代码来源:test_base.py

示例12: test_scalar_error

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeIntIndex [as 别名]
def test_scalar_error(self):

        # GH 4892
        # float_indexers should raise exceptions
        # on appropriate Index types & accessors
        # this duplicates the code below
        # but is spefically testing for the error
        # message

        for index in [tm.makeStringIndex, tm.makeUnicodeIndex,
                      tm.makeCategoricalIndex,
                      tm.makeDateIndex, tm.makeTimedeltaIndex,
                      tm.makePeriodIndex, tm.makeIntIndex,
                      tm.makeRangeIndex]:

            i = index(5)

            s = Series(np.arange(len(i)), index=i)

            msg = 'Cannot index by location index'
            with pytest.raises(TypeError, match=msg):
                s.iloc[3.0]

            def f():
                s.iloc[3.0] = 0
            pytest.raises(TypeError, f) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:28,代码来源:test_floats.py

示例13: test_combine_first

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeIntIndex [as 别名]
def test_combine_first(self):
        values = tm.makeIntIndex(20).values.astype(float)
        series = Series(values, index=tm.makeIntIndex(20))

        series_copy = series * 2
        series_copy[::2] = np.NaN

        # nothing used from the input
        combined = series.combine_first(series_copy)

        tm.assert_series_equal(combined, series)

        # Holes filled from input
        combined = series_copy.combine_first(series)
        assert np.isfinite(combined).all()

        tm.assert_series_equal(combined[::2], series[::2])
        tm.assert_series_equal(combined[1::2], series_copy[1::2])

        # mixed types
        index = tm.makeStringIndex(20)
        floats = Series(tm.randn(20), index=index)
        strings = Series(tm.makeStringIndex(10), index=index[::2])

        combined = strings.combine_first(floats)

        tm.assert_series_equal(strings, combined.loc[index[::2]])
        tm.assert_series_equal(floats[1::2].astype(object),
                               combined.loc[index[1::2]])

        # corner case
        s = Series([1., 2, 3], index=[0, 1, 2])
        result = s.combine_first(Series([], index=[]))
        assert_series_equal(s, result) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:36,代码来源:test_combine_concat.py

示例14: test_setitem

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeIntIndex [as 别名]
def test_setitem(test_data):
    test_data.ts[test_data.ts.index[5]] = np.NaN
    test_data.ts[[1, 2, 17]] = np.NaN
    test_data.ts[6] = np.NaN
    assert np.isnan(test_data.ts[6])
    assert np.isnan(test_data.ts[2])
    test_data.ts[np.isnan(test_data.ts)] = 5
    assert not np.isnan(test_data.ts[2])

    # caught this bug when writing tests
    series = Series(tm.makeIntIndex(20).astype(float),
                    index=tm.makeIntIndex(20))

    series[::2] = 0
    assert (series[::2] == 0).all()

    # set item that's not contained
    s = test_data.series.copy()
    s['foobar'] = 1

    app = Series([1], index=['foobar'], name='series')
    expected = test_data.series.append(app)
    assert_series_equal(s, expected)

    # Test for issue #10193
    key = pd.Timestamp('2012-01-01')
    series = pd.Series()
    series[key] = 47
    expected = pd.Series(47, [key])
    assert_series_equal(series, expected)

    series = pd.Series([], pd.DatetimeIndex([], freq='D'))
    series[key] = 47
    expected = pd.Series(47, pd.DatetimeIndex([key], freq='D'))
    assert_series_equal(series, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:37,代码来源:test_indexing.py

示例15: test_grouper_index_types

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeIntIndex [as 别名]
def test_grouper_index_types(self):
        # related GH5375
        # groupby misbehaving when using a Floatlike index
        df = DataFrame(np.arange(10).reshape(5, 2), columns=list('AB'))
        for index in [tm.makeFloatIndex, tm.makeStringIndex,
                      tm.makeUnicodeIndex, tm.makeIntIndex, tm.makeDateIndex,
                      tm.makePeriodIndex]:

            df.index = index(len(df))
            df.groupby(list('abcde')).apply(lambda x: x)

            df.index = list(reversed(df.index.tolist()))
            df.groupby(list('abcde')).apply(lambda x: x) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:15,代码来源:test_grouping.py


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