@@ -161,8 +161,8 @@ cdef _Timestamp create_timestamp_from_ts(
161
161
dts.sec, dts.us, tz, fold = fold)
162
162
163
163
ts_base._value = value
164
- ts_base.year = dts.year
165
- ts_base.nanosecond = dts.ps // 1000
164
+ ts_base._year = dts.year
165
+ ts_base._nanosecond = dts.ps // 1000
166
166
ts_base._creso = reso
167
167
168
168
return ts_base
@@ -355,9 +355,9 @@ cdef class _Timestamp(ABCTimestamp):
355
355
# -----------------------------------------------------------------
356
356
357
357
def __hash__ (_Timestamp self ):
358
- if self .nanosecond :
358
+ if self ._nanosecond :
359
359
return hash (self ._value)
360
- if not (1 <= self .year <= 9999 ):
360
+ if not (1 <= self ._year <= 9999 ):
361
361
# out of bounds for pydatetime
362
362
return hash (self ._value)
363
363
if self .fold:
@@ -375,7 +375,7 @@ cdef class _Timestamp(ABCTimestamp):
375
375
elif cnp.is_datetime64_object(other):
376
376
ots = Timestamp(other)
377
377
elif PyDateTime_Check(other):
378
- if self .nanosecond == 0 :
378
+ if self ._nanosecond == 0 :
379
379
val = self .to_pydatetime()
380
380
return PyObject_RichCompareBool(val, other, op)
381
381
@@ -454,7 +454,7 @@ cdef class _Timestamp(ABCTimestamp):
454
454
if not self ._can_compare(other):
455
455
return NotImplemented
456
456
457
- if self .nanosecond == 0 :
457
+ if self ._nanosecond == 0 :
458
458
return PyObject_RichCompareBool(dtval, other, op)
459
459
460
460
# otherwise we have dtval < self
@@ -463,9 +463,9 @@ cdef class _Timestamp(ABCTimestamp):
463
463
if op == Py_EQ:
464
464
return False
465
465
if op == Py_LE or op == Py_LT:
466
- return self .year <= other.year
466
+ return self ._year <= other.year
467
467
if op == Py_GE or op == Py_GT:
468
- return self .year >= other.year
468
+ return self ._year >= other.year
469
469
470
470
cdef bint _can_compare(self , datetime other):
471
471
if self .tzinfo is not None :
@@ -606,7 +606,7 @@ cdef class _Timestamp(ABCTimestamp):
606
606
607
607
if own_tz is not None and not is_utc(own_tz):
608
608
pydatetime_to_dtstruct(self , & dts)
609
- val = npy_datetimestruct_to_datetime(self ._creso, & dts) + self .nanosecond
609
+ val = npy_datetimestruct_to_datetime(self ._creso, & dts) + self ._nanosecond
610
610
else :
611
611
val = self ._value
612
612
return val
@@ -898,7 +898,7 @@ cdef class _Timestamp(ABCTimestamp):
898
898
>>> ts.is_leap_year
899
899
True
900
900
"""
901
- return bool(ccalendar.is_leapyear(self.year ))
901
+ return bool(ccalendar.is_leapyear(self._year ))
902
902
903
903
@property
904
904
def day_of_week(self) -> int:
@@ -942,7 +942,7 @@ cdef class _Timestamp(ABCTimestamp):
942
942
>>> ts.day_of_year
943
943
74
944
944
"""
945
- return ccalendar.get_day_of_year(self.year , self.month, self.day)
945
+ return ccalendar.get_day_of_year(self._year , self.month, self.day)
946
946
947
947
@property
948
948
def quarter(self) -> int:
@@ -1050,7 +1050,7 @@ cdef class _Timestamp(ABCTimestamp):
1050
1050
>>> ts.year
1051
1051
2024
1052
1052
"""
1053
- return super().year
1053
+ return self._year
1054
1054
1055
1055
@property
1056
1056
def month(self) -> int:
@@ -1188,7 +1188,7 @@ cdef class _Timestamp(ABCTimestamp):
1188
1188
>>> ts.nanosecond
1189
1189
15
1190
1190
"""
1191
- return super().nanosecond
1191
+ return self._nanosecond
1192
1192
1193
1193
@property
1194
1194
def week(self) -> int:
@@ -1210,7 +1210,7 @@ cdef class _Timestamp(ABCTimestamp):
1210
1210
>>> ts.week
1211
1211
11
1212
1212
"""
1213
- return ccalendar.get_week_of_year(self.year , self.month, self.day)
1213
+ return ccalendar.get_week_of_year(self._year , self.month, self.day)
1214
1214
1215
1215
@property
1216
1216
def days_in_month(self) -> int:
@@ -1232,7 +1232,7 @@ cdef class _Timestamp(ABCTimestamp):
1232
1232
>>> ts.days_in_month
1233
1233
31
1234
1234
"""
1235
- return ccalendar.get_days_in_month(self.year , self.month)
1235
+ return ccalendar.get_days_in_month(self._year , self.month)
1236
1236
1237
1237
# -----------------------------------------------------------------
1238
1238
# Transformation Methods
@@ -1306,7 +1306,7 @@ cdef class _Timestamp(ABCTimestamp):
1306
1306
1307
1307
The full format looks like ' YYYY-MM-DD HH:MM:SS.mmmmmmnnn' .
1308
1308
By default, the fractional part is omitted if self .microsecond == 0
1309
- and self .nanosecond == 0.
1309
+ and self ._nanosecond == 0.
1310
1310
1311
1311
If self .tzinfo is not None , the UTC offset is also attached, giving
1312
1312
giving a full format of ' YYYY-MM-DD HH:MM:SS.mmmmmmnnn+HH:MM' .
@@ -1342,21 +1342,21 @@ cdef class _Timestamp(ABCTimestamp):
1342
1342
base_ts = "microseconds" if timespec == "nanoseconds" else timespec
1343
1343
base = super(_Timestamp, self).isoformat(sep=sep, timespec=base_ts)
1344
1344
# We need to replace the fake year 1970 with our real year
1345
- base = f"{self.year :04d}-" + base.split("-", 1)[1]
1345
+ base = f"{self._year :04d}-" + base.split("-", 1)[1]
1346
1346
1347
- if self.nanosecond == 0 and timespec != "nanoseconds":
1347
+ if self._nanosecond == 0 and timespec != "nanoseconds":
1348
1348
return base
1349
1349
1350
1350
if self.tzinfo is not None:
1351
1351
base1, base2 = base[:-6], base[-6:]
1352
1352
else:
1353
1353
base1, base2 = base, ""
1354
1354
1355
- if timespec == "nanoseconds" or (timespec == "auto" and self.nanosecond ):
1355
+ if timespec == "nanoseconds" or (timespec == "auto" and self._nanosecond ):
1356
1356
if self.microsecond or timespec == "nanoseconds":
1357
- base1 += f"{self.nanosecond :03d}"
1357
+ base1 += f"{self._nanosecond :03d}"
1358
1358
else:
1359
- base1 += f".{self.nanosecond :09d}"
1359
+ base1 += f".{self._nanosecond :09d}"
1360
1360
1361
1361
return base1 + base2
1362
1362
@@ -1390,14 +1390,14 @@ cdef class _Timestamp(ABCTimestamp):
1390
1390
def _date_repr(self) -> str:
1391
1391
# Ideal here would be self.strftime("%Y -%m -%d "), but
1392
1392
# the datetime strftime() methods require year >= 1900 and is slower
1393
- return f"{self.year }-{self.month:02d}-{self.day:02d}"
1393
+ return f"{self._year }-{self.month:02d}-{self.day:02d}"
1394
1394
1395
1395
@property
1396
1396
def _time_repr(self) -> str:
1397
1397
result = f"{self.hour:02d}:{self.minute:02d}:{self.second:02d}"
1398
1398
1399
- if self.nanosecond != 0:
1400
- result += f".{self.nanosecond + 1000 * self.microsecond:09d}"
1399
+ if self._nanosecond != 0:
1400
+ result += f".{self._nanosecond + 1000 * self.microsecond:09d}"
1401
1401
elif self.microsecond != 0:
1402
1402
result += f".{self.microsecond:06d}"
1403
1403
@@ -1561,11 +1561,11 @@ cdef class _Timestamp(ABCTimestamp):
1561
1561
>>> pd.NaT.to_pydatetime()
1562
1562
NaT
1563
1563
"""
1564
- if self.nanosecond != 0 and warn:
1564
+ if self._nanosecond != 0 and warn:
1565
1565
warnings.warn("Discarding nonzero nanoseconds in conversion.",
1566
1566
UserWarning, stacklevel=find_stack_level())
1567
1567
1568
- return datetime(self.year , self.month, self.day,
1568
+ return datetime(self._year , self.month, self.day,
1569
1569
self.hour, self.minute, self.second,
1570
1570
self.microsecond, self.tzinfo, fold=self.fold)
1571
1571
@@ -2044,7 +2044,7 @@ class Timestamp(_Timestamp):
2044
2044
' 2020-03-14 15:32:52'
2045
2045
"""
2046
2046
try:
2047
- _dt = datetime(self.year , self.month, self.day,
2047
+ _dt = datetime(self._year , self.month, self.day,
2048
2048
self.hour, self.minute, self.second,
2049
2049
self.microsecond, self.tzinfo, fold=self.fold)
2050
2050
except ValueError as err:
@@ -2087,7 +2087,7 @@ class Timestamp(_Timestamp):
2087
2087
' Sun Jan 1 10:00:00 2023'
2088
2088
"""
2089
2089
try:
2090
- _dt = datetime(self.year , self.month, self.day,
2090
+ _dt = datetime(self._year , self.month, self.day,
2091
2091
self.hour, self.minute, self.second,
2092
2092
self.microsecond, self.tzinfo, fold=self.fold)
2093
2093
except ValueError as err:
@@ -2127,7 +2127,7 @@ class Timestamp(_Timestamp):
2127
2127
datetime.date(2023 , 1 , 1 )
2128
2128
"""
2129
2129
try:
2130
- _dt = dt.date(self.year , self.month, self.day)
2130
+ _dt = dt.date(self._year , self.month, self.day)
2131
2131
except ValueError as err:
2132
2132
raise NotImplementedError(
2133
2133
"date not yet supported on Timestamps which "
@@ -2176,7 +2176,7 @@ class Timestamp(_Timestamp):
2176
2176
datetime.IsoCalendarDate(year = 2022 , week = 52 , weekday = 7 )
2177
2177
"""
2178
2178
try:
2179
- _dt = datetime(self.year , self.month, self.day,
2179
+ _dt = datetime(self._year , self.month, self.day,
2180
2180
self.hour, self.minute, self.second,
2181
2181
self.microsecond, self.tzinfo, fold=self.fold)
2182
2182
except ValueError as err:
@@ -2318,7 +2318,7 @@ class Timestamp(_Timestamp):
2318
2318
tm_hour = 10 , tm_min = 0 , tm_sec = 0 , tm_wday = 6 , tm_yday = 1 , tm_isdst = - 1 )
2319
2319
"""
2320
2320
try:
2321
- _dt = datetime(self.year , self.month, self.day,
2321
+ _dt = datetime(self._year , self.month, self.day,
2322
2322
self.hour, self.minute, self.second,
2323
2323
self.microsecond, self.tzinfo, fold=self.fold)
2324
2324
except ValueError as err:
@@ -2379,7 +2379,7 @@ class Timestamp(_Timestamp):
2379
2379
738521
2380
2380
"""
2381
2381
try:
2382
- _dt = datetime(self.year , self.month, self.day,
2382
+ _dt = datetime(self._year , self.month, self.day,
2383
2383
self.hour, self.minute, self.second,
2384
2384
self.microsecond, self.tzinfo, fold=self.fold)
2385
2385
except ValueError as err:
@@ -3268,7 +3268,7 @@ default 'raise'
3268
3268
3269
3269
# setup components
3270
3270
pandas_datetime_to_datetimestruct(value, self._creso, &dts)
3271
- dts.ps = self.nanosecond * 1000
3271
+ dts.ps = self._nanosecond * 1000
3272
3272
3273
3273
# replace
3274
3274
def validate(k, v):
@@ -3358,7 +3358,7 @@ default 'raise'
3358
3358
>>> ts.to_julian_date()
3359
3359
2458923.147824074
3360
3360
"""
3361
- year = self.year
3361
+ year = self._year
3362
3362
month = self.month
3363
3363
day = self.day
3364
3364
if month <= 2:
@@ -3375,7 +3375,7 @@ default 'raise'
3375
3375
self.minute / 60.0 +
3376
3376
self.second / 3600.0 +
3377
3377
self.microsecond / 3600.0 / 1e+6 +
3378
- self.nanosecond / 3600.0 / 1e+9
3378
+ self._nanosecond / 3600.0 / 1e+9
3379
3379
) / 24.0)
3380
3380
3381
3381
def isoweekday(self):
@@ -3426,7 +3426,7 @@ default 'raise'
3426
3426
"""
3427
3427
# same as super().weekday(), but that breaks because of how
3428
3428
# we have overridden year, see note in create_timestamp_from_ts
3429
- return ccalendar.dayofweek(self.year , self.month, self.day)
3429
+ return ccalendar.dayofweek(self._year , self.month, self.day)
3430
3430
3431
3431
3432
3432
# Aliases
0 commit comments