コード例 #1
0
    def test__has_not_all_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]
            idx = _has_all(start_time, test_values)
        self.assertEqual(
            error.exception.message[:56],
            "The series given to has_all() must be a supported dtype.")
        # Test not version
        with self.assertRaises(TypeError) as error:
            test_values = [1, 2]
            idx = _not_all(start_time, test_values)
        self.assertEqual(
            error.exception.message[:56],
            "The series given to not_all() must be a supported dtype.")
コード例 #2
0
 def test__has_not_all_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]
         idx = _has_all(start_time, test_values)
     self.assertEqual(
         error.exception.message[:56],
         "The series given to has_all() must be a supported dtype."
     )
     # Test not version
     with self.assertRaises(TypeError) as error:
         test_values = [1, 2]
         idx = _not_all(start_time, test_values)
     self.assertEqual(
         error.exception.message[:56],
         "The series given to not_all() must be a supported dtype."
     )
コード例 #3
0
    def test__has_not_all(self):

        # Test _has_all 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_all returns correct results
            idx = _has_all(q2, test_values)
            self.assertTrue(
                all([
                     all([tv in v for tv in str_test_values])
                     for v in q2[idx]
                ])
            )
            # Test inverse index produced by not version
            not_idx = _not_all(q2, test_values)
            self.confirm_inverse_index(q2, idx, not_idx, incl_na=True)
        self.assertTrue((q2.fillna(0)==q2_verify_unchanged.fillna(0)).all())

        # Test _has_all on single that is stored as int64
        gender = self.example_data_A_data['gender']
        gender_verify_unchanged = gender.copy()
        for test_values in [[1], [999]]:
            # Test _has_all returns correct results
            idx = _has_all(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_all(gender, test_values)
            self.confirm_inverse_index(gender, idx, not_idx, incl_na=True)
        self.assertTrue((gender.fillna(0)==gender_verify_unchanged.fillna(0)).all())

        # Test _not_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], [999]]:
            # Test _not_any returns correct results
            idx = _has_all(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, incl_na=True)
        self.assertTrue((locality.fillna(0)==locality_verify_unchanged.fillna(0)).all())

        # Test _has_all 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_all(q2, test_values, True)
            resulting_columns = q2[idx].str.get_dummies(';').columns
            self.assertEqual(
                [int(col) for col in resulting_columns],
                test_values
            )
            # Test inverse index produced by not version
            not_idx = _not_all(q2, test_values, True)
            self.assertTrue(len(idx.intersection(not_idx))==0)
            self.assertTrue(not any(
                q2[not_idx].str.get_dummies(';')[test_values].all()))
        self.assertTrue((q2.fillna(0)==q2_verify_unchanged.fillna(0)).all())
コード例 #4
0
 def test__has_not_all(self):
      
     # Test _has_all 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_all returns correct results
         idx = _has_all(q2, test_values)
         self.assertTrue(
             all([
                  all([tv in v for tv in str_test_values])
                  for v in q2[idx]
             ])
         )
         # Test inverse index produced by not version
         not_idx = _not_all(q2, test_values)
         self.confirm_inverse_index(q2, idx, not_idx)
     self.assertTrue((q2.fillna(0)==q2_verify_unchanged.fillna(0)).all())
      
     # Test _has_all on single that is stored as int64
     gender = self.example_data_A_data['gender']
     gender_verify_unchanged = gender.copy()
     for test_values in [[1], [999]]:
         # Test _has_all returns correct results
         idx = _has_all(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_all(gender, test_values)
         self.confirm_inverse_index(gender, idx, not_idx)
     self.assertTrue((gender.fillna(0)==gender_verify_unchanged.fillna(0)).all())
      
     # Test _not_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], [999]]:
         # Test _not_any returns correct results
         idx = _has_all(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, True)
         self.confirm_inverse_index(locality, idx, not_idx)
     self.assertTrue((locality.fillna(0)==locality_verify_unchanged.fillna(0)).all())
     
     # Test _has_all 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_all(q2, test_values, True)
         resulting_columns = q2[idx].str.get_dummies(';').columns
         self.assertItemsEqual(
             [int(col) for col in resulting_columns],
             test_values
         )
         # Test inverse index produced by not version
         not_idx = _not_all(q2, test_values, True)
         self.confirm_inverse_index(q2, idx, not_idx)
     self.assertTrue((q2.fillna(0)==q2_verify_unchanged.fillna(0)).all())