diff --git a/src/sasctl/core.py b/src/sasctl/core.py index c8fc3f7a..50cf4cd3 100644 --- a/src/sasctl/core.py +++ b/src/sasctl/core.py @@ -571,11 +571,11 @@ def username(self): def hostname(self): return self._settings.get("domain") - def send(self, request, **kwargs): + def send(self, req, **kwargs): if self.message_log.isEnabledFor(logging.DEBUG): - r = copy.deepcopy(request) - for filter in self.filters: - r = filter(r) + r = copy.deepcopy(req) + for filter_ in self.filters: + r = filter_(r) self.message_log.debug( "HTTP/1.1 {verb} {url}\n{headers}\nBody:\n{body}".format( @@ -588,14 +588,14 @@ def send(self, request, **kwargs): ) ) else: - self.message_log.info("HTTP/1.1 %s %s", request.method, request.url) + self.message_log.info("HTTP/1.1 %s %s", req.method, req.url) - response = super(Session, self).send(request, **kwargs) + response = super(Session, self).send(req, **kwargs) if self.message_log.isEnabledFor(logging.DEBUG): r = copy.deepcopy(response) - for filter in self.filters: - r = filter(r) + for filter_ in self.filters: + r = filter_(r) self.message_log.debug( "HTTP {status} {url}\n{headers}\nBody:\n{body}".format( diff --git a/src/sasctl/pzmm/write_json_files.py b/src/sasctl/pzmm/write_json_files.py index 1efc45e5..6e751781 100644 --- a/src/sasctl/pzmm/write_json_files.py +++ b/src/sasctl/pzmm/write_json_files.py @@ -6,7 +6,6 @@ import importlib import json -# import math #not used import pickle import pickletools import sys @@ -1449,13 +1448,6 @@ def stat_dataset_to_dataframe( Raised if an improper data format is provided. """ - # If numpy inputs are supplied, then assume numpy is installed - try: - # noinspection PyPackageRequirements - import numpy as np - except ImportError: - np = None - # Convert target_value to numeric for creating binary probabilities if isinstance(target_value, str): target_value = float(target_value) diff --git a/src/sasctl/utils/model_info.py b/src/sasctl/utils/model_info.py index e307d26a..857497cc 100644 --- a/src/sasctl/utils/model_info.py +++ b/src/sasctl/utils/model_info.py @@ -63,7 +63,7 @@ def get_model_info(model, X, y=None): # Most PyTorch models are actually subclasses of torch.nn.Module, so checking module # name alone is not sufficient. - elif torch and isinstance(model, torch.nn.Module): + if torch and isinstance(model, torch.nn.Module): return PyTorchModelInfo(model, X, y) raise ValueError(f"Unrecognized model type {type(model)} received.") @@ -200,7 +200,8 @@ class OnnxModelInfo(ModelInfo): def __init__(self, model, X, y=None): if onnx is None: raise RuntimeError( - "The onnx package must be installed to work with ONNX models. Please `pip install onnx`." + "The onnx package must be installed to work with ONNX models. " + "Please `pip install onnx`." ) self._model = model @@ -214,38 +215,19 @@ def __init__(self, model, X, y=None): if len(inputs) > 1: warnings.warn( - f"The ONNX model has {len(inputs)} inputs but only the first input will be captured in Model Manager." + f"The ONNX model has {len(inputs)} inputs but only the first input " + f"will be captured in Model Manager." ) if len(outputs) > 1: warnings.warn( - f"The ONNX model has {len(outputs)} outputs but only the first input will be captured in Model Manager." + f"The ONNX model has {len(outputs)} outputs but only the first output " + f"will be captured in Model Manager." ) self._X_df = inputs[0] self._y_df = outputs[0] - # initializer (static params) - - # for field in model.ListFields(): - # doc_string - # domain - # metadata_props - # model_author - # model_license - # model_version - # producer_name - # producer_version - # training_info - - # irVersion - # producerName - # producerVersion - # opsetImport - - # # list of (FieldDescriptor, value) - # fields = model.ListFields() - @staticmethod def _tensor_to_dataframe(tensor): """ @@ -272,7 +254,7 @@ def _tensor_to_dataframe(tensor): name = tensor.get("name", "Var") type_ = tensor["type"] - if not "tensorType" in type_: + if "tensorType" not in type_: raise ValueError(f"Received an unexpected ONNX input type: {type_}.") dtype = onnx.helper.tensor_dtype_to_np_dtype(type_["tensorType"]["elemType"]) @@ -374,8 +356,6 @@ def __init__(self, model, X, y=None): raise ValueError( f"Expected input data to be a numpy array or PyTorch tensor, received {type(X)}." ) - # if X.ndim != 2: - # raise ValueError(f"Expected input date with shape (n_samples, n_dim), received shape {X.shape}.") # Ensure each input is a PyTorch Tensor X = tuple(x if isinstance(x, torch.Tensor) else torch.tensor(x) for x in X) @@ -395,8 +375,6 @@ def __init__(self, model, X, y=None): ) self._model = model - - # TODO: convert X and y to DF with arbitrary names self._X = X self._y = y