File: index_cached_properties.py

package info (click to toggle)
pandas 2.2.3%2Bdfsg-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 66,784 kB
  • sloc: python: 422,228; ansic: 9,190; sh: 270; xml: 102; makefile: 83
file content (72 lines) | stat: -rw-r--r-- 2,274 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import pandas as pd


class IndexCache:
    number = 1
    repeat = (3, 100, 20)

    params = [
        [
            "CategoricalIndex",
            "DatetimeIndex",
            "Float64Index",
            "IntervalIndex",
            "Int64Index",
            "MultiIndex",
            "PeriodIndex",
            "RangeIndex",
            "TimedeltaIndex",
            "UInt64Index",
        ]
    ]
    param_names = ["index_type"]

    def setup(self, index_type):
        N = 10**5
        if index_type == "MultiIndex":
            self.idx = pd.MultiIndex.from_product(
                [pd.date_range("1/1/2000", freq="min", periods=N // 2), ["a", "b"]]
            )
        elif index_type == "DatetimeIndex":
            self.idx = pd.date_range("1/1/2000", freq="min", periods=N)
        elif index_type == "Int64Index":
            self.idx = pd.Index(range(N), dtype="int64")
        elif index_type == "PeriodIndex":
            self.idx = pd.period_range("1/1/2000", freq="min", periods=N)
        elif index_type == "RangeIndex":
            self.idx = pd.RangeIndex(start=0, stop=N)
        elif index_type == "IntervalIndex":
            self.idx = pd.IntervalIndex.from_arrays(range(N), range(1, N + 1))
        elif index_type == "TimedeltaIndex":
            self.idx = pd.TimedeltaIndex(range(N))
        elif index_type == "Float64Index":
            self.idx = pd.Index(range(N), dtype="float64")
        elif index_type == "UInt64Index":
            self.idx = pd.Index(range(N), dtype="uint64")
        elif index_type == "CategoricalIndex":
            self.idx = pd.CategoricalIndex(range(N), range(N))
        else:
            raise ValueError
        assert len(self.idx) == N
        self.idx._cache = {}

    def time_values(self, index_type):
        self.idx._values

    def time_shape(self, index_type):
        self.idx.shape

    def time_is_monotonic_decreasing(self, index_type):
        self.idx.is_monotonic_decreasing

    def time_is_monotonic_increasing(self, index_type):
        self.idx.is_monotonic_increasing

    def time_is_unique(self, index_type):
        self.idx.is_unique

    def time_engine(self, index_type):
        self.idx._engine

    def time_inferred_type(self, index_type):
        self.idx.inferred_type