Skip to content

Commit a153cb6

Browse files
committed
Add a more helpful error if nltk is not installed
1 parent 245df2f commit a153cb6

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

redisvl/query/aggregate.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,13 @@ def _set_stopwords(self, stopwords: Optional[Union[str, Set[str]]] = "english"):
163163
self._stopwords = set()
164164
elif isinstance(stopwords, str):
165165
# Lazy import because nltk is an optional dependency
166-
import nltk
167-
from nltk.corpus import stopwords as nltk_stopwords
168-
166+
try:
167+
import nltk
168+
from nltk.corpus import stopwords as nltk_stopwords
169+
except ImportError:
170+
raise ValueError(
171+
f"Loading stopwords for {stopwords} failed: nltk is not installed."
172+
)
169173
try:
170174
nltk.download("stopwords", quiet=True)
171175
self._stopwords = set(nltk_stopwords.words(stopwords))

redisvl/query/query.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -811,9 +811,13 @@ def _set_stopwords(self, stopwords: Optional[Union[str, Set[str]]] = "english"):
811811
self._stopwords = set()
812812
elif isinstance(stopwords, str):
813813
# Lazy import because nltk is an optional dependency
814-
import nltk
815-
from nltk.corpus import stopwords as nltk_stopwords
816-
814+
try:
815+
import nltk
816+
from nltk.corpus import stopwords as nltk_stopwords
817+
except ImportError:
818+
raise ValueError(
819+
f"Loading stopwords for {stopwords} failed: nltk is not installed."
820+
)
817821
try:
818822
nltk.download("stopwords", quiet=True)
819823
self._stopwords = set(nltk_stopwords.words(stopwords))

0 commit comments

Comments
 (0)