-
- Notifications
You must be signed in to change notification settings - Fork 19.2k
DEPR/API: Non-ns precision in Index constructors #24806
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
Changes from 3 commits
d856bb1 37d6779 ea31555 346f71c a9a9588 File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -2,6 +2,7 @@ | |
| from __future__ import division | ||
| | ||
| from datetime import timedelta | ||
| import textwrap | ||
| import warnings | ||
| | ||
| import numpy as np | ||
| | @@ -160,16 +161,8 @@ def __init__(self, values, dtype=_TD_DTYPE, freq=None, copy=False): | |
| # nanosecond UTC (or tz-naive) unix timestamps | ||
| values = values.view(_TD_DTYPE) | ||
| | ||
| if values.dtype != _TD_DTYPE: | ||
| raise TypeError(_BAD_DTYPE.format(dtype=values.dtype)) | ||
| | ||
| try: | ||
| dtype_mismatch = dtype != _TD_DTYPE | ||
| except TypeError: | ||
| raise TypeError(_BAD_DTYPE.format(dtype=dtype)) | ||
| else: | ||
| if dtype_mismatch: | ||
| raise TypeError(_BAD_DTYPE.format(dtype=dtype)) | ||
| _validate_td64_dtype(values.dtype) | ||
| dtype = _validate_td64_dtype(dtype) | ||
| | ||
| if freq == "infer": | ||
| msg = ( | ||
| | @@ -204,9 +197,8 @@ def _simple_new(cls, values, freq=None, dtype=_TD_DTYPE): | |
| @classmethod | ||
| def _from_sequence(cls, data, dtype=_TD_DTYPE, copy=False, | ||
| freq=None, unit=None): | ||
| if dtype != _TD_DTYPE: | ||
| raise ValueError("Only timedelta64[ns] dtype is valid.") | ||
| | ||
| if dtype: | ||
| _validate_td64_dtype(dtype) | ||
| freq, freq_infer = dtl.maybe_infer_freq(freq) | ||
| | ||
| data, inferred_freq = sequence_to_td64ns(data, copy=copy, unit=unit) | ||
| | @@ -997,6 +989,30 @@ def objects_to_td64ns(data, unit="ns", errors="raise"): | |
| return result.view('timedelta64[ns]') | ||
| | ||
| | ||
| def _validate_td64_dtype(dtype): | ||
| try: | ||
| if dtype == np.dtype("timedelta64"): | ||
| ||
| dtype = _TD_DTYPE | ||
| msg = textwrap.dedent("""\ | ||
| Passing in 'timedelta' dtype with no precision is deprecated | ||
jreback marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| and will raise in a future version. Please pass in | ||
| 'timedelta64[ns]' instead.""") | ||
| warnings.warn(msg, FutureWarning, stacklevel=4) | ||
| except TypeError: | ||
| # extension dtype | ||
| pass | ||
| | ||
| try: | ||
| ||
| dtype_mismatch = dtype != _TD_DTYPE | ||
| except TypeError: | ||
| raise ValueError(_BAD_DTYPE.format(dtype=dtype)) | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note the change from TypeError to ValueError, when compared with https://github.com/pandas-dev/pandas/pull/24806/files#diff-57368e94ebd4c37c96935ab9862e3bc7L169. ValueError is more consistent with DatetimeArray. | ||
| else: | ||
| if dtype_mismatch: | ||
| raise ValueError(_BAD_DTYPE.format(dtype=dtype)) | ||
| | ||
| return dtype | ||
| | ||
| | ||
| def _generate_regular_range(start, end, periods, offset): | ||
| stride = offset.nanos | ||
| if periods is None: | ||
| | ||
Uh oh!
There was an error while loading. Please reload this page.