Best Python code snippet using pandera_python
common.py
Source:common.py  
1import numpy as np2from pandas import compat3from pandas.util._decorators import cache_readonly4import pandas.util.testing as tm5import pandas as pd6_seriesd = tm.getSeriesData()7_tsd = tm.getTimeSeriesData()8_frame = pd.DataFrame(_seriesd)9_frame2 = pd.DataFrame(_seriesd, columns=['D', 'C', 'B', 'A'])10_intframe = pd.DataFrame(dict((k, v.astype(int))11                              for k, v in compat.iteritems(_seriesd)))12_tsframe = pd.DataFrame(_tsd)13_mixed_frame = _frame.copy()14_mixed_frame['foo'] = 'bar'15class TestData(object):16    @cache_readonly17    def frame(self):18        return _frame.copy()19    @cache_readonly20    def frame2(self):21        return _frame2.copy()22    @cache_readonly23    def intframe(self):24        # force these all to int64 to avoid platform testing issues25        return pd.DataFrame(dict([(c, s) for c, s in26                                  compat.iteritems(_intframe)]),27                            dtype=np.int64)28    @cache_readonly29    def tsframe(self):30        return _tsframe.copy()31    @cache_readonly32    def mixed_frame(self):33        return _mixed_frame.copy()34    @cache_readonly35    def mixed_float(self):36        return pd.DataFrame({'A': _frame['A'].copy().astype('float32'),37                             'B': _frame['B'].copy().astype('float32'),38                             'C': _frame['C'].copy().astype('float16'),39                             'D': _frame['D'].copy().astype('float64')})40    @cache_readonly41    def mixed_float2(self):42        return pd.DataFrame({'A': _frame2['A'].copy().astype('float32'),43                             'B': _frame2['B'].copy().astype('float32'),44                             'C': _frame2['C'].copy().astype('float16'),45                             'D': _frame2['D'].copy().astype('float64')})46    @cache_readonly47    def mixed_int(self):48        return pd.DataFrame({'A': _intframe['A'].copy().astype('int32'),49                             'B': np.ones(len(_intframe['B']), dtype='uint64'),50                             'C': _intframe['C'].copy().astype('uint8'),51                             'D': _intframe['D'].copy().astype('int64')})52    @cache_readonly53    def all_mixed(self):54        return pd.DataFrame({'a': 1., 'b': 2, 'c': 'foo',55                             'float32': np.array([1.] * 10, dtype='float32'),56                             'int32': np.array([1] * 10, dtype='int32')},57                            index=np.arange(10))58    @cache_readonly59    def tzframe(self):60        result = pd.DataFrame({'A': pd.date_range('20130101', periods=3),61                               'B': pd.date_range('20130101', periods=3,62                                                  tz='US/Eastern'),63                               'C': pd.date_range('20130101', periods=3,64                                                  tz='CET')})65        result.iloc[1, 1] = pd.NaT66        result.iloc[1, 2] = pd.NaT67        return result68    @cache_readonly69    def empty(self):70        return pd.DataFrame({})71    @cache_readonly72    def ts1(self):73        return tm.makeTimeSeries(nper=30)74    @cache_readonly75    def ts2(self):76        return tm.makeTimeSeries(nper=30)[5:]77    @cache_readonly78    def simple(self):79        arr = np.array([[1., 2., 3.],80                        [4., 5., 6.],81                        [7., 8., 9.]])82        return pd.DataFrame(arr, columns=['one', 'two', 'three'],83                            index=['a', 'b', 'c'])84# self.ts3 = tm.makeTimeSeries()[-5:]85# self.ts4 = tm.makeTimeSeries()[1:-1]86def _check_mixed_float(df, dtype=None):87    # float16 are most likely to be upcasted to float3288    dtypes = dict(A='float32', B='float32', C='float16', D='float64')89    if isinstance(dtype, compat.string_types):90        dtypes = dict([(k, dtype) for k, v in dtypes.items()])91    elif isinstance(dtype, dict):92        dtypes.update(dtype)93    if dtypes.get('A'):94        assert(df.dtypes['A'] == dtypes['A'])95    if dtypes.get('B'):96        assert(df.dtypes['B'] == dtypes['B'])97    if dtypes.get('C'):98        assert(df.dtypes['C'] == dtypes['C'])99    if dtypes.get('D'):100        assert(df.dtypes['D'] == dtypes['D'])101def _check_mixed_int(df, dtype=None):102    dtypes = dict(A='int32', B='uint64', C='uint8', D='int64')103    if isinstance(dtype, compat.string_types):104        dtypes = dict([(k, dtype) for k, v in dtypes.items()])105    elif isinstance(dtype, dict):106        dtypes.update(dtype)107    if dtypes.get('A'):108        assert(df.dtypes['A'] == dtypes['A'])109    if dtypes.get('B'):110        assert(df.dtypes['B'] == dtypes['B'])111    if dtypes.get('C'):112        assert(df.dtypes['C'] == dtypes['C'])113    if dtypes.get('D'):...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
