@@ -955,19 +955,21 @@ def test_get_level_values(self):
955
955
exp = CategoricalIndex ([1 , 2 , 3 , 1 , 2 , 3 ])
956
956
tm .assert_index_equal (index .get_level_values (1 ), exp )
957
957
958
- def test_get_level_values_na (self ):
958
+ @pytest .mark .xfail (reason = 'GH 17924 (returns Int64Index with float data)' )
959
+ def test_get_level_values_int_with_na (self ):
959
960
arrays = [['a' , 'b' , 'b' ], [1 , np .nan , 2 ]]
960
961
index = pd .MultiIndex .from_arrays (arrays )
961
- values = index .get_level_values (1 )
962
- expected = np . array ([1 , np .nan , 2 ])
963
- tm .assert_numpy_array_equal ( values . values . astype ( float ) , expected )
962
+ result = index .get_level_values (1 )
963
+ expected = Index ([1 , np .nan , 2 ])
964
+ tm .assert_index_equal ( result , expected )
964
965
965
966
arrays = [['a' , 'b' , 'b' ], [np .nan , np .nan , 2 ]]
966
967
index = pd .MultiIndex .from_arrays (arrays )
967
- values = index .get_level_values (1 )
968
- expected = np . array ([np .nan , np .nan , 2 ])
969
- tm .assert_numpy_array_equal ( values . values . astype ( float ) , expected )
968
+ result = index .get_level_values (1 )
969
+ expected = Index ([np .nan , np .nan , 2 ])
970
+ tm .assert_index_equal ( result , expected )
970
971
972
+ def test_get_level_values_na (self ):
971
973
arrays = [[np .nan , np .nan , np .nan ], ['a' , np .nan , 1 ]]
972
974
index = pd .MultiIndex .from_arrays (arrays )
973
975
result = index .get_level_values (0 )
@@ -982,7 +984,7 @@ def test_get_level_values_na(self):
982
984
index = pd .MultiIndex .from_arrays (arrays )
983
985
values = index .get_level_values (1 )
984
986
expected = pd .DatetimeIndex ([0 , 1 , pd .NaT ])
985
- tm .assert_numpy_array_equal (values . values , expected . values )
987
+ tm .assert_index_equal (values , expected )
986
988
987
989
arrays = [[], []]
988
990
index = pd .MultiIndex .from_arrays (arrays )
@@ -2269,6 +2271,20 @@ def test_unique(self):
2269
2271
exp = pd .MultiIndex .from_arrays ([['a' ], ['a' ]])
2270
2272
tm .assert_index_equal (res , exp )
2271
2273
2274
+ # GH #17896 - with level= argument
2275
+ result = self .index .unique (level = 0 )
2276
+ expected = Index (['foo' , 'bar' , 'baz' , 'qux' ],
2277
+ name = 'first' )
2278
+ tm .assert_index_equal (result , expected )
2279
+
2280
+ @pytest .mark .xfail (reason = 'GH 17924 (returns Int64Index with float data)' )
2281
+ def test_unique_with_nans (self ):
2282
+ # with NaNs
2283
+ index = pd .MultiIndex .from_arrays ([['a' , 'b' , 'b' ], [2 , np .nan , 2 ]])
2284
+ result = index .unique (level = 1 )
2285
+ expected = pd .Index ([2 , np .nan ])
2286
+ tm .assert_index_equal (result , expected )
2287
+
2272
2288
def test_unique_datetimelike (self ):
2273
2289
idx1 = pd .DatetimeIndex (['2015-01-01' , '2015-01-01' , '2015-01-01' ,
2274
2290
'2015-01-01' , 'NaT' , 'NaT' ])
0 commit comments