Ejemplo n.º 1
0
    def test_minimal_compatible_input(self):
        # Matrices are already in the correct order and have matching IDs.
        np.random.seed(0)

        # input as DistanceMatrix instances
        obs = pwmantel(self.min_dms, alternative="greater")
        assert_frame_equal(obs, self.exp_results_minimal)

        np.random.seed(0)

        # input as array_like
        obs = pwmantel((self.minx, self.miny, self.minz), alternative="greater")
        assert_frame_equal(obs, self.exp_results_minimal)
Ejemplo n.º 2
0
    def test_minimal_compatible_input(self):
        # Matrices are already in the correct order and have matching IDs.
        np.random.seed(0)

        # input as DistanceMatrix instances
        obs = pwmantel(self.min_dms, alternative='greater')
        assert_frame_equal(obs, self.exp_results_minimal)

        np.random.seed(0)

        # input as array_like
        obs = pwmantel((self.minx, self.miny, self.minz),
                       alternative='greater')
        assert_frame_equal(obs, self.exp_results_minimal)
Ejemplo n.º 3
0
    def test_strict(self):
        # Matrices have some matching and nonmatching IDs, with different
        # ordering.
        x = self.x_extra.filter(['1', '0', 'foo', '2'])
        y = self.miny.filter(['0', '2', '1'])
        z = self.z_extra.filter(['bar', '1', '2', '0'])

        np.random.seed(0)

        # strict=False should discard IDs that aren't found in both matrices
        obs = pwmantel((x, y, z), alternative='greater', strict=False)
        assert_frame_equal(obs, self.exp_results_reordered_distance_matrices)

        with self.assertRaises(ValueError):
            pwmantel((x, y, z), strict=True)
Ejemplo n.º 4
0
    def test_minimal_compatible_input_with_labels(self):
        np.random.seed(0)

        obs = pwmantel(self.min_dms,
                       alternative='greater',
                       labels=('minx', 'miny', 'minz'))
        assert_frame_equal(obs, self.exp_results_minimal_with_labels)
Ejemplo n.º 5
0
    def test_id_lookup(self):
        # Matrices have mismatched IDs but a lookup is provided.
        self.minx_dm_extra.ids = ['a', 'b', 'c', 'foo']
        self.minz_dm_extra.ids = ['d', 'e', 'f', 'bar']
        lookup = {'a': '0', 'b': '1', 'c': '2', 'foo': 'foo',
                  'd': '0', 'e': '1', 'f': '2', 'bar': 'bar',
                  '0': '0', '1': '1', '2': '2'}

        x = self.minx_dm_extra.filter(['b', 'a', 'foo', 'c'])
        y = self.miny_dm.filter(['0', '2', '1'])
        z = self.minz_dm_extra.filter(['bar', 'e', 'f', 'd'])

        x_copy = x.copy()
        y_copy = y.copy()
        z_copy = z.copy()

        np.random.seed(0)

        obs = pwmantel((x, y, z), alternative='greater', strict=False,
                       lookup=lookup)
        assert_frame_equal(obs, self.exp_results_reordered_distance_matrices)

        # Make sure the inputs aren't modified.
        self.assertEqual(x, x_copy)
        self.assertEqual(y, y_copy)
        self.assertEqual(z, z_copy)
Ejemplo n.º 6
0
    def test_id_lookup(self):
        # Matrices have mismatched IDs but a lookup is provided.
        self.minx_dm_extra.ids = ['a', 'b', 'c', 'foo']
        self.minz_dm_extra.ids = ['d', 'e', 'f', 'bar']
        lookup = {'a': '0', 'b': '1', 'c': '2', 'foo': 'foo',
                  'd': '0', 'e': '1', 'f': '2', 'bar': 'bar',
                  '0': '0', '1': '1', '2': '2'}

        x = self.minx_dm_extra.filter(['b', 'a', 'foo', 'c'])
        y = self.miny_dm.filter(['0', '2', '1'])
        z = self.minz_dm_extra.filter(['bar', 'e', 'f', 'd'])

        x_copy = x.copy()
        y_copy = y.copy()
        z_copy = z.copy()

        np.random.seed(0)

        obs = pwmantel((x, y, z), alternative='greater', strict=False,
                       lookup=lookup)
        assert_data_frame_almost_equal(
            obs,
            self.exp_results_reordered_distance_matrices)

        # Make sure the inputs aren't modified.
        self.assertEqual(x, x_copy)
        self.assertEqual(y, y_copy)
        self.assertEqual(z, z_copy)
Ejemplo n.º 7
0
    def test_id_lookup(self):
        # Matrices have mismatched IDs but a lookup is provided.
        self.minx_dm_extra.ids = ["a", "b", "c", "foo"]
        self.minz_dm_extra.ids = ["d", "e", "f", "bar"]
        lookup = {
            "a": "0",
            "b": "1",
            "c": "2",
            "foo": "foo",
            "d": "0",
            "e": "1",
            "f": "2",
            "bar": "bar",
            "0": "0",
            "1": "1",
            "2": "2",
        }

        x = self.minx_dm_extra.filter(["b", "a", "foo", "c"])
        y = self.miny_dm.filter(["0", "2", "1"])
        z = self.minz_dm_extra.filter(["bar", "e", "f", "d"])

        x_copy = x.copy()
        y_copy = y.copy()
        z_copy = z.copy()

        np.random.seed(0)

        obs = pwmantel((x, y, z), alternative="greater", strict=False, lookup=lookup)
        assert_frame_equal(obs, self.exp_results_reordered_distance_matrices)

        # Make sure the inputs aren't modified.
        self.assertEqual(x, x_copy)
        self.assertEqual(y, y_copy)
        self.assertEqual(z, z_copy)
Ejemplo n.º 8
0
    def test_minimal_compatible_input_with_labels(self):
        np.random.seed(0)

        obs = pwmantel(self.min_dms, alternative='greater',
                       labels=('minx', 'miny', 'minz'))
        assert_data_frame_almost_equal(
            obs,
            self.exp_results_minimal_with_labels)
Ejemplo n.º 9
0
    def test_filepaths_as_input(self):
        dms = [
            get_data_path('dm.txt'),
            get_data_path('dm2.txt'),
        ]
        np.random.seed(0)

        obs = pwmantel(dms)
        assert_data_frame_almost_equal(obs, self.exp_results_dm_dm2)
Ejemplo n.º 10
0
    def test_filepaths_as_input(self):
        dms = [
            get_data_path('dm.txt'),
            get_data_path('dm2.txt'),
        ]
        np.random.seed(0)

        obs = pwmantel(dms)
        assert_data_frame_almost_equal(obs, self.exp_results_dm_dm2)
Ejemplo n.º 11
0
    def test_reordered_distance_matrices(self):
        # Matrices have matching IDs but they all have different ordering.
        x = self.minx_dm.filter(['1', '0', '2'])
        y = self.miny_dm.filter(['0', '2', '1'])
        z = self.minz_dm.filter(['1', '2', '0'])

        np.random.seed(0)

        obs = pwmantel((x, y, z), alternative='greater')
        assert_frame_equal(obs, self.exp_results_reordered_distance_matrices)
Ejemplo n.º 12
0
    def test_reordered_distance_matrices(self):
        # Matrices have matching IDs but they all have different ordering.
        x = self.minx.filter(['1', '0', '2'])
        y = self.miny.filter(['0', '2', '1'])
        z = self.minz.filter(['1', '2', '0'])

        np.random.seed(0)

        obs = pwmantel((x, y, z), alternative='greater')
        assert_frame_equal(obs, self.exp_results_reordered_distance_matrices)
Ejemplo n.º 13
0
    def test_reordered_distance_matrices(self):
        # Matrices have matching IDs but they all have different ordering.
        x = self.minx_dm.filter(["1", "0", "2"])
        y = self.miny_dm.filter(["0", "2", "1"])
        z = self.minz_dm.filter(["1", "2", "0"])

        np.random.seed(0)

        obs = pwmantel((x, y, z), alternative="greater")
        assert_frame_equal(obs, self.exp_results_reordered_distance_matrices)
Ejemplo n.º 14
0
    def test_many_filepaths_as_input(self):
        dms = [
            get_data_path('dm2.txt'),
            get_data_path('dm.txt'),
            get_data_path('dm4.txt'),
            get_data_path('dm3.txt')
        ]
        np.random.seed(0)

        obs = pwmantel(dms)
        self.assert_pwmantel_almost_equal(obs, self.exp_results_all_dms)
Ejemplo n.º 15
0
    def test_strict(self):
        # Matrices have some matching and nonmatching IDs, with different
        # ordering.
        x = self.minx_dm_extra.filter(['1', '0', 'foo', '2'])
        y = self.miny_dm.filter(['0', '2', '1'])
        z = self.minz_dm_extra.filter(['bar', '1', '2', '0'])

        np.random.seed(0)

        # strict=False should discard IDs that aren't found in both matrices
        obs = pwmantel((x, y, z), alternative='greater', strict=False)
        assert_frame_equal(obs, self.exp_results_reordered_distance_matrices)
Ejemplo n.º 16
0
    def test_strict(self):
        # Matrices have some matching and nonmatching IDs, with different
        # ordering.
        x = self.minx_dm_extra.filter(["1", "0", "foo", "2"])
        y = self.miny_dm.filter(["0", "2", "1"])
        z = self.minz_dm_extra.filter(["bar", "1", "2", "0"])

        np.random.seed(0)

        # strict=False should discard IDs that aren't found in both matrices
        obs = pwmantel((x, y, z), alternative="greater", strict=False)
        assert_frame_equal(obs, self.exp_results_reordered_distance_matrices)
Ejemplo n.º 17
0
 def test_duplicate_labels(self):
     with self.assertRaises(ValueError):
         pwmantel(self.min_dms, labels=['foo', 'bar', 'foo'])
Ejemplo n.º 18
0
 def test_wrong_number_of_labels(self):
     with self.assertRaises(ValueError):
         pwmantel(self.min_dms, labels=['foo', 'bar'])
Ejemplo n.º 19
0
 def test_too_few_dms(self):
     with self.assertRaises(ValueError):
         pwmantel([self.miny_dm])
Ejemplo n.º 20
0
 def test_invalid_input_type(self):
     with self.assertRaises(TypeError):
         pwmantel([self.miny, self.minx, [[0, 42], [42, 0]]])
Ejemplo n.º 21
0
 def test_na_p_value(self):
     obs = pwmantel((self.miny_dm, self.minx_dm), method='spearman',
                    permutations=0)
     assert_frame_equal(obs, self.exp_results_na_p_value)
Ejemplo n.º 22
0
 def test_too_few_dms(self):
     with self.assertRaises(ValueError):
         pwmantel([self.miny_dm])
Ejemplo n.º 23
0
    def test_many_filepaths_as_input(self):
        dms = [get_data_path("dm2.txt"), get_data_path("dm.txt"), get_data_path("dm4.txt"), get_data_path("dm3.txt")]
        np.random.seed(0)

        obs = pwmantel(dms)
        assert_frame_equal(obs, self.exp_results_all_dms)
Ejemplo n.º 24
0
 def test_duplicate_labels(self):
     with self.assertRaises(ValueError):
         pwmantel(self.min_dms, labels=["foo", "bar", "foo"])
Ejemplo n.º 25
0
    def test_minimal_compatible_input_with_labels(self):
        np.random.seed(0)

        obs = pwmantel(self.min_dms, alternative="greater", labels=("minx", "miny", "minz"))
        assert_frame_equal(obs, self.exp_results_minimal_with_labels)
Ejemplo n.º 26
0
 def test_mixed_input_types(self):
     # DistanceMatrix, DistanceMatrix, array_like
     with self.assertRaises(TypeError):
         pwmantel((self.miny_dm, self.minx_dm, self.minz))
Ejemplo n.º 27
0
    def test_no_matching_ids(self):
        self.minx.ids = ['foo', 'bar', 'baz']
        self.miny.ids = ['bro', 'fist', 'breh']

        with self.assertRaises(ValueError):
            pwmantel((self.minx, self.miny, self.minz), strict=False)
Ejemplo n.º 28
0
 def test_duplicate_dms(self):
     obs = pwmantel((self.minx_dm, self.minx_dm, self.minx_dm),
                    alternative='less')
     assert_data_frame_almost_equal(obs, self.exp_results_duplicate_dms)
Ejemplo n.º 29
0
 def test_duplicate_dms(self):
     obs = pwmantel((self.minx_dm, self.minx_dm, self.minx_dm),
                    alternative='less')
     assert_frame_equal(obs, self.exp_results_duplicate_dms)
Ejemplo n.º 30
0
 def test_na_p_value(self):
     obs = pwmantel((self.miny_dm, self.minx_dm), method='spearman',
                    permutations=0)
     assert_data_frame_almost_equal(obs, self.exp_results_na_p_value)
Ejemplo n.º 31
0
 def test_duplicate_labels(self):
     with self.assertRaises(ValueError):
         pwmantel(self.min_dms, labels=['foo', 'bar', 'foo'])
Ejemplo n.º 32
0
 def test_duplicate_dms(self):
     obs = pwmantel((self.minx_dm, self.minx_dm, self.minx_dm), alternative="less")
     assert_frame_equal(obs, self.exp_results_duplicate_dms)
Ejemplo n.º 33
0
 def test_too_few_permutations_for_p_value(self):
     obs = pwmantel((self.miny, self.minx), method='spearman',
                    permutations=9)
     assert_frame_equal(obs, self.exp_results_too_few_permutations)
Ejemplo n.º 34
0
    def test_missing_ids_in_lookup(self):
        # mapping for '1' is missing
        lookup = {'0': 'a', '2': 'c'}

        with self.assertRaises(KeyError):
            pwmantel(self.min_dms, lookup=lookup)
Ejemplo n.º 35
0
 def test_wrong_number_of_labels(self):
     with self.assertRaises(ValueError):
         pwmantel(self.min_dms, labels=['foo', 'bar'])
Ejemplo n.º 36
0
 def test_too_few_permutations_for_p_value(self):
     obs = pwmantel((self.miny_dm, self.minx_dm),
                    method='spearman',
                    permutations=9)
     assert_frame_equal(obs, self.exp_results_too_few_permutations)
Ejemplo n.º 37
0
 def test_mixed_input_types(self):
     # DistanceMatrix, DistanceMatrix, array_like
     with self.assertRaises(TypeError):
         pwmantel((self.miny_dm, self.minx_dm, self.minz))
Ejemplo n.º 38
0
    def test_minimal_compatible_input(self):
        # Matrices are already in the correct order and have matching IDs.
        np.random.seed(0)

        obs = pwmantel(self.min_dms, alternative='greater')
        assert_frame_equal(obs, self.exp_results_minimal)