@@ -297,6 +297,9 @@ def test_view(self):
297
297
i_view = i .view ()
298
298
self .assertEqual (i_view .name , 'Foo' )
299
299
300
+ # with arguments
301
+ self .assertRaises (TypeError , lambda : i .view ('i8' ))
302
+
300
303
def test_legacy_pickle_identity (self ):
301
304
302
305
# GH 8431
@@ -1469,6 +1472,12 @@ def test_view(self):
1469
1472
i_view = i .view ()
1470
1473
self .assertEqual (i_view .name , 'Foo' )
1471
1474
1475
+ i_view = i .view ('i8' )
1476
+ tm .assert_index_equal (i , Int64Index (i_view ))
1477
+
1478
+ i_view = i .view (Int64Index )
1479
+ tm .assert_index_equal (i , Int64Index (i_view ))
1480
+
1472
1481
def test_coerce_list (self ):
1473
1482
# coerce things
1474
1483
arr = Index ([1 , 2 , 3 , 4 ])
@@ -1856,7 +1865,21 @@ def test_slice_keep_name(self):
1856
1865
idx = Int64Index ([1 , 2 ], name = 'asdf' )
1857
1866
self .assertEqual (idx .name , idx [1 :].name )
1858
1867
1859
- class TestDatetimeIndex (Base , tm .TestCase ):
1868
+ class DatetimeLike (Base ):
1869
+
1870
+ def test_view (self ):
1871
+
1872
+ i = self .create_index ()
1873
+
1874
+ i_view = i .view ('i8' )
1875
+ result = self ._holder (i )
1876
+ tm .assert_index_equal (result , i )
1877
+
1878
+ i_view = i .view (self ._holder )
1879
+ result = self ._holder (i )
1880
+ tm .assert_index_equal (result , i )
1881
+
1882
+ class TestDatetimeIndex (DatetimeLike , tm .TestCase ):
1860
1883
_holder = DatetimeIndex
1861
1884
_multiprocess_can_split_ = True
1862
1885
@@ -1926,7 +1949,7 @@ def test_time_overflow_for_32bit_machines(self):
1926
1949
self .assertEqual (len (idx2 ), periods )
1927
1950
1928
1951
1929
- class TestPeriodIndex (Base , tm .TestCase ):
1952
+ class TestPeriodIndex (DatetimeLike , tm .TestCase ):
1930
1953
_holder = PeriodIndex
1931
1954
_multiprocess_can_split_ = True
1932
1955
@@ -1936,7 +1959,7 @@ def create_index(self):
1936
1959
def test_pickle_compat_construction (self ):
1937
1960
pass
1938
1961
1939
- class TestTimedeltaIndex (Base , tm .TestCase ):
1962
+ class TestTimedeltaIndex (DatetimeLike , tm .TestCase ):
1940
1963
_holder = TimedeltaIndex
1941
1964
_multiprocess_can_split_ = True
1942
1965
0 commit comments