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

don't fail on langdetect #2444

Merged
merged 2 commits into from Apr 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion deepchecks/nlp/utils/text_properties.py
Expand Up @@ -153,7 +153,14 @@ def language(raw_text: Sequence[str]) -> List[str]:
"""Return list of strings of language."""
langdetect = _import_optional_property_dependency(module='langdetect', property_name='language')
langdetect.DetectorFactory.seed = 42
return [langdetect.detect(text) for text in raw_text]

result = []
for text in raw_text:
try:
result.append(langdetect.detect(text))
except langdetect.lang_detect_exception.LangDetectException:
result.append(np.nan)
return result


def sentiment(raw_text: Sequence[str]) -> List[str]:
Expand Down