From 2ec60a6913a5e93d63141849996c4ede1d8154ef Mon Sep 17 00:00:00 2001 From: RobinFiveWords Date: Tue, 23 May 2017 23:59:12 -0500 Subject: [PATCH 1/4] added back whatsnew change --- doc/source/whatsnew/v0.20.2.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.20.2.txt b/doc/source/whatsnew/v0.20.2.txt index 6d6a148ed025f..b327e69348755 100644 --- a/doc/source/whatsnew/v0.20.2.txt +++ b/doc/source/whatsnew/v0.20.2.txt @@ -84,6 +84,7 @@ Reshaping - Bug in ``DataFrame.stack`` with unsorted levels in MultiIndex columns (:issue:`16323`) - Bug in ``pd.wide_to_long()`` where no error was raised when ``i`` was not a unique identifier (:issue:`16382`) - Bug in ``Series.isin(..)`` with a list of tuples (:issue:`16394`) +- Bug in ``maybe_infer_to_datetimelike()`` in ``core.dtypes.cast`` where result was not reshaped in all cases (:issue:`16395`) Numeric From 7a35624bc69906da259745a114837d96d1d4e794 Mon Sep 17 00:00:00 2001 From: RobinFiveWords Date: Wed, 24 May 2017 00:00:18 -0500 Subject: [PATCH 2/4] removed whatsnew entry again --- doc/source/whatsnew/v0.20.2.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v0.20.2.txt b/doc/source/whatsnew/v0.20.2.txt index b327e69348755..6d6a148ed025f 100644 --- a/doc/source/whatsnew/v0.20.2.txt +++ b/doc/source/whatsnew/v0.20.2.txt @@ -84,7 +84,6 @@ Reshaping - Bug in ``DataFrame.stack`` with unsorted levels in MultiIndex columns (:issue:`16323`) - Bug in ``pd.wide_to_long()`` where no error was raised when ``i`` was not a unique identifier (:issue:`16382`) - Bug in ``Series.isin(..)`` with a list of tuples (:issue:`16394`) -- Bug in ``maybe_infer_to_datetimelike()`` in ``core.dtypes.cast`` where result was not reshaped in all cases (:issue:`16395`) Numeric From afa2eeb880a33d4fbe30b56a07a6d132e77ed657 Mon Sep 17 00:00:00 2001 From: RobinFiveWords Date: Wed, 24 May 2017 08:35:37 -0500 Subject: [PATCH 3/4] added whatsnew0.20.2 entry --- doc/source/whatsnew/v0.20.2.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.20.2.txt b/doc/source/whatsnew/v0.20.2.txt index 6d6a148ed025f..b327e69348755 100644 --- a/doc/source/whatsnew/v0.20.2.txt +++ b/doc/source/whatsnew/v0.20.2.txt @@ -84,6 +84,7 @@ Reshaping - Bug in ``DataFrame.stack`` with unsorted levels in MultiIndex columns (:issue:`16323`) - Bug in ``pd.wide_to_long()`` where no error was raised when ``i`` was not a unique identifier (:issue:`16382`) - Bug in ``Series.isin(..)`` with a list of tuples (:issue:`16394`) +- Bug in ``maybe_infer_to_datetimelike()`` in ``core.dtypes.cast`` where result was not reshaped in all cases (:issue:`16395`) Numeric From 7ad1e7db19f23f59e2d9d8fb8a2759b81b8085bc Mon Sep 17 00:00:00 2001 From: RobinFiveWords Date: Wed, 24 May 2017 12:18:11 -0500 Subject: [PATCH 4/4] redid lost changes to cast.py and test_cast.py --- pandas/core/dtypes/cast.py | 2 +- pandas/tests/dtypes/test_cast.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index 19d3792f73de7..fd61813a57c98 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -837,7 +837,7 @@ def try_timedelta(v): try: return to_timedelta(v)._values.reshape(shape) except: - return v + return v.reshape(shape) inferred_type = lib.infer_datetimelike_array(_ensure_object(v)) diff --git a/pandas/tests/dtypes/test_cast.py b/pandas/tests/dtypes/test_cast.py index e92724a5d9cd4..767e99d98cf29 100644 --- a/pandas/tests/dtypes/test_cast.py +++ b/pandas/tests/dtypes/test_cast.py @@ -9,7 +9,7 @@ from datetime import datetime, timedelta, date import numpy as np -from pandas import Timedelta, Timestamp, DatetimeIndex +from pandas import Timedelta, Timestamp, DatetimeIndex, DataFrame, NaT from pandas.core.dtypes.cast import ( maybe_downcast_to_dtype, @@ -213,6 +213,17 @@ def test_maybe_convert_scalar(self): result = maybe_convert_scalar(Timedelta('1 day 1 min')) assert result == Timedelta('1 day 1 min').value + def test_maybe_infer_to_datetimelike(self): + # GH16362 + # pandas=0.20.1 raises IndexError: tuple index out of range + result = DataFrame(np.array([[NaT, 'a', 'b', 0], + [NaT, 'b', 'c', 1]])) + assert result.size == 8 + # this construction was fine + result = DataFrame(np.array([[NaT, 'a', 0], + [NaT, 'b', 1]])) + assert result.size == 6 + class TestConvert(object):