Skip to content

Commit 4dd2612

Browse files
committed
Merge remote-tracking branch 'upstream/main' into bug60343v1
2 parents 734c384 + 72ab3fd commit 4dd2612

File tree

8 files changed

+54
-24
lines changed

8 files changed

+54
-24
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
7373
-i "pandas.Period.freq GL08" \
7474
-i "pandas.Period.ordinal GL08" \
7575
-i "pandas.RangeIndex.from_range PR01,SA01" \
76-
-i "pandas.Series.dt.freq GL08" \
7776
-i "pandas.Series.dt.unit GL08" \
7877
-i "pandas.Series.pad PR01,SA01" \
7978
-i "pandas.Timedelta.max PR02" \
@@ -92,15 +91,11 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
9291
-i "pandas.core.groupby.DataFrameGroupBy.boxplot PR07,RT03,SA01" \
9392
-i "pandas.core.groupby.DataFrameGroupBy.get_group RT03,SA01" \
9493
-i "pandas.core.groupby.DataFrameGroupBy.indices SA01" \
95-
-i "pandas.core.groupby.DataFrameGroupBy.nth PR02" \
9694
-i "pandas.core.groupby.DataFrameGroupBy.nunique SA01" \
9795
-i "pandas.core.groupby.DataFrameGroupBy.plot PR02" \
9896
-i "pandas.core.groupby.DataFrameGroupBy.sem SA01" \
9997
-i "pandas.core.groupby.SeriesGroupBy.get_group RT03,SA01" \
10098
-i "pandas.core.groupby.SeriesGroupBy.indices SA01" \
101-
-i "pandas.core.groupby.SeriesGroupBy.is_monotonic_decreasing SA01" \
102-
-i "pandas.core.groupby.SeriesGroupBy.is_monotonic_increasing SA01" \
103-
-i "pandas.core.groupby.SeriesGroupBy.nth PR02" \
10499
-i "pandas.core.groupby.SeriesGroupBy.plot PR02" \
105100
-i "pandas.core.groupby.SeriesGroupBy.sem SA01" \
106101
-i "pandas.core.resample.Resampler.get_group RT03,SA01" \
@@ -114,7 +109,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
114109
-i "pandas.core.resample.Resampler.std SA01" \
115110
-i "pandas.core.resample.Resampler.transform PR01,RT03,SA01" \
116111
-i "pandas.core.resample.Resampler.var SA01" \
117-
-i "pandas.errors.AttributeConflictWarning SA01" \
118112
-i "pandas.errors.ChainedAssignmentError SA01" \
119113
-i "pandas.errors.DuplicateLabelError SA01" \
120114
-i "pandas.errors.IntCastingNaNError SA01" \

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ Datetimelike
626626
- Bug in :meth:`Series.dt.microsecond` producing incorrect results for pyarrow backed :class:`Series`. (:issue:`59154`)
627627
- Bug in :meth:`to_datetime` not respecting dayfirst if an uncommon date string was passed. (:issue:`58859`)
628628
- Bug in :meth:`to_datetime` reports incorrect index in case of any failure scenario. (:issue:`58298`)
629+
- Bug in :meth:`to_datetime` wrongly converts when ``arg`` is a ``np.datetime64`` object with unit of ``ps``. (:issue:`60341`)
629630
- Bug in setting scalar values with mismatched resolution into arrays with non-nanosecond ``datetime64``, ``timedelta64`` or :class:`DatetimeTZDtype` incorrectly truncating those scalars (:issue:`56410`)
630631

631632
Timedelta

pandas/_libs/src/vendored/numpy/datetime/np_datetime.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -660,11 +660,12 @@ void pandas_datetime_to_datetimestruct(npy_datetime dt, NPY_DATETIMEUNIT base,
660660
perday = 24LL * 60 * 60 * 1000 * 1000 * 1000 * 1000;
661661

662662
set_datetimestruct_days(extract_unit(&dt, perday), out);
663-
out->hour = (npy_int32)extract_unit(&dt, 1000LL * 1000 * 1000 * 60 * 60);
664-
out->min = (npy_int32)extract_unit(&dt, 1000LL * 1000 * 1000 * 60);
665-
out->sec = (npy_int32)extract_unit(&dt, 1000LL * 1000 * 1000);
666-
out->us = (npy_int32)extract_unit(&dt, 1000LL);
667-
out->ps = (npy_int32)(dt * 1000);
663+
out->hour =
664+
(npy_int32)extract_unit(&dt, 1000LL * 1000 * 1000 * 1000 * 60 * 60);
665+
out->min = (npy_int32)extract_unit(&dt, 1000LL * 1000 * 1000 * 1000 * 60);
666+
out->sec = (npy_int32)extract_unit(&dt, 1000LL * 1000 * 1000 * 1000);
667+
out->us = (npy_int32)extract_unit(&dt, 1000LL * 1000);
668+
out->ps = (npy_int32)(dt);
668669
break;
669670

670671
case NPY_FR_fs:

pandas/core/groupby/generic.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,11 @@ def is_monotonic_increasing(self) -> Series:
14431443
-------
14441444
Series
14451445
1446+
See Also
1447+
--------
1448+
SeriesGroupBy.is_monotonic_decreasing : Return whether each group's values
1449+
are monotonically decreasing.
1450+
14461451
Examples
14471452
--------
14481453
>>> s = pd.Series([2, 1, 3, 4], index=["Falcon", "Falcon", "Parrot", "Parrot"])
@@ -1462,6 +1467,11 @@ def is_monotonic_decreasing(self) -> Series:
14621467
-------
14631468
Series
14641469
1470+
See Also
1471+
--------
1472+
SeriesGroupBy.is_monotonic_increasing : Return whether each group's values
1473+
are monotonically increasing.
1474+
14651475
Examples
14661476
--------
14671477
>>> s = pd.Series([2, 1, 3, 4], index=["Falcon", "Falcon", "Parrot", "Parrot"])

pandas/core/groupby/groupby.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3983,19 +3983,6 @@ def nth(self) -> GroupByNthSelector:
39833983
'all' or 'any'; this is equivalent to calling dropna(how=dropna)
39843984
before the groupby.
39853985
3986-
Parameters
3987-
----------
3988-
n : int, slice or list of ints and slices
3989-
A single nth value for the row or a list of nth values or slices.
3990-
3991-
.. versionchanged:: 1.4.0
3992-
Added slice and lists containing slices.
3993-
Added index notation.
3994-
3995-
dropna : {'any', 'all', None}, default None
3996-
Apply the specified dropna operation before counting which row is
3997-
the nth row. Only supported if n is an int.
3998-
39993986
Returns
40003987
-------
40013988
Series or DataFrame

pandas/core/indexes/accessors.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,28 @@ def to_pydatetime(self) -> Series:
373373

374374
@property
375375
def freq(self):
376+
"""
377+
Tries to return a string representing a frequency generated by infer_freq.
378+
379+
Returns None if it can't autodetect the frequency.
380+
381+
See Also
382+
--------
383+
Series.dt.to_period : Cast to PeriodArray/PeriodIndex at a particular
384+
frequency.
385+
386+
Examples
387+
--------
388+
>>> ser = pd.Series(["2024-01-01", "2024-01-02", "2024-01-03", "2024-01-04"])
389+
>>> ser = pd.to_datetime(ser)
390+
>>> ser.dt.freq
391+
'D'
392+
393+
>>> ser = pd.Series(["2022-01-01", "2024-01-01", "2026-01-01", "2028-01-01"])
394+
>>> ser = pd.to_datetime(ser)
395+
>>> ser.dt.freq
396+
'2YS-JAN'
397+
"""
376398
return self._get_values().inferred_freq
377399

378400
def isocalendar(self) -> DataFrame:

pandas/errors/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,12 @@ class AttributeConflictWarning(Warning):
672672
name than the existing index on an HDFStore or attempting to append an index with a
673673
different frequency than the existing index on an HDFStore.
674674
675+
See Also
676+
--------
677+
HDFStore : Dict-like IO interface for storing pandas objects in PyTables.
678+
DataFrame.to_hdf : Write the contained data to an HDF5 file using HDFStore.
679+
read_hdf : Read from an HDF5 file into a DataFrame.
680+
675681
Examples
676682
--------
677683
>>> idx1 = pd.Index(["a", "b"], name="name1")

pandas/tests/tools/test_to_datetime.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3668,3 +3668,12 @@ def test_to_datetime_mixed_awareness_mixed_types(aware_val, naive_val, naive_fir
36683668
to_datetime(vec, format="mixed")
36693669
with pytest.raises(ValueError, match=msg):
36703670
DatetimeIndex(vec)
3671+
3672+
3673+
def test_to_datetime_wrapped_datetime64_ps():
3674+
# GH#60341
3675+
result = to_datetime([np.datetime64(1901901901901, "ps")])
3676+
expected = DatetimeIndex(
3677+
["1970-01-01 00:00:01.901901901"], dtype="datetime64[ns]", freq=None
3678+
)
3679+
tm.assert_index_equal(result, expected)

0 commit comments

Comments
 (0)