Skip to content

TYPING: add skeleton stub for Timestamp #28195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions pandas/_libs/tslibs/timestamps.pyi
Original file line number Diff line number Diff line change
@@ -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 = ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the plan here just to get this in first then refine types later? Seems like some of these could easily be inferred more strictly than any

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value is int64_t in cython-space but when i look it up in python-space its just int. will typing it as int here conflict with typing it as int64_t in cython?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure i follow. value is Any.

I want to avoid discussions about types in skeleton stubs in order to avoid hampering progress towards the resolution of #28133.

we are using ignore_missing_imports=True in our global config. mypy states "We recommend using this approach only as a last resort: it’s equivalent to adding a # type: ignore to all unresolved imports in your codebase."

so will discuss types in a follow up, but I don''t see an issue with int for return types, maybe we will need to type the arguments differently for complete type safety.

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): ...
3 changes: 1 addition & 2 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down