[
https://issues.apache.org/jira/browse/BEAM-5745?focusedWorklogId=155734&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-155734
]
ASF GitHub Bot logged work on BEAM-5745:
----------------------------------------
Author: ASF GitHub Bot
Created on: 18/Oct/18 07:42
Start Date: 18/Oct/18 07:42
Worklog Time Spent: 10m
Work Description: tvalentyn commented on issue #6687: [BEAM-5745] Fix
annotation test for py3
URL: https://github.com/apache/beam/pull/6687#issuecomment-430907854
1. The goal of `annotations.py` is to create a mechanism that will allow to
print a warning message when some Beam APIs are used. It is well documented in
the docstring
https://github.com/apache/beam/blob/0acb027cd7d909732e5a07ed0d2cbbedf5fbc907/sdks/python/apache_beam/utils/annotations.py#L18
My intuition says we may be reinventing the wheel here, but without further
research I don't have a recommendation at the moment.
2. One aspect of existing implementation is that we want such warnings be
seen only once, if possible, to avoid noise. This is achieved by adding a
warning filter, see:
https://docs.python.org/3/library/warnings.html#warning-filter. Unfortunately,
the restriction we impose in
https://github.com/apache/beam/blob/0acb027cd7d909732e5a07ed0d2cbbedf5fbc907/sdks/python/apache_beam/utils/annotations.py#L94
is very broad, and will apply to **all** warnings which will be generated, not
just warnings produced by annotated functions. This may have unintended side
effects beyond the scope of the code the restriction is meant for. This is what
@robertwb called out.
3. To understand why tests started to fail, we can add look into the filter
list. Everytime we add a new warning filter, it is added to the beginning list,
the order of filter application is defined in the documentation (see above). At
any point, we can print current filter list with:
```
import pprint
pprint(warnings.filter)
```
By the time we run the annotated functions in `test_frequency`, the filter
list on Python 2 looks like this:
```
...
('always', None, <class 'numpy.lib.polynomial.RankWarning'>, None, 0), #
<--- Filter added by numpy library after our filter.
('once', None, <type 'exceptions.Warning'>, None, 0), # <--- Filter
added by us. Notice that it applies to all warnings.
('ignore', None, <class 'urllib3.exceptions.DependencyWarning'>, None, 0),
# <--- Filters added before our filter.
...
```
On Python 3, the filter list looks like this:
```
...
('default', None, <class 'Warning'>, None, 0), # <--- !!! Something
adds this rule.
...
('always', None, <class 'numpy.lib.polynomial.RankWarning'>, None, 0),
('once', None, <class 'Warning'>, None, 0) # <---- Rule we add
...
```
``` ('default', None, <class 'Warning'>, None, 0)``` overrides our behavior
to print warnings only once. Therefore, the deprecation warnings are printed
twice and the test fails. Might be interesting to track down what adds this
rule. By setting `warnings.simplefilter("once")` inside `annotate` method, as
this PR proposes, we basically start a fight with somebody over whose rule will
be at the top.
I think we should reconsider whether we want to keep our annotation
mechanism, if so, we need a better way to manage the warnings. Either not add
any restrictions, or otherwise find a proper way to localize them. cc:
@robertwb @aaltay
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 155734)
Time Spent: 1h 20m (was: 1h 10m)
> Util test on annotations fails
> -------------------------------
>
> Key: BEAM-5745
> URL: https://issues.apache.org/jira/browse/BEAM-5745
> Project: Beam
> Issue Type: Sub-task
> Components: sdk-py-core
> Reporter: Ruoyun Huang
> Assignee: Ruoyun Huang
> Priority: Minor
> Time Spent: 1h 20m
> Remaining Estimate: 0h
>
> Traceback (most recent call last):
> File
> "/usr/local/google/home/ruoyun/projects/beam/sdks/python/apache_beam/utils/annotations_test.py",
> line 142, in test_frequency
> label_check_list=[])
> File
> "/usr/local/google/home/ruoyun/projects/beam/sdks/python/apache_beam/utils/annotations_test.py",
> line 149, in check_annotation
> self.assertIn(fnc_name + ' is ' + annotation_type,
> str(warning[-1].message))
> AssertionError: 'fnc2_test_annotate_frequency is experimental' not found in
> 'fnc_test_annotate_frequency is experimental.'
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)