Skip to content

Commit

Permalink
NaN checks: use math.isnan() to verify/test for NaN values
Browse files Browse the repository at this point in the history
  • Loading branch information
neomatrix369 committed Oct 3, 2020
1 parent 112cf70 commit 2e311f7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions nlp_profiler/grammar_quality_check.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import language_tool_python

language_tool = language_tool_python.LanguageTool('en-GB')
import pandas as pd
import math

from nlp_profiler.constants import NOT_APPLICABLE, NaN, DEFAULT_PARALLEL_METHOD, \
GRAMMAR_CHECK_SCORE_COL, GRAMMAR_CHECK_COL
Expand Down Expand Up @@ -31,13 +33,13 @@ def grammar_check_score(text: str) -> int:
return len(matches)


def grammar_quality(score: float) -> str:
if score is NaN:
def grammar_quality(score: int) -> str:
if math.isnan(score):
return NOT_APPLICABLE

if score == 1:
return "1 issue"
elif score > 1:
return f"{score} issues"
return f"{int(score)} issues"

return "No issues"
3 changes: 2 additions & 1 deletion nlp_profiler/sentiment_subjectivity.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from textblob import TextBlob

from nlp_profiler.constants import NOT_APPLICABLE, NaN
import math


### Sentiment Subjectivity
Expand Down Expand Up @@ -31,7 +32,7 @@ def sentiment_subjectivity_summarised(subjectivity: str) -> str:


def sentiment_subjectivity(score: float) -> str:
if score is NaN:
if math.isnan(score):
return NOT_APPLICABLE

score = float(score) * 100
Expand Down
3 changes: 2 additions & 1 deletion nlp_profiler/spelling_quality_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from joblib import Memory
from nltk.tokenize import word_tokenize
from textblob import Word
import math

from nlp_profiler.constants import \
DEFAULT_PARALLEL_METHOD
Expand Down Expand Up @@ -91,7 +92,7 @@ def actual_spell_check(each_word: str) -> str: # pragma: no cover


def spelling_quality(score: float) -> str:
if score is NaN:
if math.isnan(score):
return NOT_APPLICABLE

score = float(score) * 100
Expand Down
2 changes: 1 addition & 1 deletion tests/high_level/test_sentiment_polarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_given_a_text_when_sentiment_analysis_is_applied_then_sentiment_analysis
# given, when
actual_score = sentiment_polarity_score(text)
# then
if expected_polarity_score is NaN:
if math.isnan(expected_polarity_score):
assert actual_score is expected_polarity_score
else:
assert math.isclose(expected_polarity_score, actual_score,
Expand Down

0 comments on commit 2e311f7

Please sign in to comment.