Example #1
0
    def test(self):
        """Test the Join expression with a standard dataframe.

        Test whether the generated query is correct.

        """
        l = [
            'https://www.dov.vlaanderen.be/data/boring/1986-068853',
            'https://www.dov.vlaanderen.be/data/boring/1986-068843',
            'https://www.dov.vlaanderen.be/data/boring/1980-068861'
        ]

        df = pd.DataFrame({
            'pkey_boring': pd.Series(l),
            'diepte_tot_m': pd.Series([10, 20, 30])
        })

        query = Join(df, 'pkey_boring')
        xml = query.toXML()

        assert xml.tag == '{http://www.opengis.net/ogc}Or'
        assert len(list(xml)) == 3

        for f in xml:
            assert f.tag == '{http://www.opengis.net/ogc}PropertyIsEqualTo'

            propertyname = f.find('./{http://www.opengis.net/ogc}PropertyName')
            assert propertyname.text == 'pkey_boring'

            literal = f.find('./{http://www.opengis.net/ogc}Literal')
            assert literal.text in l

            l.remove(literal.text)

        assert len(l) == 0
Example #2
0
    def test_single_duplicate(self):
        """Test the Join expression with a dataframe containing two
        identical keys.

        Test whether the generated query is correct and does contain only a
        single PropertyIsEqualTo.

        """
        l = ['https://www.dov.vlaanderen.be/data/boring/1986-068853',
             'https://www.dov.vlaanderen.be/data/boring/1986-068853']
        l_output = ['https://www.dov.vlaanderen.be/data/boring/1986-068853']

        df = pd.DataFrame({
            'pkey_boring': pd.Series(l),
            'diepte_tot_m': pd.Series([10, 20])
        })

        query = Join(df, 'pkey_boring')
        xml = query.toXML()

        assert xml.tag == '{http://www.opengis.net/ogc}PropertyIsEqualTo'

        propertyname = xml.find('./{http://www.opengis.net/ogc}PropertyName')
        assert propertyname.text == 'pkey_boring'

        literal = xml.find('./{http://www.opengis.net/ogc}Literal')
        assert literal.text in l_output

        l_output.remove(literal.text)
        assert len(l_output) == 0
Example #3
0
    def test_single(self):
        """Test the Join expression with a dataframe containing a single row.

        Test whether the generated query is correct and does contain only a
        single PropertyIsEqualTo.

        """
        l = [build_dov_url('data/boring/1986-068853')]

        df = pd.DataFrame({
            'pkey_boring': pd.Series(l),
            'diepte_tot_m': pd.Series([10])
        })

        query = Join(df, 'pkey_boring')
        xml = query.toXML()

        assert xml.tag == '{http://www.opengis.net/ogc}PropertyIsEqualTo'

        propertyname = xml.find('./{http://www.opengis.net/ogc}PropertyName')
        assert propertyname.text == 'pkey_boring'

        literal = xml.find('./{http://www.opengis.net/ogc}Literal')
        assert literal.text in l

        l.remove(literal.text)
        assert len(l) == 0
Example #4
0
    def test_duplicate(self):
        """Test the Join expression with a column containing
        duplicates.

        Test whether the generated query is correct and does not contain the
        duplicate entry twice.

        """
        l = [
            'https://www.dov.vlaanderen.be/data/boring/1986-068853',
            'https://www.dov.vlaanderen.be/data/boring/1986-068853',
            'https://www.dov.vlaanderen.be/data/boring/1980-068861'
        ]

        l_output = [
            'https://www.dov.vlaanderen.be/data/boring/1986-068853',
            'https://www.dov.vlaanderen.be/data/boring/1980-068861'
        ]

        df = pd.DataFrame({
            'pkey_boring': pd.Series(l),
            'diepte_tot_m': pd.Series([10, 20, 30])
        })

        query = Join(df, 'pkey_boring')
        xml = query.toXML()

        assert xml.tag == '{http://www.opengis.net/ogc}Or'
        assert len(list(xml)) == 2

        for f in xml:
            assert f.tag == '{http://www.opengis.net/ogc}PropertyIsEqualTo'

            propertyname = f.find('./{http://www.opengis.net/ogc}PropertyName')
            assert propertyname.text == 'pkey_boring'

            literal = f.find('./{http://www.opengis.net/ogc}Literal')
            assert literal.text in l

            l_output.remove(literal.text)

        assert len(l_output) == 0
Example #5
0
    def test_using(self):
        """Test the Join expression with a standard dataframe and 'on' and
        'using'.

        Test whether the generated query is correct.

        """
        l = [
            build_dov_url('data/boring/1986-068853'),
            build_dov_url('data/boring/1986-068843'),
            build_dov_url('data/boring/1980-068861')
        ]

        df = pd.DataFrame({
            'boringfiche': pd.Series(l),
            'diepte_tot_m': pd.Series([10, 20, 30])
        })

        query = Join(df, on='pkey_boring', using='boringfiche')
        xml = query.toXML()

        assert xml.tag == '{http://www.opengis.net/ogc}Or'
        assert len(list(xml)) == 3

        for f in xml:
            assert f.tag == '{http://www.opengis.net/ogc}PropertyIsEqualTo'

            propertyname = f.find('./{http://www.opengis.net/ogc}PropertyName')
            assert propertyname.text == 'pkey_boring'

            literal = f.find('./{http://www.opengis.net/ogc}Literal')
            assert literal.text in l

            l.remove(literal.text)

        assert len(l) == 0