question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Warnings display twice in Jupyter notebooks

See original GitHub issue

Description

Previously I was seeing this behavior in both a Jupyter notebook context and in an interactive python session in a terminal, but pulling the most recent main branch updates and doing a dev install seems to have fixed the latter case. I’m still seeing duplicate warning messages (with minor syntax differences between the two) when I use astropy in a notebook, for example:

WARNING: No observer defined on WCS, SpectralCoord will be converted without any velocity frame change [astropy.wcs.wcsapi.fitswcs]
WARNING:astropy:No observer defined on WCS, SpectralCoord will be converted without any velocity frame change

I imagine this has something to do with the way the AstropyLogger is catching and displaying warnings.warn calls.

Steps to Reproduce

A quick snippet to trigger a warning:

import numpy as np
import astropy.units as u

flux = np.ones(3) * u.Unit("1E-17 erg/s/cm^2/Angstrom")

This displays two warnings:

WARNING: UnitsWarning: '1E-17 erg/s/cm^2/Angstrom' contains multiple slashes, which is discouraged by the FITS standard [astropy.units.format.generic]
WARNING:astropy:UnitsWarning: '1E-17 erg/s/cm^2/Angstrom' contains multiple slashes, which is discouraged by the FITS standard

System Details

Checking that my notebook is actually using the dev version of astropy:

Python 3.8.8 (default, Feb 24 2021, 13:46:16) Numpy 1.20.1 astropy 4.2.dev2287+g8615fc8ca

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
rosteencommented, Apr 19, 2021

p.s. Maybe this is why.

https://github.com/astropy/specutils/blob/57dd2b28e5122e00e28333043192d30ec9f78a9d/specutils/__init__.py#L55-L58

That’s exactly where I had just started my investigation. Thanks for the tips!

1reaction
rosteencommented, Apr 19, 2021

Ah, I just did a pull not fetch. I have astropy 4.3.dev1123+g8615fc8ca after fetching the tags.

Upon further inspection it looks like you’re correct about this originating somewhere other than astropy, I’ll close this issue and investigate further. I suspect it’s actually a specutils issue…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Warnings module prints part of warning twice - Stack Overflow
Try this: warnings.warn("The specified directory is not empty, and does not " "appear to contain a pipeline we can update. Exiting.
Read more >
Warnings are displayed twice · Issue #5592 - GitHub
Whenever a warning is emitted, the message is shown twice because the logger also prints this information to the screen.
Read more >
warnings — Warning control — Python 3.11.1 documentation
The warnings filter controls whether warnings are ignored, displayed, or turned into errors (raising an exception). Conceptually, the warnings filter maintains ...
Read more >
Troubleshooting — jupyter_contrib_nbextensions 0.5.0 ...
This can lead, for example, to having all the nbextensions listed twice on the configurator page. Extensions Not Loading for Large Notebooks¶. If...
Read more >
How To Set Up Jupyter Notebook with Python 3 on Ubuntu ...
This tutorial will walk you through setting up Jupyter Notebook to run from an Ubuntu 18.04 server, as well as teach you how...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found