Skip to content

Commit

Permalink
Investigate build and cicd issues (#206)
Browse files Browse the repository at this point in the history
* empty change to test build issues

* Correct gensim version

* Correct spaCy version

* Fix several build / dependency bugs

- stop class HeroTypes from inheriting from pd.Series and pd.DataFrame. Inheriting from them is not necessary at all, and causes issues with newer python versions
- skip kmeans doctest as we cannot be sure if it evaluates on [1,0,1,0] or [0,1,0,1] on different builds
- for tests with binary categories (0, 1), test whether either the result or the inversion of the result matches the expected value. This tests the same functionality but prevents failures on different OSes

* Fix check for length of category series before comparison
  • Loading branch information
henrifroese authored Apr 7, 2021
1 parent 5a83c6e commit f4bb900
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
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

0 comments on commit f4bb900

Please sign in to comment.