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

Strange decimal.getcontext().prec behavior #5260

Open
evan-burke opened this issue Feb 29, 2020 · 5 comments
Open

Strange decimal.getcontext().prec behavior #5260

evan-burke opened this issue Feb 29, 2020 · 5 comments

Comments

@evan-burke
Copy link

evan-burke commented Feb 29, 2020

Hi,

I'm using Python's decimal.getcontext().prec to set decimal precision for operations in a notebook.

In Jupyter, the precision seems to (somewhat intermittently) get reset to 28 between manual executions of different cells. The strangest part is - running the shell command !jupyter notebook --version fixes the issue. (I haven't tested other shell commands.)

Additionally, on a just-started version of JupyterLab, decimal.getcontext().prec behavior is normal; the bug only appears to surface after restarting the kernel in the JupyterLab UI.

"Run all cells" also appears to apply precision correctly across different cells.

Example & version details -
https://github.com/evan-burke/juptyer_getcontext_bug/blob/master/getcontext.ipynb

Same thing run in a console behaves normally:

Python 3.7.4 (default, Aug 13 2019, 20:35:49) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.13.0 -- An enhanced Interactive Python. Type '?' for help.
​
import sys
from decimal import Decimal, getcontext

sys.version
'3.7.4 (default, Aug 13 2019, 20:35:49) \n[GCC 7.3.0]'

getcontext().prec = 4
r = Decimal(2) / Decimal(3)
r
Decimal('0.6667')

getcontext().prec
4
@evan-burke
Copy link
Author

Adding version info here for clarity

jupyter core     : 4.6.3
jupyter-notebook : 6.0.3
qtconsole        : not installed
ipython          : 7.13.0
ipykernel        : 5.1.4
jupyter client   : 6.0.0
jupyter lab      : 2.0.0
nbconvert        : 5.6.1
ipywidgets       : 7.5.1
nbformat         : 5.0.4
traitlets        : 4.3.3

@evan-burke
Copy link
Author

Quick additional note. Above, this was occurring in the jupyter/tensorflow-notebook Docker image from about a month ago, with a few things installed, and a few updates run.

I've pulled the latest image with the below versions, and with nothing else installed/no updates run. Behavior is slightly different, but the issue still occurs intermittently, apparently varying based on a) if Jupyter Lab is freshly started, b) if kernel has been restarted, and c) whether the shell command has been run.

So, if you're trying to reproduce, treat as intermittent, and test with variations of those three factors.

Versions from the latest image where this is happening:
'3.7.6 | packaged by conda-forge | (default, Jan 7 2020, 22:33:48) \n[GCC 7.3.0]'

jupyter-notebook : 6.0.3
qtconsole        : not installed
ipython          : 7.13.0
ipykernel        : 5.1.4
jupyter client   : 6.0.0
jupyter lab      : 1.2.5
nbconvert        : 5.6.1
ipywidgets       : 7.5.1
nbformat         : 5.0.4
traitlets        : 4.3.3

@evan-burke
Copy link
Author

Is this the appropriate place for this issue to be opened?

@kevin-bates
Copy link
Member

Hi @evan-burke - sorry for the lack of response. This sounds like a strange issue, but one that probably should be investigated from the kernel side. I suspect you might have better success with this question in the ipykernel repo. That said, these projects do share many of the same maintainers. Good luck.

@evan-burke
Copy link
Author

Thank you Kevin - I'll open one there and reference this.

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

No branches or pull requests

2 participants