Skip to content

Commit

Permalink
Fixed missing timestamp declaration (#30)
Browse files Browse the repository at this point in the history
* Fixed missing timestamp declaration

* Add more test cases
  • Loading branch information
zkrolikowski-vl authored Mar 13, 2021
1 parent eeb82af commit dc8b537
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 3 deletions.
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ ignore_missing_imports = True

[mypy-matplotlib.*]
ignore_missing_imports = True

[mypy-dateutil.*]
ignore_missing_imports = True
3 changes: 3 additions & 0 deletions mypy_env.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ ignore_missing_imports = True

[mypy-matplotlib.*]
ignore_missing_imports = True

[mypy-dateutil.*]
ignore_missing_imports = True
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def list_packages(source_path: str = src_path) -> None:
setup(
name="pandas-stubs",
package_dir={"": src_path},
version="1.0.4.6",
version="1.0.4.7",
description="Type annotations for Pandas",
long_description=(open("README.md").read()
if os.path.exists("README.md") else ""),
Expand Down
16 changes: 16 additions & 0 deletions tests/snippets/test_timestamp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# flake8: noqa: F841

import pandas as pd
import datetime as dt

def test_types_init() -> None:
ts: pd.Timestamp = pd.Timestamp('2021-03-01T12')
ts1: pd.Timestamp = pd.Timestamp(dt.date(2021, 3, 15))
ts2: pd.Timestamp = pd.Timestamp(dt.datetime(2021, 3, 10, 12))
ts3: pd.Timestamp = pd.Timestamp(pd.Timestamp('2021-03-01T12'))
ts4: pd.Timestamp = pd.Timestamp(1515590000.1, unit='s')
ts5: pd.Timestamp = pd.Timestamp(1515590000.1, unit='s', tz='US/Pacific')
ts6: pd.Timestamp = pd.Timestamp(1515590000100000000) # plain integer (nanosecond)
ts7: pd.Timestamp = pd.Timestamp(2021, 3, 10, 12)
ts8: pd.Timestamp = pd.Timestamp(year=2021, month=3, day=10, hour=12)
ts9: pd.Timestamp = pd.Timestamp(year=2021, month=3, day=10, hour=12, tz='US/Pacific')
81 changes: 79 additions & 2 deletions third_party/3/pandas/_libs/tslibs/timestamps.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,85 @@
from typing import Any
import sys
from typing import Any, Optional, Union, Literal, overload

from dateutil.tz import tzfile
from datetime import tzinfo, date

from pandas._libs.tslibs.period import Period
from pandas._typing import DatetimeLikeScalar

OptInt = Optional[int]

# Literals have only been introduced in version 3.8
if sys.version_info >= (3, 8):
Fold = Literal[0, 1]
else:
Fold = int

class Timestamp:
...
@overload
def __init__(self, ts_input: Union[DatetimeLikeScalar, date, str, int, float], freq: Optional[str] = ..., tz: Optional[Union[str, tzinfo, tzfile]] = ..., unit: Optional[str] = ..., tzinfo: Optional[tzinfo] = ..., fold: Optional[Fold] = ...): ...
@overload
def __init__(self, year: OptInt = ..., month: OptInt = ..., day: OptInt = ..., hour: OptInt = ..., minute: OptInt = ..., second: OptInt = ..., microsecond: OptInt = ..., nanosecond: OptInt = ..., tz: Optional[Union[str, tzinfo, tzfile]] = ..., tzinfo: Optional[tzinfo] = ..., fold: Optional[Fold] = ..., freq: Optional[str] = ...): ...
def to_period(self, freq: Optional[str]) -> Period: ...
def to_julian_date(self) -> float: ...
def tz_localize(self, tz: Any = ..., ambigious: Any = ..., nonexistent: Any = ...) -> Timestamp: ...
def tz_convert(self, tz: Any) -> Timestamp: ...
def astimezone(self, tz: Any) -> Timestamp: ...
def replace(self, year: OptInt = ..., month: OptInt = ..., day: OptInt = ..., hour: OptInt = ..., minute: OptInt = ..., second: OptInt = ..., microsecond: OptInt = ..., nanosecond: OptInt = ..., tzinfo: Optional[tzinfo] = ..., fold: Fold = ...) -> Timestamp: ...
def round(self, freq: str, ambiguous: Any = ..., nonexistent: Any = ...) -> Timestamp: ...
def ceil(self, freq: str, ambiguous: Any = ...,nonexistent: Any = ...) -> Timestamp: ...
def floor(self, freq: str, ambiguous: Any = ...,nonexistent: Any = ...) -> Timestamp: ...
def isoformat(self, sep: str = ...) -> str: ...
def day_name(self, locale: Optional[str]) -> str: ...
def month_name(self, locale: Optional[str]) -> str: ...
def normalize(self) -> Timestamp: ...

@classmethod
def utcnow(cls) -> Timestamp: ...
@classmethod
def utcfromtimestamp(cls, ts: Timestamp) -> Timestamp: ...
@classmethod
def fromtimestamp(cls, ts: Timestamp) -> Timestamp: ...
@classmethod
def combine(cls, date: Any, time: Any) -> Timestamp: ...
@classmethod
def now(cls, tz: Optional[Any] = ...) -> Timestamp: ...
@classmethod
def today(cls, tz: Optional[Any] = ...) -> Timestamp: ...
@classmethod
def fromordinal(cls, ordinal: Any, freq: Optional[Any] = ..., tz: Optional[Any] = ...) -> Timestamp: ...
@property
def dayofweek(self) -> int: ...
@property
def dayofyear(self) -> int: ...
@property
def quarter(self) -> int: ...
@property
def days_in_month(self) -> int: ...
@property
def daysinmonth(self) -> int: ...
@property
def week(self) -> int: ...
@property
def weekofyear(self) -> int: ...
@property
def freqstr(self) -> str: ...
@property
def is_month_end(self) -> bool: ...
@property
def is_month_start(self) -> bool: ...
@property
def is_quarter_start(self) -> bool: ...
@property
def is_quarter_end(self) -> bool: ...
@property
def is_year_start(self) -> bool: ...
@property
def is_year_end(self) -> bool: ...
@property
def is_leap_year(self) -> bool: ...
@property
def tz(self) -> tzinfo: ...


def integer_op_not_supported(obj: Any) -> Any: ...

0 comments on commit dc8b537

Please sign in to comment.