Skip to content

Add basic datetime functionality #275

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

Merged
merged 8 commits into from
Oct 26, 2023
Merged
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
105 changes: 105 additions & 0 deletions spec/API_specification/dataframe_api/column_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from typing import Any,NoReturn, TYPE_CHECKING, Literal, Generic

from datetime import timedelta

if TYPE_CHECKING:
from ._types import NullType, Scalar, DType, Namespace

Expand Down Expand Up @@ -763,3 +765,106 @@ def rename(self, name: str) -> Column:
New column - this does not operate in-place.
"""
...

@property
def dt(self) -> DatetimeAccessor:
"""
Return accessor with functions which work on temporal dtypes.
"""
...

class DatetimeAccessor:
"""
Method which operate on temporal Columns.
"""

def year(self) -> Column:
"""
Return 'year' component of each element.

For example, return 1981 for 1981-01-02T12:34:56.123456.
"""

def month(self) -> Column:
"""
Return 'month' component of each element.

For example, return 1 for 1981-01-02T12:34:56.123456.
"""

def day(self) -> Column:
"""
Return 'day' component of each element.

For example, return 2 for 1981-01-02T12:34:56.123456.
"""

def hour(self) -> Column:
"""
Return 'hour' component of each element.

For example, return 12 for 1981-01-02T12:34:56.123456.
"""

def minute(self) -> Column:
"""
Return 'minute' component of each element.

For example, return 34 for 1981-01-02T12:34:56.123456.
"""

def second(self) -> Column:
"""
Return 'second' component of each element.

For example, return 56 for 1981-01-02T12:34:56.123456.
"""

def microsecond(self) -> Column:
"""
Return number of microseconds since last second, for each element.

For example, return 123456 for 1981-01-02T12:34:56.123456.
"""

def floor(self, frequency: timedelta) -> Column:
"""
Return floor of each element according to the specified frequency.

Flooring is done according to local time. For example,
for a ``Datetime('us', 'Europe/London')`` column,
``"2020-10-25T00:30:00 BST"`` floored by ``"1day"`` gives
``"2020-10-25T00:00:00 BST"``.

Behaviours in the face of ambiguous and non-existent times are
currently unspecified and may vary across implementations.

Flooring by non-fixed durations (e.g. calendar month) are not supported.
Note that flooring by ``timedelta(days=1)`` is equivalent to flooring
by ``timedelta(hours=24)``.

Parameters
----------
freq : timedelta
Frequency to floor by.
"""

def iso_weekday(self) -> Column:
"""
Return ISO weekday for each element.

Note that Monday=1, ..., Sunday=7.
"""

def timestamp(self) -> Column:
"""
Return number of units since UNIX epoch (1970-01-01).

Units depend on the dtype of the column:

- For a :class:`Date` column, ``1970-01-02`` should return `1`;
- For a :class:`Datetime('ms', '*')` column, ``1970-01-02``
should return `86_400_000`;
- For a :class:`Datetime('us', '*')` column, ``1970-01-02``
should return `86_400_000_000`;
"""