How to use numpy_dtype method in pandera

Best Python code snippet using pandera_python

types.py

Source:types.py Github

copy

Full Screen

1# Copyright 2018 The TensorFlow Authors. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the 'License');4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an 'AS IS' BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14# ======================================15"""Utilities for XLA-specific Python types."""16from __future__ import absolute_import17from __future__ import division18from __future__ import print_function19import collections20import numpy as np21from tensorflow.compiler.xla import xla_data_pb222# Records corresponsence between a XLA primitive type and Python/Numpy types.23#24# primitive_type: value of type xla_data_pb2.PrimitiveType25# numpy_dtype: corresponsing Numpy "dtype" (like np.float32)26# literal_field_name: name of the field in the LiteralProto message elements27# of this type go into.28# literal_field_type: type of the field named 'literal_field_name'.29#30# TODO(eliben): figure out how to avoid knowing the extra Python type and the31# astype cast when writing into Literals.32TypeConversionRecord = collections.namedtuple('TypeConversionRecord', [33 'primitive_type', 'numpy_dtype', 'literal_field_name', 'literal_field_type'34])35# Maps from XLA primitive types to TypeConversionRecord.36MAP_XLA_TYPE_TO_RECORD = {37 xla_data_pb2.F16:38 TypeConversionRecord(39 primitive_type=xla_data_pb2.F16,40 numpy_dtype=np.float16,41 literal_field_name='f16s',42 literal_field_type=float),43 xla_data_pb2.F32:44 TypeConversionRecord(45 primitive_type=xla_data_pb2.F32,46 numpy_dtype=np.float32,47 literal_field_name='f32s',48 literal_field_type=float),49 xla_data_pb2.F64:50 TypeConversionRecord(51 primitive_type=xla_data_pb2.F64,52 numpy_dtype=np.float64,53 literal_field_name='f64s',54 literal_field_type=float),55 xla_data_pb2.S8:56 TypeConversionRecord(57 primitive_type=xla_data_pb2.S8,58 numpy_dtype=np.int8,59 literal_field_name='s8s',60 literal_field_type=int),61 xla_data_pb2.S16:62 TypeConversionRecord(63 primitive_type=xla_data_pb2.S16,64 numpy_dtype=np.int16,65 literal_field_name='s16s',66 literal_field_type=int),67 xla_data_pb2.S32:68 TypeConversionRecord(69 primitive_type=xla_data_pb2.S32,70 numpy_dtype=np.int32,71 literal_field_name='s32s',72 literal_field_type=int),73 xla_data_pb2.S64:74 TypeConversionRecord(75 primitive_type=xla_data_pb2.S64,76 numpy_dtype=np.int64,77 literal_field_name='s64s',78 literal_field_type=int),79 xla_data_pb2.U8:80 TypeConversionRecord(81 primitive_type=xla_data_pb2.U8,82 numpy_dtype=np.uint8,83 literal_field_name='s8s',84 literal_field_type=int),85 xla_data_pb2.U16:86 TypeConversionRecord(87 primitive_type=xla_data_pb2.U16,88 numpy_dtype=np.uint16,89 literal_field_name='s16s',90 literal_field_type=int),91 xla_data_pb2.U32:92 TypeConversionRecord(93 primitive_type=xla_data_pb2.U32,94 numpy_dtype=np.uint32,95 literal_field_name='s32s',96 literal_field_type=int),97 xla_data_pb2.U64:98 TypeConversionRecord(99 primitive_type=xla_data_pb2.U64,100 numpy_dtype=np.uint64,101 literal_field_name='s64s',102 literal_field_type=int),103 xla_data_pb2.PRED:104 TypeConversionRecord(105 primitive_type=xla_data_pb2.PRED,106 numpy_dtype=np.bool,107 literal_field_name='preds',108 literal_field_type=bool)109}110# Maps from Numpy dtypes to TypeConversionRecord.111# Note the conversion on the key. Numpy has a known issue wherein dtype hashing112# doesn't work as expected (https://github.com/numpy/numpy/issues/7242). Thus,113# when keying by dtype in this dict, we use the string form of dtypes.114MAP_DTYPE_TO_RECORD = {115 str(np.dtype(record.numpy_dtype)): record116 for record in MAP_XLA_TYPE_TO_RECORD.values()...

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