Skip to content

DOC: fix closed and dtype arguments of TimedeltaIndex #50660

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
wants to merge 2 commits into from
Closed
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
9 changes: 8 additions & 1 deletion pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ class TimedeltaIndex(DatetimeTimedeltaMixin):
Make a copy of input ndarray.
name : object
Name to be stored in the index.
dtype : numpy.dtype
Currently, only ``numpy.dtype("timedelta64[ns]")`` is accepted.

.. warning::

A future version of pandas will change dtype to be an instance
Copy link
Member

Choose a reason for hiding this comment

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

Not familiar with that are of the code. Is this already enforced?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, dtype is enforced to be 'timedelta64[ns]' inside the constructor TimedeltaArray._from_sequence_not_strict, which is called inside TimedeltaIndex constructor. The definition of TimedeltaArray._from_sequence_not_strict is here

Copy link
Member

Choose a reason for hiding this comment

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

So the warning is no longer necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know, since the instantiated class TimedeltaArray reports that warning, I've copied it. Do I remove it?

Copy link
Member

Choose a reason for hiding this comment

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

Can you show an example? Code-example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm sorry, would you mind clarifying which code example?

Copy link
Member

Choose a reason for hiding this comment

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

That shows the warning you are describing here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I got the question. The TimedeltaArray docstring reports this warning (see here https://pandas.pydata.org/docs/dev/reference/api/pandas.arrays.TimedeltaArray.html) and also the TimedeltaArray.dtype property docstring report a similar warning https://github.com/pandas-dev/pandas/blob/main/pandas/core/arrays/timedeltas.py#L160.

This is the function that validate the dtype of TimedeltaArray https://github.com/pandas-dev/pandas/blob/main/pandas/core/arrays/timedeltas.py#L1029

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@phofl
is there something that I can do to get it merged? thank you

of an ``ExtensionDtype`` subclass, not a ``numpy.dtype``.
See :class:`pandas.arrays.TimedeltaArray`.

Attributes
----------
Expand Down Expand Up @@ -120,7 +128,6 @@ def __new__(
data=None,
unit=None,
freq=lib.no_default,
closed=None,
dtype=None,
copy: bool = False,
name=None,
Expand Down