
    |Le                         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 Zd	 Zd
 Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$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                     t          | t                    rt          |           } t          | t                    rt	          |           dk    r| 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   dss    ?lib/python3.11/site-packages/datashader/datashape/predicates.pyr   r      sk     "c BZZ"i   SWW\\Ugb$++dK-@AAA    c                     t          | t                    rt          |           } t          | t                    rt	          |           dk    r| 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%   s    r'   r   r   $   sf     "c BZZ"i   SWW\\Ugb$++V444r(   c                 ,    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%   s    r'   r   r   5   s     b/***r(   c                     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%   s    r'   r   r   C   s>     
Bs6+wx'<'<==>>??1DDr(   c                 D    t          t          |           j                  S )z&Number of dimensions of datashape
    )r#   r   shaper%   s    r'   _dimensionsr0   R   s     vbzz   r(   c                    t          |           } t          | d         t                    rdS t          | d         t                    rdS t          | d         t                    r-t          t          t          | d         j                            S t          |           dk    r"t          | 
                    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#   subarrayr%   s    r'   r   r   X   s     
B"Q%!! t"Q% u"Q%   .3w1,,---
2ww{{r{{1~~&&&4r(   c                 n    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   r0   r   measurer%   s    r'   r   r   p   s/     
Br??a8HRZ$8$88r(   c                 t    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%   s    r'   r   r      s3     "c BZZr!ur(   c                     t          |           } 	 t          |           }t          | t                    ot	          j        |t          j                  S # t          $ r Y dS w xY w)z Has a numeric measure

    >>> isnumeric('int32')
    True
    >>> isnumeric('3 * ?real')
    True
    >>> isnumeric('string')
    False
    >>> isnumeric('var * {amount: ?int32}')
    False
    F)launderr   r!   r   np
issubdtypenumber	TypeError)r&   npdtypes     r'   r   r      sk     
BJ $$ "d##Igry(I(II    uus   A 
A"!A"c                     t          | t                    rt          |           } t          | t                    r| j        } t          | d|           S )Nr    )r!   r"   r   r   r7   r$   r%   s    r'   r:   r:      sJ    "c BZZ"i   Z2tR   r(   c                 \    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%   s    r'   r   r      s(     
Bb$2B(N2r(   c                 .    t          |           t          v S )z Has a boolean measure

    >>> isboolean('bool')
    True
    >>> isboolean('3 * ?bool')
    True
    >>> isboolean('int')
    False
    )r:   r   r%   s    r'   r   r      s     2;;'!!r(   c                 L    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%   s    r'   r   r      s"     
B;)"	/)r(   )&numpyr;   utilr   r   internal_utilsr   	coretypesr   r   r	   r
   r   r   r   r   r   r   r   typesetsr   r   __all__intr+   r   r   r   r   r0   r   r   r   r   r:   r   r   r    r(   r'   <module>rL      s       ! ! ! ! ! ! ! ! " " " " " "% % % % % % % % % % % % % % % % % % % % % % % % % % ( ' ' ' ' ' ' '   h+B B B"5 5 5"+ + +E E E! ! !  09 9 9 
 
 
J J J,! ! !3 3 3
" 
" 
"* * * * *r(   