Skip to content

Commit 3d12e83

Browse files
committed
warn() goes to stderr instead of stdout, so print all messages
1 parent 2496857 commit 3d12e83

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/acquisition/fluview/impute_missing_values.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@
5959
from delphi.utils.geo.locations import Locations
6060

6161

62-
UNDERDETERMINED_MSG = "system is underdetermined"
63-
6462
class Database:
6563
"""Database wrapper and abstraction layer."""
6664

@@ -243,7 +241,7 @@ def get_fusion_parameters(known_locations):
243241
H = graph[is_known, :]
244242
W = graph[is_unknown, :]
245243
if np.linalg.matrix_rank(H) != len(atoms):
246-
raise StatespaceException(UNDERDETERMINED_MSG)
244+
raise StatespaceException("system is underdetermined")
247245

248246
HtH = np.dot(H.T, H)
249247
HtH_inv = np.linalg.inv(HtH)
@@ -299,11 +297,7 @@ def impute_missing_values(database, test_mode=False):
299297
try:
300298
F, known, unknown = get_fusion_parameters(known_values.keys())
301299
except StatespaceException as e:
302-
message = str(e)
303-
if message == UNDERDETERMINED_MSG:
304-
warn(message)
305-
else:
306-
print(message)
300+
print(e)
307301
continue
308302

309303
# finally, impute the missing values

tests/acquisition/fluview/test_impute_missing_values.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
# standard library
44
import argparse
5+
import sys
56
import unittest
67
from unittest.mock import MagicMock
8+
from io import StringIO
79

810
# first party
911
from delphi.utils.geo.locations import Locations
@@ -86,8 +88,12 @@ def test_impute_missing_values_vipr(self):
8688
db.get_known_values.return_value = known_data
8789

8890
db.find_missing_rows.return_value = [(201340, 201340)]
89-
with self.assertWarns(Warning):
90-
impute_missing_values(db, test_mode=True)
91+
92+
capturedOutput = StringIO()
93+
sys.stdout = capturedOutput
94+
impute_missing_values(db, test_mode=True)
95+
sys.stdout = sys.__stdout__
96+
self.assertTrue("system is underdetermined" in capturedOutput.getvalue().split("\n"))
9197

9298
db.find_missing_rows.return_value = [(201339, 201339)]
9399
impute_missing_values(db, test_mode=True)
@@ -130,5 +136,8 @@ def test_impute_missing_values_underdetermined(self):
130136
db.find_missing_rows.return_value = [(201740, 201740)]
131137
db.get_known_values.return_value = known_data
132138

133-
with self.assertWarns(Warning):
134-
impute_missing_values(db, test_mode=True)
139+
capturedOutput = StringIO()
140+
sys.stdout = capturedOutput
141+
impute_missing_values(db, test_mode=True)
142+
sys.stdout = sys.__stdout__
143+
self.assertTrue("system is underdetermined" in capturedOutput.getvalue().split("\n"))

0 commit comments

Comments
 (0)