a
    ƒ¼Df	  ã                   @   s>   d dl mZ d dlZd dlmZ ddgZd	dd„Zdd„ ZdS )
é    )Úabsolute_importN)Ú	datashapeÚpromoteÚ	optionifyTc                 C   s€   | |kr| S t | d| ƒt |d|ƒ }}||  kr<tjkrHn ntj}n$t t |¡t |¡¡}tj |¡}|r|t| ||ƒ}|S )a›  Promote two scalar dshapes to a possibly larger, but compatible type.

    Examples
    --------
    >>> from datashader.datashape import int32, int64, Option, string
    >>> x = Option(int32)
    >>> y = int64
    >>> promote(x, y)
    Option(ty=ctype("int64"))
    >>> promote(int64, int64)
    ctype("int64")

    Don't promote to option types.
    >>> promote(x, y, promote_option=False)
    ctype("int64")

    Strings are handled differently than NumPy, which promotes to ctype("object")
    >>> x = string
    >>> y = Option(string)
    >>> promote(x, y) == promote(y, x) == Option(string)
    True
    >>> promote(x, y, promote_option=False)
    ctype("string")

    Notes
    ----
    Except for ``datashader.datashape.string`` types, this uses ``numpy.result_type`` for
    type promotion logic.  See the numpy documentation at:

    http://docs.scipy.org/doc/numpy/reference/generated/numpy.result_type.html
    Úty)	Úgetattrr   ÚstringÚnpZresult_typeZto_numpy_dtypeZCTypeZfrom_numpy_dtyper   )ÚlhsÚrhsZpromote_optionÚleftÚrightZdtypeZnp_res_type© r   úi/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/datashader/datashape/promote.pyr   
   s     ÿc                 C   s2   t |jdƒr|S t | dƒs$t |dƒr.t |¡S |S )aÃ  Check whether a binary operation's dshape came from
    :class:`~datashape.coretypes.Option` typed operands and construct an
    :class:`~datashape.coretypes.Option` type accordingly.

    Examples
    --------
    >>> from datashader.datashape import int32, int64, Option
    >>> x = Option(int32)
    >>> x
    Option(ty=ctype("int32"))
    >>> y = int64
    >>> y
    ctype("int64")
    >>> optionify(x, y, int64)
    Option(ty=ctype("int64"))
    r   )ÚhasattrZmeasurer   ÚOption)r
   r   Zdshaper   r   r   r   9   s
    
)T)	Ú
__future__r   Únumpyr	   Z
datashaderr   Ú__all__r   r   r   r   r   r   Ú<module>   s
   
/