Skip to content
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

EA: tighten TimedeltaArray._from_sequence signature #36731

Merged
merged 2 commits into from
Oct 2, 2020
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
13 changes: 13 additions & 0 deletions pandas/core/arrays/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,19 @@ def _simple_new(

@classmethod
def _from_sequence(
cls, data, dtype=TD64NS_DTYPE, copy: bool = False
) -> "TimedeltaArray":
if dtype:
_validate_td64_dtype(dtype)

data, inferred_freq = sequence_to_td64ns(data, copy=copy, unit=None)
freq, _ = dtl.validate_inferred_freq(None, inferred_freq, False)

result = cls._simple_new(data, freq=freq)
return result

@classmethod
def _from_sequence_not_strict(
Copy link
Contributor

Choose a reason for hiding this comment

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

umm, have we standarized on this naming? or even the concept of 2 from_sequence?
cc @jorisvandenbossche @TomAugspurger

IIRC we had a need for a coerce= keyword that we nixed for StringArray

Copy link
Contributor

Choose a reason for hiding this comment

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

xref #36718 as well

Copy link
Member Author

Choose a reason for hiding this comment

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

yah my best guess is we're gonna end up dropping this method altogether and having it only reached via the DTI/TDI constructors

Copy link
Contributor

Choose a reason for hiding this comment

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

ok as a temporary work-around prob ok.

Copy link
Member Author

Choose a reason for hiding this comment

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

yah, there's also more work to do in tightening what dtypes _from_sequence accepts, plenty left to do

cls,
data,
dtype=TD64NS_DTYPE,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def __new__(

# - Cases checked above all return/raise before reaching here - #

tdarr = TimedeltaArray._from_sequence(
tdarr = TimedeltaArray._from_sequence_not_strict(
data, freq=freq, unit=unit, dtype=dtype, copy=copy
)
return cls._simple_new(tdarr, name=name)
Expand Down