How to use _build_number_equivalents method in pandera

Best Python code snippet using pandera_python

numpy_engine.py

Source:numpy_engine.py Github

copy

Full Screen

...89)90@immutable91class Bool(DataType, dtypes.Bool):92 type = np.dtype("bool")93def _build_number_equivalents(94 builtin_name: str, pandera_name: str, sizes: List[int]95) -> Dict[int, List[Union[type, str, np.dtype, dtypes.DataType]]]:96 """Return a dict of equivalent builtin, numpy, pandera dtypes97 indexed by size in bit_width."""98 builtin_type = getattr(builtins, builtin_name, None)99 default_np_dtype = np.dtype(builtin_name)100 default_size = int(default_np_dtype.name.replace(builtin_name, ""))101 default_equivalents = [102 # e.g.: np.int64103 np.dtype(builtin_name).type,104 # e.g: pandera.dtypes.Int105 getattr(dtypes, pandera_name),106 ]107 if builtin_type:108 default_equivalents.append(builtin_type)109 return {110 bit_width: list(111 set(112 (113 # e.g.: numpy.int64114 getattr(np, f"{builtin_name}{bit_width}"),115 # e.g.: pandera.dtypes.Int64116 getattr(dtypes, f"{pandera_name}{bit_width}"),117 getattr(dtypes, f"{pandera_name}{bit_width}")(),118 # e.g.: pandera.dtypes.Int(64)119 getattr(dtypes, pandera_name)(),120 )121 )122 | set(default_equivalents if bit_width == default_size else [])123 )124 for bit_width in sizes125 }126###############################################################################127# signed integer128###############################################################################129_int_equivalents = _build_number_equivalents(130 builtin_name="int", pandera_name="Int", sizes=[64, 32, 16, 8]131)132@Engine.register_dtype(equivalents=_int_equivalents[64])133@immutable134class Int64(DataType, dtypes.Int64):135 type = np.dtype("int64")136 bit_width: int = 64137@Engine.register_dtype(equivalents=_int_equivalents[32])138@immutable139class Int32(Int64):140 type = np.dtype("int32") # type: ignore141 bit_width: int = 32142@Engine.register_dtype(equivalents=_int_equivalents[16])143@immutable144class Int16(Int32):145 type = np.dtype("int16") # type: ignore146 bit_width: int = 16147@Engine.register_dtype(equivalents=_int_equivalents[8])148@immutable149class Int8(Int16):150 type = np.dtype("int8") # type: ignore151 bit_width: int = 8152###############################################################################153# unsigned integer154###############################################################################155_uint_equivalents = _build_number_equivalents(156 builtin_name="uint",157 pandera_name="UInt",158 sizes=[64, 32, 16, 8],159)160@Engine.register_dtype(equivalents=_uint_equivalents[64])161@immutable162class UInt64(DataType, dtypes.UInt64):163 type = np.dtype("uint64")164 bit_width: int = 64165@Engine.register_dtype(equivalents=_uint_equivalents[32])166@immutable167class UInt32(UInt64):168 type = np.dtype("uint32") # type: ignore169 bit_width: int = 32170@Engine.register_dtype(equivalents=_uint_equivalents[16])171@immutable172class UInt16(UInt32):173 type = np.dtype("uint16") # type: ignore174 bit_width: int = 16175@Engine.register_dtype(equivalents=_uint_equivalents[8])176@immutable177class UInt8(UInt16):178 type = np.dtype("uint8") # type: ignore179 bit_width: int = 8180###############################################################################181# float182###############################################################################183_float_equivalents = _build_number_equivalents(184 builtin_name="float",185 pandera_name="Float",186 sizes=[128, 64, 32, 16] if FLOAT_128_AVAILABLE else [64, 32, 16],187)188if FLOAT_128_AVAILABLE:189 # not supported in windows:190 # https://github.com/winpython/winpython/issues/613191 #192 # or Mac M1:193 # https://github.com/pandera-dev/pandera/issues/623194 @Engine.register_dtype(equivalents=_float_equivalents[128])195 @immutable196 class Float128(DataType, dtypes.Float128):197 type = np.dtype("float128")198 bit_width: int = 128199 @Engine.register_dtype(equivalents=_float_equivalents[64])200 @immutable201 class Float64(Float128):202 type = np.dtype("float64")203 bit_width: int = 64204else:205 @Engine.register_dtype(equivalents=_float_equivalents[64])206 @immutable207 class Float64(DataType, dtypes.Float64): # type: ignore208 type = np.dtype("float64")209 bit_width: int = 64210@Engine.register_dtype(equivalents=_float_equivalents[32])211@immutable212class Float32(Float64):213 type = np.dtype("float32") # type: ignore214 bit_width: int = 32215@Engine.register_dtype(equivalents=_float_equivalents[16])216@immutable217class Float16(Float32):218 type = np.dtype("float16") # type: ignore219 bit_width: int = 16220###############################################################################221# complex222###############################################################################223_complex_equivalents = _build_number_equivalents(224 builtin_name="complex",225 pandera_name="Complex",226 sizes=[256, 128, 64] if FLOAT_128_AVAILABLE else [128, 64],227)228if FLOAT_128_AVAILABLE:229 # not supported in windows230 # https://github.com/winpython/winpython/issues/613231 @Engine.register_dtype(equivalents=_complex_equivalents[256])232 @immutable233 class Complex256(DataType, dtypes.Complex256):234 type = np.dtype("complex256")235 bit_width: int = 256236 @Engine.register_dtype(equivalents=_complex_equivalents[128])237 @immutable...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pandera automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful