Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions doc/internals/time-coding.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,17 @@ except Exception as err:

{py:class}`pandas.Timestamp` is used within xarray to wrap strings of CF encoding reference times and datetime.datetime.

When arguments are numeric (not strings) "unit" can be anything from `'Y'`, `'W'`, `'D'`, `'h'`, `'m'`, `'s'`, `'ms'`, `'us'` or `'ns'`, though the returned resolution will be `"ns"`.
When arguments are numeric (not strings) "unit" can be anything from `'Y'`, `'W'`, `'D'`, `'h'`, `'m'`, `'s'`, `'ms'`, `'us'` or `'ns'`. It only defines how the number is interpreted: since pandas 3.1 the returned resolution is `'us'`, or `'ns'` if the input needs nanosecond precision.

In normal operation {py:class}`pandas.Timestamp` holds the timestamp in the provided resolution, but only one of `'s'`, `'ms'`, `'us'`, `'ns'`. Lower resolution input is automatically converted to `'s'`, higher resolution input is truncated to `'ns'`.
{py:class}`pandas.Timestamp` holds the timestamp in one of `'s'`, `'ms'`, `'us'`, `'ns'`. Created from a {py:class}`numpy.datetime64` it keeps that resolution, lower resolution input is converted to `'s'`, higher resolution input is truncated to `'ns'`.

The same conversion rules apply here as for {py:func}`pandas.to_timedelta` (see [to_timedelta]).
Depending on the internal resolution Timestamps can be represented in the range:

```{code-cell}
for unit in ["s", "ms", "us", "ns"]:
print(
f"unit: {unit!r} time range ({pd.Timestamp(int64_min, unit=unit)}, {pd.Timestamp(int64_max, unit=unit)})"
f"unit: {unit!r} time range ({pd.Timestamp(np.datetime64(int64_min, unit))}, {pd.Timestamp(np.datetime64(int64_max, unit))})"
)
```

Expand Down
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,9 @@ Documentation
(:issue:`10832`, :pull:`11156`).
By `dolliecoder <https://github.com/dolliecoder>`_ and
`Michael Niklas <https://github.com/headtr1ck>`_.
- Fix the time coding docs for pandas 3.1, which now gives microsecond
resolution for numeric input with any ``unit`` (:pull:`11796`).
By `Michael Niklas <https://github.com/headtr1ck>`_.

Performance
~~~~~~~~~~~
Expand Down
Loading