@@ -13,6 +13,15 @@ def _isnan(val):
1313 return False
1414
1515
16+ def _equivalent_na (dtype , null ):
17+ if dtype .na_value is pd .NA and null is pd .NA :
18+ return True
19+ elif _isnan (dtype .na_value ) and _isnan (null ):
20+ return True
21+ else :
22+ return False
23+
24+
1625class TestGetLoc :
1726 def test_get_loc (self , any_string_dtype ):
1827 index = Index (["a" , "b" , "c" ], dtype = any_string_dtype )
@@ -41,14 +50,7 @@ def test_get_loc_non_missing(self, any_string_dtype, nulls_fixture):
4150
4251 def test_get_loc_missing (self , any_string_dtype , nulls_fixture ):
4352 index = Index (["a" , "b" , nulls_fixture ], dtype = any_string_dtype )
44- if any_string_dtype == "string" and (
45- (any_string_dtype .na_value is pd .NA and nulls_fixture is not pd .NA )
46- or (_isnan (any_string_dtype .na_value ) and not _isnan (nulls_fixture ))
47- ):
48- with pytest .raises (KeyError ):
49- index .get_loc (nulls_fixture )
50- else :
51- assert index .get_loc (nulls_fixture ) == 2
53+ assert index .get_loc (nulls_fixture ) == 2
5254
5355
5456class TestGetIndexer :
@@ -93,9 +95,8 @@ def test_get_indexer_missing(self, any_string_dtype, null, using_infer_string):
9395 result = index .get_indexer (["a" , null , "c" ])
9496 if using_infer_string :
9597 expected = np .array ([0 , 2 , - 1 ], dtype = np .intp )
96- elif any_string_dtype == "string" and (
97- (any_string_dtype .na_value is pd .NA and null is not pd .NA )
98- or (_isnan (any_string_dtype .na_value ) and not _isnan (null ))
98+ elif any_string_dtype == "string" and not _equivalent_na (
99+ any_string_dtype , null
99100 ):
100101 expected = np .array ([0 , - 1 , - 1 ], dtype = np .intp )
101102 else :
@@ -115,9 +116,8 @@ def test_get_indexer_non_unique_nas(
115116 if using_infer_string :
116117 expected_indexer = np .array ([0 , 2 ], dtype = np .intp )
117118 expected_missing = np .array ([], dtype = np .intp )
118- elif any_string_dtype == "string" and (
119- (any_string_dtype .na_value is pd .NA and null is not pd .NA )
120- or (_isnan (any_string_dtype .na_value ) and not _isnan (null ))
119+ elif any_string_dtype == "string" and not _equivalent_na (
120+ any_string_dtype , null
121121 ):
122122 expected_indexer = np .array ([0 , - 1 ], dtype = np .intp )
123123 expected_missing = np .array ([1 ], dtype = np .intp )
@@ -133,9 +133,8 @@ def test_get_indexer_non_unique_nas(
133133
134134 if using_infer_string :
135135 expected_indexer = np .array ([0 , 1 , 3 ], dtype = np .intp )
136- elif any_string_dtype == "string" and (
137- (any_string_dtype .na_value is pd .NA and null is not pd .NA )
138- or (_isnan (any_string_dtype .na_value ) and not _isnan (null ))
136+ elif any_string_dtype == "string" and not _equivalent_na (
137+ any_string_dtype , null
139138 ):
140139 pass
141140 else :
0 commit comments