Ejemplo n.º 1
0
def ipython():
    ''' A PyTest fixture that will automatically skip a test if IPython is
    not installed.

    '''
    ipython = import_optional('IPython')
    if ipython is None:
        pytest.skip('IPython is not installed')
    return ipython
Ejemplo n.º 2
0
def pd() -> ModuleType | None: # XXX: should be pandas | None, but not supported
    ''' A PyTest fixture that will automatically skip a test if Pandas is
    not installed.

    '''
    pandas = import_optional('pandas')
    if pandas is None:
        pytest.skip('pandas is not installed')
    return pandas
Ejemplo n.º 3
0
def pd():
    ''' A PyTest fixture that will automatically skip a test if Pandas is
    not installed.

    '''
    pandas = import_optional('pandas')
    if pandas is None:
        pytest.skip('pandas is not installed')
    return pandas
Ejemplo n.º 4
0
def pd():
    ''' A PyTest fixture that will automatically skip a test if Pandas is
    not installed.

    '''
    pandas = import_optional('pandas')
    if pandas is None:
        pytest.skip('pandas is not installed')
    return pandas
Ejemplo n.º 5
0
def nx(
) -> ModuleType | None:  # XXX: should be networkx | None, but not supported
    ''' A PyTest fixture that will automatically skip a test if networkx is
    not installed.

    '''
    nx = import_optional('networkx')
    if nx is None:
        pytest.skip('networkx is not installed')
    return nx
Ejemplo n.º 6
0
def ipython(
) -> ModuleType | None:  # XXX: should be IPython | None, but not supported
    ''' A PyTest fixture that will automatically skip a test if IPython is
    not installed.

    '''
    ipython = import_optional('IPython')
    if ipython is None:
        pytest.skip('IPython is not installed')
    return ipython
Ejemplo n.º 7
0
import base64

import numpy as np

import warnings

import matplotlib
from matplotlib.colors import colorConverter
from matplotlib.path import Path
from matplotlib.markers import MarkerStyle
from matplotlib.transforms import Affine2D
from matplotlib import ticker

# NOTE: bokeh mod
from bokeh.util.dependencies import import_optional
pd = import_optional('pandas')


def color_to_hex(color):
    """Convert matplotlib color code to hex color code"""
    if color is None or colorConverter.to_rgba(color)[3] == 0:
        return 'none'
    else:
        rgb = colorConverter.to_rgb(color)
        return '#{0:02X}{1:02X}{2:02X}'.format(*(int(255 * c) for c in rgb))


def _many_to_one(input_dict):
    """Convert a many-to-one mapping to a one-to-one mapping"""
    return dict((key, val) for keys, val in input_dict.items() for key in keys)
def _version(modname: str, attr: str) -> Optional[Any]:
    mod = import_optional(modname)
    if mod:
        return getattr(mod, attr)
    else:  # explicit None return for mypy typing
        return None
def test_optional_fail():
    assert dep.import_optional('bleepbloop') is None
Ejemplo n.º 10
0
Archivo: utils.py Proyecto: 0-T-0/bokeh
import base64

import numpy as np

import warnings

import matplotlib
from matplotlib.colors import colorConverter
from matplotlib.path import Path
from matplotlib.markers import MarkerStyle
from matplotlib.transforms import Affine2D
from matplotlib import ticker

# NOTE: bokeh mod
from bokeh.util.dependencies import import_optional
pd = import_optional('pandas')

def color_to_hex(color):
    """Convert matplotlib color code to hex color code"""
    if color is None or colorConverter.to_rgba(color)[3] == 0:
        return 'none'
    else:
        rgb = colorConverter.to_rgb(color)
        return '#{0:02X}{1:02X}{2:02X}'.format(*(int(255 * c) for c in rgb))


def _many_to_one(input_dict):
    """Convert a many-to-one mapping to a one-to-one mapping"""
    return dict((key, val)
                for keys, val in input_dict.items()
                for key in keys)
Ejemplo n.º 11
0
 def test_success(self):
     assert dep.import_optional('sys') is not None
Ejemplo n.º 12
0
 def test_fail(self) -> None:
     assert dep.import_optional('bleepbloop') is None
Ejemplo n.º 13
0
 def test_success(self) -> None:
     assert dep.import_optional('sys') is not None
Ejemplo n.º 14
0
try:
    from urllib.request import urlopen
except ImportError:  # python 2
    from urllib import urlopen

from io import BytesIO
from six import string_types

import param

from bokeh.util.dependencies import import_optional
from pyviz_comms import JupyterComm

from .base import PaneBase

vtk = import_optional('vtk')

arrayTypesMapping = '  bBhHiIlLfdL'  # last one is idtype

_js_mapping = {
    'b': 'Int8Array',
    'B': 'Uint8Array',
    'h': 'Int16Array',
    'H': 'Int16Array',
    'i': 'Int32Array',
    'I': 'Uint32Array',
    'l': 'Int32Array',
    'L': 'Uint32Array',
    'f': 'Float32Array',
    'd': 'Float64Array'
}
Ejemplo n.º 15
0
def _version(modname, attr):
    mod = import_optional(modname)
    if mod:
        return getattr(mod, attr)
Ejemplo n.º 16
0
def _version(module_name: str, attr: str) -> str | None:
    module = import_optional(module_name)
    return getattr(module, attr) if module else None
def test_optional_success():
    assert dep.import_optional('sys') is not None
Ejemplo n.º 18
0
def _version(modname, attr):
    mod = import_optional(modname)
    if mod:
        return getattr(mod, attr)
Ejemplo n.º 19
0
 def test_fail(self):
     assert dep.import_optional('bleepbloop') is None