Skip to content

PEP8: test/indexes/base #13771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 75 additions & 56 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

from datetime import datetime, timedelta

# TODO(wesm): fix long line flake8 issues
# flake8: noqa

import pandas.util.testing as tm
from pandas.indexes.api import Index, MultiIndex
from .common import Base
Expand Down Expand Up @@ -286,16 +283,19 @@ def test_constructor_dtypes(self):

for idx in [Index(np.array([True, False, True], dtype=bool)),
Index([True, False, True]),
Index(np.array([True, False, True], dtype=bool), dtype=bool),
Index(np.array([True, False, True], dtype=bool),
dtype=bool),
Index([True, False, True], dtype=bool)]:
self.assertIsInstance(idx, Index)
self.assertEqual(idx.dtype, object)

for idx in [Index(np.array([1, 2, 3], dtype=int), dtype='category'),
Index([1, 2, 3], dtype='category'),
Index(np.array([np_datetime64_compat('2011-01-01'),
np_datetime64_compat('2011-01-02')]), dtype='category'),
Index([datetime(2011, 1, 1), datetime(2011, 1, 2)], dtype='category')]:
np_datetime64_compat('2011-01-02')]),
dtype='category'),
Index([datetime(2011, 1, 1), datetime(2011, 1, 2)],
dtype='category')]:
self.assertIsInstance(idx, CategoricalIndex)

for idx in [Index(np.array([np_datetime64_compat('2011-01-01'),
Expand All @@ -304,7 +304,8 @@ def test_constructor_dtypes(self):
self.assertIsInstance(idx, DatetimeIndex)

for idx in [Index(np.array([np_datetime64_compat('2011-01-01'),
np_datetime64_compat('2011-01-02')]), dtype=object),
np_datetime64_compat('2011-01-02')]),
dtype=object),
Index([datetime(2011, 1, 1),
datetime(2011, 1, 2)], dtype=object)]:
self.assertNotIsInstance(idx, DatetimeIndex)
Expand Down Expand Up @@ -483,10 +484,9 @@ def test_nanosecond_index_access(self):
# self.assertEqual(first_value,
# x['2013-01-01 00:00:00.000000050+0000'])

self.assertEqual(
first_value,
x[Timestamp(np_datetime64_compat('2013-01-01 00:00:00.000000050+0000',
'ns'))])
exp_ts = np_datetime64_compat('2013-01-01 00:00:00.000000050+0000',
'ns')
self.assertEqual(first_value, x[Timestamp(exp_ts)])

def test_comparators(self):
index = self.dateIndex
Expand Down Expand Up @@ -1585,41 +1585,47 @@ def test_string_index_repr(self):
expected = u"""Index(['あ', 'いい', 'ううう'], dtype='object')"""
self.assertEqual(repr(idx), expected)
else:
expected = u"""\
Index([u'あ', u'いい', u'ううう'], dtype='object')"""
expected = u"""Index([u'あ', u'いい', u'ううう'], dtype='object')"""
self.assertEqual(coerce(idx), expected)

# multiple lines
idx = pd.Index([u'あ', u'いい', u'ううう'] * 10)
if PY3:
expected = u"""Index(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',
'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',
'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう'],
dtype='object')"""

expected = (u"Index(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', "
u"'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',\n"
u" 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', "
u"'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',\n"
u" 'あ', 'いい', 'ううう', 'あ', 'いい', "
u"'ううう'],\n"
u" dtype='object')")
self.assertEqual(repr(idx), expected)
else:
expected = u"""Index([u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ',
u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい',
u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう'],
dtype='object')"""

expected = (u"Index([u'あ', u'いい', u'ううう', u'あ', u'いい', "
u"u'ううう', u'あ', u'いい', u'ううう', u'あ',\n"
u" u'いい', u'ううう', u'あ', u'いい', u'ううう', "
u"u'あ', u'いい', u'ううう', u'あ', u'いい',\n"
u" u'ううう', u'あ', u'いい', u'ううう', u'あ', "
u"u'いい', u'ううう', u'あ', u'いい', u'ううう'],\n"
u" dtype='object')")
self.assertEqual(coerce(idx), expected)

# truncated
idx = pd.Index([u'あ', u'いい', u'ううう'] * 100)
if PY3:
expected = u"""Index(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ',
...
'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう'],
dtype='object', length=300)"""

expected = (u"Index(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', "
u"'あ', 'いい', 'ううう', 'あ',\n"
u" ...\n"
u" 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', "
u"'ううう', 'あ', 'いい', 'ううう'],\n"
u" dtype='object', length=300)")
self.assertEqual(repr(idx), expected)
else:
expected = u"""Index([u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ',
...
u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう'],
dtype='object', length=300)"""
expected = (u"Index([u'あ', u'いい', u'ううう', u'あ', u'いい', "
u"u'ううう', u'あ', u'いい', u'ううう', u'あ',\n"
u" ...\n"
u" u'ううう', u'あ', u'いい', u'ううう', u'あ', "
u"u'いい', u'ううう', u'あ', u'いい', u'ううう'],\n"
u" dtype='object', length=300)")

self.assertEqual(coerce(idx), expected)

Expand All @@ -1629,49 +1635,62 @@ def test_string_index_repr(self):
# short
idx = pd.Index([u'あ', u'いい', u'ううう'])
if PY3:
expected = u"""Index(['あ', 'いい', 'ううう'], dtype='object')"""
expected = (u"Index(['あ', 'いい', 'ううう'], "
u"dtype='object')")
self.assertEqual(repr(idx), expected)
else:
expected = u"""Index([u'あ', u'いい', u'ううう'], dtype='object')"""
expected = (u"Index([u'あ', u'いい', u'ううう'], "
u"dtype='object')")
self.assertEqual(coerce(idx), expected)

# multiple lines
idx = pd.Index([u'あ', u'いい', u'ううう'] * 10)
if PY3:
expected = u"""Index(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',
'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',
'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',
'あ', 'いい', 'ううう'],
dtype='object')"""
expected = (u"Index(['あ', 'いい', 'ううう', 'あ', 'いい', "
u"'ううう', 'あ', 'いい', 'ううう',\n"
u" 'あ', 'いい', 'ううう', 'あ', 'いい', "
u"'ううう', 'あ', 'いい', 'ううう',\n"
u" 'あ', 'いい', 'ううう', 'あ', 'いい', "
u"'ううう', 'あ', 'いい', 'ううう',\n"
u" 'あ', 'いい', 'ううう'],\n"
u" dtype='object')""")

self.assertEqual(repr(idx), expected)
else:
expected = u"""Index([u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい',
u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ',
u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい',
u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう'],
dtype='object')"""
expected = (u"Index([u'あ', u'いい', u'ううう', u'あ', u'いい', "
u"u'ううう', u'あ', u'いい',\n"
u" u'ううう', u'あ', u'いい', u'ううう', "
u"u'あ', u'いい', u'ううう', u'あ',\n"
u" u'いい', u'ううう', u'あ', u'いい', "
u"u'ううう', u'あ', u'いい',\n"
u" u'ううう', u'あ', u'いい', u'ううう', "
u"u'あ', u'いい', u'ううう'],\n"
u" dtype='object')")

self.assertEqual(coerce(idx), expected)

# truncated
idx = pd.Index([u'あ', u'いい', u'ううう'] * 100)
if PY3:
expected = u"""Index(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',
'あ',
...
'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい',
'ううう'],
dtype='object', length=300)"""
expected = (u"Index(['あ', 'いい', 'ううう', 'あ', 'いい', "
u"'ううう', 'あ', 'いい', 'ううう',\n"
u" 'あ',\n"
u" ...\n"
u" 'ううう', 'あ', 'いい', 'ううう', 'あ', "
u"'いい', 'ううう', 'あ', 'いい',\n"
u" 'ううう'],\n"
u" dtype='object', length=300)")

self.assertEqual(repr(idx), expected)
else:
expected = u"""Index([u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい',
u'ううう', u'あ',
...
u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ',
u'いい', u'ううう'],
dtype='object', length=300)"""
expected = (u"Index([u'あ', u'いい', u'ううう', u'あ', u'いい', "
u"u'ううう', u'あ', u'いい',\n"
u" u'ううう', u'あ',\n"
u" ...\n"
u" u'ううう', u'あ', u'いい', u'ううう', "
u"u'あ', u'いい', u'ううう', u'あ',\n"
u" u'いい', u'ううう'],\n"
u" dtype='object', length=300)")

self.assertEqual(coerce(idx), expected)

Expand Down