From d62170f8bc5e51a91f8da215ecf2f93321595cd2 Mon Sep 17 00:00:00 2001 From: Chris Bertinato Date: Sun, 24 Feb 2019 21:31:47 -0500 Subject: [PATCH] Fixes --- doc/source/whatsnew/v0.24.0.rst | 1 - doc/source/whatsnew/v0.25.0.rst | 1 + pandas/core/indexes/datetimelike.py | 6 +----- pandas/tests/indexes/datetimes/test_tools.py | 8 ++++++-- pandas/tests/scalar/timedelta/test_timedelta.py | 8 ++++---- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index c59885f5f7c297..a49ea2cf493a6e 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -1326,7 +1326,6 @@ Deprecations - Passing an integer to :meth:`Series.fillna` and :meth:`DataFrame.fillna` with ``timedelta64[ns]`` dtypes is deprecated, will raise ``TypeError`` in a future version. Use ``obj.fillna(pd.Timedelta(...))`` instead (:issue:`24694`) - ``Series.cat.categorical``, ``Series.cat.name`` and ``Sersies.cat.index`` have been deprecated. Use the attributes on ``Series.cat`` or ``Series`` directly. (:issue:`24751`). - Passing a dtype without a precision like ``np.dtype('datetime64')`` or ``timedelta64`` to :class:`Index`, :class:`DatetimeIndex` and :class:`TimedeltaIndex` is now deprecated. Use the nanosecond-precision dtype instead (:issue:`24753`). -- The functions :func:`pandas.to_datetime` and :func:`pandas.to_timedelta` have deprecated the ``box`` keyword. Use :attr:`Series.values` and :meth:`Timestamp.to_datetime64`/:meth:`Timedelta.to_timedelta64` instead to get an ndarray of values or ``numpy.timestamp64``/``numpy.timedelta64``, respectively (:issue:`24416`). .. _whatsnew_0240.deprecations.datetimelike_int_ops: diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 170e7f14da3973..9130d127086822 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -79,6 +79,7 @@ Deprecations ~~~~~~~~~~~~ - Deprecated the `M (months)` and `Y (year)` `units` parameter of :func: `pandas.to_timedelta`, :func: `pandas.Timedelta` and :func: `pandas.TimedeltaIndex` (:issue:`16344`) +- The functions :func:`pandas.to_datetime` and :func:`pandas.to_timedelta` have deprecated the ``box`` keyword. Use :attr:`Series.values` and :meth:`Timestamp.to_datetime64`/:meth:`Timedelta.to_timedelta64` instead to get an ndarray of values or ``numpy.timestamp64``/``numpy.timedelta64``, respectively (:issue:`24416`) .. _whatsnew_0250.prior_deprecations: diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index 1c6b152eacfd63..830f234b857579 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -300,11 +300,7 @@ def asobject(self): return self.astype(object) def _convert_tolerance(self, tolerance, target): - tolerance = to_timedelta(tolerance) - if isinstance(tolerance, ABCIndexClass): - tolerance = tolerance.to_numpy() - else: - tolerance = np.asarray(tolerance.to_timedelta64()) + tolerance = np.asarray(to_timedelta(tolerance).to_numpy()) if target.size != tolerance.size and tolerance.size > 1: raise ValueError('list-like tolerance size must match ' diff --git a/pandas/tests/indexes/datetimes/test_tools.py b/pandas/tests/indexes/datetimes/test_tools.py index 8481011f926c3a..8d2aabd1826043 100644 --- a/pandas/tests/indexes/datetimes/test_tools.py +++ b/pandas/tests/indexes/datetimes/test_tools.py @@ -1215,11 +1215,15 @@ def test_to_datetime_types(self, cache): def test_to_datetime_unprocessable_input(self, cache, box, klass): # GH 4928 # GH 21864 - result = to_datetime([1, '1'], errors='ignore', cache=cache, box=box) + with tm.assert_produces_warning(FutureWarning): + result = to_datetime([1, '1'], errors='ignore', cache=cache, + box=box) + expected = klass(np.array([1, '1'], dtype='O')) tm.assert_equal(result, expected) msg = "invalid string coercion to datetime" - with pytest.raises(TypeError, match=msg): + with pytest.raises(TypeError, match=msg), \ + tm.assert_produces_warning(FutureWarning): to_datetime([1, '1'], errors='raise', cache=cache, box=box) def test_to_datetime_other_datetime64_units(self): diff --git a/pandas/tests/scalar/timedelta/test_timedelta.py b/pandas/tests/scalar/timedelta/test_timedelta.py index bf71c37aa9c3d5..7b145a45b4104e 100644 --- a/pandas/tests/scalar/timedelta/test_timedelta.py +++ b/pandas/tests/scalar/timedelta/test_timedelta.py @@ -310,12 +310,12 @@ def test_iso_conversion(self): assert to_timedelta('P0DT0H0M1S') == expected def test_nat_converters(self): - result = to_timedelta('nat', box=False) - assert result.dtype.kind == 'm' + result = to_timedelta('nat').to_numpy() + assert result.dtype.kind == 'M' assert result.astype('int64') == iNaT - result = to_timedelta('nan', box=False) - assert result.dtype.kind == 'm' + result = to_timedelta('nan').to_numpy() + assert result.dtype.kind == 'M' assert result.astype('int64') == iNaT @pytest.mark.filterwarnings("ignore:M and Y units are deprecated")