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 1 commit
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
Prev Previous commit
Next Next commit
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
  • Loading branch information
henrifroese committed Apr 7, 2021
commit 2767b67276ea7d88593688307243cd83e21881fa
43 changes: 43 additions & 0 deletions tests/test_representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,27 @@ 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 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 +269,35 @@ 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 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