Skip to content

Commit

Permalink
Give warnings on SSL errors
Browse files Browse the repository at this point in the history
  • Loading branch information
StijnKas committed Dec 23, 2024
1 parent 2157a90 commit b7faf43
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
9 changes: 8 additions & 1 deletion python/pdstools/pega_io/File.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,14 @@ def read_ds_export(

except ImportError:
warnings.warn(
"Unable to import `requests`, so not able to check for remote files. If you're trying to read in a file from the internet (or, for instance, using the built-in cdh_sample method), try installing the 'requests' package (`uv pip install requests`)"
"Unable to import `requests`, so not able to check for remote files. If you're trying to read in a file from the internet (or, for instance, using the built-in cdh_sample method), try installing the 'requests' package (`uv pip install requests`)",
ImportWarning,
)

except (urllib.error.URLError, requests.exceptions.SSLError):
warnings.warn(
"There was an error making a HTTP request call. This is likely due to your certificates not being installed correctly. Please follow these instructions: https://stackoverflow.com/a/70495761",
RuntimeWarning,
)

except Exception as e:
Expand Down
49 changes: 34 additions & 15 deletions python/pdstools/utils/datasets.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from typing import Optional

from ..adm.ADMDatamart import ADMDatamart
Expand All @@ -22,18 +23,30 @@ def cdh_sample(query: Optional[QUERY] = None) -> ADMDatamart:
path = "https://raw.githubusercontent.com/pegasystems/pega-datascientist-tools/master/data"
models = "Data-Decision-ADM-ModelSnapshot_pyModelSnapshots_20210526T131808_GMT.zip"
predictors = "Data-Decision-ADM-PredictorBinningSnapshot_pyADMPredictorSnapshots_20210526T133622_GMT.zip"
return ADMDatamart.from_ds_export(
model_filename=models,
predictor_filename=predictors,
base_path=path,
query=query,
)
with warnings.catch_warnings(record=True) as w:
try:
return ADMDatamart.from_ds_export(
model_filename=models,
predictor_filename=predictors,
base_path=path,
query=query,
)
except Exception as e:
raise RuntimeError(
f"Error importing CDH Sample. Warnings: {w}, exceptions: {e}"
)


def sample_trees():
return ADMTrees(
"https://raw.githubusercontent.com/pegasystems/pega-datascientist-tools/master/data/agb/_974a7f9c-66a6-4f00-bf3e-3acf5f188b1d.txt"
)
with warnings.catch_warnings(record=True) as w:
try:
return ADMTrees(
"https://raw.githubusercontent.com/pegasystems/pega-datascientist-tools/master/data/agb/_974a7f9c-66a6-4f00-bf3e-3acf5f188b1d.txt"
)
except Exception as e:
raise RuntimeError(
f"Error importing the Sample Trees dataset. Warnings: {w}, exceptions: {e}"
)


def sample_value_finder(threshold: Optional[float] = None) -> ValueFinder:
Expand All @@ -51,9 +64,15 @@ def sample_value_finder(threshold: Optional[float] = None) -> ValueFinder:
ValueFinder
The Value Finder class populated with the Value Finder simulation data
"""
return ValueFinder.from_ds_export(
base_path="https://raw.githubusercontent.com/pegasystems/pega-datascientist-tools/master/data",
filename="Data-Insights_pyValueFinder_20210824T112615_GMT.zip",
n_customers=10000,
threshold=threshold,
)
with warnings.catch_warnings(record=True) as w:
try:
return ValueFinder.from_ds_export(
base_path="https://raw.githubusercontent.com/pegasystems/pega-datascientist-tools/master/data",
filename="Data-Insights_pyValueFinder_20210824T112615_GMT.zip",
n_customers=10000,
threshold=threshold,
)
except Exception as e:
raise RuntimeError(
f"Error importing the Value Finder dataset. Warnings: {w}, exceptions: {e}"
)

0 comments on commit b7faf43

Please sign in to comment.