From ea527003f31a0651dcb519a2471661e4872b2a4b Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 28 Aug 2019 15:56:39 +0100 Subject: [PATCH 1/2] TYPING: add skeleton stub for Timestamp --- pandas/_libs/tslibs/timestamps.pyi | 109 +++++++++++++++++++++++++++++ pandas/core/arrays/datetimelike.py | 3 +- 2 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 pandas/_libs/tslibs/timestamps.pyi diff --git a/pandas/_libs/tslibs/timestamps.pyi b/pandas/_libs/tslibs/timestamps.pyi new file mode 100644 index 0000000000000..090d4091cbe00 --- /dev/null +++ b/pandas/_libs/tslibs/timestamps.pyi @@ -0,0 +1,109 @@ +# flake8: noqa + +from typing import Any + +class RoundTo: + @property + def MINUS_INFTY(self) -> int: ... + @property + def PLUS_INFTY(self) -> int: ... + @property + def NEAREST_HALF_EVEN(self) -> int: ... + @property + def NEAREST_HALF_PLUS_INFTY(self) -> int: ... + @property + def NEAREST_HALF_MINUS_INFTY(self) -> int: ... + +def round_nsint64(values, mode, freq): ... + +class Timestamp: + value: Any = ... + freq: Any = ... + tzinfo: Any = ... + min: Any = ... + max: Any = ... + weekofyear: Any = ... + daysinmonth: Any = ... + astimezone: Any = ... + def fromordinal(cls, ordinal, freq=..., tz=...): ... + def now(cls, tz=...): ... + def today(cls, tz=...): ... + def utcnow(cls): ... + def utcfromtimestamp(cls, ts): ... + def fromtimestamp(cls, ts): ... + def strptime(cls, date_string, format): ... + def combine(cls, date, time): ... + def __new__( + cls, + ts_input=..., + freq=..., + tz=..., + unit=..., + year=..., + month=..., + day=..., + hour=..., + minute=..., + second=..., + microsecond=..., + nanosecond=..., + tzinfo=..., + ): ... + def round(self, freq, ambiguous=..., nonexistent=...): ... + def floor(self, freq, ambiguous=..., nonexistent=...): ... + def ceil(self, freq, ambiguous=..., nonexistent=...): ... + @property + def tz(self): ... + @tz.setter + def tz(self, value): ... + def to_period(self, freq=...): ... + @property + def dayofweek(self): ... + def day_name(self, locale=...): ... + def month_name(self, locale=...): ... + @property + def weekday_name(self): ... + @property + def dayofyear(self): ... + @property + def week(self): ... + @property + def quarter(self): ... + @property + def days_in_month(self): ... + @property + def freqstr(self): ... + @property + def is_month_start(self): ... + @property + def is_month_end(self): ... + @property + def is_quarter_start(self): ... + @property + def is_quarter_end(self): ... + @property + def is_year_start(self): ... + @property + def is_year_end(self): ... + @property + def is_leap_year(self): ... + @property + def resolution(self): ... + def tz_localize(self, tz, ambiguous=..., nonexistent=..., errors=...): ... + def tz_convert(self, tz): ... + def replace( + self, + year=..., + month=..., + day=..., + hour=..., + minute=..., + second=..., + microsecond=..., + nanosecond=..., + tzinfo=..., + fold=..., + ): ... + def isoformat(self, sep=...): ... + def to_julian_date(self): ... + def normalize(self): ... diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index 1988726edc79b..5ccbcda905b0f 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -42,7 +42,6 @@ from pandas.core.dtypes.inference import is_array_like from pandas.core.dtypes.missing import is_valid_nat_for_dtype, isna -from pandas._typing import DatetimeLikeScalar from pandas.core import missing, nanops from pandas.core.algorithms import checked_add_with_arr, take, unique1d, value_counts import pandas.core.common as com @@ -62,7 +61,7 @@ def _simple_new(cls, values, **kwargs): raise AbstractMethodError(cls) @property - def _scalar_type(self) -> Type[DatetimeLikeScalar]: + def _scalar_type(self) -> Type[Union[Period, Timestamp, Timedelta]]: """The scalar associated with this datelike * PeriodArray : Period From 6cdc161eb128bc5e1e4fbf8e4068fc034c64e97a Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 28 Aug 2019 17:18:43 +0100 Subject: [PATCH 2/2] change _scalar_type to property --- pandas/core/arrays/datetimelike.py | 3 ++- pandas/core/arrays/datetimes.py | 5 ++++- pandas/core/arrays/period.py | 5 ++++- pandas/core/arrays/timedeltas.py | 6 +++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index 5ccbcda905b0f..1988726edc79b 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -42,6 +42,7 @@ from pandas.core.dtypes.inference import is_array_like from pandas.core.dtypes.missing import is_valid_nat_for_dtype, isna +from pandas._typing import DatetimeLikeScalar from pandas.core import missing, nanops from pandas.core.algorithms import checked_add_with_arr, take, unique1d, value_counts import pandas.core.common as com @@ -61,7 +62,7 @@ def _simple_new(cls, values, **kwargs): raise AbstractMethodError(cls) @property - def _scalar_type(self) -> Type[Union[Period, Timestamp, Timedelta]]: + def _scalar_type(self) -> Type[DatetimeLikeScalar]: """The scalar associated with this datelike * PeriodArray : Period diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 70df708d36b3b..fed9ed9745889 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -272,7 +272,10 @@ class DatetimeArray(dtl.DatetimeLikeArrayMixin, dtl.TimelikeOps, dtl.DatelikeOps """ _typ = "datetimearray" - _scalar_type = Timestamp + + @property + def _scalar_type(self): + return Timestamp # define my properties & methods for delegation _bool_ops = [ diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index f2d74794eadf5..feb8a0c9e8120 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -162,7 +162,10 @@ class PeriodArray(dtl.DatetimeLikeArrayMixin, dtl.DatelikeOps): # array priority higher than numpy scalars __array_priority__ = 1000 _typ = "periodarray" # ABCPeriodArray - _scalar_type = Period + + @property + def _scalar_type(self): + return Period # Names others delegate to us _other_ops = [] # type: List[str] diff --git a/pandas/core/arrays/timedeltas.py b/pandas/core/arrays/timedeltas.py index 3609c68a26c0f..17ba812ac58c3 100644 --- a/pandas/core/arrays/timedeltas.py +++ b/pandas/core/arrays/timedeltas.py @@ -157,7 +157,11 @@ class TimedeltaArray(dtl.DatetimeLikeArrayMixin, dtl.TimelikeOps): """ _typ = "timedeltaarray" - _scalar_type = Timedelta + + @property + def _scalar_type(self): + return Timedelta + __array_priority__ = 1000 # define my properties & methods for delegation _other_ops = [] # type: List[str]