2
2
3
3
from datetime import datetime , timedelta
4
4
5
- # TODO(wesm): fix long line flake8 issues
6
- # flake8: noqa
7
-
8
5
import pandas .util .testing as tm
9
6
from pandas .indexes .api import Index , MultiIndex
10
7
from .common import Base
@@ -286,16 +283,19 @@ def test_constructor_dtypes(self):
286
283
287
284
for idx in [Index (np .array ([True , False , True ], dtype = bool )),
288
285
Index ([True , False , True ]),
289
- Index (np .array ([True , False , True ], dtype = bool ), dtype = bool ),
286
+ Index (np .array ([True , False , True ], dtype = bool ),
287
+ dtype = bool ),
290
288
Index ([True , False , True ], dtype = bool )]:
291
289
self .assertIsInstance (idx , Index )
292
290
self .assertEqual (idx .dtype , object )
293
291
294
292
for idx in [Index (np .array ([1 , 2 , 3 ], dtype = int ), dtype = 'category' ),
295
293
Index ([1 , 2 , 3 ], dtype = 'category' ),
296
294
Index (np .array ([np_datetime64_compat ('2011-01-01' ),
297
- np_datetime64_compat ('2011-01-02' )]), dtype = 'category' ),
298
- Index ([datetime (2011 , 1 , 1 ), datetime (2011 , 1 , 2 )], dtype = 'category' )]:
295
+ np_datetime64_compat ('2011-01-02' )]),
296
+ dtype = 'category' ),
297
+ Index ([datetime (2011 , 1 , 1 ), datetime (2011 , 1 , 2 )],
298
+ dtype = 'category' )]:
299
299
self .assertIsInstance (idx , CategoricalIndex )
300
300
301
301
for idx in [Index (np .array ([np_datetime64_compat ('2011-01-01' ),
@@ -304,7 +304,8 @@ def test_constructor_dtypes(self):
304
304
self .assertIsInstance (idx , DatetimeIndex )
305
305
306
306
for idx in [Index (np .array ([np_datetime64_compat ('2011-01-01' ),
307
- np_datetime64_compat ('2011-01-02' )]), dtype = object ),
307
+ np_datetime64_compat ('2011-01-02' )]),
308
+ dtype = object ),
308
309
Index ([datetime (2011 , 1 , 1 ),
309
310
datetime (2011 , 1 , 2 )], dtype = object )]:
310
311
self .assertNotIsInstance (idx , DatetimeIndex )
@@ -483,10 +484,9 @@ def test_nanosecond_index_access(self):
483
484
# self.assertEqual(first_value,
484
485
# x['2013-01-01 00:00:00.000000050+0000'])
485
486
486
- self .assertEqual (
487
- first_value ,
488
- x [Timestamp (np_datetime64_compat ('2013-01-01 00:00:00.000000050+0000' ,
489
- 'ns' ))])
487
+ exp_ts = np_datetime64_compat ('2013-01-01 00:00:00.000000050+0000' ,
488
+ 'ns' )
489
+ self .assertEqual (first_value , x [Timestamp (exp_ts )])
490
490
491
491
def test_comparators (self ):
492
492
index = self .dateIndex
@@ -1585,41 +1585,47 @@ def test_string_index_repr(self):
1585
1585
expected = u"""Index(['あ', 'いい', 'ううう'], dtype='object')"""
1586
1586
self .assertEqual (repr (idx ), expected )
1587
1587
else :
1588
- expected = u"""\
1589
- Index([u'あ', u'いい', u'ううう'], dtype='object')"""
1588
+ expected = u"""Index([u'あ', u'いい', u'ううう'], dtype='object')"""
1590
1589
self .assertEqual (coerce (idx ), expected )
1591
1590
1592
1591
# multiple lines
1593
1592
idx = pd .Index ([u'あ' , u'いい' , u'ううう' ] * 10 )
1594
1593
if PY3 :
1595
- expected = u"""Index(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',
1596
- 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',
1597
- 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう'],
1598
- dtype='object')"""
1599
-
1594
+ expected = (u"Index(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', "
1595
+ u"'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',\n "
1596
+ u" 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', "
1597
+ u"'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',\n "
1598
+ u" 'あ', 'いい', 'ううう', 'あ', 'いい', "
1599
+ u"'ううう'],\n "
1600
+ u" dtype='object')" )
1600
1601
self .assertEqual (repr (idx ), expected )
1601
1602
else :
1602
- expected = u"""Index([u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ',
1603
- u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい',
1604
- u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう'],
1605
- dtype='object')"""
1606
-
1603
+ expected = (u"Index([u'あ', u'いい', u'ううう', u'あ', u'いい', "
1604
+ u"u'ううう', u'あ', u'いい', u'ううう', u'あ',\n "
1605
+ u" u'いい', u'ううう', u'あ', u'いい', u'ううう', "
1606
+ u"u'あ', u'いい', u'ううう', u'あ', u'いい',\n "
1607
+ u" u'ううう', u'あ', u'いい', u'ううう', u'あ', "
1608
+ u"u'いい', u'ううう', u'あ', u'いい', u'ううう'],\n "
1609
+ u" dtype='object')" )
1607
1610
self .assertEqual (coerce (idx ), expected )
1608
1611
1609
1612
# truncated
1610
1613
idx = pd .Index ([u'あ' , u'いい' , u'ううう' ] * 100 )
1611
1614
if PY3 :
1612
- expected = u"""Index(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ',
1613
- ...
1614
- 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう'],
1615
- dtype='object', length=300)"""
1616
-
1615
+ expected = (u"Index(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', "
1616
+ u"'あ', 'いい', 'ううう', 'あ',\n "
1617
+ u" ...\n "
1618
+ u" 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', "
1619
+ u"'ううう', 'あ', 'いい', 'ううう'],\n "
1620
+ u" dtype='object', length=300)" )
1617
1621
self .assertEqual (repr (idx ), expected )
1618
1622
else :
1619
- expected = u"""Index([u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ',
1620
- ...
1621
- u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう'],
1622
- dtype='object', length=300)"""
1623
+ expected = (u"Index([u'あ', u'いい', u'ううう', u'あ', u'いい', "
1624
+ u"u'ううう', u'あ', u'いい', u'ううう', u'あ',\n "
1625
+ u" ...\n "
1626
+ u" u'ううう', u'あ', u'いい', u'ううう', u'あ', "
1627
+ u"u'いい', u'ううう', u'あ', u'いい', u'ううう'],\n "
1628
+ u" dtype='object', length=300)" )
1623
1629
1624
1630
self .assertEqual (coerce (idx ), expected )
1625
1631
@@ -1629,49 +1635,62 @@ def test_string_index_repr(self):
1629
1635
# short
1630
1636
idx = pd .Index ([u'あ' , u'いい' , u'ううう' ])
1631
1637
if PY3 :
1632
- expected = u"""Index(['あ', 'いい', 'ううう'], dtype='object')"""
1638
+ expected = (u"Index(['あ', 'いい', 'ううう'], "
1639
+ u"dtype='object')" )
1633
1640
self .assertEqual (repr (idx ), expected )
1634
1641
else :
1635
- expected = u"""Index([u'あ', u'いい', u'ううう'], dtype='object')"""
1642
+ expected = (u"Index([u'あ', u'いい', u'ううう'], "
1643
+ u"dtype='object')" )
1636
1644
self .assertEqual (coerce (idx ), expected )
1637
1645
1638
1646
# multiple lines
1639
1647
idx = pd .Index ([u'あ' , u'いい' , u'ううう' ] * 10 )
1640
1648
if PY3 :
1641
- expected = u"""Index(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',
1642
- 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',
1643
- 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',
1644
- 'あ', 'いい', 'ううう'],
1645
- dtype='object')"""
1649
+ expected = (u"Index(['あ', 'いい', 'ううう', 'あ', 'いい', "
1650
+ u"'ううう', 'あ', 'いい', 'ううう',\n "
1651
+ u" 'あ', 'いい', 'ううう', 'あ', 'いい', "
1652
+ u"'ううう', 'あ', 'いい', 'ううう',\n "
1653
+ u" 'あ', 'いい', 'ううう', 'あ', 'いい', "
1654
+ u"'ううう', 'あ', 'いい', 'ううう',\n "
1655
+ u" 'あ', 'いい', 'ううう'],\n "
1656
+ u" dtype='object')" "" )
1646
1657
1647
1658
self .assertEqual (repr (idx ), expected )
1648
1659
else :
1649
- expected = u"""Index([u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい',
1650
- u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ',
1651
- u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい',
1652
- u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう'],
1653
- dtype='object')"""
1660
+ expected = (u"Index([u'あ', u'いい', u'ううう', u'あ', u'いい', "
1661
+ u"u'ううう', u'あ', u'いい',\n "
1662
+ u" u'ううう', u'あ', u'いい', u'ううう', "
1663
+ u"u'あ', u'いい', u'ううう', u'あ',\n "
1664
+ u" u'いい', u'ううう', u'あ', u'いい', "
1665
+ u"u'ううう', u'あ', u'いい',\n "
1666
+ u" u'ううう', u'あ', u'いい', u'ううう', "
1667
+ u"u'あ', u'いい', u'ううう'],\n "
1668
+ u" dtype='object')" )
1654
1669
1655
1670
self .assertEqual (coerce (idx ), expected )
1656
1671
1657
1672
# truncated
1658
1673
idx = pd .Index ([u'あ' , u'いい' , u'ううう' ] * 100 )
1659
1674
if PY3 :
1660
- expected = u"""Index(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',
1661
- 'あ',
1662
- ...
1663
- 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい',
1664
- 'ううう'],
1665
- dtype='object', length=300)"""
1675
+ expected = (u"Index(['あ', 'いい', 'ううう', 'あ', 'いい', "
1676
+ u"'ううう', 'あ', 'いい', 'ううう',\n "
1677
+ u" 'あ',\n "
1678
+ u" ...\n "
1679
+ u" 'ううう', 'あ', 'いい', 'ううう', 'あ', "
1680
+ u"'いい', 'ううう', 'あ', 'いい',\n "
1681
+ u" 'ううう'],\n "
1682
+ u" dtype='object', length=300)" )
1666
1683
1667
1684
self .assertEqual (repr (idx ), expected )
1668
1685
else :
1669
- expected = u"""Index([u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい',
1670
- u'ううう', u'あ',
1671
- ...
1672
- u'ううう', u'あ', u'いい', u'ううう', u'あ', u'いい', u'ううう', u'あ',
1673
- u'いい', u'ううう'],
1674
- dtype='object', length=300)"""
1686
+ expected = (u"Index([u'あ', u'いい', u'ううう', u'あ', u'いい', "
1687
+ u"u'ううう', u'あ', u'いい',\n "
1688
+ u" u'ううう', u'あ',\n "
1689
+ u" ...\n "
1690
+ u" u'ううう', u'あ', u'いい', u'ううう', "
1691
+ u"u'あ', u'いい', u'ううう', u'あ',\n "
1692
+ u" u'いい', u'ううう'],\n "
1693
+ u" dtype='object', length=300)" )
1675
1694
1676
1695
self .assertEqual (coerce (idx ), expected )
1677
1696
0 commit comments