@@ -1783,24 +1783,6 @@ def test_constructor_datetime64arr(self):
1783
1783
1784
1784
self .assertRaises (ValueError , PeriodIndex , vals , freq = 'D' )
1785
1785
1786
- def test_view (self ):
1787
- idx = pd .PeriodIndex ([], freq = 'M' )
1788
-
1789
- exp = np .array ([], dtype = np .int64 )
1790
- tm .assert_numpy_array_equal (idx .view ('i8' ), exp )
1791
- tm .assert_numpy_array_equal (idx .asi8 , exp )
1792
-
1793
- idx = pd .PeriodIndex (['2011-01' , pd .NaT ], freq = 'M' )
1794
-
1795
- exp = np .array ([492 , - 9223372036854775808 ], dtype = np .int64 )
1796
- tm .assert_numpy_array_equal (idx .view ('i8' ), exp )
1797
- tm .assert_numpy_array_equal (idx .asi8 , exp )
1798
-
1799
- exp = np .array ([14975 , - 9223372036854775808 ], dtype = np .int64 )
1800
- idx = pd .PeriodIndex (['2011-01-01' , pd .NaT ], freq = 'D' )
1801
- tm .assert_numpy_array_equal (idx .view ('i8' ), exp )
1802
- tm .assert_numpy_array_equal (idx .asi8 , exp )
1803
-
1804
1786
def test_constructor_empty (self ):
1805
1787
idx = pd .PeriodIndex ([], freq = 'M' )
1806
1788
tm .assertIsInstance (idx , PeriodIndex )
@@ -1988,6 +1970,66 @@ def test_constructor_freq_combined(self):
1988
1970
freq = '25H' )
1989
1971
tm .assert_index_equal (pidx , expected )
1990
1972
1973
+ def test_view_asi8 (self ):
1974
+ idx = pd .PeriodIndex ([], freq = 'M' )
1975
+
1976
+ exp = np .array ([], dtype = np .int64 )
1977
+ tm .assert_numpy_array_equal (idx .view ('i8' ), exp )
1978
+ tm .assert_numpy_array_equal (idx .asi8 , exp )
1979
+
1980
+ idx = pd .PeriodIndex (['2011-01' , pd .NaT ], freq = 'M' )
1981
+
1982
+ exp = np .array ([492 , - 9223372036854775808 ], dtype = np .int64 )
1983
+ tm .assert_numpy_array_equal (idx .view ('i8' ), exp )
1984
+ tm .assert_numpy_array_equal (idx .asi8 , exp )
1985
+
1986
+ exp = np .array ([14975 , - 9223372036854775808 ], dtype = np .int64 )
1987
+ idx = pd .PeriodIndex (['2011-01-01' , pd .NaT ], freq = 'D' )
1988
+ tm .assert_numpy_array_equal (idx .view ('i8' ), exp )
1989
+ tm .assert_numpy_array_equal (idx .asi8 , exp )
1990
+
1991
+ def test_values (self ):
1992
+ # ToDo: .values and .get_values() should return Period as object
1993
+ # dtype array. ._values shouldn't be changed
1994
+ idx = pd .PeriodIndex ([], freq = 'M' )
1995
+
1996
+ exp = np .array ([], dtype = np .int64 )
1997
+ tm .assert_numpy_array_equal (idx .values , exp )
1998
+ tm .assert_numpy_array_equal (idx .get_values (), exp )
1999
+ tm .assert_numpy_array_equal (idx ._values , exp )
2000
+
2001
+ idx = pd .PeriodIndex (['2011-01' , pd .NaT ], freq = 'M' )
2002
+
2003
+ exp = np .array ([492 , - 9223372036854775808 ], dtype = np .int64 )
2004
+ tm .assert_numpy_array_equal (idx .values , exp )
2005
+ tm .assert_numpy_array_equal (idx .get_values (), exp )
2006
+ tm .assert_numpy_array_equal (idx ._values , exp )
2007
+
2008
+ exp = np .array ([14975 , - 9223372036854775808 ], dtype = np .int64 )
2009
+ idx = pd .PeriodIndex (['2011-01-01' , pd .NaT ], freq = 'D' )
2010
+ tm .assert_numpy_array_equal (idx .values , exp )
2011
+ tm .assert_numpy_array_equal (idx .get_values (), exp )
2012
+ tm .assert_numpy_array_equal (idx ._values , exp )
2013
+
2014
+ def test_asobject_like (self ):
2015
+ idx = pd .PeriodIndex ([], freq = 'M' )
2016
+
2017
+ exp = np .array ([], dtype = object )
2018
+ tm .assert_numpy_array_equal (idx .asobject .values , exp )
2019
+ tm .assert_numpy_array_equal (idx ._mpl_repr (), exp )
2020
+
2021
+ idx = pd .PeriodIndex (['2011-01' , pd .NaT ], freq = 'M' )
2022
+
2023
+ exp = np .array ([pd .Period ('2011-01' , freq = 'M' ), pd .NaT ], dtype = object )
2024
+ tm .assert_numpy_array_equal (idx .asobject .values , exp )
2025
+ tm .assert_numpy_array_equal (idx ._mpl_repr (), exp )
2026
+
2027
+ exp = np .array ([pd .Period ('2011-01-01' , freq = 'D' ), pd .NaT ],
2028
+ dtype = object )
2029
+ idx = pd .PeriodIndex (['2011-01-01' , pd .NaT ], freq = 'D' )
2030
+ tm .assert_numpy_array_equal (idx .asobject .values , exp )
2031
+ tm .assert_numpy_array_equal (idx ._mpl_repr (), exp )
2032
+
1991
2033
def test_is_ (self ):
1992
2034
create_index = lambda : PeriodIndex (freq = 'A' , start = '1/1/2001' ,
1993
2035
end = '12/1/2009' )
0 commit comments