<s> from __future__ import print_function , division , absolute_import <EOL> from datashape . dispatch import dispatch <EOL> from . coretypes import * <EOL> from . predicates import isdimension <EOL> from . util import dshape <EOL> import sys <EOL> from datetime import date , time , datetime <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> basetypes = np . generic , int , float , str , date , time , datetime <EOL> @ dispatch ( np . dtype , basetypes ) <EOL> def validate ( schema , value ) : <EOL> return np . issubdtype ( type ( value ) , schema ) <EOL> @ dispatch ( CType , basetypes ) <EOL> def validate ( schema , value ) : <EOL> return validate ( to_numpy_dtype ( schema ) , value ) <EOL> @ dispatch ( DataShape , ( tuple , list ) ) <EOL> def validate ( schema , value ) : <EOL> head = schema [ <NUM_LIT:0> ] <EOL> return ( ( len ( schema ) == <NUM_LIT:1> and validate ( head , value ) ) <EOL> or ( isdimension ( head ) <EOL> and ( isinstance ( head , Var ) or int ( head ) == len ( value ) ) <EOL> and all ( validate ( DataShape ( * schema [ <NUM_LIT:1> : ] ) , item ) for item in value ) ) ) <EOL> @ dispatch ( DataShape , object ) <EOL> def validate ( schema , value ) : <EOL> if len ( schema ) == <NUM_LIT:1> : <EOL> return validate ( schema [ <NUM_LIT:0> ] , value ) <EOL> @ dispatch ( Record , dict ) <EOL> def validate ( schema , d ) : <EOL> return all ( validate ( sch , d . get ( k ) ) for k , sch in schema . parameters [ <NUM_LIT:0> ] ) <EOL> @ dispatch ( Record , ( tuple , list ) ) <EOL> def validate ( schema , seq ) : <EOL> return all ( validate ( sch , item ) for ( k , sch ) , item <EOL> in zip ( schema . parameters [ <NUM_LIT:0> ] , seq ) ) <EOL> @ dispatch ( str , object ) <EOL> def validate ( schema , value ) : <EOL> return validate ( dshape ( schema ) , value ) <EOL> @ dispatch ( type , object ) <EOL> def validate ( schema , value ) : <EOL> return isinstance ( value , schema ) <EOL> @ dispatch ( tuple , object ) <EOL> def validate ( schemas , value ) : <EOL> return any ( validate ( schema , value ) for schema in schemas ) <EOL> @ dispatch ( object , object ) <EOL> def validate ( schema , value ) : <EOL> return False <EOL> @ validate . register ( String , str ) <EOL> @ validate . register ( Time , time ) <EOL> @ validate . register ( Date , date ) <EOL> @ validate . register ( DateTime , datetime ) <EOL> def validate_always_true ( schema , value ) : <EOL> return True <EOL> @ dispatch ( DataShape , np . ndarray ) <EOL> def validate ( schema , value ) : <EOL> return issubschema ( from_numpy ( value . shape , value . dtype ) , schema ) <EOL> @ dispatch ( object , object ) <EOL> def issubschema ( a , b ) : <EOL> return issubschema ( dshape ( a ) , dshape ( b ) ) <EOL> @ dispatch ( DataShape , DataShape ) <EOL> def issubschema ( a , b ) : <EOL> if a == b : <EOL> return True <EOL> return None </s>
