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

import rerun modifies default warnings, adding rerun: to all warnings #2408

Closed
roym899 opened this issue Jun 13, 2023 · 0 comments · Fixed by #2985
Closed

import rerun modifies default warnings, adding rerun: to all warnings #2408

roym899 opened this issue Jun 13, 2023 · 0 comments · Fixed by #2985
Assignees
Labels
😤 annoying Something in the UI / SDK is annoying to use 🪳 bug Something isn't working 🐍 Python API Python logging API 🏎️ Quick Issue Can be fixed in a few hours or less

Comments

@roym899
Copy link
Collaborator

roym899 commented Jun 13, 2023

To Reproduce

import rerun as rr
import warnings
warnings.warn("some warning")

gives

WARNING:rerun:some warning

Expected behavior
Importing rerun shouldn't affect default warning behavior. That is, I would expect the following output

{path_to_file}:2: UserWarning: some warning
  warnings.warn("some warning")

Desktop:

  • OS: Ubuntu 20.04

Rerun version
rerun-sdk 0.7.0a0+2023.6.13.0f89b62

@roym899 roym899 added 👀 needs triage This issue needs to be triaged by the Rerun team 🪳 bug Something isn't working labels Jun 13, 2023
@nikolausWest nikolausWest added 😤 annoying Something in the UI / SDK is annoying to use and removed 👀 needs triage This issue needs to be triaged by the Rerun team labels Jun 13, 2023
@roym899 roym899 changed the title import rerun as rr modifies default warnings, adding rerun: to all warnings import rerun modifies default warnings, adding rerun: to all warnings Jun 13, 2023
@emilk emilk added 🐍 Python API Python logging API 🏎️ Quick Issue Can be fixed in a few hours or less labels Jun 27, 2023
@jleibs jleibs self-assigned this Aug 15, 2023
Wumpf pushed a commit that referenced this issue Aug 15, 2023
…2985)

Resolves: #2408

### What:
Stop overriding the global `warnings.formatwarning`

Instead introduce a RerunWarning category and also set stacklevel
appropriately for better warning context.

Consider this example:
```
import warnings
import rerun as rr

warnings.warn("my warning")
rr.log_points("foo", [1, 2, 3])
rr.init("foo")
rr.log_points("foo", "not a point")
```

Before: wrongly annotated user-warning. No way to identify source of
error.
```
WARNING:rerun:my warning
WARNING:rerun:Rerun is disabled - log_points() call ignored. You must call rerun.init before using log APIs.
WARNING:root:Ignoring rerun log call: Traceback (most recent call last):
  File "/home/jleibs/venv/lib/python3.10/site-packages/rerun_sdk/rerun/log/log_decorator.py", line 47, in wrapper
    return func(*args, **kwargs)
  File "/home/jleibs/venv/lib/python3.10/site-packages/rerun_sdk/rerun/log/points.py", line 228, in log_points
    positions = np.require(positions, dtype="float32")
  File "/home/jleibs/venv/lib/python3.10/site-packages/numpy/core/_asarray.py", line 110, in require
    return asanyarray(a, dtype=dtype)
ValueError: could not convert string to float: 'not a point'
```

After: Consistent pythonic warnings and actionable line-numbers.
```
/home/jleibs/rerun/test.py:4: UserWarning: my warning
  warnings.warn("my warning")
/home/jleibs/rerun/test.py:5: RerunWarning: Rerun is disabled - log_points() call ignored. You must call rerun.init before using log APIs.
  rr.log_points("foo", [1, 2, 3])
/home/jleibs/rerun/test.py:7: RerunWarning: Ignoring rerun log call: Traceback (most recent call last):
  File "/home/jleibs/rerun/rerun_py/rerun_sdk/rerun/log/log_decorator.py", line 51, in wrapper
    return func(*args, **kwargs)
  File "/home/jleibs/rerun/rerun_py/rerun_sdk/rerun/log/points.py", line 208, in log_points
    positions = np.require(positions, dtype="float32")
  File "/home/jleibs/rerun/venv/lib/python3.10/site-packages/numpy/core/_asarray.py", line 106, in require
    return asanyarray(a, dtype=dtype)
ValueError: could not convert string to float: 'not a point'

  rr.log_points("foo", "not a point")
```

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/2985) (if
applicable)

- [PR Build Summary](https://build.rerun.io/pr/2985)
- [Docs
preview](https://rerun.io/preview/pr%3Ajleibs%2Frerun_warnings/docs)
- [Examples
preview](https://rerun.io/preview/pr%3Ajleibs%2Frerun_warnings/examples)
emilk pushed a commit that referenced this issue Aug 17, 2023
…2985)

Resolves: #2408

### What:
Stop overriding the global `warnings.formatwarning`

Instead introduce a RerunWarning category and also set stacklevel
appropriately for better warning context.

Consider this example:
```
import warnings
import rerun as rr

warnings.warn("my warning")
rr.log_points("foo", [1, 2, 3])
rr.init("foo")
rr.log_points("foo", "not a point")
```

Before: wrongly annotated user-warning. No way to identify source of
error.
```
WARNING:rerun:my warning
WARNING:rerun:Rerun is disabled - log_points() call ignored. You must call rerun.init before using log APIs.
WARNING:root:Ignoring rerun log call: Traceback (most recent call last):
  File "/home/jleibs/venv/lib/python3.10/site-packages/rerun_sdk/rerun/log/log_decorator.py", line 47, in wrapper
    return func(*args, **kwargs)
  File "/home/jleibs/venv/lib/python3.10/site-packages/rerun_sdk/rerun/log/points.py", line 228, in log_points
    positions = np.require(positions, dtype="float32")
  File "/home/jleibs/venv/lib/python3.10/site-packages/numpy/core/_asarray.py", line 110, in require
    return asanyarray(a, dtype=dtype)
ValueError: could not convert string to float: 'not a point'
```

After: Consistent pythonic warnings and actionable line-numbers.
```
/home/jleibs/rerun/test.py:4: UserWarning: my warning
  warnings.warn("my warning")
/home/jleibs/rerun/test.py:5: RerunWarning: Rerun is disabled - log_points() call ignored. You must call rerun.init before using log APIs.
  rr.log_points("foo", [1, 2, 3])
/home/jleibs/rerun/test.py:7: RerunWarning: Ignoring rerun log call: Traceback (most recent call last):
  File "/home/jleibs/rerun/rerun_py/rerun_sdk/rerun/log/log_decorator.py", line 51, in wrapper
    return func(*args, **kwargs)
  File "/home/jleibs/rerun/rerun_py/rerun_sdk/rerun/log/points.py", line 208, in log_points
    positions = np.require(positions, dtype="float32")
  File "/home/jleibs/rerun/venv/lib/python3.10/site-packages/numpy/core/_asarray.py", line 106, in require
    return asanyarray(a, dtype=dtype)
ValueError: could not convert string to float: 'not a point'

  rr.log_points("foo", "not a point")
```

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/2985) (if
applicable)

- [PR Build Summary](https://build.rerun.io/pr/2985)
- [Docs
preview](https://rerun.io/preview/pr%3Ajleibs%2Frerun_warnings/docs)
- [Examples
preview](https://rerun.io/preview/pr%3Ajleibs%2Frerun_warnings/examples)
emilk pushed a commit that referenced this issue Aug 17, 2023
…2985)

Resolves: #2408

### What:
Stop overriding the global `warnings.formatwarning`

Instead introduce a RerunWarning category and also set stacklevel
appropriately for better warning context.

Consider this example:
```
import warnings
import rerun as rr

warnings.warn("my warning")
rr.log_points("foo", [1, 2, 3])
rr.init("foo")
rr.log_points("foo", "not a point")
```

Before: wrongly annotated user-warning. No way to identify source of
error.
```
WARNING:rerun:my warning
WARNING:rerun:Rerun is disabled - log_points() call ignored. You must call rerun.init before using log APIs.
WARNING:root:Ignoring rerun log call: Traceback (most recent call last):
  File "/home/jleibs/venv/lib/python3.10/site-packages/rerun_sdk/rerun/log/log_decorator.py", line 47, in wrapper
    return func(*args, **kwargs)
  File "/home/jleibs/venv/lib/python3.10/site-packages/rerun_sdk/rerun/log/points.py", line 228, in log_points
    positions = np.require(positions, dtype="float32")
  File "/home/jleibs/venv/lib/python3.10/site-packages/numpy/core/_asarray.py", line 110, in require
    return asanyarray(a, dtype=dtype)
ValueError: could not convert string to float: 'not a point'
```

After: Consistent pythonic warnings and actionable line-numbers.
```
/home/jleibs/rerun/test.py:4: UserWarning: my warning
  warnings.warn("my warning")
/home/jleibs/rerun/test.py:5: RerunWarning: Rerun is disabled - log_points() call ignored. You must call rerun.init before using log APIs.
  rr.log_points("foo", [1, 2, 3])
/home/jleibs/rerun/test.py:7: RerunWarning: Ignoring rerun log call: Traceback (most recent call last):
  File "/home/jleibs/rerun/rerun_py/rerun_sdk/rerun/log/log_decorator.py", line 51, in wrapper
    return func(*args, **kwargs)
  File "/home/jleibs/rerun/rerun_py/rerun_sdk/rerun/log/points.py", line 208, in log_points
    positions = np.require(positions, dtype="float32")
  File "/home/jleibs/rerun/venv/lib/python3.10/site-packages/numpy/core/_asarray.py", line 106, in require
    return asanyarray(a, dtype=dtype)
ValueError: could not convert string to float: 'not a point'

  rr.log_points("foo", "not a point")
```

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/2985) (if
applicable)

- [PR Build Summary](https://build.rerun.io/pr/2985)
- [Docs
preview](https://rerun.io/preview/pr%3Ajleibs%2Frerun_warnings/docs)
- [Examples
preview](https://rerun.io/preview/pr%3Ajleibs%2Frerun_warnings/examples)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
😤 annoying Something in the UI / SDK is annoying to use 🪳 bug Something isn't working 🐍 Python API Python logging API 🏎️ Quick Issue Can be fixed in a few hours or less
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants