Skip to content

Commit

Permalink
Order the result of get_ncfiles by filename
Browse files Browse the repository at this point in the history
If nothing else, this guarantees the test will pass regardless of the
order in which the files are indexed, but I think it's good to have
some kind of canonical ordering anyway.
  • Loading branch information
angus-g committed Aug 19, 2019
1 parent b74cedb commit 0c53ee3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
3 changes: 2 additions & 1 deletion cosima_cookbook/querying.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def get_ncfiles(session, experiment):
q = (session
.query(NCFile.ncfile, NCFile.index_time)
.join(NCFile.experiment)
.filter(NCExperiment.experiment == experiment))
.filter(NCExperiment.experiment == experiment)
.order_by(NCFile.ncfile))

return pd.DataFrame(q)

Expand Down
22 changes: 15 additions & 7 deletions test/test_querying.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def session(tmpdir_factory):
def test_valid_query(session):
with cc.querying.getvar('querying', 'temp', session, decode_times=False) as v:
assert(isinstance(v, xr.DataArray))

def test_invalid_query(session):
with pytest.raises(cc.querying.VariableNotFoundError):
cc.querying.getvar('querying', 'notfound', session, decode_times=False)
Expand Down Expand Up @@ -71,12 +71,20 @@ def test_get_experiments(session):
def test_get_ncfiles(session):
r = cc.querying.get_ncfiles(session, 'querying')

df = pd.DataFrame.from_dict({'ncfile': {0: 'output000/ocean.nc',
1: 'output000/hi_m.nc',
2: 'output000/ty_trans.nc'},
'index_time': {0: pd.Timestamp('2019-08-09 21:51:12.090930'),
1: pd.Timestamp('2019-08-09 21:51:12.143794'),
2: pd.Timestamp('2019-08-09 21:51:12.148942')}})
df = pd.DataFrame.from_dict(
{
"ncfile": {
0: "output000/hi_m.nc",
1: "output000/ocean.nc",
2: "output000/ty_trans.nc",
},
"index_time": {
0: pd.Timestamp("2019-08-09 21:51:12.090930"),
1: pd.Timestamp("2019-08-09 21:51:12.143794"),
2: pd.Timestamp("2019-08-09 21:51:12.148942"),
},
}
)

# The Timestamps will not be the same so check only that the ncfiles are correct
assert_series_equal(r['ncfile'], df['ncfile'])
Expand Down

0 comments on commit 0c53ee3

Please sign in to comment.