File: timestamp.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 (152 lines) | stat: -rw-r--r-- 3,557 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from datetime import datetime

import numpy as np
import pytz

from pandas import Timestamp

from .tslib import _tzs


class TimestampConstruction:
    def setup(self):
        self.npdatetime64 = np.datetime64("2020-01-01 00:00:00")
        self.dttime_unaware = datetime(2020, 1, 1, 0, 0, 0)
        self.dttime_aware = datetime(2020, 1, 1, 0, 0, 0, 0, pytz.UTC)
        self.ts = Timestamp("2020-01-01 00:00:00")

    def time_parse_iso8601_no_tz(self):
        Timestamp("2017-08-25 08:16:14")

    def time_parse_iso8601_tz(self):
        Timestamp("2017-08-25 08:16:14-0500")

    def time_parse_dateutil(self):
        Timestamp("2017/08/25 08:16:14 AM")

    def time_parse_today(self):
        Timestamp("today")

    def time_parse_now(self):
        Timestamp("now")

    def time_fromordinal(self):
        Timestamp.fromordinal(730120)

    def time_fromtimestamp(self):
        Timestamp.fromtimestamp(1515448538)

    def time_from_npdatetime64(self):
        Timestamp(self.npdatetime64)

    def time_from_datetime_unaware(self):
        Timestamp(self.dttime_unaware)

    def time_from_datetime_aware(self):
        Timestamp(self.dttime_aware)

    def time_from_pd_timestamp(self):
        Timestamp(self.ts)


class TimestampProperties:
    params = [_tzs]
    param_names = ["tz"]

    def setup(self, tz):
        self.ts = Timestamp("2017-08-25 08:16:14", tzinfo=tz)

    def time_tz(self, tz):
        self.ts.tz

    def time_dayofweek(self, tz):
        self.ts.dayofweek

    def time_dayofyear(self, tz):
        self.ts.dayofyear

    def time_week(self, tz):
        self.ts.week

    def time_quarter(self, tz):
        self.ts.quarter

    def time_days_in_month(self, tz):
        self.ts.days_in_month

    def time_is_month_start(self, tz):
        self.ts.is_month_start

    def time_is_month_end(self, tz):
        self.ts.is_month_end

    def time_is_quarter_start(self, tz):
        self.ts.is_quarter_start

    def time_is_quarter_end(self, tz):
        self.ts.is_quarter_end

    def time_is_year_start(self, tz):
        self.ts.is_year_start

    def time_is_year_end(self, tz):
        self.ts.is_year_end

    def time_is_leap_year(self, tz):
        self.ts.is_leap_year

    def time_microsecond(self, tz):
        self.ts.microsecond

    def time_month_name(self, tz):
        self.ts.month_name()

    def time_weekday_name(self, tz):
        self.ts.day_name()


class TimestampOps:
    params = _tzs
    param_names = ["tz"]

    def setup(self, tz):
        self.ts = Timestamp("2017-08-25 08:16:14", tz=tz)

    def time_replace_tz(self, tz):
        self.ts.replace(tzinfo=pytz.timezone("US/Eastern"))

    def time_replace_None(self, tz):
        self.ts.replace(tzinfo=None)

    def time_to_pydatetime(self, tz):
        self.ts.to_pydatetime()

    def time_normalize(self, tz):
        self.ts.normalize()

    def time_tz_convert(self, tz):
        if self.ts.tz is not None:
            self.ts.tz_convert(tz)

    def time_tz_localize(self, tz):
        if self.ts.tz is None:
            self.ts.tz_localize(tz)

    def time_to_julian_date(self, tz):
        self.ts.to_julian_date()

    def time_floor(self, tz):
        self.ts.floor("5min")

    def time_ceil(self, tz):
        self.ts.ceil("5min")


class TimestampAcrossDst:
    def setup(self):
        dt = datetime(2016, 3, 27, 1)
        self.tzinfo = pytz.timezone("CET").localize(dt, is_dst=False).tzinfo
        self.ts2 = Timestamp(dt)

    def time_replace_across_dst(self):
        self.ts2.replace(tzinfo=self.tzinfo)