Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give warnings on SSL errors #307

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}"
)
Loading