Skip to content

Commit

Permalink
Merge pull request #817 from PrimozGodec/remove-deprecation
Browse files Browse the repository at this point in the history
Remove deprecated extend_corpus
  • Loading branch information
PrimozGodec authored Apr 15, 2022
2 parents 5276211 + 79a4311 commit c8a60d2
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 50 deletions.
36 changes: 0 additions & 36 deletions orangecontrib/text/corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,42 +255,6 @@ def _infer_text_features(self):
include_feats.append(first)
self.set_text_features(include_feats)

def extend_corpus(self, metadata, Y):
"""
Append documents to corpus.
Args:
metadata (numpy.ndarray): Meta data
Y (numpy.ndarray): Class variables
"""
warn(
"extend_corpus is deprecated and will be removed in orange3-text 1.8",
FutureWarning
)
if np.prod(self.X.shape) != 0:
raise ValueError("Extending corpus only works when X is empty"
"while the shape of X is {}".format(self.X.shape))

self.metas = np.vstack((self.metas, metadata))

cv = self.domain.class_var
for val in set(filter(None, Y)):
if val not in cv.values:
cv.add_value(val)

if len(self._Y.shape) == 1:
new_Y = np.array([cv.to_val(i) for i in Y])
self._Y = np.hstack((self._Y, new_Y))
else:
new_Y = np.array([cv.to_val(i) for i in Y])[:, None]
self._Y = np.vstack((self._Y, new_Y))

self.X = self.W = np.zeros((self.metas.shape[0], 0))
Table._init_ids(self)

self._tokens = None # invalidate tokens
self._set_unique_titles()

def extend_attributes(
self, X, feature_names, feature_values=None, compute_values=None,
var_attrs=None, sparse=False, rename_existing=False
Expand Down
14 changes: 0 additions & 14 deletions orangecontrib/text/tests/test_corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,6 @@ def test_corpus_from_init(self):
c2 = Corpus(c.domain, c.X, c.Y, c.metas, c.W, c.text_features)
self.assertEqual(c, c2)

def test_extend_corpus(self):
"""
Extend corpus is deprecated and removed from testing since it is not
compatible with the idea of not changing Table and it is not used in
the add-on. When this test start to fail remove the function and test.
"""
cur_version = pkg_resources.get_distribution("orange3-text").version
self.assertLess(cur_version, "1.8.0")

def test_extend_corpus_non_empty_X(self):
c = Corpus.from_file('election-tweets-2016')[:10]
with self.assertRaises(ValueError):
c.extend_corpus(c.metas, c.Y)

def test_extend_attributes(self):
"""
Test correctness of extending attributes, variables must have unique
Expand Down

0 comments on commit c8a60d2

Please sign in to comment.