Skip to content

Commit 256df8c

Browse files
committed
Change printed warnings to use warnings.warn() or include warning in raised error #143
1 parent 89a4369 commit 256df8c

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

src/sasctl/pzmm/write_json_files.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import math
1111
import pickle
1212
import pickletools
13+
import warnings
1314
from collections.abc import Iterable
1415

1516

@@ -196,7 +197,7 @@ def writeModelPropertiesJSON(
196197
# Check if model description provided is smaller than then 1024 character limit
197198
if len(modelDesc) > 1024:
198199
modelDesc = modelDesc[:1024]
199-
print(
200+
warnings.warn(
200201
"WARNING: The provided model description was truncated to 1024 characters."
201202
)
202203

@@ -533,15 +534,10 @@ def calculateFitStat(
533534
dataSets[i] = data.tolist()
534535

535536
if len(dataPartitionExists) == 0:
536-
try:
537-
raise ValueError
538-
except ValueError:
539-
print(
540-
"No data was provided. Please provide the actual "
541-
+ "and predicted values for at least one of the "
542-
+ "partitions (VALIDATE, TRAIN, or TEST)."
543-
)
544-
raise
537+
raise ValueError(
538+
"No data was provided. Please provide the actual and predicted values for at least one of the "
539+
"partitions (VALIDATE, TRAIN, or TEST). "
540+
)
545541

546542
for j in dataPartitionExists:
547543
fitStats = nullJSONDict["data"][j]["dataMap"]
@@ -705,12 +701,10 @@ def generateROCLiftStat(
705701
dataSets[i][columns] = data.transpose()
706702

707703
if len(dataPartitionExists) == 0:
708-
print(
709-
"No data was provided. Please provide the actual "
710-
+ "and predicted values for at least one of the "
711-
+ "partitions (VALIDATE, TRAIN, or TEST)."
704+
raise ValueError(
705+
"No data was provided. Please provide the actual and predicted values for at least one "
706+
"of the partitions (VALIDATE, TRAIN, or TEST)"
712707
)
713-
raise ValueError
714708

715709
nullLiftRow = list(range(1, 64))
716710
nullROCRow = list(range(1, 301))
@@ -1075,7 +1069,7 @@ def get_local_package_version(cls, package_list):
10751069
"""
10761070

10771071
def package_not_found_output(package_name, package_versions):
1078-
print(
1072+
warnings.warn(
10791073
f"Warning: Package {package_name} was not found in the local environment. Either {package_name} is not "
10801074
f"a valid Python package, or the package is not present in this environment. The requirements.json file"
10811075
f" will include a commented out version of the pip installation command at the bottom of the file. "

0 commit comments

Comments
 (0)