From acc90f3765d5f112df3734192fd74d8c8572ea8f Mon Sep 17 00:00:00 2001 From: Alex Athorne Date: Mon, 1 Aug 2022 09:50:15 +0100 Subject: [PATCH 1/3] Add comment explaining usage of ERROR_TYPES --- alibi_detect/utils/missing_optional_dependency.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/alibi_detect/utils/missing_optional_dependency.py b/alibi_detect/utils/missing_optional_dependency.py index 4d6331286..f364d5887 100644 --- a/alibi_detect/utils/missing_optional_dependency.py +++ b/alibi_detect/utils/missing_optional_dependency.py @@ -18,6 +18,15 @@ )) +"""Map used to ensure correct pip install message is generated if a missing optional dependency is detected. This dict +is used to control two behaviours: + 1. When we import objects from missing dependencies we check that any `ModuleNotFoundError` or `ImportError` + corresponds to a missing optional dependency by checking the name of the missing dependency is in `ERROR_TYPES`. We + then map this name to the corresponding optional dependency bucket that will resolve the issue. + 2. Some optional dependencies have multiple names such as `torch` and `pytorch`, instead of enforcing a single + naming convention across the whole code base we instead use `ERROR_TYPES` to capture both cases. This is done right + before the pip install message is issued as this is the most robust place to capture these differences. +""" ERROR_TYPES = { "fbprophet": 'prophet', "holidays": 'prophet', From 979b9f4f670307654ce31160f2b4ba0acf17c427 Mon Sep 17 00:00:00 2001 From: Alex Athorne Date: Mon, 8 Aug 2022 13:13:28 +0100 Subject: [PATCH 2/3] Fix tensorflow probability import edge case issue --- alibi_detect/utils/frameworks.py | 1 + alibi_detect/utils/missing_optional_dependency.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/alibi_detect/utils/frameworks.py b/alibi_detect/utils/frameworks.py index 86c51277b..b1def72af 100644 --- a/alibi_detect/utils/frameworks.py +++ b/alibi_detect/utils/frameworks.py @@ -3,6 +3,7 @@ try: import tensorflow as tf # noqa + import tensorflow_probability as tfp # noqa has_tensorflow = True except ImportError: has_tensorflow = False diff --git a/alibi_detect/utils/missing_optional_dependency.py b/alibi_detect/utils/missing_optional_dependency.py index f364d5887..115405a33 100644 --- a/alibi_detect/utils/missing_optional_dependency.py +++ b/alibi_detect/utils/missing_optional_dependency.py @@ -20,10 +20,10 @@ """Map used to ensure correct pip install message is generated if a missing optional dependency is detected. This dict is used to control two behaviours: - 1. When we import objects from missing dependencies we check that any `ModuleNotFoundError` or `ImportError` + 1. When we import objects from missing dependencies we check that any `ModuleNotFoundError` or `ImportError` corresponds to a missing optional dependency by checking the name of the missing dependency is in `ERROR_TYPES`. We then map this name to the corresponding optional dependency bucket that will resolve the issue. - 2. Some optional dependencies have multiple names such as `torch` and `pytorch`, instead of enforcing a single + 2. Some optional dependencies have multiple names such as `torch` and `pytorch`, instead of enforcing a single naming convention across the whole code base we instead use `ERROR_TYPES` to capture both cases. This is done right before the pip install message is issued as this is the most robust place to capture these differences. """ From 6ef81f01244c7a9e06355c121be48c465dc7ae95 Mon Sep 17 00:00:00 2001 From: Alex Athorne Date: Wed, 10 Aug 2022 14:32:28 +0100 Subject: [PATCH 3/3] Minor change suggested in PR --- alibi_detect/utils/missing_optional_dependency.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alibi_detect/utils/missing_optional_dependency.py b/alibi_detect/utils/missing_optional_dependency.py index 115405a33..af52409cc 100644 --- a/alibi_detect/utils/missing_optional_dependency.py +++ b/alibi_detect/utils/missing_optional_dependency.py @@ -18,8 +18,8 @@ )) -"""Map used to ensure correct pip install message is generated if a missing optional dependency is detected. This dict -is used to control two behaviours: +"""Mapping used to ensure correct pip install message is generated if a missing optional dependency is detected. This +dict is used to control two behaviours: 1. When we import objects from missing dependencies we check that any `ModuleNotFoundError` or `ImportError` corresponds to a missing optional dependency by checking the name of the missing dependency is in `ERROR_TYPES`. We then map this name to the corresponding optional dependency bucket that will resolve the issue.