From 3451902344f7f1d97175678f2021277c8f5e879a Mon Sep 17 00:00:00 2001 From: usersblock Date: Tue, 20 Jul 2021 01:52:59 -0400 Subject: [PATCH 1/9] Update test_to_datetime.py --- pandas/tests/tools/test_to_datetime.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index 9da7951c199ca..349943c6d0b50 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -2530,3 +2530,16 @@ def test_empty_string_datetime_coerce__unit(): # verify that no exception is raised even when errors='raise' is set result = to_datetime([1, ""], unit="s", errors="raise") tm.assert_index_equal(expected, result) + + +def test_to_datetime_monotonic_increasing_index(): + # GH28238 + # Create date range of 1000 hour periods + times = pd.date_range(datetime.now(), periods=1000, freq='h') + # Random sort + times = times.to_frame(index=False, name='DT').sample(1000) + # Divide index integers by 1000 + times.index = times.index.to_series().astype(float) / 1000 + # Convert to datetime + result = pd.to_datetime(times.iloc[:, 0]) + assert result.values.dtype == np.dtype('datetime64[ns]') From 1b528225089d7469f83ddc0e20ce86f750ccfdb2 Mon Sep 17 00:00:00 2001 From: usersblock Date: Tue, 20 Jul 2021 03:33:02 -0400 Subject: [PATCH 2/9] Update test_to_datetime.py --- pandas/tests/tools/test_to_datetime.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index 349943c6d0b50..d5e90162d671e 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -2535,11 +2535,11 @@ def test_empty_string_datetime_coerce__unit(): def test_to_datetime_monotonic_increasing_index(): # GH28238 # Create date range of 1000 hour periods - times = pd.date_range(datetime.now(), periods=1000, freq='h') + times = date_range(datetime.now(), periods=1000, freq="h") # Random sort - times = times.to_frame(index=False, name='DT').sample(1000) + times = times.to_frame(index=False, name="DT").sample(1000) # Divide index integers by 1000 times.index = times.index.to_series().astype(float) / 1000 # Convert to datetime - result = pd.to_datetime(times.iloc[:, 0]) - assert result.values.dtype == np.dtype('datetime64[ns]') + result = to_datetime(times.iloc[:, 0]) + assert result.values.dtype == np.dtype("datetime64[ns]") From 59d4145c6f62d87bccd13bdc213fffe262903485 Mon Sep 17 00:00:00 2001 From: usersblock Date: Tue, 20 Jul 2021 20:08:02 -0400 Subject: [PATCH 3/9] Update test_to_datetime.py --- pandas/tests/tools/test_to_datetime.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index d5e90162d671e..a172ecd8e8f56 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -2534,12 +2534,10 @@ def test_empty_string_datetime_coerce__unit(): def test_to_datetime_monotonic_increasing_index(): # GH28238 - # Create date range of 1000 hour periods times = date_range(datetime.now(), periods=1000, freq="h") - # Random sort times = times.to_frame(index=False, name="DT").sample(1000) - # Divide index integers by 1000 times.index = times.index.to_series().astype(float) / 1000 - # Convert to datetime - result = to_datetime(times.iloc[:, 0]) - assert result.values.dtype == np.dtype("datetime64[ns]") + converted = to_datetime(times.iloc[:, 0]) + expected = np.ravel(times.values) + result = np.ravel(converted.values) + tm.assert_equal(result, expected) From 763d84ca65fa34dca69f648b43728b137445584c Mon Sep 17 00:00:00 2001 From: usersblock Date: Thu, 22 Jul 2021 16:58:44 -0400 Subject: [PATCH 4/9] Update test_to_datetime.py --- pandas/tests/tools/test_to_datetime.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index a172ecd8e8f56..7e876e1c1d8c0 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -2532,12 +2532,12 @@ def test_empty_string_datetime_coerce__unit(): tm.assert_index_equal(expected, result) -def test_to_datetime_monotonic_increasing_index(): +@pytest.mark.parametrize("cache", [True, False]) +def test_to_datetime_monotonic_increasing_index(cache): # GH28238 - times = date_range(datetime.now(), periods=1000, freq="h") - times = times.to_frame(index=False, name="DT").sample(1000) + times = date_range(pd.Timestamp("2002"), periods=3, freq="h") + times = times.to_frame(index=False, name="DT").sample() times.index = times.index.to_series().astype(float) / 1000 - converted = to_datetime(times.iloc[:, 0]) - expected = np.ravel(times.values) - result = np.ravel(converted.values) - tm.assert_equal(result, expected) + result = to_datetime(times.iloc[:, 0], cache=cache) + expected = times.iloc[:, 0] + tm.assert_series_equal(result, expected) From 1404f7a55f7642af1801bec4b7862dd699740ede Mon Sep 17 00:00:00 2001 From: usersblock Date: Fri, 23 Jul 2021 14:13:41 -0400 Subject: [PATCH 5/9] Update test_to_datetime.py --- pandas/tests/tools/test_to_datetime.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index 7e876e1c1d8c0..8f1a918bef4d6 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -2535,8 +2535,8 @@ def test_empty_string_datetime_coerce__unit(): @pytest.mark.parametrize("cache", [True, False]) def test_to_datetime_monotonic_increasing_index(cache): # GH28238 - times = date_range(pd.Timestamp("2002"), periods=3, freq="h") - times = times.to_frame(index=False, name="DT").sample() + times = Series([Timestamp("2002"), Timestamp("2012"), Timestamp("2020")]) + times = times.to_frame(name="DT").sample(3) times.index = times.index.to_series().astype(float) / 1000 result = to_datetime(times.iloc[:, 0], cache=cache) expected = times.iloc[:, 0] From c649998f35ec4ac6aa67502a10b523372c5c4a44 Mon Sep 17 00:00:00 2001 From: usersblock Date: Fri, 23 Jul 2021 19:26:17 -0400 Subject: [PATCH 6/9] Update test_to_datetime.py --- pandas/tests/tools/test_to_datetime.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index 8f1a918bef4d6..c0b782354c6f2 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -2535,8 +2535,8 @@ def test_empty_string_datetime_coerce__unit(): @pytest.mark.parametrize("cache", [True, False]) def test_to_datetime_monotonic_increasing_index(cache): # GH28238 - times = Series([Timestamp("2002"), Timestamp("2012"), Timestamp("2020")]) - times = times.to_frame(name="DT").sample(3) + times = pd.date_range(pd.Timestamp("1980"), periods=50, freq="YS") + times = times.to_frame(index=False, name="DT").sample(50) times.index = times.index.to_series().astype(float) / 1000 result = to_datetime(times.iloc[:, 0], cache=cache) expected = times.iloc[:, 0] From 44645d73f372bd43cb63bb952dead3073a03aaf3 Mon Sep 17 00:00:00 2001 From: usersblock Date: Sat, 24 Jul 2021 01:37:31 -0400 Subject: [PATCH 7/9] Update test_to_datetime.py --- pandas/tests/tools/test_to_datetime.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index c0b782354c6f2..3a67b8b128050 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -2535,8 +2535,8 @@ def test_empty_string_datetime_coerce__unit(): @pytest.mark.parametrize("cache", [True, False]) def test_to_datetime_monotonic_increasing_index(cache): # GH28238 - times = pd.date_range(pd.Timestamp("1980"), periods=50, freq="YS") - times = times.to_frame(index=False, name="DT").sample(50) + times = date_range(Timestamp("1980"), periods=50, freq="YS") + times = times.to_frame(index=False, name="DT").sample(n=50, random_state=1) times.index = times.index.to_series().astype(float) / 1000 result = to_datetime(times.iloc[:, 0], cache=cache) expected = times.iloc[:, 0] From e3cb80c298f3c2bd2988532bbac6a53bf0df493f Mon Sep 17 00:00:00 2001 From: usersblock Date: Sat, 24 Jul 2021 15:07:24 -0400 Subject: [PATCH 8/9] Update test_to_datetime.py --- pandas/tests/tools/test_to_datetime.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index 3a67b8b128050..7078661b4568a 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -2535,8 +2535,9 @@ def test_empty_string_datetime_coerce__unit(): @pytest.mark.parametrize("cache", [True, False]) def test_to_datetime_monotonic_increasing_index(cache): # GH28238 + cstart = start_caching_at times = date_range(Timestamp("1980"), periods=50, freq="YS") - times = times.to_frame(index=False, name="DT").sample(n=50, random_state=1) + times = times.to_frame(index=False, name="DT").sample(n=cstart, random_state=1) times.index = times.index.to_series().astype(float) / 1000 result = to_datetime(times.iloc[:, 0], cache=cache) expected = times.iloc[:, 0] From 970ed06055ec703159a26af5895127d28f105bc3 Mon Sep 17 00:00:00 2001 From: usersblock Date: Sun, 25 Jul 2021 00:21:41 -0400 Subject: [PATCH 9/9] Update test_to_datetime.py --- pandas/tests/tools/test_to_datetime.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index 7078661b4568a..7351f50aea8c1 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -2536,7 +2536,7 @@ def test_empty_string_datetime_coerce__unit(): def test_to_datetime_monotonic_increasing_index(cache): # GH28238 cstart = start_caching_at - times = date_range(Timestamp("1980"), periods=50, freq="YS") + times = date_range(Timestamp("1980"), periods=cstart, freq="YS") times = times.to_frame(index=False, name="DT").sample(n=cstart, random_state=1) times.index = times.index.to_series().astype(float) / 1000 result = to_datetime(times.iloc[:, 0], cache=cache)