Esempio n. 1
0
    def test_with_artifacts(self):
        artifact1 = Artifact.import_data('Mapping', {'a': '1', 'b': '2'})
        artifact2 = Artifact.import_data('Mapping', {'d': '4'})

        md_from_artifact1 = Metadata.from_artifact(artifact1)
        md_from_artifact2 = Metadata.from_artifact(artifact2)
        md_no_artifact = Metadata(
            pd.DataFrame({'c': ['3', '42']},
                         index=pd.Index(['0', '1'], name='id')))

        # Merge three metadata objects -- the first has an artifact, the second
        # does not, and the third has an artifact.
        obs_md = md_from_artifact1.merge(md_no_artifact, md_from_artifact2)

        exp_df = pd.DataFrame({
            'a': '1',
            'b': '2',
            'c': '3',
            'd': '4'
        },
                              index=pd.Index(['0'], name='id'))
        exp_md = Metadata(exp_df)
        exp_md._add_artifacts((artifact1, artifact2))

        self.assertEqual(obs_md, exp_md)
        self.assertEqual(obs_md.artifacts, (artifact1, artifact2))
Esempio n. 2
0
    def test_artifact_mismatch(self):
        # Metadata created from different artifacts shouldn't compare equal,
        # even if the data is the same.
        artifact1 = Artifact.import_data('Mapping', {'a': '1', 'b': '2'})
        artifact2 = Artifact.import_data('Mapping', {'a': '1', 'b': '2'})

        md1 = Metadata.from_artifact(artifact1)
        md2 = Metadata.from_artifact(artifact2)

        pdt.assert_frame_equal(md1.to_dataframe(), md2.to_dataframe())
        self.assertReallyNotEqual(md1, md2)
Esempio n. 3
0
    def test_source_mismatch(self):
        # Metadata created from an artifact vs not shouldn't compare equal,
        # even if the data is the same.
        artifact = Artifact.import_data('Mapping', {'a': '1', 'b': '2'})
        md_from_artifact = Metadata.from_artifact(artifact)

        md_no_artifact = Metadata(md_from_artifact.to_dataframe())

        pdt.assert_frame_equal(md_from_artifact.to_dataframe(),
                               md_no_artifact.to_dataframe())
        self.assertReallyNotEqual(md_from_artifact, md_no_artifact)
Esempio n. 4
0
    def test_artifacts_are_propagated(self):
        A = Artifact.import_data('Mapping', {'a': '1', 'b': '3'})
        md = Metadata.from_artifact(A)

        obs = md.get_column('b')

        # TODO update to use MetadataColumn.__eq__
        self.assertEqual(obs.artifacts, (A, ))
        pdt.assert_series_equal(
            obs.to_series(),
            pd.Series(['3'], index=pd.Index(['0'], name='id'), name='b'))
Esempio n. 5
0
    def test_from_artifact(self):
        A = Artifact.import_data('Mapping', {'a': '1', 'b': '3'})

        obs_md = Metadata.from_artifact(A)

        exp_df = pd.DataFrame({
            'a': '1',
            'b': '3'
        },
                              index=pd.Index(['0'], name='id', dtype=object),
                              dtype=object)
        exp_md = Metadata(exp_df)
        exp_md._add_artifacts([A])

        self.assertEqual(obs_md, exp_md)
Esempio n. 6
0
    def test_equality_with_artifact(self):
        artifact = Artifact.import_data('Mapping', {'a': '1', 'b': '2'})
        md1 = Metadata.from_artifact(artifact)
        md2 = Metadata.from_artifact(artifact)

        self.assertReallyEqual(md1, md2)
Esempio n. 7
0
 def test_artifacts(self):
     A = Artifact.import_data('Mapping', {'a': 'abc', 'b': '-42'})
     md = Metadata.from_artifact(A)
     obs = md.artifacts
     self.assertEqual(obs, (A, ))
Esempio n. 8
0
 def test_from_bad_artifact(self):
     A = Artifact.import_data('IntSequence1', [1, 2, 3, 4])
     with self.assertRaisesRegex(ValueError, 'Artifact has no metadata'):
         Metadata.from_artifact(A)