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

BUG: Move handling of context arguments after handling of .depends keyword #465

Merged
merged 11 commits into from
Sep 8, 2021
6 changes: 2 additions & 4 deletions skypy/pipeline/_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ def __init__(self, configuration):
self.dag.add_node(job, skip=False)
if isinstance(settings, Item):
items[job] = settings
# infer additional item properties from context
settings.infer(context)
for table, columns in self.table_config.items():
table_complete = '.'.join((table, 'complete'))
self.dag.add_node(table_complete)
Expand All @@ -115,8 +113,6 @@ def __init__(self, configuration):
self.dag.add_edge(job, table_complete)
if isinstance(settings, Item):
items[job] = settings
# infer additional item properties from context
settings.infer(context)
# DAG nodes for individual columns in multi-column assignment
names = [n.strip() for n in column.split(',')]
if len(names) > 1:
Expand All @@ -138,6 +134,8 @@ def __init__(self, configuration):
while c:
self.dag.add_edge(c, d)
c, d = c.rpartition('.')[0], c
# infer additional item properties from context
settings.infer(context)

def execute(self, parameters={}):
r'''Run a pipeline.
Expand Down
24 changes: 23 additions & 1 deletion skypy/pipeline/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from astropy.cosmology.core import Cosmology
from astropy.io import fits
from astropy.io.misc.hdf5 import read_table_hdf5
from astropy.table import Table
from astropy.table import Table, vstack
from astropy.table.column import Column
from astropy.units import Quantity
from astropy.utils.data import get_pkg_data_filename
Expand Down Expand Up @@ -269,6 +269,28 @@ def test_hdf5():
assert np.all(hdf_table == pipeline['test_table'])


def test_depends():

# Regression test for pull request #464
rrjbca marked this conversation as resolved.
Show resolved Hide resolved
# Previously the .depends keyword was also being passed to functions as a
# keyword argument. This was because Pipeline was executing Item.infer to
# handle additional function arguments from context before handling
# additional dependencies specified using the .depends keyword. The
# .depends keyword is now handled first.

config = {'tables': {
'table_1': {
'column1': Call(np.random.uniform, [0, 1, 10])},
'table_2': {
'.init': Call(vstack, [], {
'tables': [Ref('table_1')],
'.depends': ['table_1.complete']})}}}

pipeline = Pipeline(config)
pipeline.execute()
assert np.all(pipeline['table_1'] == pipeline['table_2'])


def teardown_module(module):

# Remove fits file generated in test_pipeline
Expand Down