Skip to content

Commit

Permalink
BUG: Move handling of context arguments after handling of .depends ke…
Browse files Browse the repository at this point in the history
…yword (skypyproject#465)
  • Loading branch information
rrjbca committed Sep 18, 2021
1 parent aa95dec commit 1f9d0fc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
6 changes: 2 additions & 4 deletions skypy/pipeline/_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,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 @@ -114,8 +112,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 @@ -137,6 +133,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
@@ -1,7 +1,7 @@
from astropy.cosmology import FlatLambdaCDM, default_cosmology
from astropy.cosmology.core import Cosmology
from astropy.io import fits
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 @@ -237,6 +237,28 @@ def value_in_cm(q):
np.testing.assert_array_less(pipeline['test_table.lengths_in_cm'], 100)


def test_depends():

# Regression test for GitHub Issue #464
# 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

0 comments on commit 1f9d0fc

Please sign in to comment.