def test__has_not_any_errors(self): # Test unsupported dtype series is given start_time = self.example_data_A_data['start_time'] start_time = start_time.astype(np.datetime64) # Test has version with self.assertRaises(TypeError) as error: test_values = [1, 2] # Test _has_all raises TypeError idx = _has_any(start_time, test_values) self.assertEqual( error.exception.message[:56], "The series given to has_any() must be a supported dtype.") # Test not version with self.assertRaises(TypeError) as error: test_values = [1, 2] # Test _has_all raises TypeError idx = _not_any(start_time, test_values) self.assertEqual( error.exception.message[:56], "The series given to not_any() must be a supported dtype.")
def test__has_not_any_errors(self): # Test unsupported dtype series is given start_time = self.example_data_A_data['start_time'] start_time = start_time.astype(np.datetime64) # Test has version with self.assertRaises(TypeError) as error: test_values = [1, 2] # Test _has_all raises TypeError idx = _has_any(start_time, test_values) self.assertEqual( error.exception.message[:56], "The series given to has_any() must be a supported dtype." ) # Test not version with self.assertRaises(TypeError) as error: test_values = [1, 2] # Test _has_all raises TypeError idx = _not_any(start_time, test_values) self.assertEqual( error.exception.message[:56], "The series given to not_any() must be a supported dtype." )
def test__has_not_any(self): # Test _has_any on delimited set q2 = self.example_data_A_data['q2'] q2_verify_unchanged = q2.copy() for test_values in [[1, 3, 5], [2, 4, 6], [999]]: # Make string versions of test_values str_test_values = [str(v) for v in test_values] # Test _has_any returns correct results idx = _has_any(q2, test_values) self.assertTrue( all([ any([tv in v for tv in str_test_values]) for v in q2[idx] ]) ) # Test inverse index produced by not version not_idx = _not_any(q2, test_values) not_resulting_columns = q2[not_idx].str.get_dummies(';').columns self.assertTrue(all([ not int(col) in test_values for col in not_resulting_columns ])) self.confirm_inverse_index(q2, idx, not_idx, incl_na=True) self.assertTrue((q2.fillna(0)==q2_verify_unchanged.fillna(0)).all()) # Test _has_any on single that is stored as int64 gender = self.example_data_A_data['gender'] gender_verify_unchanged = gender.copy() for test_values in [[1], [1, 2], [999]]: # Test _has_any returns correct results idx = _has_any(gender, test_values) filter_idx = gender.isin(test_values) self.assertTrue( all(gender[idx].index==gender[filter_idx].index) ) # Test inverse index produced by not version not_idx = _not_any(gender, test_values) not_resulting_columns = gender[not_idx].astype('str').str.get_dummies(';').columns self.assertTrue(all([ not int(col) in test_values for col in not_resulting_columns ])) self.confirm_inverse_index(gender, idx, not_idx, incl_na=True) self.assertTrue((gender.fillna(0)==gender_verify_unchanged.fillna(0)).all()) # Test _has_any on single that is stored as float64 locality = self.example_data_A_data['locality'] locality_verify_unchanged = locality.copy() for test_values in [[1], [1, 2], [999]]: # Test _has_any returns correct results idx = _has_any(locality, test_values) filter_idx = locality.isin(test_values) self.assertTrue( all(locality[idx].index==locality[filter_idx].index) ) # Test inverse index produced by not version not_idx = _not_any(locality, test_values) not_resulting_columns = locality[not_idx].astype('str').str.get_dummies(';').columns self.assertTrue(all([ not str(float(col)) in test_values for col in not_resulting_columns ])) self.confirm_inverse_index(locality, idx, not_idx, incl_na=True) self.assertTrue((locality.fillna(0)==locality_verify_unchanged.fillna(0)).all()) # Test _has_any using exclusivity q2 = self.example_data_A_data['q2'] q2_verify_unchanged = q2.copy() for test_values in [[1, 3, 5], [2, 4, 6]]: # Make string versions of test_values str_test_values = [str(v) for v in test_values] # Test _has_all returns correct results idx = _has_any(q2, test_values, True) resulting_columns = q2[idx].astype('object').str.get_dummies(';').columns self.assertTrue(all([ int(col) in test_values for col in resulting_columns ])) # Test inverse index produced by not version, exclusive not_idx = _not_any(q2, test_values, True) not_resulting_columns = q2[not_idx].str.get_dummies(';').columns self.assertTrue(all([ not int(col) in test_values for col in not_resulting_columns ])) self.assertTrue(len(idx.intersection(not_idx))==0) self.assertTrue(len(resulting_columns.intersection(not_resulting_columns))==0) self.assertTrue((q2.fillna(0)==q2_verify_unchanged.fillna(0)).all())
def test__has_not_any(self): # Test _has_any on delimited set q2 = self.example_data_A_data['q2'] q2_verify_unchanged = q2.copy() for test_values in [[1, 3, 5], [2, 4, 6], [999]]: # Make string versions of test_values str_test_values = [str(v) for v in test_values] # Test _has_any returns correct results idx = _has_any(q2, test_values) self.assertTrue( all([ any([tv in v for tv in str_test_values]) for v in q2[idx] ]) ) # Test inverse index produced by not version not_idx = _not_any(q2, test_values) self.confirm_inverse_index(q2, idx, not_idx) self.assertTrue((q2.fillna(0)==q2_verify_unchanged.fillna(0)).all()) # Test _has_any on single that is stored as int64 gender = self.example_data_A_data['gender'] gender_verify_unchanged = gender.copy() for test_values in [[1], [1, 2], [999]]: # Test _has_any returns correct results idx = _has_any(gender, test_values) filter_idx = gender.isin(test_values) self.assertTrue( all(gender[idx].index==gender[filter_idx].index) ) # Test inverse index produced by not version not_idx = _not_any(gender, test_values) self.confirm_inverse_index(gender, idx, not_idx) self.assertTrue((gender.fillna(0)==gender_verify_unchanged.fillna(0)).all()) # Test _has_any on single that is stored as float64 locality = self.example_data_A_data['locality'] locality_verify_unchanged = locality.copy() for test_values in [[1], [1, 2], [999]]: # Test _has_any returns correct results idx = _has_any(locality, test_values) filter_idx = locality.isin(test_values) self.assertTrue( all(locality[idx].index==locality[filter_idx].index) ) # Test inverse index produced by not version not_idx = _not_any(locality, test_values) self.confirm_inverse_index(locality, idx, not_idx) self.assertTrue((locality.fillna(0)==locality_verify_unchanged.fillna(0)).all()) # Test _has_any using exclusivity q2 = self.example_data_A_data['q2'] q2_verify_unchanged = q2.copy() for test_values in [[1, 3, 5], [2, 4, 6]]: # Make string versions of test_values str_test_values = [str(v) for v in test_values] # Test _has_all returns correct results idx = _has_any(q2, test_values, True) resulting_columns = q2[idx].astype('object').str.get_dummies(';').columns self.assertTrue(all([ int(col) in test_values for col in resulting_columns ])) # Test inverse index produced by not version not_idx = _not_any(q2, test_values, True) self.confirm_inverse_index(q2, idx, not_idx) self.assertTrue((q2.fillna(0)==q2_verify_unchanged.fillna(0)).all())