Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
fa342a9
added MultiIndex DF support
mk2510 Aug 18, 2020
59a9f8c
beginning with tests
henrifroese Aug 19, 2020
19c52de
implemented correct sparse support
mk2510 Aug 19, 2020
66e566c
Merge branch 'master_upstream' into change_representation_to_multicolumn
mk2510 Aug 21, 2020
41f55a8
added back list() and rm .tolist()
mk2510 Aug 21, 2020
217611a
rm .tolist() and added list()
mk2510 Aug 21, 2020
6a3b56d
Adopted the test to the new dataframes
mk2510 Aug 21, 2020
b8ff561
wrong format
mk2510 Aug 21, 2020
e3af2f9
Address most review comments.
henrifroese Aug 21, 2020
77ad80e
Add more unittests for representation
henrifroese Aug 21, 2020
f7eb7c3
- Update _types.py with DocumentTermDF
henrifroese Aug 22, 2020
4937a4f
Fix DocumentTermDF example DataFrame column names
henrifroese Aug 22, 2020
e2768b5
implemented the suggested changes
mk2510 Sep 4, 2020
b09f624
fixed messy docstring
mk2510 Sep 4, 2020
508c361
fix black issues
mk2510 Sep 4, 2020
75e955f
fix formatting
mk2510 Sep 4, 2020
9ca244d
begin switch away from multiindex
henrifroese Sep 4, 2020
4ebc266
Merge remote-tracking branch 'origin/change_representation_to_multico…
henrifroese Sep 4, 2020
559a7bd
Finish switch from DocumentTermDF to MatrixDF
henrifroese Sep 4, 2020
75a999c
changed Dataframe name from MatrixDF to DataFrame
mk2510 Sep 4, 2020
a38a32b
henrifroese Sep 12, 2020
c7b0ece
henrifroese Sep 12, 2020
4aeec2a
finish switch to DataFrame type
henrifroese Sep 12, 2020
a304413
Merge remote-tracking branch 'origin/Hero_Types_in_Representation' in…
henrifroese Sep 12, 2020
8d49bff
merge remote
henrifroese Sep 12, 2020
85076b8
Remove check for nlevels
henrifroese Sep 12, 2020
91ed11a
incorporate suggested changes
henrifroese Sep 14, 2020
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
24 changes: 12 additions & 12 deletions tests/test_representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ def _tfidf(term, corpus, document_index):


vector_s = pd.Series([[1.0, 0.0], [0.0, 0.0]], index=[5, 7])
document_term_df = pd.DataFrame(
[[1.0, 0.0], [0.0, 0.0]], index=[5, 7], columns=["a", "b"],
).astype("Sparse[float64, nan]")
df = pd.DataFrame([[1.0, 0.0], [0.0, 0.0]], index=[5, 7], columns=["a", "b"],).astype(
"Sparse[float64, nan]"
)


test_cases_dim_reduction_and_clustering = [
# format: [function_name, function, correct output for s_vector_series and s_documenttermDF input above]
# format: [function_name, function, correct output for s_vector_series and df input above]
["pca", representation.pca, pd.Series([[-0.5, 0.0], [0.5, 0.0]], index=[5, 7],),],
[
"nmf",
Expand Down Expand Up @@ -232,7 +232,7 @@ def test_dim_reduction_and_clustering_with_vector_series_input(
)

@parameterized.expand(test_cases_dim_reduction_and_clustering)
def test_dim_reduction_and_clustering_with_documenttermDF_input(
def test_dim_reduction_and_clustering_with_dataframe_input(
self, name, test_function, correct_output
):
s_true = correct_output
Expand All @@ -242,11 +242,11 @@ def test_dim_reduction_and_clustering_with_documenttermDF_input(
return

if name == "kmeans":
result_s = test_function(document_term_df, random_state=42, n_clusters=2)
elif name == "dbscan" or name == "meanshift":
result_s = test_function(document_term_df)
result_s = test_function(df, random_state=42, n_clusters=2)
elif name == "dbscan" or name == "meanshift" or name == "normalize":
result_s = test_function(df)
else:
result_s = test_function(document_term_df, random_state=42)
result_s = test_function(df, random_state=42)

pd.testing.assert_series_equal(
s_true,
Expand All @@ -257,10 +257,10 @@ def test_dim_reduction_and_clustering_with_documenttermDF_input(
check_category_order=False,
)

def test_normalize_document_term_df_also_as_output(self):
# normalize should also return DocumentTermDF output for DocumentTermDF
def test_normalize_DataFrame_also_as_output(self):
# normalize should also return DataFrame output for DataFrame
# input so we test it separately
result = representation.normalize(document_term_df)
result = representation.normalize(df)
correct_output = pd.DataFrame(
[[1.0, 0.0], [0.0, 0.0]], index=[5, 7], columns=["a", "b"],
)
Expand Down
33 changes: 23 additions & 10 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,13 @@ def f(s):
except TypeError:
self.fail("Failed although input type is correct.")

def test_inputseries_correct_type_documentrepresentationseries(self):
@_types.InputSeries(_types.RepresentationSeries)
def test_inputseries_correct_type_DataFrame(self):
@_types.InputSeries(_types.DataFrame)
def f(s):
pass

try:
f(
pd.Series(
[1, 2, 3],
index=pd.MultiIndex.from_tuples(
[("doc1", "word1"), ("doc1", "word2"), ("doc2", "word1")]
),
)
)
f(pd.DataFrame([[1, 2, 3]], columns=["a", "b", "c"], dtype="Sparse",))
except TypeError:
self.fail("Failed although input type is correct.")

Expand Down Expand Up @@ -118,3 +111,23 @@ def f(s):
f(pd.Series([np.nan, pd.NA, [0, 1, 2]]))
except TypeError:
self.fail("Failed although input type is correct.")

def test_several_possible_types_correct_type(self):
@_types.InputSeries([_types.DataFrame, _types.VectorSeries])
def f(x):
pass

try:
f(pd.DataFrame([[1, 2, 3]], columns=["a", "b", "c"], dtype="Sparse",))

f(pd.Series([[1.0, 2.0]]))

except TypeError:
self.fail("Failed although input type is correct.")

def test_several_possible_types_wrong_type(self):
@_types.InputSeries([_types.DataFrame, _types.VectorSeries])
def f(x):
pass

self.assertRaises(TypeError, f, pd.Series([["token", "ized"]]))
Loading