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

Improve warnings: use color and sane defaults #4780

Merged
merged 9 commits into from
Jan 29, 2020
Merged

Improve warnings: use color and sane defaults #4780

merged 9 commits into from
Jan 29, 2020

Conversation

imLew
Copy link
Contributor

@imLew imLew commented Nov 15, 2019

Proposed changes:

  • Improve warnings: use color and sane defaults when emitting warnings for our users
  • Makes sure the warning messages are colored and use a sane stack level for the warning message (e.g. by default this would be the line emitting the warning, which in most cases doesn't make sense).
  • If the code line is not relevant (e.g. if the warning is about an intent that should be listed in the domain but is not) we add a link to some relevant documentation page.
  • related to failing tests for expected warnings #4356

Status (please check what you already did):

  • made PR ready for code review
  • added some tests for the functionality
  • updated the documentation
  • updated the changelog
  • reformat files using black (please check Readme for instructions)

@wochinge
Copy link
Contributor

@tmbo Who is taking this over?

@tmbo
Copy link
Member

tmbo commented Dec 16, 2019

Can you please take that over as a squad?

I think it is unrealistic to set the warnings filter to error just yet (due to the strange errors we get with that), but here is what I think we should keep:

  • helper that sets default values for category and stacklevel
  • optional: red formatting of these messages in the log if possible

@wochinge
Copy link
Contributor

You mean as production squad? ok

@claassistantio
Copy link

claassistantio commented Jan 23, 2020

CLA assistant check
All committers have signed the CLA.

@alwx alwx self-assigned this Jan 23, 2020
@wochinge
Copy link
Contributor

@alwx I think @tmbo is currently also doing something here. Best keep off for now

@alwx alwx removed their assignment Jan 24, 2020
@tmbo tmbo self-assigned this Jan 24, 2020
@tmbo
Copy link
Member

tmbo commented Jan 24, 2020

should have assigned me, sorry for the confusion

@tmbo tmbo changed the title Improve testing Improve warnings by coloring them and using sane defaults Jan 24, 2020
@tmbo tmbo changed the title Improve warnings by coloring them and using sane defaults Improve warnings: use color and sane defaults Jan 24, 2020
@@ -722,9 +713,6 @@ def keys(self) -> Iterable[Text]:
def retrieve(self, sender_id: Text) -> Optional[DialogueStateTracker]:
"""Create a tracker from all previously stored events."""

import sqlalchemy as sa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if this import is needed

intent_keyword_map = None
return cls(meta, intent_keyword_map)
else:
raise Exception(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

converted this to an exception to stay in line with other components

@@ -108,7 +110,12 @@ def train(

self.clf = self._create_classifier(num_threads, y)

self.clf.fit(X, y)
with warnings.catch_warnings():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore sklearn warnings

@@ -140,6 +147,7 @@ def _create_classifier(
cv=cv_splits,
scoring=self.component_config["scoring_function"],
verbose=1,
iid=False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prevents deprecation warning

@@ -295,3 +299,47 @@ def _lazyprop(self):
return getattr(self, attr_name)

return _lazyprop


def raise_warning(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implementation for raise_warning

@@ -13,6 +13,7 @@ codestyle_exclude =
rasa/core/policies/__init__.py
filterwarnings =
ignore::ResourceWarning:ruamel[.*]
#error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be activated later on to fail on warnings, doesn't work yet though



def test_print_error_and_exit():
with pytest.raises(SystemExit):
rasa.cli.utils.print_error_and_exit("")


def test_logging_capture(caplog: LogCaptureFixture):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests removed since that function (assert_log_emitted ) isn't used anywhere

@tmbo tmbo added this to the Rasa 1.7 milestone Jan 28, 2020
@tmbo
Copy link
Member

tmbo commented Jan 28, 2020

This is ready for review and should go into the 1.7 release (cc @federicotdn).

@degiz can you please give this a review? it looks like a lot of changes but most of them are import reorg (thought about adding isort to prevent this from happening, but different story). I've commented on the lines where I did more than just rename warnings.warn.

@tmbo tmbo assigned degiz and unassigned tmbo Jan 28, 2020
@tmbo tmbo requested a review from degiz January 28, 2020 14:01
@tmbo
Copy link
Member

tmbo commented Jan 28, 2020

(@degiz ideally today or early tomorrow so that we can get it into the release - let me know if you have to much on your plate)

@@ -18,7 +18,7 @@ slots:
name:
type: text

templates:
responses:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover from an earlier rename (created a warning that it is deprecated, that is why I changed it)

@tmbo tmbo force-pushed the improve-testing branch 4 times, most recently from 211226e to 5a60ea5 Compare January 28, 2020 14:25
Copy link
Contributor

@degiz degiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left few comments, but non of them is critical. So you can merge it the PR is urgent to get in.

warnings.warn(
"Continue training will be removed in the next release. It won't be "
raise_warning(
"Continue training will be removed in the 2.0 release. It won't be "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: maybe it makes sense to mark the function as deprecated? is it exposed to the users?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mhm not sure what you mean, there isn't a @Deprecated like in java 😅

rasa/core/agent.py Show resolved Hide resolved
rasa/core/brokers/file_producer.py Outdated Show resolved Hide resolved
rasa/core/training/dsl.py Outdated Show resolved Hide resolved
rasa/core/validator.py Outdated Show resolved Hide resolved
rasa/nlu/classifiers/keyword_intent_classifier.py Outdated Show resolved Hide resolved
rasa/nlu/classifiers/keyword_intent_classifier.py Outdated Show resolved Hide resolved
rasa/utils/common.py Outdated Show resolved Hide resolved
tests/core/test_processor.py Show resolved Hide resolved
@ricwo
Copy link
Contributor

ricwo commented Jan 29, 2020

pytest has introduced coloured test summaries with 5.3.0: https://docs.pytest.org/en/latest/changelog.html#id29

we could upgrade to latest v 5.3.4

tmbo and others added 5 commits January 29, 2020 15:21
Co-Authored-By: Alexander Khizov <degiz@users.noreply.github.com>
Co-Authored-By: Alexander Khizov <degiz@users.noreply.github.com>
Co-Authored-By: Alexander Khizov <degiz@users.noreply.github.com>
Co-Authored-By: Alexander Khizov <degiz@users.noreply.github.com>
@tmbo
Copy link
Member

tmbo commented Jan 29, 2020

@ricwo that sounds great we should def do that, but would do that after the release 👍

@tmbo tmbo merged commit d53eef5 into master Jan 29, 2020
@tmbo tmbo deleted the improve-testing branch January 29, 2020 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants