How to use test_parallel method in tox

Best Python code snippet using tox_python

gil.py

Source:gil.py Github

copy

Full Screen

...12 from pandas.util.testing import test_parallel13 have_real_test_parallel = True14except ImportError:15 have_real_test_parallel = False16 def test_parallel(num_threads=1):17 def wrapper(fname):18 return fname19 return wrapper20class NoGilGroupby(object):21 goal_time = 0.222 def setup(self):23 self.N = 100000024 self.ngroups = 100025 np.random.seed(1234)26 self.df = DataFrame({'key': np.random.randint(0, self.ngroups, size=self.N), 'data': np.random.randn(self.N), })27 np.random.seed(1234)28 self.size = 2 ** 2229 self.ngroups = 10030 self.data = Series(np.random.randint(0, self.ngroups, size=self.size))31 if (not have_real_test_parallel):32 raise NotImplementedError33 @test_parallel(num_threads=2)34 def _pg2_count(self):35 self.df.groupby('key')['data'].count()36 def time_count_2(self):37 self._pg2_count()38 @test_parallel(num_threads=2)39 def _pg2_last(self):40 self.df.groupby('key')['data'].last()41 def time_last_2(self):42 self._pg2_last()43 @test_parallel(num_threads=2)44 def _pg2_max(self):45 self.df.groupby('key')['data'].max()46 def time_max_2(self):47 self._pg2_max()48 @test_parallel(num_threads=2)49 def _pg2_mean(self):50 self.df.groupby('key')['data'].mean()51 def time_mean_2(self):52 self._pg2_mean()53 @test_parallel(num_threads=2)54 def _pg2_min(self):55 self.df.groupby('key')['data'].min()56 def time_min_2(self):57 self._pg2_min()58 @test_parallel(num_threads=2)59 def _pg2_prod(self):60 self.df.groupby('key')['data'].prod()61 def time_prod_2(self):62 self._pg2_prod()63 @test_parallel(num_threads=2)64 def _pg2_sum(self):65 self.df.groupby('key')['data'].sum()66 def time_sum_2(self):67 self._pg2_sum()68 @test_parallel(num_threads=4)69 def _pg4_sum(self):70 self.df.groupby('key')['data'].sum()71 def time_sum_4(self):72 self._pg4_sum()73 def time_sum_4_notp(self):74 for i in range(4):75 self.df.groupby('key')['data'].sum()76 def _f_sum(self):77 self.df.groupby('key')['data'].sum()78 @test_parallel(num_threads=8)79 def _pg8_sum(self):80 self._f_sum()81 def time_sum_8(self):82 self._pg8_sum()83 def time_sum_8_notp(self):84 for i in range(8):85 self._f_sum()86 @test_parallel(num_threads=2)87 def _pg2_var(self):88 self.df.groupby('key')['data'].var()89 def time_var_2(self):90 self._pg2_var()91 # get groups92 def _groups(self):93 self.data.groupby(self.data).groups94 @test_parallel(num_threads=2)95 def _pg2_groups(self):96 self._groups()97 def time_groups_2(self):98 self._pg2_groups()99 @test_parallel(num_threads=4)100 def _pg4_groups(self):101 self._groups()102 def time_groups_4(self):103 self._pg4_groups()104 @test_parallel(num_threads=8)105 def _pg8_groups(self):106 self._groups()107 def time_groups_8(self):108 self._pg8_groups()109class nogil_take1d_float64(object):110 goal_time = 0.2111 def setup(self):112 self.N = 1000000113 self.ngroups = 1000114 np.random.seed(1234)115 self.df = DataFrame({'key': np.random.randint(0, self.ngroups, size=self.N), 'data': np.random.randn(self.N), })116 if (not have_real_test_parallel):117 raise NotImplementedError118 self.N = 10000000.0119 self.df = DataFrame({'int64': np.arange(self.N, dtype='int64'), 'float64': np.arange(self.N, dtype='float64'), })120 self.indexer = np.arange(100, (len(self.df) - 100))121 def time_nogil_take1d_float64(self):122 self.take_1d_pg2_int64()123 @test_parallel(num_threads=2)124 def take_1d_pg2_int64(self):125 take_1d(self.df.int64.values, self.indexer)126 @test_parallel(num_threads=2)127 def take_1d_pg2_float64(self):128 take_1d(self.df.float64.values, self.indexer)129class nogil_take1d_int64(object):130 goal_time = 0.2131 def setup(self):132 self.N = 1000000133 self.ngroups = 1000134 np.random.seed(1234)135 self.df = DataFrame({'key': np.random.randint(0, self.ngroups, size=self.N), 'data': np.random.randn(self.N), })136 if (not have_real_test_parallel):137 raise NotImplementedError138 self.N = 10000000.0139 self.df = DataFrame({'int64': np.arange(self.N, dtype='int64'), 'float64': np.arange(self.N, dtype='float64'), })140 self.indexer = np.arange(100, (len(self.df) - 100))141 def time_nogil_take1d_int64(self):142 self.take_1d_pg2_float64()143 @test_parallel(num_threads=2)144 def take_1d_pg2_int64(self):145 take_1d(self.df.int64.values, self.indexer)146 @test_parallel(num_threads=2)147 def take_1d_pg2_float64(self):148 take_1d(self.df.float64.values, self.indexer)149class nogil_kth_smallest(object):150 number = 1151 repeat = 5152 def setup(self):153 if (not have_real_test_parallel):154 raise NotImplementedError155 np.random.seed(1234)156 self.N = 10000000157 self.k = 500000158 self.a = np.random.randn(self.N)159 self.b = self.a.copy()160 self.kwargs_list = [{'arr': self.a}, {'arr': self.b}]161 def time_nogil_kth_smallest(self):162 @test_parallel(num_threads=2, kwargs_list=self.kwargs_list)163 def run(arr):164 algos.kth_smallest(arr, self.k)165 run()166class nogil_datetime_fields(object):167 goal_time = 0.2168 def setup(self):169 self.N = 100000000170 self.dti = pd.date_range('1900-01-01', periods=self.N, freq='T')171 self.period = self.dti.to_period('D')172 if (not have_real_test_parallel):173 raise NotImplementedError174 def time_datetime_field_year(self):175 @test_parallel(num_threads=2)176 def run(dti):177 dti.year178 run(self.dti)179 def time_datetime_field_day(self):180 @test_parallel(num_threads=2)181 def run(dti):182 dti.day183 run(self.dti)184 def time_datetime_field_daysinmonth(self):185 @test_parallel(num_threads=2)186 def run(dti):187 dti.days_in_month188 run(self.dti)189 def time_datetime_field_normalize(self):190 @test_parallel(num_threads=2)191 def run(dti):192 dti.normalize()193 run(self.dti)194 def time_datetime_to_period(self):195 @test_parallel(num_threads=2)196 def run(dti):197 dti.to_period('S')198 run(self.dti)199 def time_period_to_datetime(self):200 @test_parallel(num_threads=2)201 def run(period):202 period.to_timestamp()203 run(self.period)204class nogil_rolling_algos_slow(object):205 goal_time = 0.2206 def setup(self):207 self.win = 100208 np.random.seed(1234)209 self.arr = np.random.rand(100000)210 if (not have_real_test_parallel):211 raise NotImplementedError212 def time_nogil_rolling_median(self):213 @test_parallel(num_threads=2)214 def run(arr, win):215 rolling_median(arr, win)216 run(self.arr, self.win)217class nogil_rolling_algos_fast(object):218 goal_time = 0.2219 def setup(self):220 self.win = 100221 np.random.seed(1234)222 self.arr = np.random.rand(1000000)223 if (not have_real_test_parallel):224 raise NotImplementedError225 def time_nogil_rolling_mean(self):226 @test_parallel(num_threads=2)227 def run(arr, win):228 rolling_mean(arr, win)229 run(self.arr, self.win)230 def time_nogil_rolling_min(self):231 @test_parallel(num_threads=2)232 def run(arr, win):233 rolling_min(arr, win)234 run(self.arr, self.win)235 def time_nogil_rolling_max(self):236 @test_parallel(num_threads=2)237 def run(arr, win):238 rolling_max(arr, win)239 run(self.arr, self.win)240 def time_nogil_rolling_var(self):241 @test_parallel(num_threads=2)242 def run(arr, win):243 rolling_var(arr, win)244 run(self.arr, self.win)245 def time_nogil_rolling_skew(self):246 @test_parallel(num_threads=2)247 def run(arr, win):248 rolling_skew(arr, win)249 run(self.arr, self.win)250 def time_nogil_rolling_kurt(self):251 @test_parallel(num_threads=2)252 def run(arr, win):253 rolling_kurt(arr, win)254 run(self.arr, self.win)255 def time_nogil_rolling_std(self):256 @test_parallel(num_threads=2)257 def run(arr, win):258 rolling_std(arr, win)259 run(self.arr, self.win)260class nogil_read_csv(object):261 number = 1262 repeat = 5263 def setup(self):264 if (not have_real_test_parallel):265 raise NotImplementedError266 # Using the values267 self.df = DataFrame(np.random.randn(10000, 50))268 self.df.to_csv('__test__.csv')269 self.rng = date_range('1/1/2000', periods=10000)270 self.df_date_time = DataFrame(np.random.randn(10000, 50), index=self.rng)271 self.df_date_time.to_csv('__test_datetime__.csv')272 self.df_object = DataFrame('foo', index=self.df.index, columns=self.create_cols('object'))273 self.df_object.to_csv('__test_object__.csv')274 def create_cols(self, name):275 return [('%s%03d' % (name, i)) for i in range(5)]276 @test_parallel(num_threads=2)277 def pg_read_csv(self):278 read_csv('__test__.csv', sep=',', header=None, float_precision=None)279 def time_read_csv(self):280 self.pg_read_csv()281 @test_parallel(num_threads=2)282 def pg_read_csv_object(self):283 read_csv('__test_object__.csv', sep=',')284 def time_read_csv_object(self):285 self.pg_read_csv_object()286 @test_parallel(num_threads=2)287 def pg_read_csv_datetime(self):288 read_csv('__test_datetime__.csv', sep=',', header=None)289 def time_read_csv_datetime(self):290 self.pg_read_csv_datetime()291class nogil_factorize(object):292 number = 1293 repeat = 5294 def setup(self):295 if (not have_real_test_parallel):296 raise NotImplementedError297 np.random.seed(1234)298 self.strings = tm.makeStringIndex(100000)299 def factorize_strings(self):300 pd.factorize(self.strings)301 @test_parallel(num_threads=4)302 def _pg_factorize_strings_4(self):303 self.factorize_strings()304 def time_factorize_strings_4(self):305 for i in range(2):306 self._pg_factorize_strings_4()307 @test_parallel(num_threads=2)308 def _pg_factorize_strings_2(self):309 self.factorize_strings()310 def time_factorize_strings_2(self):311 for i in range(4):312 self._pg_factorize_strings_2()313 def time_factorize_strings(self):314 for i in range(8):...

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 tox 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