Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

DOC: Clarify existence Series.dt.to_timestamp #59671

Copy link
Copy link
Open
@sfc-gh-joshi

Description

@sfc-gh-joshi
Issue body actions

Pandas version checks

  • I have checked that the issue still exists on the latest versions of the docs on main here

Location of the documentation

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.dt.to_timestamp.html (does not exist)

Documentation problem

Copied from a Modin issue: modin-project/modin#7232 (comment)

Series.dt.to_timestamp() is a valid method for PeriodProperties, but not for DatetimeProperties, TimedeltaProperties. For example, following is valid:

>>> seconds_series = pd.Series(pd.period_range(start="2000-01-01 00:00:00", end="2000-01-01 00:00:03", freq="s"))
>>> seconds_series
0    2000-01-01 00:00:00
1    2000-01-01 00:00:01
2    2000-01-01 00:00:02
3    2000-01-01 00:00:03
dtype: period[s]
>>> seconds_series.dt.to_timestamp()
0   2000-01-01 00:00:00
1   2000-01-01 00:00:01
2   2000-01-01 00:00:02
3   2000-01-01 00:00:03
dtype: datetime64[ns]

However, it is invalid for timedelta:

>>> seconds_series = pd.Series(pd.timedelta_range(start="1 second", periods=3, freq="s"))
>>> seconds_series.dt.to_timestamp()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'TimedeltaProperties' object has no attribute 'to_timestamp'
>>> seconds_series
0   0 days 00:00:01
1   0 days 00:00:02
2   0 days 00:00:03
dtype: timedelta64[ns]

Suggested fix for documentation

Clarify whether to_timestamp should exist for all Series.dt accessors, and whether it should be implemented for classes other than PeriodProperties.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Accessorsaccessor registration mechanism (not .str, .dt, .cat)accessor registration mechanism (not .str, .dt, .cat)DatetimeDatetime data dtypeDatetime data dtypeDocs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.