Hide DeprecationWarning via the server config?

Hi,
We are looking for a way to hide specific DeprecationWarning messages by default in JupyterLab and configure this in the server. In this case for instance it’s related to panda warnings regarding pyarrow. We just don’t want to see them for now and avoid our user to have to input additional code for this.

We use z2jh deployed via the helm chart.

Is there a way to configure the warnings in for instance the /etc/jupyter/jupyter_notebook_config.json file?
I’ve seen mentions of a possible LabApp section, but couldn’t find documentation about it.
Or should it be done elsewhere like in the extraConfig section?
or would there be a way to do it in specific single user profiles?

We are thinking of doing something along those lines

import warnings
warnings.filterwarnings("ignore",module="pyarrow",category=DeprecationWarning)

Thanks.

You can add a file via singleuser.extraFiles, see z2jh config reference for details

Thanks. I use the extraFiles already to set the /etc/jupyter/jupyter_notebook_config.json file for instance.

Is it possible via this config to set those few lines of python that should always be run when the IPython kernel starts?

I mean for instance, could those be configured in the Jupyter config file like any other settings?

IPKernelApp.exec_PYTHONSTARTUP[¶](https://ipython.readthedocs.io/en/stable/config/options/kernel.html#configtrait-IPKernelApp.exec_PYTHONSTARTUP)
Run the file referenced by the PYTHONSTARTUP environment variable at IPython startup.
Trait type:Bool
Default:`True`

IPKernelApp.exec_files[¶](https://ipython.readthedocs.io/en/stable/config/options/kernel.html#configtrait-IPKernelApp.exec_files)
List of files to run at IPython startup.
Trait type:List

IPKernelApp.exec_lines[¶](https://ipython.readthedocs.io/en/stable/config/options/kernel.html#configtrait-IPKernelApp.exec_lines)
lines of code to run at IPython startup.
Trait type:List

I dug a bit more into the IPython settings.

The best way I found now to hide those Warnings is as follow.

in the Jupyter terminal, create an ipython default profile.

ipython profile create

add the following python code in a file named
~/.ipython/profile_default/startup/00-warnings-filter.py

import warnings

# pandas
warnings.filterwarnings('ignore',message="(?s).*Pyarrow will become a required dependency of pandas",category=DeprecationWarning)

restart any notebook kernels you have and try again to import pandas.

No more warning!

The IPython equivalent to be loaded in all users’ IPython sessions is /etc/ipython/ipython_config.json.

1 Like