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


Python testing.makeUnicodeIndex方法代码示例

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


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

示例1: setup_method

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeUnicodeIndex [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: get_objs

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeUnicodeIndex [as 别名]
def get_objs():
    indexes = [
        tm.makeBoolIndex(10, name='a'),
        tm.makeIntIndex(10, name='a'),
        tm.makeFloatIndex(10, name='a'),
        tm.makeDateIndex(10, name='a'),
        tm.makeDateIndex(10, name='a').tz_localize(tz='US/Eastern'),
        tm.makePeriodIndex(10, name='a'),
        tm.makeStringIndex(10, name='a'),
        tm.makeUnicodeIndex(10, name='a')
    ]

    arr = np.random.randn(10)
    series = [Series(arr, index=idx, name='a') for idx in indexes]

    objs = indexes + series
    return objs 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_reductions.py

示例3: setup_method

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeUnicodeIndex [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:birforce,项目名称:vnpy_crypto,代码行数:27,代码来源:test_base.py

示例4: setup_method

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

示例5: test_invalid_index_types

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

示例6: setup_method

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

示例7: test_head_tail

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

        o = self._construct(shape=10)

        # check all index types
        for index in [tm.makeFloatIndex, tm.makeIntIndex, tm.makeStringIndex,
                      tm.makeUnicodeIndex, tm.makeDateIndex,
                      tm.makePeriodIndex]:
            axis = o._get_axis_name(0)
            setattr(o, axis, index(len(getattr(o, axis))))

            # Panel + dims
            try:
                o.head()
            except (NotImplementedError):
                pytest.skip('not implemented on {0}'.format(
                    o.__class__.__name__))

            self._compare(o.head(), o.iloc[:5])
            self._compare(o.tail(), o.iloc[-5:])

            # 0-len
            self._compare(o.head(0), o.iloc[0:0])
            self._compare(o.tail(0), o.iloc[0:0])

            # bounded
            self._compare(o.head(len(o) + 1), o)
            self._compare(o.tail(len(o) + 1), o)

            # neg index
            self._compare(o.head(-3), o.head(7))
            self._compare(o.tail(-3), o.tail(7)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:35,代码来源:test_generic.py

示例8: test_scalar_error

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

示例9: test_grouper_index_types

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

示例10: test_to_string_truncate_indices

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeUnicodeIndex [as 别名]
def test_to_string_truncate_indices(self):
        for index in [tm.makeStringIndex, tm.makeUnicodeIndex, tm.makeIntIndex,
                      tm.makeDateIndex, tm.makePeriodIndex]:
            for column in [tm.makeStringIndex]:
                for h in [10, 20]:
                    for w in [10, 20]:
                        with option_context("display.expand_frame_repr",
                                            False):
                            df = DataFrame(index=index(h), columns=column(w))
                            with option_context("display.max_rows", 15):
                                if h == 20:
                                    assert has_vertically_truncated_repr(df)
                                else:
                                    assert not has_vertically_truncated_repr(
                                        df)
                            with option_context("display.max_columns", 15):
                                if w == 20:
                                    assert has_horizontally_truncated_repr(df)
                                else:
                                    assert not (
                                        has_horizontally_truncated_repr(df))
                            with option_context("display.max_rows", 15,
                                                "display.max_columns", 15):
                                if h == 20 and w == 20:
                                    assert has_doubly_truncated_repr(df)
                                else:
                                    assert not has_doubly_truncated_repr(
                                        df) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:30,代码来源:test_format.py

示例11: test_unicode

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeUnicodeIndex [as 别名]
def test_unicode(self):
        i = tm.makeUnicodeIndex(100)

        i_rec = self.encode_decode(i)
        tm.assert_index_equal(i, i_rec) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:test_packers.py

示例12: test_fails_on_no_datetime_index

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeUnicodeIndex [as 别名]
def test_fails_on_no_datetime_index(self):
        index_names = ('Int64Index', 'Index', 'Float64Index', 'MultiIndex')
        index_funcs = (tm.makeIntIndex,
                       tm.makeUnicodeIndex, tm.makeFloatIndex,
                       lambda m: tm.makeCustomIndex(m, 2))
        n = 2
        for name, func in zip(index_names, index_funcs):
            index = func(n)
            df = DataFrame({'a': np.random.randn(n)}, index=index)
            with tm.assert_raises_regex(TypeError,
                                        "Only valid with "
                                        "DatetimeIndex, TimedeltaIndex "
                                        "or PeriodIndex, but got an "
                                        "instance of %r" % name):
                df.groupby(TimeGrouper('D')) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:17,代码来源:test_resample.py

示例13: test_fails_on_no_datetime_index

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeUnicodeIndex [as 别名]
def test_fails_on_no_datetime_index(self):
        index_names = ('Int64Index', 'PeriodIndex', 'Index', 'Float64Index',
                       'MultiIndex')
        index_funcs = (tm.makeIntIndex, tm.makePeriodIndex,
                       tm.makeUnicodeIndex, tm.makeFloatIndex,
                       lambda m: tm.makeCustomIndex(m, 2))
        n = 2
        for name, func in zip(index_names, index_funcs):
            index = func(n)
            df = DataFrame({'a': np.random.randn(n)}, index=index)
            with tm.assertRaisesRegexp(TypeError,
                                       "axis must be a DatetimeIndex, "
                                       "but got an instance of %r" % name):
                df.groupby(TimeGrouper('D')) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:16,代码来源:test_resample.py

示例14: test_store_index_types

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeUnicodeIndex [as 别名]
def test_store_index_types(self):
        # GH5386
        # test storing various index types

        with ensure_clean_store(self.path) as store:

            def check(format,index):
                df = DataFrame(np.random.randn(10,2),columns=list('AB'))
                df.index = index(len(df))

                _maybe_remove(store, 'df')
                store.put('df',df,format=format)
                assert_frame_equal(df,store['df'])

            for index in [ tm.makeFloatIndex, tm.makeStringIndex, tm.makeIntIndex,
                           tm.makeDateIndex, tm.makePeriodIndex ]:

                check('table',index)
                check('fixed',index)

            # unicode
            index = tm.makeUnicodeIndex
            if compat.PY3:
                check('table',index)
                check('fixed',index)
            else:

                # only support for fixed types (and they have a perf warning)
                self.assertRaises(TypeError, check, 'table', index)
                with tm.assert_produces_warning(expected_warning=PerformanceWarning):
                    check('fixed',index) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:33,代码来源:test_pytables.py

示例15: test_unicode

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeUnicodeIndex [as 别名]
def test_unicode(self):
        i = tm.makeUnicodeIndex(100)

        # this currently fails
        self.assertRaises(UnicodeEncodeError, self.encode_decode, i)

        #i_rec = self.encode_decode(i)
        #self.assert_(i.equals(i_rec)) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_packers.py


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