From ef98122bef23eec8cb95ac45000ce9860dc751b7 Mon Sep 17 00:00:00 2001 From: Tilova Shahrin <46762829+tilovashahrin@users.noreply.github.com> Date: Fri, 14 Jun 2024 17:01:50 -0400 Subject: [PATCH 1/6] Change link from NEP 29 to SPEC 0 for Numpy Guidelines --- doc/source/development/policies.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/development/policies.rst b/doc/source/development/policies.rst index f958e4c4ad1fc..8e3829ed60295 100644 --- a/doc/source/development/policies.rst +++ b/doc/source/development/policies.rst @@ -51,7 +51,7 @@ pandas may change the behavior of experimental features at any time. Python support ~~~~~~~~~~~~~~ -pandas mirrors the `NumPy guidelines for Python support `__. +pandas mirrors the `NumPy guidelines for Python support `__. Security policy ~~~~~~~~~~~~~~~ From bc89591ca380f22a800a8f572eba61ce51dd05dd Mon Sep 17 00:00:00 2001 From: Tilova Shahrin <46762829+tilovashahrin@users.noreply.github.com> Date: Fri, 14 Jun 2024 18:46:43 -0400 Subject: [PATCH 2/6] Update doc/source/development/policies.rst Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> --- doc/source/development/policies.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/development/policies.rst b/doc/source/development/policies.rst index 8e3829ed60295..a3665c5bb4d1f 100644 --- a/doc/source/development/policies.rst +++ b/doc/source/development/policies.rst @@ -51,7 +51,7 @@ pandas may change the behavior of experimental features at any time. Python support ~~~~~~~~~~~~~~ -pandas mirrors the `NumPy guidelines for Python support `__. +pandas mirrors the `SPEC 0 guideline for Python support `__. Security policy ~~~~~~~~~~~~~~~ From 9cf4b28e3361faddefb0c4c988dfa28fd34d6889 Mon Sep 17 00:00:00 2001 From: Tilova Shahrin <46762829+tilovashahrin@users.noreply.github.com> Date: Wed, 19 Jun 2024 12:24:02 -0400 Subject: [PATCH 3/6] Infer the unit based on the frequency Modified the pd.date_range function based on the provided frequency and the start/stop timestamp. --- pandas/core/indexes/datetimes.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index c276750314a34..fd5d1395d38c6 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1003,6 +1003,14 @@ def date_range( """ if freq is None and com.any_none(periods, start, end): freq = "D" + + if unit is None and freq is not None: + offset = to_offset(freq) + if offset is not None: + unit = offset.n + + if unit is None: + unit = 'ns' dtarr = DatetimeArray._generate_range( start=start, From 3b2e45319641363712c91e2afafe415493921637 Mon Sep 17 00:00:00 2001 From: Tilova Shahrin <46762829+tilovashahrin@users.noreply.github.com> Date: Wed, 19 Jun 2024 12:41:11 -0400 Subject: [PATCH 4/6] Additional tests for date_range inferred resolution --- pandas/tests/dtypes/test_inference.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pandas/tests/dtypes/test_inference.py b/pandas/tests/dtypes/test_inference.py index db18cd4aef14e..7339e61605b40 100644 --- a/pandas/tests/dtypes/test_inference.py +++ b/pandas/tests/dtypes/test_inference.py @@ -1810,12 +1810,28 @@ def test_is_datetime_dtypes(self): assert is_datetime64_any_dtype("datetime64[ns]") assert is_datetime64_any_dtype(ts) assert is_datetime64_any_dtype(tsa) + + result_min = pd.date_range("2013-01-01", periods=3, freq="1min") + assert result_min.dtype == 'datetime64[s]' + + result_day = pd.date_range("2013-01-01", periods=3, freq="1D") + assert result_day.dtype == 'datetime64[D]' + + result_hour = pd.date_range("2013-01-01", periods=3, freq="1H") + assert result_hour.dtype == 'datetime64[h]' + + result_ms = pd.date_range("2013-01-01", periods=3, freq="1ms") + assert result_ms.dtype == 'datetime64[ms]' + + result_ns = pd.date_range("2013-01-01", periods=3, freq="1s") + assert result_ns.dtype == 'datetime64[ns]' with tm.assert_produces_warning(DeprecationWarning, match=msg): assert not is_datetime64tz_dtype("datetime64") assert not is_datetime64tz_dtype("datetime64[ns]") assert not is_datetime64tz_dtype(ts) assert is_datetime64tz_dtype(tsa) + @pytest.mark.parametrize("tz", ["US/Eastern", "UTC"]) def test_is_datetime_dtypes_with_tz(self, tz): From 799ca3ef522396269c4729e3bef80a96c68e6e40 Mon Sep 17 00:00:00 2001 From: Tilova Shahrin <46762829+tilovashahrin@users.noreply.github.com> Date: Thu, 20 Jun 2024 16:18:50 -0400 Subject: [PATCH 5/6] Update test_inference.py --- pandas/tests/dtypes/test_inference.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/pandas/tests/dtypes/test_inference.py b/pandas/tests/dtypes/test_inference.py index 7339e61605b40..f2b4178c4f9dc 100644 --- a/pandas/tests/dtypes/test_inference.py +++ b/pandas/tests/dtypes/test_inference.py @@ -1810,21 +1810,6 @@ def test_is_datetime_dtypes(self): assert is_datetime64_any_dtype("datetime64[ns]") assert is_datetime64_any_dtype(ts) assert is_datetime64_any_dtype(tsa) - - result_min = pd.date_range("2013-01-01", periods=3, freq="1min") - assert result_min.dtype == 'datetime64[s]' - - result_day = pd.date_range("2013-01-01", periods=3, freq="1D") - assert result_day.dtype == 'datetime64[D]' - - result_hour = pd.date_range("2013-01-01", periods=3, freq="1H") - assert result_hour.dtype == 'datetime64[h]' - - result_ms = pd.date_range("2013-01-01", periods=3, freq="1ms") - assert result_ms.dtype == 'datetime64[ms]' - - result_ns = pd.date_range("2013-01-01", periods=3, freq="1s") - assert result_ns.dtype == 'datetime64[ns]' with tm.assert_produces_warning(DeprecationWarning, match=msg): assert not is_datetime64tz_dtype("datetime64") From e87c3459aff2aed6d3a14ff5f2dd9502a96b54c8 Mon Sep 17 00:00:00 2001 From: Tilova Shahrin <46762829+tilovashahrin@users.noreply.github.com> Date: Thu, 20 Jun 2024 16:20:23 -0400 Subject: [PATCH 6/6] Update test_inference.py --- pandas/tests/dtypes/test_inference.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/dtypes/test_inference.py b/pandas/tests/dtypes/test_inference.py index f2b4178c4f9dc..db18cd4aef14e 100644 --- a/pandas/tests/dtypes/test_inference.py +++ b/pandas/tests/dtypes/test_inference.py @@ -1816,7 +1816,6 @@ def test_is_datetime_dtypes(self): assert not is_datetime64tz_dtype("datetime64[ns]") assert not is_datetime64tz_dtype(ts) assert is_datetime64tz_dtype(tsa) - @pytest.mark.parametrize("tz", ["US/Eastern", "UTC"]) def test_is_datetime_dtypes_with_tz(self, tz):