Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove mandatory argument for Reader/Engine #79

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/how-to-add-new-reader.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ and it must implement the following methods:

The ``YourReader`` should extend :py:class:`~pyaro.timeseries.AutoFilterReaderEngine.AutoFilterReader`

- the ``__init__`` method of :py:class:`~pyaro.timeseries.Reader` with two fixed args (`self` and `filename_or_obj_or_url`) and several kwargs,
- the ``__init__`` method of :py:class:`~pyaro.timeseries.Reader` with one fixed arg (`self`) and several kwargs,
one of them should be `filters`
- it must store the `filters` calling `self._set_filters(filters)`
- the :py:meth:`~pyaro.timeseries.AutoFilterReaderEngine.AutoFilterReader._unfiltered_data` method
Expand Down Expand Up @@ -83,7 +83,7 @@ This is what a ``TimeseriesReader`` subclass should look like:
class MyTimeseriesReader(Reader):
def __init__(
self,
filename_or_obj_or_url,
filename,
*,
filters=[],
# other backend specific keyword arguments
Expand All @@ -102,11 +102,11 @@ This is what a ``TimeseriesReader`` subclass should look like:
...

class MyTimeseriesEngine(Engine)
def open(self, filename_or_obj_or_url, *args, **kwargs):
return MyTimeseriesReader(filename_or_obj_or_url, *args, **kwargs)
def open(self, *args, **kwargs):
return MyTimeseriesReader(*args, **kwargs)

def args(self):
open_parameters = ["filename_or_obj", "filters"]
open_parameters = ["filename", "filters"]
return open_parameters

def supported_filters(self):
Expand Down
4 changes: 2 additions & 2 deletions src/pyaro/csvreader/CSVTimeseriesReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def __init__(
):
"""open a new csv timeseries-reader

:param filename_or_obj_or_url: path-like object to csv-file. For multi-file support
:param filename: path-like object to csv-file. For multi-file support
path may also start with the `glob:`-keyword, e.g. `glob:/data/csvdir/**/*.csv` will
add all csv-files under `/data/csvdir/`, recursively.
All multi-files need to have the same csv-format.
If filename_or_obj_or_url is a directory, all *.csv file in this directory will be read,
If filename is a directory, all *.csv file in this directory will be read,
i.e. it is mapped to glob:/directory/*.csv
:param columns: mapping of column in the csv-file to key, see col_keys().
Column-numbering starts with 0.
Expand Down
6 changes: 3 additions & 3 deletions src/pyaro/timeseries/AutoFilterReaderEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def supported_filters(self) -> list[Filter]:
def args(self):
sig = inspect.signature(self.reader_class().__init__)
pars = tuple(sig.parameters.keys())
return pars[1:]
return pars[:]

def open(self, filename, *args, **kwargs) -> Reader:
return self.reader_class()(filename, *args, **kwargs)
def open(self, *args, **kwargs) -> Reader:
return self.reader_class()(*args, **kwargs)
7 changes: 3 additions & 4 deletions src/pyaro/timeseries/Engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Engine(abc.ABC):
"""The engine is the 'singleton' generator object for databases of the engines type."""

@abc.abstractmethod
def open(self, filename_or_obj_or_url, *, filters=None):
def open(self, *, filters=None):
"""open-function of the timeseries, initializing the reader-object, i.e.
equivalent to Reader(filename_or_object_or_url, *, filters)

Expand All @@ -17,10 +17,9 @@ def open(self, filename_or_obj_or_url, *, filters=None):
@property
@abc.abstractmethod
def args(self) -> list[str]:
"""return a tuple of parameters to be passed to open_timeseries, including
the mandatory filename_or_obj_or_url parameter.
"""return a tuple of parameters to be passed to open_timeseries
"""
return ["filename_or_obj_or_url"]
return []

@property
@abc.abstractmethod
Expand Down
3 changes: 1 addition & 2 deletions src/pyaro/timeseries/Reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ class Reader(abc.ABC):
"""Baseclass for timeseries. This can be used with a context manager"""

@abc.abstractmethod
def __init__(self, filename_or_obj_or_url, *, filters=None):
def __init__(self, *, filters=None):
"""Initialize the reader.

This function is usually called from the Engine's open function.
All parameters should also be listed in the Engine's args function.

:param filename_or_obj_or_url: location of database instance
:param filters: list of filters, or dict of (name, kwargs) for FilterFactory
"""
pass
Expand Down
Loading