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
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
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
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
def test_empty(self): """Test the Join expression with an empty dataframe. Test whether a ValueError is raised """ df = pd.DataFrame({ 'pkey_boring': [np.nan, np.nan], 'diepte_tot_m': pd.Series([10, 20]) }) with pytest.raises(ValueError): Join(df, 'pkey_boring')
def test_tooshort(self): """Test the Join expression with a dataframe containing a single row. Test whether a ValueError is raised. """ with pytest.raises(ValueError): l = ['https://www.dov.vlaanderen.be/data/boring/1986-068853'] df = pd.DataFrame({ 'pkey_boring': pd.Series(l), 'diepte_tot_m': pd.Series([10]) }) Join(df, 'pkey_boring')
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
def test_wrongcolumn(self): """Test the Join expression with a join_column not available in the dataframe. Test whether a ValueError is raised. """ with pytest.raises(ValueError): 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]) }) Join(df, 'pkey_sondering')
def test_search_join(self, mp_remote_describefeaturetype, mp_remote_wfs_feature, mp_dov_xml): """Test the search method with a Join query. Parameters ---------- mp_remote_describefeaturetype : pytest.fixture Monkeypatch the call to a remote DescribeFeatureType. mp_remote_wfs_feature : pytest.fixture Monkeypatch the call to get WFS features. mp_dov_xml : pytest.fixture Monkeypatch the call to get the remote XML data. """ df1 = self.get_search_object().search( query=self.get_valid_query_single()) df2 = self.get_search_object().search( query=Join(df1, self.get_df_default_columns()[0]))
def test_search_join(self, mp_get_schema, mp_remote_describefeaturetype, mp_remote_wfs_feature, mp_dov_xml): """Test the search method with a Join query. Parameters ---------- mp_get_schema : pytest.fixture Monkeypatch the call to a remote OWSLib schema. mp_remote_describefeaturetype : pytest.fixture Monkeypatch the call to a remote DescribeFeatureType. mp_remote_wfs_feature : pytest.fixture Monkeypatch the call to get WFS features. mp_dov_xml : pytest.fixture Monkeypatch the call to get the remote XML data. """ df1 = self.search_instance.search(query=self.valid_query_single) self.search_instance.search( query=Join(df1, self.df_default_columns[0]))