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

sage.plot, sage.repl: Modularization fixes (imports), # needs #38181

Merged
merged 4 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/sage/plot/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2438,15 +2438,15 @@ def _matplotlib_tick_formatter(self, subplot, base=(10, 10),
x_formatter, y_formatter = tick_formatter
from matplotlib.ticker import FuncFormatter, FixedFormatter
from sage.misc.latex import latex
from sage.symbolic.ring import SR
from sage.structure.element import Expression
from .misc import _multiple_of_constant
# ---------------------- Formatting x-ticks ----------------------
if x_formatter is None:
if scale[0] == 'log':
x_formatter = LogFormatterMathtext(base=base[0])
else:
x_formatter = ScalarFormatter()
elif x_formatter in SR:
elif isinstance(x_formatter, Expression):
x_const = x_formatter
x_formatter = FuncFormatter(lambda n, pos:
_multiple_of_constant(n, pos, x_const))
Expand Down Expand Up @@ -2475,7 +2475,7 @@ def _matplotlib_tick_formatter(self, subplot, base=(10, 10),
y_formatter = LogFormatterMathtext(base=base[1])
else:
y_formatter = ScalarFormatter()
elif y_formatter in SR:
elif isinstance(y_formatter, Expression):
y_const = y_formatter
y_formatter = FuncFormatter(lambda n, pos:
_multiple_of_constant(n, pos, y_const))
Expand Down Expand Up @@ -2763,10 +2763,10 @@ def matplotlib(self, filename=None,
if stylesheet in plt.style.available:
plt.style.use(stylesheet)

from sage.symbolic.ring import SR
from sage.structure.element import Expression
# make sure both formatters typeset or both don't
if not isinstance(tick_formatter, (list, tuple)):
if tick_formatter == "latex" or tick_formatter in SR:
if tick_formatter == "latex" or isinstance(tick_formatter, Expression):
tick_formatter = (tick_formatter, "latex")
else:
tick_formatter = (tick_formatter, None)
Expand Down
7 changes: 4 additions & 3 deletions src/sage/plot/hyperbolic_regular_polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
from sage.rings.cc import CC
from sage.rings.integer import Integer
from sage.misc.decorators import options, rename_keyword
from sage.symbolic.constants import pi, e
from sage.functions.hyperbolic import arccosh
from sage.functions.trig import sin, cos, cot
from sage.misc.lazy_import import lazy_import
lazy_import("sage.symbolic.constants", ["pi", "e"])
lazy_import("sage.functions.hyperbolic", "arccosh")
lazy_import("sage.functions.trig", ["sin", "cos", "cot"])
from sage.misc.functional import is_odd
from sage.matrix.constructor import matrix

Expand Down
3 changes: 2 additions & 1 deletion src/sage/plot/plot3d/plot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def f(x,y): return math.exp(x/5)*math.cos(y)
from sage.plot.colors import rainbow
from .texture import Texture

from sage.functions.trig import cos, sin
from sage.misc.lazy_import import lazy_import
lazy_import("sage.functions.trig", ["cos", "sin"])
from sage.misc.sageinspect import sage_getargspec, is_function_or_cython_function


Expand Down
30 changes: 17 additions & 13 deletions src/sage/repl/display/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
contains a new facility for displaying lists of matrices in an easier
to read format::

sage: [identity_matrix(i) for i in range(2,5)]
sage: [identity_matrix(i) for i in range(2, 5)] # needs sage.modules
[
[1 0 0 0]
[1 0 0] [0 1 0 0]
Expand Down Expand Up @@ -236,19 +236,23 @@
sage: shell.run_cell('matrix.options.precision') # indirect doctest # needs sage.modules
None
"""
from sage.matrix.constructor import options
s = change.new
if not s:
# unset the precision
options.precision = None
try:
from sage.matrix.constructor import options
except ImportError:
pass

Check warning on line 242 in src/sage/repl/display/formatter.py

View check run for this annotation

Codecov / codecov/patch

src/sage/repl/display/formatter.py#L241-L242

Added lines #L241 - L242 were not covered by tests
else:
try:
prec = int(s)
if prec >= 0:
options.precision = prec
# otherwise ignore the change
except ValueError:
pass
s = change.new
if not s:
# unset the precision
options.precision = None
else:
try:
prec = int(s)
if prec >= 0:
options.precision = prec
# otherwise ignore the change
except ValueError:
pass

Check warning on line 255 in src/sage/repl/display/formatter.py

View check run for this annotation

Codecov / codecov/patch

src/sage/repl/display/formatter.py#L254-L255

Added lines #L254 - L255 were not covered by tests


class SagePlainTextFormatter(PlainTextFormatter):
Expand Down
1 change: 1 addition & 0 deletions src/sage/repl/image.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# sage_setup: distribution = sagemath-repl
# sage.doctest: needs pillow
"""
Sage Wrapper for Bitmap Images

Expand Down
16 changes: 12 additions & 4 deletions src/sage/repl/ipython_kernel/interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
# https://www.gnu.org/licenses/
# ****************************************************************************

from ipywidgets.widgets import SelectionSlider, ValueWidget, ToggleButtons
from ipywidgets.widgets.interaction import interactive, signature
from collections import OrderedDict
from collections.abc import Iterable, Iterator

from ipywidgets.widgets import SelectionSlider, ValueWidget, ToggleButtons
from ipywidgets.widgets.interaction import interactive, signature

from .widgets import EvalText, SageColorPicker
from sage.structure.element import parent
import sage.rings.abc
Expand Down Expand Up @@ -173,8 +175,14 @@

return input_grid(abbrev.nrows(), abbrev.ncols(),
default=abbrev.list(), to_value=abbrev.parent())
if isinstance(abbrev, Color):
return SageColorPicker(value=abbrev.html_color())

try:
from sage.plot.colors import Color
except ImportError:
pass

Check warning on line 182 in src/sage/repl/ipython_kernel/interact.py

View check run for this annotation

Codecov / codecov/patch

src/sage/repl/ipython_kernel/interact.py#L181-L182

Added lines #L181 - L182 were not covered by tests
else:
if isinstance(abbrev, Color):
return SageColorPicker(value=abbrev.html_color())
# Get widget from IPython if possible
widget = super().widget_from_single_value(abbrev, *args, **kwds)
if widget is not None or isinstance(abbrev, Iterable):
Expand Down
17 changes: 11 additions & 6 deletions src/sage/repl/ipython_kernel/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class TransformWidget():
sage: from ipywidgets import ToggleButtons
sage: from sage.repl.ipython_kernel.widgets import TransformWidget
sage: class TransformToggleButtons(TransformWidget, ToggleButtons): pass
sage: w = TransformToggleButtons(options=["pi", "e"], transform=lambda x: x+x)
sage: w = TransformToggleButtons(options=["pi", "e"], transform=lambda x: x + x)
sage: w
TransformToggleButtons(options=('pi', 'e'), value='pi')
sage: w.get_interact_value()
Expand Down Expand Up @@ -240,7 +240,8 @@ class TransformIntRangeSlider(TransformWidget, IntRangeSlider):
EXAMPLES::

sage: from sage.repl.ipython_kernel.widgets import TransformIntRangeSlider
sage: w = TransformIntRangeSlider(min=0, max=100, value=(7,9), transform=lambda x: x[1]-x[0])
sage: w = TransformIntRangeSlider(min=0, max=100, value=(7, 9),
....: transform=lambda x: x[1] - x[0])
sage: w
TransformIntRangeSlider(value=(7, 9))
sage: w.get_interact_value()
Expand All @@ -257,7 +258,8 @@ class TransformFloatRangeSlider(TransformWidget, FloatRangeSlider):
EXAMPLES::

sage: from sage.repl.ipython_kernel.widgets import TransformFloatRangeSlider
sage: w = TransformFloatRangeSlider(min=0, max=100, value=(7,9), transform=lambda x: x[1]-x[0])
sage: w = TransformFloatRangeSlider(min=0, max=100, value=(7, 9),
....: transform=lambda x: x[1] - x[0])
sage: w
TransformFloatRangeSlider(value=(7.0, 9.0))
sage: w.get_interact_value()
Expand All @@ -274,7 +276,7 @@ class TransformText(TransformWidget, Text):
EXAMPLES::

sage: from sage.repl.ipython_kernel.widgets import TransformText
sage: w = TransformText(value="hello", transform=lambda x: x+x)
sage: w = TransformText(value="hello", transform=lambda x: x + x)
sage: w
TransformText(value='hello')
sage: w.get_interact_value()
Expand All @@ -291,7 +293,7 @@ class TransformTextarea(TransformWidget, Textarea):
EXAMPLES::

sage: from sage.repl.ipython_kernel.widgets import TransformTextarea
sage: w = TransformTextarea(value="hello", transform=lambda x: x+x)
sage: w = TransformTextarea(value="hello", transform=lambda x: x + x)
sage: w
TransformTextarea(value='hello')
sage: w.get_interact_value()
Expand Down Expand Up @@ -371,7 +373,10 @@ class Grid(TransformWidget, HBox, ValueWidget):
sage: from sage.repl.ipython_kernel.widgets import Grid
sage: w = Grid(2, 2, lambda i,j: Text(value="%s,%s"%(i,j)))
sage: w
Grid(value=[['0,0', '0,1'], ['1,0', '1,1']], children=(Label(value=''), VBox(children=(Text(value='0,0'), Text(value='1,0'))), VBox(children=(Text(value='0,1'), Text(value='1,1')))))
Grid(value=[['0,0', '0,1'], ['1,0', '1,1']],
children=(Label(value=''),
VBox(children=(Text(value='0,0'), Text(value='1,0'))),
VBox(children=(Text(value='0,1'), Text(value='1,1')))))
sage: w.get_interact_value()
[['0,0', '0,1'], ['1,0', '1,1']]
"""
Expand Down
6 changes: 3 additions & 3 deletions src/sage/repl/preparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
4
sage: 87.factor()
3 * 29
sage: 15.10.sqrt()
sage: 15.10.sqrt() # needs sage.rings.real_mpfr
3.88587184554509
sage: preparse('87.sqrt()')
'Integer(87).sqrt()'
Expand All @@ -83,7 +83,7 @@
Symbolic functional notation::

sage: # needs sage.symbolic
sage: a=10; f(theta, beta) = theta + beta; b = x^2 + theta
sage: a = 10; f(theta, beta) = theta + beta; b = x^2 + theta
sage: f
(theta, beta) |--> beta + theta
sage: a
Expand Down Expand Up @@ -1032,7 +1032,7 @@ def parse_ellipsis(code, preparse_step=True):
'(ellipsis_range(1,2,Ellipsis,n))'
sage: parse_ellipsis("for i in (f(x) .. L[10]):")
'for i in (ellipsis_iter(f(x) ,Ellipsis, L[10])):'
sage: [1.0..2.0]
sage: [1.0..2.0] # needs sage.rings.real_mpfr
[1.00000000000000, 2.00000000000000]

TESTS:
Expand Down
5 changes: 3 additions & 2 deletions src/sage/repl/user_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ def initialize_globals(all, g=None):

def get_global(name):
"""
Return the value of global variable ``name``. Raise ``NameError``
if there is no such global variable.
Return the value of global variable ``name``.

Raise :class:`NameError` if there is no such global variable.

INPUT:

Expand Down
Loading