Skip to content

Commit

Permalink
Merge pull request #873 from PrimozGodec/fix-warnings
Browse files Browse the repository at this point in the history
Resolve warnings
  • Loading branch information
ajdapretnar authored Jul 8, 2022
2 parents 3243b21 + ad91a38 commit b3b3591
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 38 deletions.
11 changes: 7 additions & 4 deletions orangecontrib/text/import_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,10 +528,13 @@ def _create_corpus(self) -> Corpus:
domain["name"].attributes["title"] = True
data = np.array(data, dtype=object)
if len(data):
corpus = Corpus(domain,
Y=category_data,
metas=data,
text_features=[domain.metas[-1]])
corpus = Corpus.from_numpy(
domain,
X=np.empty((len(category_data), 0)),
Y=category_data,
metas=data,
text_features=[domain.metas[-1]]
)
return corpus

def _add_metadata(self, corpus: Corpus) -> Corpus:
Expand Down
4 changes: 3 additions & 1 deletion orangecontrib/text/pubmed.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ def _corpus_from_records(records, includes_metadata):

Y = np.array([class_vars[0].to_val(cv) for cv in class_values])[:, None]

return Corpus(domain=domain, Y=Y, metas=meta_values)
return Corpus.from_numpy(
domain=domain, X=np.empty((len(Y), 0)), Y=Y, metas=meta_values
)


class Pubmed:
Expand Down
4 changes: 4 additions & 0 deletions orangecontrib/text/tests/test_pubmed.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,7 @@ def test_pubmed_epost_exception(self):
num_records,
use_cache=False
)


if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion orangecontrib/text/tests/test_twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
EXPECTED_RESULTS = {
"Content": ["my first tweet", "good start", "it is boring afternoon", "test"],
"Author": ["@anaana", "@bert", "@bert", "@cc"],
"Date": [date(2020, 1, 1), date(2020, 1, 2), date(2020, 1, 3), date(2020, 1, 4)],
"Date": pd.to_datetime([date(2020, 1, 1), date(2020, 1, 2), date(2020, 1, 3), date(2020, 1, 4)]),
"Language": ["en", "it", "en", np.nan],
"Location": ["sl", np.nan, np.nan, np.nan],
"Number of Likes": [1, 100, 100, 1],
Expand Down
2 changes: 1 addition & 1 deletion orangecontrib/text/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def to_val(attr, val):
)
x = np.empty((len(metas), 0))

return Corpus(domain, x, metas=metas, text_features=self.text_features)
return Corpus.from_numpy(domain, x, metas=metas, text_features=self.text_features)

def append_history(
self,
Expand Down
18 changes: 14 additions & 4 deletions orangecontrib/text/widgets/owconcordance.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,17 @@ def get_data(self):
txt.append(str(self.data(index)))
data.append([" ".join(txt)])
docs.append([self.corpus.titles[self.word_index[row][0]]])
conc = np.array(np.hstack((data, docs)), dtype=object) if data else np.empty((0,2))
return Corpus(domain, metas=conc, text_features=[domain.metas[0]])
conc = (
np.array(np.hstack((data, docs)), dtype=object)
if data
else np.empty((0, 2))
)
return Corpus.from_numpy(
domain,
X=np.empty((len(conc), 0)),
metas=conc,
text_features=[domain.metas[0]],
)


class OWConcordance(OWWidget, ConcurrentWidgetMixin):
Expand Down Expand Up @@ -262,7 +271,7 @@ def set_width(self):
def selection_changed(self):
selection = self.conc_view.selectionModel().selection()
self.selected_rows = sorted(set(cell.row() for cell in selection.indexes()))
self.commit()
self.commit.deferred()

def set_selection(self, selection):
if selection:
Expand Down Expand Up @@ -306,7 +315,7 @@ def set_word(self):

def on_done(self, _):
self.update_widget()
self.commit()
self.commit.deferred()

def handleNewSignals(self):
self.set_selection(self.selected_rows)
Expand Down Expand Up @@ -336,6 +345,7 @@ def update_widget(self):
self.n_tokens = ''
self.n_types = ''

@gui.deferred
def commit(self):
selected_docs = sorted(set(self.model.word_index[row][0]
for row in self.selected_rows))
Expand Down
5 changes: 2 additions & 3 deletions orangecontrib/text/widgets/owcorpustonetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from Orange.widgets.widget import OWWidget, Input, Output, Msg
from Orange.widgets.settings import Setting
from Orange.widgets.gui import widgetBox, comboBox, spin, button
from Orange.widgets.gui import widgetBox, comboBox, spin, button, deferred
from Orange.widgets.utils.concurrent import ConcurrentWidgetMixin, TaskState
from Orange.data import Table

Expand Down Expand Up @@ -50,7 +50,6 @@ class OWCorpusToNetwork(OWWidget, ConcurrentWidgetMixin):
priority = 250

want_main_area = False
_auto_apply = Setting(default=True)
node_type = Setting(default=0)
threshold = Setting(default=1)
window_size = Setting(default=1)
Expand All @@ -60,7 +59,7 @@ class Inputs:
corpus = Input("Corpus", Corpus)

class Outputs:
network = Output("Network", "orangecontrib.network.Network")
network = Output("Network", "orangecontrib.network.Network", auto_summary=True)
items = Output("Node Data", Table)

class Error(OWWidget.Error):
Expand Down
7 changes: 4 additions & 3 deletions orangecontrib/text/widgets/owcorpusviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def set_data(self, corpus=None):
self.update_info()
self.set_selection()
self.show_docs()
self.commit()
self.commit.now()

def reset_widget(self):
# Corpus
Expand Down Expand Up @@ -245,7 +245,7 @@ def selection_changed(self) -> None:
"""
self.selected_documents = self.get_selected_documents_from_view()
self.show_docs()
self.commit()
self.commit.deferred()

def show_docs(self):
""" Show the selected documents in the right area """
Expand Down Expand Up @@ -405,7 +405,7 @@ def refresh_search(self):
self.list_docs()
self.set_selection()
self.update_info()
self.commit()
self.commit.deferred()

def update_info(self):
if self.corpus is not None:
Expand All @@ -419,6 +419,7 @@ def update_info(self):
self.n_tokens = ''
self.n_types = ''

@gui.deferred
def commit(self):
matched = unmatched = annotated_corpus = None
corpus = self.corpus
Expand Down
4 changes: 2 additions & 2 deletions orangecontrib/text/widgets/owimportdocuments.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ def __init__(self):
url_combo.setEditable(True)
url_combo.setInsertPolicy(url_combo.InsertAtTop)
url_edit = url_combo.lineEdit()
l, t, r, b = url_edit.getTextMargins()
url_edit.setTextMargins(l + 5, t, r, b)
m = url_edit.textMargins()
url_edit.setTextMargins(m.left() + 5, m.top(), m.right(), m.bottom())
layout.addWidget(url_combo, 3, 1, 1, 3)
url_combo.activated.connect(self._url_set)
# whit completer we set that combo box is case sensitive when
Expand Down
12 changes: 8 additions & 4 deletions orangecontrib/text/widgets/owkeywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ def callback(i: float, status=""):
# Normalize words
for preprocessor in corpus.used_preprocessor.preprocessors:
if isinstance(preprocessor, BaseNormalizer):
dummy = Corpus(Domain((), metas=[StringVariable("Words")]),
metas=np.array(words)[:, None])
dummy = Corpus.from_numpy(
Domain((), metas=[StringVariable("Words")]),
X=np.empty((len(words), 0)),
metas=np.array(words)[:, None]
)
words = list(preprocessor(dummy).tokens.flatten())

# Filter scores using words
Expand Down Expand Up @@ -339,14 +342,14 @@ def __on_horizontal_header_clicked(self, index: int):
# invoked, since selection is actually the same, only order is not
if self.sel_method == SelectionMethods.MANUAL and self.selected_words \
or self.sel_method == SelectionMethods.ALL:
self.commit()
self.commit.deferred()

def __on_selection_changed(self):
selected_rows = self.view.selectionModel().selectedRows(0)
model = self.view.model()
self.selected_words = [model.data(model.index(i.row(), 0))
for i in selected_rows]
self.commit()
self.commit.deferred()

@Inputs.corpus
def set_corpus(self, corpus: Optional[Corpus]):
Expand Down Expand Up @@ -461,6 +464,7 @@ def onDeleteWidget(self):
self.shutdown()
super().onDeleteWidget()

@gui.deferred
def commit(self):
words = None
if self.selected_words:
Expand Down
5 changes: 3 additions & 2 deletions orangecontrib/text/widgets/owscoredocuments.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,11 +613,12 @@ def _clear_and_run(self) -> None:
self.scores = {}
self.cancel()
self._fill_and_output()
self.commit()
self.commit.now()

def __setting_changed(self) -> None:
self.commit()
self.commit.deferred()

@gui.deferred
def commit(self) -> None:
self.Error.custom_err.clear()
self.cancel()
Expand Down
5 changes: 3 additions & 2 deletions orangecontrib/text/widgets/owsentimentanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,12 @@ def set_corpus(self, data=None):
self.pp_corpus = PreprocessorList(pp_list)(self.corpus)
else:
self.pp_corpus = self.corpus
self.commit()
self.commit.now()

def _method_changed(self):
self.commit()
self.commit.deferred()

@gui.deferred
def commit(self):
if self.corpus is not None:
self.Warning.senti_offline.clear()
Expand Down
5 changes: 3 additions & 2 deletions orangecontrib/text/widgets/owtopicmodeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def __init__(self):
for i, (method, attr_name) in enumerate(self.methods):
widget = method(self, title='Options')
widget.setFixedWidth(self.control_area_width)
widget.valueChanged.connect(self.commit)
widget.valueChanged.connect(self.commit.deferred)
self.widgets.append(widget)
setattr(self, attr_name, widget)

Expand Down Expand Up @@ -220,6 +220,7 @@ def set_data(self, data=None):
self.corpus = data
self.apply()

@gui.deferred
def commit(self):
if self.corpus is not None:
self.apply()
Expand All @@ -232,7 +233,7 @@ def change_method(self, new_index):
if self.method_index != new_index:
self.method_index = new_index
self.toggle_widgets()
self.commit()
self.commit.deferred()

def toggle_widgets(self):
for i, widget in enumerate(self.widgets):
Expand Down
5 changes: 3 additions & 2 deletions orangecontrib/text/widgets/owtweetprofiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,15 @@ def set_corpus(self, corpus):
if ind:
self.tweet_attr = ind[0]

self.commit()
self.commit.now()

def apply(self):
self.commit()
self.commit.deferred()

def _get_config(self):
return self.tweet_attr, self.model_name, self.output_mode

@gui.deferred
def commit(self):
self.Error.clear()

Expand Down
3 changes: 2 additions & 1 deletion orangecontrib/text/widgets/owwordenrichment.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def filter_and_display(self):
for i in range(len(self.cols)):
self.sig_words.resizeColumnToContents(i)
self.set_displayed_info(count)
self.commit()
self.commit.deferred()

def build_tree(self) -> int:
count = 0
Expand Down Expand Up @@ -263,6 +263,7 @@ def tree_to_table(self):
view.append(line)
return view

@gui.deferred
def commit(self):
if not self.sig_words:
self.Outputs.words.send(None)
Expand Down
4 changes: 2 additions & 2 deletions orangecontrib/text/widgets/tests/test_owsentimentanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ def test_no_file_warnings(self):
self.assertTrue(widget.Warning.no_dicts_loaded.is_shown())
widget.pos_file = os.path.join(os.path.dirname(__file__),
"data/sentiment/pos.txt")
widget.commit()
widget.commit.now()
self.assertTrue(widget.Warning.one_dict_only.is_shown())
self.assertFalse(widget.Warning.no_dicts_loaded.is_shown())
widget.neg_file = os.path.join(os.path.dirname(__file__),
"data/sentiment/neg.txt")
widget.commit()
widget.commit.now()
self.assertFalse(widget.Warning.one_dict_only.is_shown())
self.assertFalse(widget.Warning.no_dicts_loaded.is_shown())
widget.vader.click()
Expand Down
2 changes: 1 addition & 1 deletion orangecontrib/text/widgets/tests/test_owstatistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _create_simple_data(self) -> None:
)
text_var = StringVariable("text")
domain = Domain([], metas=[text_var])
self.corpus = Corpus(
self.corpus = Corpus.from_numpy(
domain,
X=np.empty((len(metas), 0)),
metas=metas,
Expand Down
2 changes: 1 addition & 1 deletion orangecontrib/text/widgets/tests/test_owtopicmodeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_topic_evaluation(self):

# test LDA, which is the only one with log perplexity
self.widget.method_index = 1
self.widget.commit()
self.widget.commit.now()
self.wait_until_finished()

self.assertNotEqual(self.widget.perplexity, "n/a")
Expand Down
4 changes: 2 additions & 2 deletions orangecontrib/text/widgets/tests/test_owwordenrichment.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def test_output(self):
widget.filter_fdr_value = 0.01

widget.filter_and_display()
widget.commit()
widget.commit.now()
output = self.get_output(self.widget.Outputs.words)
self.assertEqual(
len(output), int(widget.info_fil.text().split(": ")[1])
Expand All @@ -261,7 +261,7 @@ def test_output(self):
widget.filter_fdr_value = 0.01

widget.filter_and_display()
widget.commit()
widget.commit.now()
output = self.get_output(self.widget.Outputs.words)
self.assertEqual(len(output), 0)

Expand Down

0 comments on commit b3b3591

Please sign in to comment.