Skip to content

Commit d73da2a

Browse files
committed
TYP: typing in tslibs
1 parent ded1d6e commit d73da2a

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

pandas/_libs/tslibs/c_timestamp.pyx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ cdef class _Timestamp(datetime):
201201
"""
202202
return np.datetime64(self.value, 'ns')
203203

204-
def to_numpy(self, dtype=None, copy=False):
204+
def to_numpy(self, dtype=None, copy=False) -> np.datetime64:
205205
"""
206206
Convert the Timestamp to a NumPy datetime64.
207207

@@ -369,18 +369,18 @@ cdef class _Timestamp(datetime):
369369
return out[0]
370370

371371
@property
372-
def _repr_base(self):
372+
def _repr_base(self) -> str:
373373
return '{date} {time}'.format(date=self._date_repr,
374374
time=self._time_repr)
375375

376376
@property
377-
def _date_repr(self):
377+
def _date_repr(self) -> str:
378378
# Ideal here would be self.strftime("%Y-%m-%d"), but
379379
# the datetime strftime() methods require year >= 1900
380380
return '%d-%.2d-%.2d' % (self.year, self.month, self.day)
381381

382382
@property
383-
def _time_repr(self):
383+
def _time_repr(self) -> str:
384384
result = '%.2d:%.2d:%.2d' % (self.hour, self.minute, self.second)
385385

386386
if self.nanosecond != 0:
@@ -391,7 +391,7 @@ cdef class _Timestamp(datetime):
391391
return result
392392

393393
@property
394-
def _short_repr(self):
394+
def _short_repr(self) -> str:
395395
# format a Timestamp with only _date_repr if possible
396396
# otherwise _repr_base
397397
if (self.hour == 0 and
@@ -403,7 +403,7 @@ cdef class _Timestamp(datetime):
403403
return self._repr_base
404404

405405
@property
406-
def asm8(self):
406+
def asm8(self) -> np.datetime64:
407407
"""
408408
Return numpy datetime64 format in nanoseconds.
409409
"""

pandas/_libs/tslibs/nattype.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,16 @@ cdef class _NaT(datetime):
230230
return NotImplemented
231231

232232
@property
233-
def asm8(self):
233+
def asm8(self) -> np.datetime64:
234234
return np.datetime64(NPY_NAT, 'ns')
235235

236-
def to_datetime64(self):
236+
def to_datetime64(self) -> np.datetime64:
237237
"""
238238
Return a numpy.datetime64 object with 'ns' precision.
239239
"""
240240
return np.datetime64('NaT', 'ns')
241241

242-
def to_numpy(self, dtype=None, copy=False):
242+
def to_numpy(self, dtype=None, copy=False) -> np.datetime64:
243243
"""
244244
Convert the Timestamp to a NumPy datetime64.
245245

@@ -265,7 +265,7 @@ cdef class _NaT(datetime):
265265
def __str__(self) -> str:
266266
return 'NaT'
267267

268-
def isoformat(self, sep='T'):
268+
def isoformat(self, sep='T') -> str:
269269
# This allows Timestamp(ts.isoformat()) to always correctly roundtrip.
270270
return 'NaT'
271271

pandas/_libs/tslibs/timedeltas.pyx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -841,15 +841,15 @@ cdef class _Timedelta(timedelta):
841841
"""
842842
return timedelta(microseconds=int(self.value) / 1000)
843843

844-
def to_timedelta64(self):
844+
def to_timedelta64(self) -> np.timedelta64:
845845
"""
846846
Return a numpy.timedelta64 object with 'ns' precision.
847847
"""
848848
return np.timedelta64(self.value, 'ns')
849849

850-
def to_numpy(self, dtype=None, copy=False):
850+
def to_numpy(self, dtype=None, copy=False) -> np.timedelta64:
851851
"""
852-
Convert the Timestamp to a NumPy timedelta64.
852+
Convert the Timedelta to a NumPy timedelta64.
853853

854854
.. versionadded:: 0.25.0
855855

@@ -920,7 +920,7 @@ cdef class _Timedelta(timedelta):
920920
return self.value
921921

922922
@property
923-
def asm8(self):
923+
def asm8(self) -> np.timedelta64:
924924
"""
925925
Return a numpy timedelta64 array scalar view.
926926

@@ -955,7 +955,7 @@ cdef class _Timedelta(timedelta):
955955
return np.int64(self.value).view('m8[ns]')
956956

957957
@property
958-
def resolution_string(self):
958+
def resolution_string(self) -> str:
959959
"""
960960
Return a string representing the lowest timedelta resolution.
961961

@@ -1095,7 +1095,7 @@ cdef class _Timedelta(timedelta):
10951095
self._ensure_components()
10961096
return self._ns
10971097

1098-
def _repr_base(self, format=None):
1098+
def _repr_base(self, format=None) -> str:
10991099
"""
11001100

11011101
Parameters
@@ -1148,10 +1148,10 @@ cdef class _Timedelta(timedelta):
11481148
def __str__(self) -> str:
11491149
return self._repr_base(format='long')
11501150

1151-
def __bool__(self):
1151+
def __bool__(self) -> bool:
11521152
return self.value != 0
11531153

1154-
def isoformat(self):
1154+
def isoformat(self) -> str:
11551155
"""
11561156
Format Timedelta as ISO 8601 Duration like
11571157
``P[n]Y[n]M[n]DT[n]H[n]M[n]S``, where the ``[n]`` s are replaced by the

0 commit comments

Comments
 (0)