Example #1
0
    def test_to_data_frame(self):
        ds = Dataset(metadata=dict(fields="A,B,C"),
                     records=[[1, 2.2, 3.1], [3, 2.3, 3.2], [5, 2.4, 3.3]])

        try:
            import pandas

            # noinspection PyUnresolvedReferences
            df = ds.to_data_frame()
            print(df)

        except ImportError:
            pass
    def test_field_present(self):
        rule = MetaFieldObsoleteRule("station", "@field_obsolete")

        dataset = Dataset({"station": "whatever"}, [])

        issue = rule.eval(dataset, self._lib)
        self.assertIsNotNone(issue)
        self.assertEqual(ISSUE_TYPE_WARNING, issue.type)
        self.assertEqual("@field_obsolete", issue.description)
Example #3
0
    def test_int_equal_invalid_field(self):
        rule = MetaFieldCompareRule("int_1", "int_2", "==", error="must be same", data_type="number")

        dataset = Dataset({"int_1": "16"}, [])

        issue = rule.eval(dataset, self._lib)
        self.assertIsNotNone(issue)
        self.assertEqual(ISSUE_TYPE_ERROR, issue.type)
        self.assertEqual("Requested field not contained in metadata: int_2", issue.description)
    def test_field_empty(self):
        rule = MetaFieldRequiredRule("investigator", "@required_field_missing")

        dataset = Dataset({"investigator": ""}, [])

        issue = rule.eval(dataset, self._lib)
        self.assertIsNotNone(issue)
        self.assertEqual(ISSUE_TYPE_ERROR, issue.type)
        self.assertEqual("@required_field_missing", issue.description)
Example #5
0
    def test_field_present_but_empty(self):
        rule = MetaFieldOptionalRule("station", "@field_value_missing")

        dataset = Dataset({"station": ""}, [])

        issue = rule.eval(dataset, self._lib)
        self.assertIsNotNone(issue)
        self.assertEqual(ISSUE_TYPE_WARNING, issue.type)
        self.assertEqual("@field_value_missing", issue.description)
Example #6
0
    def test_date_smaller_equal_failure(self):
        rule = MetaFieldCompareRule("start_date", "end_date", "<", error="end date before start date", data_type="date")

        dataset = Dataset({"start_date": "20080416", "end_date": "20080416"}, [])

        issue = rule.eval(dataset, self._lib)
        self.assertIsNotNone(issue)
        self.assertEqual("end date before start date", issue.description)
        self.assertEqual("ERROR", issue.type)
Example #7
0
    def test_int_less_than_error(self):
        rule = MetaFieldCompareRule("int_1", "int_2", "<", warning="should be smaller", data_type="number")

        dataset = Dataset({"int_1": "16", "int_2": "15"}, [])

        issue = rule.eval(dataset, self._lib)
        self.assertIsNotNone(issue)
        self.assertEqual(ISSUE_TYPE_WARNING, issue.type)
        self.assertEqual("should be smaller", issue.description)
Example #8
0
    def test_float_not_equal_warning(self):
        rule = MetaFieldCompareRule("north_lat", "south_lat", "!=", warning="should not be equal", data_type="number")

        dataset = Dataset({"north_lat": "28.33", "south_lat": "28.33"}, [])

        issue = rule.eval(dataset, self._lib)
        self.assertIsNotNone(issue)
        self.assertEqual(ISSUE_TYPE_WARNING, issue.type)
        self.assertEqual("should not be equal", issue.description)
Example #9
0
    def test_float_larger_equal_error(self):
        rule = MetaFieldCompareRule("north_lat", "south_lat", ">=", error="@south_north_mismatch", data_type="number")

        dataset = Dataset({"north_lat": "11.56", "south_lat": "28.33"}, [])

        issue = rule.eval(dataset, self._lib)
        self.assertIsNotNone(issue)
        self.assertEqual(ISSUE_TYPE_ERROR, issue.type)
        self.assertEqual("@south_north_mismatch", issue.description)
Example #10
0
    def test_from_data_frame(self):
        try:
            import pandas

            ds = Dataset.from_data_frame(
                pandas.DataFrame(data=[[1, 2.2, 3.1], [3, 2.3, 3.2],
                                       [5, 2.4, 3.3]],
                                 columns=["A", "B", "C"]))

            print(ds)

        except ImportError:
            pass
    def test_field_missing(self):
        rule = MetaFieldObsoleteRule("station", "@field_obsolete")

        dataset = Dataset({}, [])

        self.assertIsNone(rule.eval(dataset, self._lib))
    def test_field_present(self):
        rule = MetaFieldRequiredRule("investigator", "@required_field_missing")

        dataset = Dataset({"investigator": "Hans_Dampf"}, [])

        self.assertIsNone(rule.eval(dataset, self._lib))
Example #13
0
    def test_field_present(self):
        rule = MetaFieldOptionalRule("station", "@field_value_missing")

        dataset = Dataset({"station": "Svalbard"}, [])

        self.assertIsNone(rule.eval(dataset, self._lib))
Example #14
0
    def test_date_smaller_equal_success(self):
        rule = MetaFieldCompareRule("start_date", "end_date", "<=", error="end date before start date", data_type="date")

        dataset = Dataset({"start_date": "20080416", "end_date": "20080416"}, [])

        self.assertIsNone(rule.eval(dataset, self._lib))
Example #15
0
    def test_float_larger_equal_success(self):
        rule = MetaFieldCompareRule("north_lat", "south_lat", ">=", error="@south_north_mismatch", data_type="number")

        dataset = Dataset({"north_lat": "34.56", "south_lat": "28.33"}, [])

        self.assertIsNone(rule.eval(dataset, self._lib))