Skip to content

Commit

Permalink
Merge pull request #273 from Roel/remove-duplicate-docstrings
Browse files Browse the repository at this point in the history
Remove duplicate docstrings and refactor abstract test classes to use class variables
  • Loading branch information
Roel authored May 29, 2020
2 parents b0b0718 + 71299ce commit 142ed67
Show file tree
Hide file tree
Showing 43 changed files with 1,003 additions and 4,816 deletions.
34 changes: 15 additions & 19 deletions pydov/search/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,17 @@
from distutils.util import strtobool

import owslib
import pydov
from owslib.etree import etree
from owslib.feature import get_schema
from owslib.fes import (
FilterRequest,
)
from owslib.fes import FilterRequest
from owslib.wfs import WebFeatureService

import pydov
from pydov.util import owsutil
from pydov.util.dovutil import (
get_xsd_schema,
build_dov_url,
)
from pydov.util.errors import (
LayerNotFoundError,
InvalidSearchParameterError,
FeatureOverflowError,
InvalidFieldError,
WfsGetFeatureError,
)
from pydov.util.dovutil import build_dov_url, get_xsd_schema
from pydov.util.errors import (FeatureOverflowError, InvalidFieldError,
InvalidSearchParameterError, LayerNotFoundError,
WfsGetFeatureError)
from pydov.util.hooks import HookRunner


Expand Down Expand Up @@ -63,15 +55,15 @@ def typeconvert(x):
# Patch for Zulu-time issue of geoserver for WFS 1.1.0
if x.endswith('Z'):
return datetime.datetime.strptime(x, '%Y-%m-%dZ').date() \
+ datetime.timedelta(days=1)
+ datetime.timedelta(days=1)
else:
return datetime.datetime.strptime(x, '%Y-%m-%d').date()
elif returntype == 'datetime':
def typeconvert(x):
if x.endswith('Z'):
return datetime.datetime.strptime(
x, '%Y-%m-%dT%H:%M:%SZ').date() \
+ datetime.timedelta(days=1)
x, '%Y-%m-%dT%H:%M:%SZ').date() \
+ datetime.timedelta(days=1)
else:
return datetime.datetime.strptime(
x.split('.')[0], '%Y-%m-%dT%H:%M:%S')
Expand Down Expand Up @@ -800,5 +792,9 @@ def search(self, location=None, query=None,
When the argument supplied as return_fields is not a list,
tuple or set.
NotImplementedError
This is an abstract method that should be implemented in a
subclass.
"""
raise NotImplementedError
raise NotImplementedError('This should be implemented in a subclass.')
60 changes: 2 additions & 58 deletions pydov/search/boring.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import pandas as pd

from pydov.types.fields import _WfsInjectedField
from .abstract import AbstractSearch

from ..types.boring import Boring
from ..util import owsutil
from .abstract import AbstractSearch


class BoringSearch(AbstractSearch):
Expand All @@ -31,13 +32,10 @@ def __init__(self, objecttype=Boring):
super(BoringSearch, self).__init__('dov-pub:Boringen', objecttype)

def _init_namespace(self):
"""Initialise the WFS namespace associated with the layer."""
if BoringSearch.__wfs_namespace is None:
BoringSearch.__wfs_namespace = self._get_namespace()

def _init_fields(self):
"""Initialise the fields and their metadata available in this search
class."""
if self._fields is None:
if BoringSearch.__wfs_schema is None:
BoringSearch.__wfs_schema = self._get_schema()
Expand Down Expand Up @@ -76,60 +74,6 @@ def _init_fields(self):

def search(self, location=None, query=None,
sort_by=None, return_fields=None, max_features=None):
"""Search for boreholes (Boring). Provide `location` and/or `query`
and/or `max_features`.
When `return_fields` is None, all fields are returned.
Parameters
----------
location : pydov.util.location.AbstractLocationFilter or \
owslib.fes.BinaryLogicOpType<AbstractLocationFilter> or \
owslib.fes.UnaryLogicOpType<AbstractLocationFilter>
Location filter limiting the features to retrieve. Can either be a
single instance of a subclass of AbstractLocationFilter, or a
combination using And, Or, Not of AbstractLocationFilters.
query : owslib.fes.OgcExpression
OGC filter expression to use for searching. This can contain any
combination of filter elements defined in owslib.fes. The query
should use the fields provided in `get_fields()`. Note that not
all fields are currently supported as a search parameter.
sort_by : owslib.fes.SortBy, optional
List of properties to sort by.
return_fields : list<str> or tuple<str> or set<str>
A list of fields to be returned in the output data. This should
be a subset of the fields provided in `get_fields()`. Note that
not all fields are currently supported as return fields.
max_features : int
Limit the maximum number of features to request.
Returns
-------
pandas.core.frame.DataFrame
DataFrame containing the output of the search query.
Raises
------
pydov.util.errors.InvalidSearchParameterError
When not one of `location`, `query` or `max_features` is provided.
pydov.util.errors.InvalidFieldError
When at least one of the fields in `return_fields` is unknown.
When a field that is only accessible as return field is used as
a query parameter.
When a field that can only be used as a query parameter is used as
a return field.
pydov.util.errors.FeatureOverflowError
When the number of features to be returned is equal to the
maxFeatures limit of the WFS server.
AttributeError
When the argument supplied as return_fields is not a list,
tuple or set.
"""
fts = self._search(location=location, query=query, sort_by=sort_by,
return_fields=return_fields,
max_features=max_features)
Expand Down
57 changes: 0 additions & 57 deletions pydov/search/grondmonster.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@ def __init__(self, objecttype=Grondmonster):
__init__('boringen:grondmonsters', objecttype)

def _init_namespace(self):
"""Initialise the WFS namespace associated with the layer."""
if GrondmonsterSearch.__wfs_namespace is None:
GrondmonsterSearch.__wfs_namespace = self._get_namespace()

def _init_fields(self):
"""Initialise the fields and their metadata available in this search
class."""
if self._fields is None:
if GrondmonsterSearch.__wfs_schema is None:
GrondmonsterSearch.__wfs_schema = self._get_schema()
Expand Down Expand Up @@ -79,60 +76,6 @@ def _init_fields(self):

def search(self, location=None, query=None, sort_by=None,
return_fields=None, max_features=None):
"""Search for ground samples (Grondmonster). Provide either
`location` or `query`. When `return_fields` is None,
all fields are returned.
Parameters
----------
location : pydov.util.location.AbstractLocationFilter or \
owslib.fes.BinaryLogicOpType<AbstractLocationFilter> or \
owslib.fes.UnaryLogicOpType<AbstractLocationFilter>
Location filter limiting the features to retrieve. Can either be a
single instance of a subclass of AbstractLocationFilter, or a
combination using And, Or, Not of AbstractLocationFilters.
query : owslib.fes.OgcExpression
OGC filter expression to use for searching. This can contain any
combination of filter elements defined in owslib.fes. The query
should use the fields provided in `get_fields()`. Note that not
all fields are currently supported as a search parameter.
sort_by : owslib.fes.SortBy, optional
List of properties to sort by.
return_fields : list<str> or tuple<str> or set<str>
A list of fields to be returned in the output data. This should
be a subset of the fields provided in `get_fields()`. Note that
not all fields are currently supported as return fields.
max_features : int
Limit the maximum number of features to request.
Returns
-------
pandas.core.frame.DataFrame
DataFrame containing the output of the search query.
Raises
------
pydov.util.errors.InvalidSearchParameterError
When not one of `location`, `query` or `max_features` is provided.
pydov.util.errors.InvalidFieldError
When at least one of the fields in `return_fields` is unknown.
When a field that is only accessible as return field is used as
a query parameter.
When a field that can only be used as a query parameter is used as
a return field.
pydov.util.errors.FeatureOverflowError
When the number of features to be returned is equal to the
maxFeatures limit of the WFS server.
AttributeError
When the argument supplied as return_fields is not a list,
tuple or set.
"""
self._pre_search_validation(location, query, sort_by, return_fields,
max_features)

Expand Down
27 changes: 13 additions & 14 deletions pydov/search/grondwaterfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
"""Module containing the search classes to retrieve DOV groundwater screen
data."""
import pandas as pd
from owslib.fes import And, Not, PropertyIsNull

from owslib.fes import (
Not,
PropertyIsNull,
And,
)
from pydov.types.fields import _WfsInjectedField
from .abstract import AbstractSearch

from ..types.grondwaterfilter import GrondwaterFilter
from ..util import owsutil
from .abstract import AbstractSearch


class GrondwaterFilterSearch(AbstractSearch):
Expand Down Expand Up @@ -40,13 +37,10 @@ def __init__(self, objecttype=GrondwaterFilter):
self).__init__('gw_meetnetten:meetnetten', objecttype)

def _init_namespace(self):
"""Initialise the WFS namespace associated with the layer."""
if GrondwaterFilterSearch.__wfs_namespace is None:
GrondwaterFilterSearch.__wfs_namespace = self._get_namespace()

def _init_fields(self):
"""Initialise the fields and their metadata available in this search
class."""
if self._fields is None:
if GrondwaterFilterSearch.__wfs_schema is None:
GrondwaterFilterSearch.__wfs_schema = self._get_schema()
Expand Down Expand Up @@ -86,8 +80,8 @@ def _init_fields(self):

def search(self, location=None, query=None, sort_by=None,
return_fields=None, max_features=None):
"""Search for groundwater screens (GrondwaterFilter). Provide
`location` and/or `query` and/or `max_features`.
"""Search for objects of this type. Provide `location` and/or
`query` and/or `max_features`.
When `return_fields` is None, all fields are returned.
Excludes 'empty' filters (i.e. Putten without Filters) by extending
Expand All @@ -96,8 +90,8 @@ def search(self, location=None, query=None, sort_by=None,
Parameters
----------
location : pydov.util.location.AbstractLocationFilter or \
owslib.fes.BinaryLogicOpType<AbstractLocationFilter> or \
owslib.fes.UnaryLogicOpType<AbstractLocationFilter>
owslib.fes.BinaryLogicOpType<AbstractLocationFilter> or \
owslib.fes.UnaryLogicOpType<AbstractLocationFilter>
Location filter limiting the features to retrieve. Can either be a
single instance of a subclass of AbstractLocationFilter, or a
combination using And, Or, Not of AbstractLocationFilters.
Expand All @@ -123,7 +117,8 @@ def search(self, location=None, query=None, sort_by=None,
Raises
------
pydov.util.errors.InvalidSearchParameterError
When not one of `location`, `query` or `max_features` is provided.
When not one of `location` or `query` or `max_features` is
provided.
pydov.util.errors.InvalidFieldError
When at least one of the fields in `return_fields` is unknown.
Expand All @@ -142,6 +137,10 @@ def search(self, location=None, query=None, sort_by=None,
When the argument supplied as return_fields is not a list,
tuple or set.
NotImplementedError
This is an abstract method that should be implemented in a
subclass.
"""
self._pre_search_validation(location, query, sort_by, return_fields,
max_features)
Expand Down
63 changes: 2 additions & 61 deletions pydov/search/grondwatermonster.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import pandas as pd

from pydov.types.fields import _WfsInjectedField
from .abstract import AbstractSearch

from ..types.grondwatermonster import GrondwaterMonster
from ..util import owsutil
from .abstract import AbstractSearch


class GrondwaterMonsterSearch(AbstractSearch):
Expand Down Expand Up @@ -34,13 +35,10 @@ def __init__(self, objecttype=GrondwaterMonster):
self).__init__('gw_meetnetten:grondwatermonsters', objecttype)

def _init_namespace(self):
"""Initialise the WFS namespace associated with the layer."""
if GrondwaterMonsterSearch.__wfs_namespace is None:
GrondwaterMonsterSearch.__wfs_namespace = self._get_namespace()

def _init_fields(self):
"""Initialise the fields and their metadata available in this search
class."""
if self._fields is None:
if GrondwaterMonsterSearch.__wfs_schema is None:
GrondwaterMonsterSearch.__wfs_schema = self._get_schema()
Expand Down Expand Up @@ -80,63 +78,6 @@ def _init_fields(self):

def search(self, location=None, query=None, sort_by=None,
return_fields=None, max_features=None):
"""Search for groundwater samples (GrondwaterMonsterSearch). Provide
`location` and/or `query`. When `return_fields` is None,
all fields are returned.
Excludes 'empty' filters (i.e. Putten without Filters) by extending
the `query` with a not-null check on pkey_filter.
Parameters
----------
location : pydov.util.location.AbstractLocationFilter or \
owslib.fes.BinaryLogicOpType<AbstractLocationFilter> or \
owslib.fes.UnaryLogicOpType<AbstractLocationFilter>
Location filter limiting the features to retrieve. Can either be a
single instance of a subclass of AbstractLocationFilter, or a
combination using And, Or, Not of AbstractLocationFilters.
query : owslib.fes.OgcExpression
OGC filter expression to use for searching. This can contain any
combination of filter elements defined in owslib.fes. The query
should use the fields provided in `get_fields()`. Note that not
all fields are currently supported as a search parameter.
sort_by : owslib.fes.SortBy, optional
List of properties to sort by.
return_fields : list<str> or tuple<str> or set<str>
A list of fields to be returned in the output data. This should
be a subset of the fields provided in `get_fields()`. Note that
not all fields are currently supported as return fields.
max_features : int
Limit the maximum number of features to request.
Returns
-------
pandas.core.frame.DataFrame
DataFrame containing the output of the search query.
Raises
------
pydov.util.errors.InvalidSearchParameterError
When not one of `location` or `query` is provided.
pydov.util.errors.InvalidFieldError
When at least one of the fields in `return_fields` is unknown.
When a field that is only accessible as return field is used as
a query parameter.
When a field that can only be used as a query parameter is used as
a return field.
pydov.util.errors.FeatureOverflowError
When the number of features to be returned is equal to the
maxFeatures limit of the WFS server.
AttributeError
When the argument supplied as return_fields is not a list,
tuple or set.
"""
fts = self._search(location=location, query=query, sort_by=sort_by,
return_fields=return_fields,
max_features=max_features)
Expand Down
Loading

0 comments on commit 142ed67

Please sign in to comment.