a
    Df                     @   s   d dl ZddlmZmZ ddlmZ ddlmZm	Z	m
Z
mZmZmZmZmZmZmZmZ ddlmZmZ g dZe	e
eefZdd	 Zd
d Zdd Zdd Zdd Zdd Zdd Zdd Z dd Z!dd Z"dd Z#dd Z$d d! Z%dS )"    N   )collectdshape)remove)	DataShapeFixedVarEllipsisRecordUnitdate_	datetime_TypeVarto_numpy_dtypeCategorical)floatingboolean)isdimensionishomogeneous	istabularisfixedisscalarisrecordiscollection	isnumeric	isboolean
isdatelikeisrealc                 C   sF   t | trt| } t | tr0t| dkr0| d } t t| d| ttfS )z Is this dshape a single dtype?

    >>> isscalar('int')
    True
    >>> isscalar('?int')
    True
    >>> isscalar('{name: string, amount: int}')
    False
    r   r   ty)
isinstancestrr   r   lengetattrr   r   ds r%   l/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/datashader/datashape/predicates.pyr      s
    

r   c                 C   sB   t | trt| } t | tr0t| dkr0| d } t t| d| tS )z Is this dshape a record type?

    >>> isrecord('{name: string, amount: int}')
    True
    >>> isrecord('int')
    False
    >>> isrecord('?{name: string, amount: int}')
    True
    r   r   r   )r   r    r   r   r!   r"   r
   r#   r%   r%   r&   r   $   s
    

r   c                 C   s
   t | tS )z Is a component a dimension?

    >>> from datashader.datashape import int32
    >>> isdimension(Fixed(10))
    True
    >>> isdimension(Var())
    True
    >>> isdimension(int32)
    False
    )r   dimension_typesr#   r%   r%   r&   r   5   s    r   c                 C   s$   t | } tttttt| dkS )z Does datashape contain only one dtype?

    >>> from datashader.datashape import int32
    >>> ishomogeneous(int32)
    True
    >>> ishomogeneous('var * 3 * string')
    True
    >>> ishomogeneous('var * {name: string, amount: int}')
    False
    r   )r   r!   setr   r   r   r   r#   r%   r%   r&   r   C   s    r   c                 C   s   t t| jS )z&Number of dimensions of datashape
    )r!   r   shaper#   r%   r%   r&   _dimensionsR   s    r*   c                 C   sl   t | } t| d trdS t| d tr,dS t| d trNttt| d jS t	| dkrht| 
dS dS )z Contains no variable dimensions

    >>> isfixed('10 * int')
    True
    >>> isfixed('var * int')
    False
    >>> isfixed('10 * {name: string, amount: int}')
    True
    >>> isfixed('10 * {name: string, amounts: var * int}')
    False
    r   NFr   T)r   r   r   r   r
   allmapr   typesr!   Zsubarrayr#   r%   r%   r&   r   X   s    r   c                 C   s   t | } t| dkot| jS )z A collection of records

    >>> istabular('var * {name: string, amount: int}')
    True
    >>> istabular('var * 10 * 3 * int')
    False
    >>> istabular('10 * var * int')
    False
    >>> istabular('var * (int64, string, ?float64)')
    False
    r   )r   r*   r   measurer#   r%   r%   r&   r   p   s    r   c                 C   s   t | trt| } t| d S )z Is a collection of items, has dimension

    >>> iscollection('5 * int32')
    True
    >>> iscollection('int32')
    False
    r   )r   r    r   r   r#   r%   r%   r&   r      s    
r   c                 C   sF   t | } zt| }W n ty(   Y dS 0 t| to@t|tjS dS )z Has a numeric measure

    >>> isnumeric('int32')
    True
    >>> isnumeric('3 * ?real')
    True
    >>> isnumeric('string')
    False
    >>> isnumeric('var * {amount: ?int32}')
    False
    FN)launderr   	TypeErrorr   r   npZ
issubdtypenumber)r$   Znpdtyper%   r%   r&   r      s    r   c                 C   s.   t | trt| } t | tr"| j} t| d| S )Nr   )r   r    r   r   r.   r"   r#   r%   r%   r&   r/      s
    

r/   c                 C   s   t | } t| to| tv S )z Has a numeric measure

    >>> isreal('float32')
    True
    >>> isreal('3 * ?real')
    True
    >>> isreal('string')
    False
    )r/   r   r   r   r#   r%   r%   r&   r      s    
r   c                 C   s   t | tv S )z Has a boolean measure

    >>> isboolean('bool')
    True
    >>> isboolean('3 * ?bool')
    True
    >>> isboolean('int')
    False
    )r/   r   r#   r%   r%   r&   r      s    
r   c                 C   s   t | } | tkp| tkS )z Has a date or datetime measure

    >>> isdatelike('int32')
    False
    >>> isdatelike('3 * datetime')
    True
    >>> isdatelike('?datetime')
    True
    )r/   r   r   r#   r%   r%   r&   r      s    
r   )&numpyr1   utilr   r   Zinternal_utilsr   Z	coretypesr   r   r   r	   r
   r   r   r   r   r   r   Ztypesetsr   r   __all__intr'   r   r   r   r   r*   r   r   r   r   r/   r   r   r   r%   r%   r%   r&   <module>   s&   4