123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529 |
- # -*- coding: utf-8 -*-
- import numpy as np
- from pandas.compat import PY3, u
- from pandas import (
- Categorical, CategoricalIndex, Series, date_range, period_range,
- timedelta_range)
- from pandas.core.config import option_context
- from pandas.tests.arrays.categorical.common import TestCategorical
- class TestCategoricalReprWithFactor(TestCategorical):
- def test_print(self):
- expected = ["[a, b, b, a, a, c, c, c]",
- "Categories (3, object): [a < b < c]"]
- expected = "\n".join(expected)
- actual = repr(self.factor)
- assert actual == expected
- class TestCategoricalRepr(object):
- def test_big_print(self):
- factor = Categorical([0, 1, 2, 0, 1, 2] * 100, ['a', 'b', 'c'],
- fastpath=True)
- expected = ["[a, b, c, a, b, ..., b, c, a, b, c]", "Length: 600",
- "Categories (3, object): [a, b, c]"]
- expected = "\n".join(expected)
- actual = repr(factor)
- assert actual == expected
- def test_empty_print(self):
- factor = Categorical([], ["a", "b", "c"])
- expected = ("[], Categories (3, object): [a, b, c]")
- actual = repr(factor)
- assert actual == expected
- assert expected == actual
- factor = Categorical([], ["a", "b", "c"], ordered=True)
- expected = ("[], Categories (3, object): [a < b < c]")
- actual = repr(factor)
- assert expected == actual
- factor = Categorical([], [])
- expected = ("[], Categories (0, object): []")
- assert expected == repr(factor)
- def test_print_none_width(self):
- # GH10087
- a = Series(Categorical([1, 2, 3, 4]))
- exp = u("0 1\n1 2\n2 3\n3 4\n" +
- "dtype: category\nCategories (4, int64): [1, 2, 3, 4]")
- with option_context("display.width", None):
- assert exp == repr(a)
- def test_unicode_print(self):
- if PY3:
- _rep = repr
- else:
- _rep = unicode # noqa
- c = Categorical(['aaaaa', 'bb', 'cccc'] * 20)
- expected = u"""\
- [aaaaa, bb, cccc, aaaaa, bb, ..., bb, cccc, aaaaa, bb, cccc]
- Length: 60
- Categories (3, object): [aaaaa, bb, cccc]"""
- assert _rep(c) == expected
- c = Categorical([u'ああああ', u'いいいいい', u'ううううううう'] * 20)
- expected = u"""\
- [ああああ, いいいいい, ううううううう, ああああ, いいいいい, ..., いいいいい, ううううううう, ああああ, いいいいい, ううううううう]
- Length: 60
- Categories (3, object): [ああああ, いいいいい, ううううううう]""" # noqa
- assert _rep(c) == expected
- # unicode option should not affect to Categorical, as it doesn't care
- # the repr width
- with option_context('display.unicode.east_asian_width', True):
- c = Categorical([u'ああああ', u'いいいいい', u'ううううううう'] * 20)
- expected = u"""[ああああ, いいいいい, ううううううう, ああああ, いいいいい, ..., いいいいい, ううううううう, ああああ, いいいいい, ううううううう]
- Length: 60
- Categories (3, object): [ああああ, いいいいい, ううううううう]""" # noqa
- assert _rep(c) == expected
- def test_categorical_repr(self):
- c = Categorical([1, 2, 3])
- exp = """[1, 2, 3]
- Categories (3, int64): [1, 2, 3]"""
- assert repr(c) == exp
- c = Categorical([1, 2, 3, 1, 2, 3], categories=[1, 2, 3])
- exp = """[1, 2, 3, 1, 2, 3]
- Categories (3, int64): [1, 2, 3]"""
- assert repr(c) == exp
- c = Categorical([1, 2, 3, 4, 5] * 10)
- exp = """[1, 2, 3, 4, 5, ..., 1, 2, 3, 4, 5]
- Length: 50
- Categories (5, int64): [1, 2, 3, 4, 5]"""
- assert repr(c) == exp
- c = Categorical(np.arange(20))
- exp = """[0, 1, 2, 3, 4, ..., 15, 16, 17, 18, 19]
- Length: 20
- Categories (20, int64): [0, 1, 2, 3, ..., 16, 17, 18, 19]"""
- assert repr(c) == exp
- def test_categorical_repr_ordered(self):
- c = Categorical([1, 2, 3], ordered=True)
- exp = """[1, 2, 3]
- Categories (3, int64): [1 < 2 < 3]"""
- assert repr(c) == exp
- c = Categorical([1, 2, 3, 1, 2, 3], categories=[1, 2, 3], ordered=True)
- exp = """[1, 2, 3, 1, 2, 3]
- Categories (3, int64): [1 < 2 < 3]"""
- assert repr(c) == exp
- c = Categorical([1, 2, 3, 4, 5] * 10, ordered=True)
- exp = """[1, 2, 3, 4, 5, ..., 1, 2, 3, 4, 5]
- Length: 50
- Categories (5, int64): [1 < 2 < 3 < 4 < 5]"""
- assert repr(c) == exp
- c = Categorical(np.arange(20), ordered=True)
- exp = """[0, 1, 2, 3, 4, ..., 15, 16, 17, 18, 19]
- Length: 20
- Categories (20, int64): [0 < 1 < 2 < 3 ... 16 < 17 < 18 < 19]"""
- assert repr(c) == exp
- def test_categorical_repr_datetime(self):
- idx = date_range('2011-01-01 09:00', freq='H', periods=5)
- c = Categorical(idx)
- # TODO(wesm): exceeding 80 characters in the console is not good
- # behavior
- exp = (
- "[2011-01-01 09:00:00, 2011-01-01 10:00:00, 2011-01-01 11:00:00, "
- "2011-01-01 12:00:00, 2011-01-01 13:00:00]\n"
- "Categories (5, datetime64[ns]): [2011-01-01 09:00:00, "
- "2011-01-01 10:00:00, 2011-01-01 11:00:00,\n"
- " 2011-01-01 12:00:00, "
- "2011-01-01 13:00:00]""")
- assert repr(c) == exp
- c = Categorical(idx.append(idx), categories=idx)
- exp = (
- "[2011-01-01 09:00:00, 2011-01-01 10:00:00, 2011-01-01 11:00:00, "
- "2011-01-01 12:00:00, 2011-01-01 13:00:00, 2011-01-01 09:00:00, "
- "2011-01-01 10:00:00, 2011-01-01 11:00:00, 2011-01-01 12:00:00, "
- "2011-01-01 13:00:00]\n"
- "Categories (5, datetime64[ns]): [2011-01-01 09:00:00, "
- "2011-01-01 10:00:00, 2011-01-01 11:00:00,\n"
- " 2011-01-01 12:00:00, "
- "2011-01-01 13:00:00]")
- assert repr(c) == exp
- idx = date_range('2011-01-01 09:00', freq='H', periods=5,
- tz='US/Eastern')
- c = Categorical(idx)
- exp = (
- "[2011-01-01 09:00:00-05:00, 2011-01-01 10:00:00-05:00, "
- "2011-01-01 11:00:00-05:00, 2011-01-01 12:00:00-05:00, "
- "2011-01-01 13:00:00-05:00]\n"
- "Categories (5, datetime64[ns, US/Eastern]): "
- "[2011-01-01 09:00:00-05:00, 2011-01-01 10:00:00-05:00,\n"
- " "
- "2011-01-01 11:00:00-05:00, 2011-01-01 12:00:00-05:00,\n"
- " "
- "2011-01-01 13:00:00-05:00]")
- assert repr(c) == exp
- c = Categorical(idx.append(idx), categories=idx)
- exp = (
- "[2011-01-01 09:00:00-05:00, 2011-01-01 10:00:00-05:00, "
- "2011-01-01 11:00:00-05:00, 2011-01-01 12:00:00-05:00, "
- "2011-01-01 13:00:00-05:00, 2011-01-01 09:00:00-05:00, "
- "2011-01-01 10:00:00-05:00, 2011-01-01 11:00:00-05:00, "
- "2011-01-01 12:00:00-05:00, 2011-01-01 13:00:00-05:00]\n"
- "Categories (5, datetime64[ns, US/Eastern]): "
- "[2011-01-01 09:00:00-05:00, 2011-01-01 10:00:00-05:00,\n"
- " "
- "2011-01-01 11:00:00-05:00, 2011-01-01 12:00:00-05:00,\n"
- " "
- "2011-01-01 13:00:00-05:00]")
- assert repr(c) == exp
- def test_categorical_repr_datetime_ordered(self):
- idx = date_range('2011-01-01 09:00', freq='H', periods=5)
- c = Categorical(idx, ordered=True)
- exp = """[2011-01-01 09:00:00, 2011-01-01 10:00:00, 2011-01-01 11:00:00, 2011-01-01 12:00:00, 2011-01-01 13:00:00]
- Categories (5, datetime64[ns]): [2011-01-01 09:00:00 < 2011-01-01 10:00:00 < 2011-01-01 11:00:00 <
- 2011-01-01 12:00:00 < 2011-01-01 13:00:00]""" # noqa
- assert repr(c) == exp
- c = Categorical(idx.append(idx), categories=idx, ordered=True)
- exp = """[2011-01-01 09:00:00, 2011-01-01 10:00:00, 2011-01-01 11:00:00, 2011-01-01 12:00:00, 2011-01-01 13:00:00, 2011-01-01 09:00:00, 2011-01-01 10:00:00, 2011-01-01 11:00:00, 2011-01-01 12:00:00, 2011-01-01 13:00:00]
- Categories (5, datetime64[ns]): [2011-01-01 09:00:00 < 2011-01-01 10:00:00 < 2011-01-01 11:00:00 <
- 2011-01-01 12:00:00 < 2011-01-01 13:00:00]""" # noqa
- assert repr(c) == exp
- idx = date_range('2011-01-01 09:00', freq='H', periods=5,
- tz='US/Eastern')
- c = Categorical(idx, ordered=True)
- exp = """[2011-01-01 09:00:00-05:00, 2011-01-01 10:00:00-05:00, 2011-01-01 11:00:00-05:00, 2011-01-01 12:00:00-05:00, 2011-01-01 13:00:00-05:00]
- Categories (5, datetime64[ns, US/Eastern]): [2011-01-01 09:00:00-05:00 < 2011-01-01 10:00:00-05:00 <
- 2011-01-01 11:00:00-05:00 < 2011-01-01 12:00:00-05:00 <
- 2011-01-01 13:00:00-05:00]""" # noqa
- assert repr(c) == exp
- c = Categorical(idx.append(idx), categories=idx, ordered=True)
- exp = """[2011-01-01 09:00:00-05:00, 2011-01-01 10:00:00-05:00, 2011-01-01 11:00:00-05:00, 2011-01-01 12:00:00-05:00, 2011-01-01 13:00:00-05:00, 2011-01-01 09:00:00-05:00, 2011-01-01 10:00:00-05:00, 2011-01-01 11:00:00-05:00, 2011-01-01 12:00:00-05:00, 2011-01-01 13:00:00-05:00]
- Categories (5, datetime64[ns, US/Eastern]): [2011-01-01 09:00:00-05:00 < 2011-01-01 10:00:00-05:00 <
- 2011-01-01 11:00:00-05:00 < 2011-01-01 12:00:00-05:00 <
- 2011-01-01 13:00:00-05:00]""" # noqa
- assert repr(c) == exp
- def test_categorical_repr_int_with_nan(self):
- c = Categorical([1, 2, np.nan])
- c_exp = """[1, 2, NaN]\nCategories (2, int64): [1, 2]"""
- assert repr(c) == c_exp
- s = Series([1, 2, np.nan], dtype="object").astype("category")
- s_exp = """0 1\n1 2\n2 NaN
- dtype: category
- Categories (2, int64): [1, 2]"""
- assert repr(s) == s_exp
- def test_categorical_repr_period(self):
- idx = period_range('2011-01-01 09:00', freq='H', periods=5)
- c = Categorical(idx)
- exp = """[2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, 2011-01-01 13:00]
- Categories (5, period[H]): [2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00,
- 2011-01-01 13:00]""" # noqa
- assert repr(c) == exp
- c = Categorical(idx.append(idx), categories=idx)
- exp = """[2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, 2011-01-01 13:00, 2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, 2011-01-01 13:00]
- Categories (5, period[H]): [2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00,
- 2011-01-01 13:00]""" # noqa
- assert repr(c) == exp
- idx = period_range('2011-01', freq='M', periods=5)
- c = Categorical(idx)
- exp = """[2011-01, 2011-02, 2011-03, 2011-04, 2011-05]
- Categories (5, period[M]): [2011-01, 2011-02, 2011-03, 2011-04, 2011-05]"""
- assert repr(c) == exp
- c = Categorical(idx.append(idx), categories=idx)
- exp = """[2011-01, 2011-02, 2011-03, 2011-04, 2011-05, 2011-01, 2011-02, 2011-03, 2011-04, 2011-05]
- Categories (5, period[M]): [2011-01, 2011-02, 2011-03, 2011-04, 2011-05]""" # noqa
- assert repr(c) == exp
- def test_categorical_repr_period_ordered(self):
- idx = period_range('2011-01-01 09:00', freq='H', periods=5)
- c = Categorical(idx, ordered=True)
- exp = """[2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, 2011-01-01 13:00]
- Categories (5, period[H]): [2011-01-01 09:00 < 2011-01-01 10:00 < 2011-01-01 11:00 < 2011-01-01 12:00 <
- 2011-01-01 13:00]""" # noqa
- assert repr(c) == exp
- c = Categorical(idx.append(idx), categories=idx, ordered=True)
- exp = """[2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, 2011-01-01 13:00, 2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, 2011-01-01 13:00]
- Categories (5, period[H]): [2011-01-01 09:00 < 2011-01-01 10:00 < 2011-01-01 11:00 < 2011-01-01 12:00 <
- 2011-01-01 13:00]""" # noqa
- assert repr(c) == exp
- idx = period_range('2011-01', freq='M', periods=5)
- c = Categorical(idx, ordered=True)
- exp = """[2011-01, 2011-02, 2011-03, 2011-04, 2011-05]
- Categories (5, period[M]): [2011-01 < 2011-02 < 2011-03 < 2011-04 < 2011-05]"""
- assert repr(c) == exp
- c = Categorical(idx.append(idx), categories=idx, ordered=True)
- exp = """[2011-01, 2011-02, 2011-03, 2011-04, 2011-05, 2011-01, 2011-02, 2011-03, 2011-04, 2011-05]
- Categories (5, period[M]): [2011-01 < 2011-02 < 2011-03 < 2011-04 < 2011-05]""" # noqa
- assert repr(c) == exp
- def test_categorical_repr_timedelta(self):
- idx = timedelta_range('1 days', periods=5)
- c = Categorical(idx)
- exp = """[1 days, 2 days, 3 days, 4 days, 5 days]
- Categories (5, timedelta64[ns]): [1 days, 2 days, 3 days, 4 days, 5 days]"""
- assert repr(c) == exp
- c = Categorical(idx.append(idx), categories=idx)
- exp = """[1 days, 2 days, 3 days, 4 days, 5 days, 1 days, 2 days, 3 days, 4 days, 5 days]
- Categories (5, timedelta64[ns]): [1 days, 2 days, 3 days, 4 days, 5 days]""" # noqa
- assert repr(c) == exp
- idx = timedelta_range('1 hours', periods=20)
- c = Categorical(idx)
- exp = """[0 days 01:00:00, 1 days 01:00:00, 2 days 01:00:00, 3 days 01:00:00, 4 days 01:00:00, ..., 15 days 01:00:00, 16 days 01:00:00, 17 days 01:00:00, 18 days 01:00:00, 19 days 01:00:00]
- Length: 20
- Categories (20, timedelta64[ns]): [0 days 01:00:00, 1 days 01:00:00, 2 days 01:00:00,
- 3 days 01:00:00, ..., 16 days 01:00:00, 17 days 01:00:00,
- 18 days 01:00:00, 19 days 01:00:00]""" # noqa
- assert repr(c) == exp
- c = Categorical(idx.append(idx), categories=idx)
- exp = """[0 days 01:00:00, 1 days 01:00:00, 2 days 01:00:00, 3 days 01:00:00, 4 days 01:00:00, ..., 15 days 01:00:00, 16 days 01:00:00, 17 days 01:00:00, 18 days 01:00:00, 19 days 01:00:00]
- Length: 40
- Categories (20, timedelta64[ns]): [0 days 01:00:00, 1 days 01:00:00, 2 days 01:00:00,
- 3 days 01:00:00, ..., 16 days 01:00:00, 17 days 01:00:00,
- 18 days 01:00:00, 19 days 01:00:00]""" # noqa
- assert repr(c) == exp
- def test_categorical_repr_timedelta_ordered(self):
- idx = timedelta_range('1 days', periods=5)
- c = Categorical(idx, ordered=True)
- exp = """[1 days, 2 days, 3 days, 4 days, 5 days]
- Categories (5, timedelta64[ns]): [1 days < 2 days < 3 days < 4 days < 5 days]""" # noqa
- assert repr(c) == exp
- c = Categorical(idx.append(idx), categories=idx, ordered=True)
- exp = """[1 days, 2 days, 3 days, 4 days, 5 days, 1 days, 2 days, 3 days, 4 days, 5 days]
- Categories (5, timedelta64[ns]): [1 days < 2 days < 3 days < 4 days < 5 days]""" # noqa
- assert repr(c) == exp
- idx = timedelta_range('1 hours', periods=20)
- c = Categorical(idx, ordered=True)
- exp = """[0 days 01:00:00, 1 days 01:00:00, 2 days 01:00:00, 3 days 01:00:00, 4 days 01:00:00, ..., 15 days 01:00:00, 16 days 01:00:00, 17 days 01:00:00, 18 days 01:00:00, 19 days 01:00:00]
- Length: 20
- Categories (20, timedelta64[ns]): [0 days 01:00:00 < 1 days 01:00:00 < 2 days 01:00:00 <
- 3 days 01:00:00 ... 16 days 01:00:00 < 17 days 01:00:00 <
- 18 days 01:00:00 < 19 days 01:00:00]""" # noqa
- assert repr(c) == exp
- c = Categorical(idx.append(idx), categories=idx, ordered=True)
- exp = """[0 days 01:00:00, 1 days 01:00:00, 2 days 01:00:00, 3 days 01:00:00, 4 days 01:00:00, ..., 15 days 01:00:00, 16 days 01:00:00, 17 days 01:00:00, 18 days 01:00:00, 19 days 01:00:00]
- Length: 40
- Categories (20, timedelta64[ns]): [0 days 01:00:00 < 1 days 01:00:00 < 2 days 01:00:00 <
- 3 days 01:00:00 ... 16 days 01:00:00 < 17 days 01:00:00 <
- 18 days 01:00:00 < 19 days 01:00:00]""" # noqa
- assert repr(c) == exp
- def test_categorical_index_repr(self):
- idx = CategoricalIndex(Categorical([1, 2, 3]))
- exp = """CategoricalIndex([1, 2, 3], categories=[1, 2, 3], ordered=False, dtype='category')""" # noqa
- assert repr(idx) == exp
- i = CategoricalIndex(Categorical(np.arange(10)))
- exp = """CategoricalIndex([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], categories=[0, 1, 2, 3, 4, 5, 6, 7, ...], ordered=False, dtype='category')""" # noqa
- assert repr(i) == exp
- def test_categorical_index_repr_ordered(self):
- i = CategoricalIndex(Categorical([1, 2, 3], ordered=True))
- exp = """CategoricalIndex([1, 2, 3], categories=[1, 2, 3], ordered=True, dtype='category')""" # noqa
- assert repr(i) == exp
- i = CategoricalIndex(Categorical(np.arange(10), ordered=True))
- exp = """CategoricalIndex([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], categories=[0, 1, 2, 3, 4, 5, 6, 7, ...], ordered=True, dtype='category')""" # noqa
- assert repr(i) == exp
- def test_categorical_index_repr_datetime(self):
- idx = date_range('2011-01-01 09:00', freq='H', periods=5)
- i = CategoricalIndex(Categorical(idx))
- exp = """CategoricalIndex(['2011-01-01 09:00:00', '2011-01-01 10:00:00',
- '2011-01-01 11:00:00', '2011-01-01 12:00:00',
- '2011-01-01 13:00:00'],
- categories=[2011-01-01 09:00:00, 2011-01-01 10:00:00, 2011-01-01 11:00:00, 2011-01-01 12:00:00, 2011-01-01 13:00:00], ordered=False, dtype='category')""" # noqa
- assert repr(i) == exp
- idx = date_range('2011-01-01 09:00', freq='H', periods=5,
- tz='US/Eastern')
- i = CategoricalIndex(Categorical(idx))
- exp = """CategoricalIndex(['2011-01-01 09:00:00-05:00', '2011-01-01 10:00:00-05:00',
- '2011-01-01 11:00:00-05:00', '2011-01-01 12:00:00-05:00',
- '2011-01-01 13:00:00-05:00'],
- categories=[2011-01-01 09:00:00-05:00, 2011-01-01 10:00:00-05:00, 2011-01-01 11:00:00-05:00, 2011-01-01 12:00:00-05:00, 2011-01-01 13:00:00-05:00], ordered=False, dtype='category')""" # noqa
- assert repr(i) == exp
- def test_categorical_index_repr_datetime_ordered(self):
- idx = date_range('2011-01-01 09:00', freq='H', periods=5)
- i = CategoricalIndex(Categorical(idx, ordered=True))
- exp = """CategoricalIndex(['2011-01-01 09:00:00', '2011-01-01 10:00:00',
- '2011-01-01 11:00:00', '2011-01-01 12:00:00',
- '2011-01-01 13:00:00'],
- categories=[2011-01-01 09:00:00, 2011-01-01 10:00:00, 2011-01-01 11:00:00, 2011-01-01 12:00:00, 2011-01-01 13:00:00], ordered=True, dtype='category')""" # noqa
- assert repr(i) == exp
- idx = date_range('2011-01-01 09:00', freq='H', periods=5,
- tz='US/Eastern')
- i = CategoricalIndex(Categorical(idx, ordered=True))
- exp = """CategoricalIndex(['2011-01-01 09:00:00-05:00', '2011-01-01 10:00:00-05:00',
- '2011-01-01 11:00:00-05:00', '2011-01-01 12:00:00-05:00',
- '2011-01-01 13:00:00-05:00'],
- categories=[2011-01-01 09:00:00-05:00, 2011-01-01 10:00:00-05:00, 2011-01-01 11:00:00-05:00, 2011-01-01 12:00:00-05:00, 2011-01-01 13:00:00-05:00], ordered=True, dtype='category')""" # noqa
- assert repr(i) == exp
- i = CategoricalIndex(Categorical(idx.append(idx), ordered=True))
- exp = """CategoricalIndex(['2011-01-01 09:00:00-05:00', '2011-01-01 10:00:00-05:00',
- '2011-01-01 11:00:00-05:00', '2011-01-01 12:00:00-05:00',
- '2011-01-01 13:00:00-05:00', '2011-01-01 09:00:00-05:00',
- '2011-01-01 10:00:00-05:00', '2011-01-01 11:00:00-05:00',
- '2011-01-01 12:00:00-05:00', '2011-01-01 13:00:00-05:00'],
- categories=[2011-01-01 09:00:00-05:00, 2011-01-01 10:00:00-05:00, 2011-01-01 11:00:00-05:00, 2011-01-01 12:00:00-05:00, 2011-01-01 13:00:00-05:00], ordered=True, dtype='category')""" # noqa
- assert repr(i) == exp
- def test_categorical_index_repr_period(self):
- # test all length
- idx = period_range('2011-01-01 09:00', freq='H', periods=1)
- i = CategoricalIndex(Categorical(idx))
- exp = """CategoricalIndex(['2011-01-01 09:00'], categories=[2011-01-01 09:00], ordered=False, dtype='category')""" # noqa
- assert repr(i) == exp
- idx = period_range('2011-01-01 09:00', freq='H', periods=2)
- i = CategoricalIndex(Categorical(idx))
- exp = """CategoricalIndex(['2011-01-01 09:00', '2011-01-01 10:00'], categories=[2011-01-01 09:00, 2011-01-01 10:00], ordered=False, dtype='category')""" # noqa
- assert repr(i) == exp
- idx = period_range('2011-01-01 09:00', freq='H', periods=3)
- i = CategoricalIndex(Categorical(idx))
- exp = """CategoricalIndex(['2011-01-01 09:00', '2011-01-01 10:00', '2011-01-01 11:00'], categories=[2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00], ordered=False, dtype='category')""" # noqa
- assert repr(i) == exp
- idx = period_range('2011-01-01 09:00', freq='H', periods=5)
- i = CategoricalIndex(Categorical(idx))
- exp = """CategoricalIndex(['2011-01-01 09:00', '2011-01-01 10:00', '2011-01-01 11:00',
- '2011-01-01 12:00', '2011-01-01 13:00'],
- categories=[2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, 2011-01-01 13:00], ordered=False, dtype='category')""" # noqa
- assert repr(i) == exp
- i = CategoricalIndex(Categorical(idx.append(idx)))
- exp = """CategoricalIndex(['2011-01-01 09:00', '2011-01-01 10:00', '2011-01-01 11:00',
- '2011-01-01 12:00', '2011-01-01 13:00', '2011-01-01 09:00',
- '2011-01-01 10:00', '2011-01-01 11:00', '2011-01-01 12:00',
- '2011-01-01 13:00'],
- categories=[2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, 2011-01-01 13:00], ordered=False, dtype='category')""" # noqa
- assert repr(i) == exp
- idx = period_range('2011-01', freq='M', periods=5)
- i = CategoricalIndex(Categorical(idx))
- exp = """CategoricalIndex(['2011-01', '2011-02', '2011-03', '2011-04', '2011-05'], categories=[2011-01, 2011-02, 2011-03, 2011-04, 2011-05], ordered=False, dtype='category')""" # noqa
- assert repr(i) == exp
- def test_categorical_index_repr_period_ordered(self):
- idx = period_range('2011-01-01 09:00', freq='H', periods=5)
- i = CategoricalIndex(Categorical(idx, ordered=True))
- exp = """CategoricalIndex(['2011-01-01 09:00', '2011-01-01 10:00', '2011-01-01 11:00',
- '2011-01-01 12:00', '2011-01-01 13:00'],
- categories=[2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00, 2011-01-01 13:00], ordered=True, dtype='category')""" # noqa
- assert repr(i) == exp
- idx = period_range('2011-01', freq='M', periods=5)
- i = CategoricalIndex(Categorical(idx, ordered=True))
- exp = """CategoricalIndex(['2011-01', '2011-02', '2011-03', '2011-04', '2011-05'], categories=[2011-01, 2011-02, 2011-03, 2011-04, 2011-05], ordered=True, dtype='category')""" # noqa
- assert repr(i) == exp
- def test_categorical_index_repr_timedelta(self):
- idx = timedelta_range('1 days', periods=5)
- i = CategoricalIndex(Categorical(idx))
- exp = """CategoricalIndex(['1 days', '2 days', '3 days', '4 days', '5 days'], categories=[1 days 00:00:00, 2 days 00:00:00, 3 days 00:00:00, 4 days 00:00:00, 5 days 00:00:00], ordered=False, dtype='category')""" # noqa
- assert repr(i) == exp
- idx = timedelta_range('1 hours', periods=10)
- i = CategoricalIndex(Categorical(idx))
- exp = """CategoricalIndex(['0 days 01:00:00', '1 days 01:00:00', '2 days 01:00:00',
- '3 days 01:00:00', '4 days 01:00:00', '5 days 01:00:00',
- '6 days 01:00:00', '7 days 01:00:00', '8 days 01:00:00',
- '9 days 01:00:00'],
- categories=[0 days 01:00:00, 1 days 01:00:00, 2 days 01:00:00, 3 days 01:00:00, 4 days 01:00:00, 5 days 01:00:00, 6 days 01:00:00, 7 days 01:00:00, ...], ordered=False, dtype='category')""" # noqa
- assert repr(i) == exp
- def test_categorical_index_repr_timedelta_ordered(self):
- idx = timedelta_range('1 days', periods=5)
- i = CategoricalIndex(Categorical(idx, ordered=True))
- exp = """CategoricalIndex(['1 days', '2 days', '3 days', '4 days', '5 days'], categories=[1 days 00:00:00, 2 days 00:00:00, 3 days 00:00:00, 4 days 00:00:00, 5 days 00:00:00], ordered=True, dtype='category')""" # noqa
- assert repr(i) == exp
- idx = timedelta_range('1 hours', periods=10)
- i = CategoricalIndex(Categorical(idx, ordered=True))
- exp = """CategoricalIndex(['0 days 01:00:00', '1 days 01:00:00', '2 days 01:00:00',
- '3 days 01:00:00', '4 days 01:00:00', '5 days 01:00:00',
- '6 days 01:00:00', '7 days 01:00:00', '8 days 01:00:00',
- '9 days 01:00:00'],
- categories=[0 days 01:00:00, 1 days 01:00:00, 2 days 01:00:00, 3 days 01:00:00, 4 days 01:00:00, 5 days 01:00:00, 6 days 01:00:00, 7 days 01:00:00, ...], ordered=True, dtype='category')""" # noqa
- assert repr(i) == exp
|