How to use monotonic method in pytest-benchmark

Best Python code snippet using pytest-benchmark

test_monotonic.py

Source:test_monotonic.py Github

copy

Full Screen

1import numpy as np2import pandas as pd3from pandas import Index, MultiIndex4def test_is_monotonic_increasing():5 i = MultiIndex.from_product([np.arange(10), np.arange(10)], names=["one", "two"])6 assert i.is_monotonic is True7 assert i._is_strictly_monotonic_increasing is True8 assert Index(i.values).is_monotonic is True9 assert i._is_strictly_monotonic_increasing is True10 i = MultiIndex.from_product(11 [np.arange(10, 0, -1), np.arange(10)], names=["one", "two"]12 )13 assert i.is_monotonic is False14 assert i._is_strictly_monotonic_increasing is False15 assert Index(i.values).is_monotonic is False16 assert Index(i.values)._is_strictly_monotonic_increasing is False17 i = MultiIndex.from_product(18 [np.arange(10), np.arange(10, 0, -1)], names=["one", "two"]19 )20 assert i.is_monotonic is False21 assert i._is_strictly_monotonic_increasing is False22 assert Index(i.values).is_monotonic is False23 assert Index(i.values)._is_strictly_monotonic_increasing is False24 i = MultiIndex.from_product([[1.0, np.nan, 2.0], ["a", "b", "c"]])25 assert i.is_monotonic is False26 assert i._is_strictly_monotonic_increasing is False27 assert Index(i.values).is_monotonic is False28 assert Index(i.values)._is_strictly_monotonic_increasing is False29 # string ordering30 i = MultiIndex(31 levels=[["foo", "bar", "baz", "qux"], ["one", "two", "three"]],32 codes=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3], [0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],33 names=["first", "second"],34 )35 assert i.is_monotonic is False36 assert Index(i.values).is_monotonic is False37 assert i._is_strictly_monotonic_increasing is False38 assert Index(i.values)._is_strictly_monotonic_increasing is False39 i = MultiIndex(40 levels=[["bar", "baz", "foo", "qux"], ["mom", "next", "zenith"]],41 codes=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3], [0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],42 names=["first", "second"],43 )44 assert i.is_monotonic is True45 assert Index(i.values).is_monotonic is True46 assert i._is_strictly_monotonic_increasing is True47 assert Index(i.values)._is_strictly_monotonic_increasing is True48 # mixed levels, hits the TypeError49 i = MultiIndex(50 levels=[51 [1, 2, 3, 4],52 [53 "gb00b03mlx29",54 "lu0197800237",55 "nl0000289783",56 "nl0000289965",57 "nl0000301109",58 ],59 ],60 codes=[[0, 1, 1, 2, 2, 2, 3], [4, 2, 0, 0, 1, 3, -1]],61 names=["household_id", "asset_id"],62 )63 assert i.is_monotonic is False64 assert i._is_strictly_monotonic_increasing is False65 # empty66 i = MultiIndex.from_arrays([[], []])67 assert i.is_monotonic is True68 assert Index(i.values).is_monotonic is True69 assert i._is_strictly_monotonic_increasing is True70 assert Index(i.values)._is_strictly_monotonic_increasing is True71def test_is_monotonic_decreasing():72 i = MultiIndex.from_product(73 [np.arange(9, -1, -1), np.arange(9, -1, -1)], names=["one", "two"]74 )75 assert i.is_monotonic_decreasing is True76 assert i._is_strictly_monotonic_decreasing is True77 assert Index(i.values).is_monotonic_decreasing is True78 assert i._is_strictly_monotonic_decreasing is True79 i = MultiIndex.from_product(80 [np.arange(10), np.arange(10, 0, -1)], names=["one", "two"]81 )82 assert i.is_monotonic_decreasing is False83 assert i._is_strictly_monotonic_decreasing is False84 assert Index(i.values).is_monotonic_decreasing is False85 assert Index(i.values)._is_strictly_monotonic_decreasing is False86 i = MultiIndex.from_product(87 [np.arange(10, 0, -1), np.arange(10)], names=["one", "two"]88 )89 assert i.is_monotonic_decreasing is False90 assert i._is_strictly_monotonic_decreasing is False91 assert Index(i.values).is_monotonic_decreasing is False92 assert Index(i.values)._is_strictly_monotonic_decreasing is False93 i = MultiIndex.from_product([[2.0, np.nan, 1.0], ["c", "b", "a"]])94 assert i.is_monotonic_decreasing is False95 assert i._is_strictly_monotonic_decreasing is False96 assert Index(i.values).is_monotonic_decreasing is False97 assert Index(i.values)._is_strictly_monotonic_decreasing is False98 # string ordering99 i = MultiIndex(100 levels=[["qux", "foo", "baz", "bar"], ["three", "two", "one"]],101 codes=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3], [0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],102 names=["first", "second"],103 )104 assert i.is_monotonic_decreasing is False105 assert Index(i.values).is_monotonic_decreasing is False106 assert i._is_strictly_monotonic_decreasing is False107 assert Index(i.values)._is_strictly_monotonic_decreasing is False108 i = MultiIndex(109 levels=[["qux", "foo", "baz", "bar"], ["zenith", "next", "mom"]],110 codes=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3], [0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],111 names=["first", "second"],112 )113 assert i.is_monotonic_decreasing is True114 assert Index(i.values).is_monotonic_decreasing is True115 assert i._is_strictly_monotonic_decreasing is True116 assert Index(i.values)._is_strictly_monotonic_decreasing is True117 # mixed levels, hits the TypeError118 i = MultiIndex(119 levels=[120 [4, 3, 2, 1],121 [122 "nl0000301109",123 "nl0000289965",124 "nl0000289783",125 "lu0197800237",126 "gb00b03mlx29",127 ],128 ],129 codes=[[0, 1, 1, 2, 2, 2, 3], [4, 2, 0, 0, 1, 3, -1]],130 names=["household_id", "asset_id"],131 )132 assert i.is_monotonic_decreasing is False133 assert i._is_strictly_monotonic_decreasing is False134 # empty135 i = MultiIndex.from_arrays([[], []])136 assert i.is_monotonic_decreasing is True137 assert Index(i.values).is_monotonic_decreasing is True138 assert i._is_strictly_monotonic_decreasing is True139 assert Index(i.values)._is_strictly_monotonic_decreasing is True140def test_is_strictly_monotonic_increasing():141 idx = pd.MultiIndex(142 levels=[["bar", "baz"], ["mom", "next"]], codes=[[0, 0, 1, 1], [0, 0, 0, 1]]143 )144 assert idx.is_monotonic_increasing is True145 assert idx._is_strictly_monotonic_increasing is False146def test_is_strictly_monotonic_decreasing():147 idx = pd.MultiIndex(148 levels=[["baz", "bar"], ["next", "mom"]], codes=[[0, 0, 1, 1], [0, 0, 0, 1]]149 )150 assert idx.is_monotonic_decreasing is True...

Full Screen

Full Screen

test_indexing_engines.py

Source:test_indexing_engines.py Github

copy

Full Screen

1import numpy as np2from pandas._libs import algos as libalgos, index as libindex3import pandas.util.testing as tm4class TestNumericEngine:5 def test_is_monotonic(self, numeric_indexing_engine_type_and_dtype):6 engine_type, dtype = numeric_indexing_engine_type_and_dtype7 num = 10008 arr = np.array([1] * num + [2] * num + [3] * num, dtype=dtype)9 # monotonic increasing10 engine = engine_type(lambda: arr, len(arr))11 assert engine.is_monotonic_increasing is True12 assert engine.is_monotonic_decreasing is False13 # monotonic decreasing14 engine = engine_type(lambda: arr[::-1], len(arr))15 assert engine.is_monotonic_increasing is False16 assert engine.is_monotonic_decreasing is True17 # neither monotonic increasing or decreasing18 arr = np.array([1] * num + [2] * num + [1] * num, dtype=dtype)19 engine = engine_type(lambda: arr[::-1], len(arr))20 assert engine.is_monotonic_increasing is False21 assert engine.is_monotonic_decreasing is False22 def test_is_unique(self, numeric_indexing_engine_type_and_dtype):23 engine_type, dtype = numeric_indexing_engine_type_and_dtype24 # unique25 arr = np.array([1, 3, 2], dtype=dtype)26 engine = engine_type(lambda: arr, len(arr))27 assert engine.is_unique is True28 # not unique29 arr = np.array([1, 2, 1], dtype=dtype)30 engine = engine_type(lambda: arr, len(arr))31 assert engine.is_unique is False32 def test_get_loc(self, numeric_indexing_engine_type_and_dtype):33 engine_type, dtype = numeric_indexing_engine_type_and_dtype34 # unique35 arr = np.array([1, 2, 3], dtype=dtype)36 engine = engine_type(lambda: arr, len(arr))37 assert engine.get_loc(2) == 138 # monotonic39 num = 100040 arr = np.array([1] * num + [2] * num + [3] * num, dtype=dtype)41 engine = engine_type(lambda: arr, len(arr))42 assert engine.get_loc(2) == slice(1000, 2000)43 # not monotonic44 arr = np.array([1, 2, 3] * num, dtype=dtype)45 engine = engine_type(lambda: arr, len(arr))46 expected = np.array([False, True, False] * num, dtype=bool)47 result = engine.get_loc(2)48 assert (result == expected).all()49 def test_get_backfill_indexer(self, numeric_indexing_engine_type_and_dtype):50 engine_type, dtype = numeric_indexing_engine_type_and_dtype51 arr = np.array([1, 5, 10], dtype=dtype)52 engine = engine_type(lambda: arr, len(arr))53 new = np.arange(12, dtype=dtype)54 result = engine.get_backfill_indexer(new)55 expected = libalgos.backfill(arr, new)56 tm.assert_numpy_array_equal(result, expected)57 def test_get_pad_indexer(self, numeric_indexing_engine_type_and_dtype):58 engine_type, dtype = numeric_indexing_engine_type_and_dtype59 arr = np.array([1, 5, 10], dtype=dtype)60 engine = engine_type(lambda: arr, len(arr))61 new = np.arange(12, dtype=dtype)62 result = engine.get_pad_indexer(new)63 expected = libalgos.pad(arr, new)64 tm.assert_numpy_array_equal(result, expected)65class TestObjectEngine:66 engine_type = libindex.ObjectEngine67 dtype = np.object_68 values = list("abc")69 def test_is_monotonic(self):70 num = 100071 arr = np.array(["a"] * num + ["a"] * num + ["c"] * num, dtype=self.dtype)72 # monotonic increasing73 engine = self.engine_type(lambda: arr, len(arr))74 assert engine.is_monotonic_increasing is True75 assert engine.is_monotonic_decreasing is False76 # monotonic decreasing77 engine = self.engine_type(lambda: arr[::-1], len(arr))78 assert engine.is_monotonic_increasing is False79 assert engine.is_monotonic_decreasing is True80 # neither monotonic increasing or decreasing81 arr = np.array(["a"] * num + ["b"] * num + ["a"] * num, dtype=self.dtype)82 engine = self.engine_type(lambda: arr[::-1], len(arr))83 assert engine.is_monotonic_increasing is False...

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 pytest-benchmark 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