From 06cb6d5e8a7160ce2aaa07763c5f15e00706999c Mon Sep 17 00:00:00 2001 From: tp Date: Thu, 11 Oct 2018 12:05:15 +0100 Subject: [PATCH] add tests for indexing engines and Uint64Engine --- asv_bench/benchmarks/indexing.py | 7 +-- asv_bench/benchmarks/indexing_engines.py | 54 ++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 asv_bench/benchmarks/indexing_engines.py diff --git a/asv_bench/benchmarks/indexing.py b/asv_bench/benchmarks/indexing.py index 8290731fd7eea..49d6311a7bb66 100644 --- a/asv_bench/benchmarks/indexing.py +++ b/asv_bench/benchmarks/indexing.py @@ -2,8 +2,9 @@ import numpy as np import pandas.util.testing as tm -from pandas import (Series, DataFrame, Panel, MultiIndex, Int64Index, - Float64Index, IntervalIndex, CategoricalIndex, +from pandas import (Series, DataFrame, Panel, MultiIndex, + Int64Index, UInt64Index, Float64Index, + IntervalIndex, CategoricalIndex, IndexSlice, concat, date_range) @@ -11,7 +12,7 @@ class NumericSeriesIndexing(object): goal_time = 0.2 params = [ - (Int64Index, Float64Index), + (Int64Index, UInt64Index, Float64Index), ('unique_monotonic_inc', 'nonunique_monotonic_inc'), ] param_names = ['index_dtype', 'index_structure'] diff --git a/asv_bench/benchmarks/indexing_engines.py b/asv_bench/benchmarks/indexing_engines.py new file mode 100644 index 0000000000000..243f2ada7be32 --- /dev/null +++ b/asv_bench/benchmarks/indexing_engines.py @@ -0,0 +1,54 @@ +import numpy as np + +from pandas._libs.index import (Int64Engine, UInt64Engine, Float64Engine, + ObjectEngine) + + +class NumericEngineIndexing(object): + + goal_time = 0.2 + params = [[Int64Engine, UInt64Engine, Float64Engine], + [np.int64, np.uint64, np.float64], + ['monotonic_incr', 'monotonic_decr', 'non_monotonic'], + ] + param_names = ['engine', 'dtype', 'index_type'] + + def setup(self, engine, dtype, index_type): + N = 10**5 + values = list([1] * N + [2] * N + [3] * N) + arr = { + 'monotonic_incr': np.array(values, dtype=dtype), + 'monotonic_decr': np.array(list(reversed(values)), + dtype=dtype), + 'non_monotonic': np.array([1, 2, 3] * N, dtype=dtype), + }[index_type] + + self.data = engine(lambda: arr, len(arr)) + # code belows avoids populating the mapping etc. while timing. + self.data.get_loc(2) + + def time_get_loc(self, engine, dtype, index_type): + self.data.get_loc(2) + + +class ObjectEngineIndexing(object): + + goal_time = 0.2 + params = [('monotonic_incr', 'monotonic_decr', 'non_monotonic')] + param_names = ['index_type'] + + def setup(self, index_type): + N = 10**5 + values = list('a' * N + 'b' * N + 'c' * N) + arr = { + 'monotonic_incr': np.array(values, dtype=object), + 'monotonic_decr': np.array(list(reversed(values)), dtype=object), + 'non_monotonic': np.array(list('abc') * N, dtype=object), + }[index_type] + + self.data = ObjectEngine(lambda: arr, len(arr)) + # code belows avoids populating the mapping etc. while timing. + self.data.get_loc('b') + + def time_get_loc(self, index_type): + self.data.get_loc('b')