Skip to content

Commit

Permalink
Add a default interpolator argument to FileSource (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
shpiyu authored Sep 12, 2024
1 parent 65e4b16 commit ccab983
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions ingen/data_source/file_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from ingen.data_source.source import DataSource
from ingen.reader.file_reader import ReaderFactory
from ingen.utils.interpolators.Interpolator import Interpolator
from ingen.utils.path_parser import PathParser
from ingen.utils.timer import log_time

Expand All @@ -17,7 +18,7 @@ class FileSource(DataSource):
This class represents a File source
"""

def __init__(self, source, params_map):
def __init__(self, source, params_map, interpolator=Interpolator()):
"""
Loads a file
Expand All @@ -26,6 +27,7 @@ def __init__(self, source, params_map):
"""
super().__init__(source.get('id'))
self.interpolator = interpolator
if params_map.get('infile') and source['use_infile']:
source['file_path'] = params_map['infile']
self._src = source
Expand Down Expand Up @@ -61,7 +63,7 @@ def format_file_path(self, source, params_map):
else:
run_date = params_map.get('run_date', date.today())

path_parser = PathParser(run_date)
path_parser = PathParser(run_date, interpolator=self.interpolator)
if 'file_path' in source:
source['file_path'] = path_parser.parse(source['file_path'])
return source
2 changes: 1 addition & 1 deletion test/data_source/test_file_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def setUp(self):
self.params_map = {'query_params': {'table_name': 'positions'}, 'infile': {}}
self.source = FileSource(self._src, self.params_map)

@patch('src.data_source.file_source.ReaderFactory')
@patch('ingen.data_source.file_source.ReaderFactory')
def test_source_fetch(self, mock_reader_factory):
fileReader = Mock()
fileReader.read.return_value = pd.DataFrame()
Expand Down

0 comments on commit ccab983

Please sign in to comment.