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

Investigate build and cicd issues #206

Merged
merged 5 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ install:
# 'python3' is a 'command not found' error on Windows but 'py' works on Windows only
script:
- black --check .
- python -m unittest discover -s tests -t . || python3 -m unittest discover -s tests -t .
- python -m unittest discover -s tests -t . || python3 -m unittest discover -s tests -t .
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ python_requires = >=3.6.1
install_requires =
numpy>=1.17
scikit-learn>=0.22
spacy>=2.2.2
spacy<3.0.0
tqdm>=4.3
nltk>=3.3
plotly>=4.2.0
pandas>=1.0.2
wordcloud>=1.5.0
gensim>=3.6.0
gensim>=3.6.0,<4.0
matplotlib>=3.1.0
# TODO pick the correct version.
[options.extras_require]
Expand Down
47 changes: 47 additions & 0 deletions tests/test_representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,29 @@ def test_dim_reduction_and_clustering_with_vector_series_input(
else:
result_s = test_function(vector_s, random_state=42)

# Binary categories: also test if it equals with
# the category labels inverted (e.g. [0, 1, 0] instead
# of [1, 0, 1], which makes no difference functionally)
if pd.api.types.is_categorical_dtype(result_s):
if len(result_s.cat.categories) == 2 and all(
result_s.cat.categories == [0, 1]
):
try:
result_s_inverted = result_s.apply(lambda category: 1 - category)
pd.testing.assert_series_equal(
s_true,
result_s_inverted,
check_dtype=False,
rtol=0.1,
atol=0.1,
check_category_order=False,
check_categorical=False,
)
return
# inverted comparison fails -> continue to normal comparison
except AssertionError:
pass

pd.testing.assert_series_equal(
s_true,
result_s,
Expand All @@ -248,13 +271,37 @@ def test_dim_reduction_and_clustering_with_dataframe_input(
else:
result_s = test_function(df, random_state=42)

# Binary categories: also test if it equals with
# the category labels inverted (e.g. [0, 1, 0] instead
# of [1, 0, 1], which makes no difference functionally)
if pd.api.types.is_categorical_dtype(result_s):
if len(result_s.cat.categories) == 2 and all(
result_s.cat.categories == [0, 1]
):
try:
result_s_inverted = result_s.apply(lambda category: 1 - category)
pd.testing.assert_series_equal(
s_true,
result_s_inverted,
check_dtype=False,
rtol=0.1,
atol=0.1,
check_category_order=False,
check_categorical=False,
)
return
# inverted comparison fails -> continue to normal comparison
except AssertionError:
pass

pd.testing.assert_series_equal(
s_true,
result_s,
check_dtype=False,
rtol=0.1,
atol=0.1,
check_category_order=False,
check_categorical=False,
)

def test_normalize_DataFrame_also_as_output(self):
Expand Down
2 changes: 1 addition & 1 deletion texthero/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def tfidf(s: TokenSeries) -> DataFrame:
# This class is mainly for documentation in the docstring.


class HeroTypes(pd.Series, pd.DataFrame):
class HeroTypes:
"""
Hero Series Types
=================
Expand Down
2 changes: 1 addition & 1 deletion texthero/representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ def kmeans(
>>> s = s.pipe(hero.clean).pipe(hero.tokenize).pipe(
... hero.term_frequency
... )
>>> hero.kmeans(s, n_clusters=2, random_state=42)
>>> hero.kmeans(s, n_clusters=2, random_state=42) # doctest: +SKIP
0 1
1 0
2 1
Expand Down