Skip to content

Commit e0e7483

Browse files
committed
Merge remote-tracking branch 'upstream/main' into dateoffset-bug
2 parents ea24433 + 012575a commit e0e7483

File tree

12 files changed

+368
-33
lines changed

12 files changed

+368
-33
lines changed

ci/code_checks.sh

-10
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
105105
pandas.errors.UnsupportedFunctionCall \
106106
pandas.test \
107107
pandas.NaT \
108-
pandas.Timestamp.strptime \
109-
pandas.Timestamp.time \
110-
pandas.Timestamp.timetuple \
111-
pandas.Timestamp.timetz \
112-
pandas.Timestamp.to_datetime64 \
113-
pandas.Timestamp.toordinal \
114-
pandas.Timestamp.tzname \
115-
pandas.Timestamp.utcoffset \
116-
pandas.Timestamp.utctimetuple \
117-
pandas.Timestamp.weekday \
118108
pandas.arrays.TimedeltaArray \
119109
pandas.Period.asfreq \
120110
pandas.Period.now \

doc/source/whatsnew/v2.1.0.rst

+16-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ Enhancements
1919
Copy-on-Write improvements
2020
^^^^^^^^^^^^^^^^^^^^^^^^^^
2121

22+
- Calling :meth:`Index.values` will now return a read-only NumPy array (:issue:`53704`)
2223
- Setting a :class:`Series` into a :class:`DataFrame` now creates a lazy instead of a deep copy (:issue:`53142`)
24+
- The :class:`DataFrame` constructor, when constructing a DataFrame from a dictionary
25+
of Index objects and specifying ``copy=False``, will now use a lazy copy
26+
of those Index objects for the columns of the DataFrame (:issue:`52947`)
2327

2428
.. _whatsnew_210.enhancements.enhancement2:
2529

@@ -109,6 +113,7 @@ Other enhancements
109113
- Added ``engine_kwargs`` parameter to :meth:`DataFrame.to_excel` (:issue:`53220`)
110114
- Added a new parameter ``by_row`` to :meth:`Series.apply`. When set to ``False`` the supplied callables will always operate on the whole Series (:issue:`53400`).
111115
- Groupby aggregations (such as :meth:`DataFrameGroupby.sum`) now can preserve the dtype of the input instead of casting to ``float64`` (:issue:`44952`)
116+
- Improved error message when :meth:`DataFrameGroupBy.agg` failed (:issue:`52930`)
112117
- Many read/to_* functions, such as :meth:`DataFrame.to_pickle` and :func:`read_csv`, support forwarding compression arguments to lzma.LZMAFile (:issue:`52979`)
113118
- Performance improvement in :func:`concat` with homogeneous ``np.float64`` or ``np.float32`` dtypes (:issue:`52685`)
114119
- Performance improvement in :meth:`DataFrame.filter` when ``items`` is given (:issue:`52941`)
@@ -288,12 +293,14 @@ Deprecations
288293
- Deprecated behavior of :func:`assert_series_equal` and :func:`assert_frame_equal` considering NA-like values (e.g. ``NaN`` vs ``None`` as equivalent) (:issue:`52081`)
289294
- Deprecated constructing :class:`SparseArray` from scalar data, pass a sequence instead (:issue:`53039`)
290295
- Deprecated falling back to filling when ``value`` is not specified in :meth:`DataFrame.replace` and :meth:`Series.replace` with non-dict-like ``to_replace`` (:issue:`33302`)
296+
- Deprecated literal json input to :func:`read_json`. Wrap literal json string input in ``io.StringIO`` instead. (:issue:`53409`)
291297
- Deprecated option "mode.use_inf_as_na", convert inf entries to ``NaN`` before instead (:issue:`51684`)
298+
- Deprecated parameter ``obj`` in :meth:`GroupBy.get_group` (:issue:`53545`)
292299
- Deprecated positional indexing on :class:`Series` with :meth:`Series.__getitem__` and :meth:`Series.__setitem__`, in a future version ``ser[item]`` will *always* interpret ``item`` as a label, not a position (:issue:`50617`)
300+
- Deprecated strings ``T``, ``t``, ``L`` and ``l`` denoting units in :func:`to_timedelta` (:issue:`52536`)
293301
- Deprecated the "method" and "limit" keywords on :meth:`Series.fillna`, :meth:`DataFrame.fillna`, :meth:`SeriesGroupBy.fillna`, :meth:`DataFrameGroupBy.fillna`, and :meth:`Resampler.fillna`, use ``obj.bfill()`` or ``obj.ffill()`` instead (:issue:`53394`)
294302
- Deprecated the ``method`` and ``limit`` keywords in :meth:`DataFrame.replace` and :meth:`Series.replace` (:issue:`33302`)
295303
- Deprecated values "pad", "ffill", "bfill", "backfill" for :meth:`Series.interpolate` and :meth:`DataFrame.interpolate`, use ``obj.ffill()`` or ``obj.bfill()`` instead (:issue:`53581`)
296-
-
297304

298305
.. ---------------------------------------------------------------------------
299306
.. _whatsnew_210.performance:
@@ -319,6 +326,7 @@ Performance improvements
319326
- Performance improvement accessing :attr:`arrays.IntegerArrays.dtype` & :attr:`arrays.FloatingArray.dtype` (:issue:`52998`)
320327
- Performance improvement in :class:`Series` reductions (:issue:`52341`)
321328
- Performance improvement in :func:`concat` when ``axis=1`` and objects have different indexes (:issue:`52541`)
329+
- Performance improvement in :func:`concat` when the concatenation axis is a :class:`MultiIndex` (:issue:`53574`)
322330
- Performance improvement in :meth:`.DataFrameGroupBy.groups` (:issue:`53088`)
323331
- Performance improvement in :meth:`DataFrame.isin` for extension dtypes (:issue:`53514`)
324332
- Performance improvement in :meth:`DataFrame.loc` when selecting rows and columns (:issue:`53014`)
@@ -342,6 +350,7 @@ Bug fixes
342350

343351
Categorical
344352
^^^^^^^^^^^
353+
- Bug in :meth:`Series.astype` with ``dtype="category"`` for nullable arrays with read-only null value masks (:issue:`53658`)
345354
- Bug in :meth:`Series.map` , where the value of the ``na_action`` parameter was not used if the series held a :class:`Categorical` (:issue:`22527`).
346355
-
347356

@@ -350,6 +359,7 @@ Datetimelike
350359
- :meth:`DatetimeIndex.map` with ``na_action="ignore"`` now works as expected. (:issue:`51644`)
351360
- Bug in :class:`DateOffset` which had inconsistent behavior when multiplying a :class:`DateOffset` object by a constant (:issue:`47953`)
352361
- Bug in :func:`date_range` when ``freq`` was a :class:`DateOffset` with ``nanoseconds`` (:issue:`46877`)
362+
- Bug in :meth:`Timestamp.date`, :meth:`Timestamp.isocalendar` were returning incorrect results for inputs outside those supported by the Python standard library's datetime module (:issue:`53668`)
353363
- Bug in :meth:`Timestamp.round` with values close to the implementation bounds returning incorrect results instead of raising ``OutOfBoundsDatetime`` (:issue:`51494`)
354364
- Bug in :meth:`arrays.DatetimeArray.map` and :meth:`DatetimeIndex.map`, where the supplied callable operated array-wise instead of element-wise (:issue:`51977`)
355365
- Bug in constructing a :class:`Series` or :class:`DataFrame` from a datetime or timedelta scalar always inferring nanosecond resolution instead of inferring from the input (:issue:`52212`)
@@ -360,6 +370,7 @@ Timedelta
360370
^^^^^^^^^
361371
- :meth:`TimedeltaIndex.map` with ``na_action="ignore"`` now works as expected (:issue:`51644`)
362372
- Bug in :class:`TimedeltaIndex` division or multiplication leading to ``.freq`` of "0 Days" instead of ``None`` (:issue:`51575`)
373+
- Bug in :class:`Timedelta` with Numpy timedelta64 objects not properly raising ``ValueError`` (:issue:`52806`)
363374
- Bug in :meth:`Timedelta.round` with values close to the implementation bounds returning incorrect results instead of raising ``OutOfBoundsTimedelta`` (:issue:`51494`)
364375
- Bug in :meth:`arrays.TimedeltaArray.map` and :meth:`TimedeltaIndex.map`, where the supplied callable operated array-wise instead of element-wise (:issue:`51977`)
365376
-
@@ -401,7 +412,7 @@ Strings
401412

402413
Interval
403414
^^^^^^^^
404-
-
415+
- :meth:`pd.IntervalIndex.get_indexer` and :meth:`pd.IntervalIndex.get_indexer_nonunique` raising if ``target`` is read-only array (:issue:`53703`)
405416
-
406417

407418
Indexing
@@ -453,6 +464,7 @@ Plotting
453464
Groupby/resample/rolling
454465
^^^^^^^^^^^^^^^^^^^^^^^^
455466
- Bug in :meth:`DataFrame.resample` and :meth:`Series.resample` in incorrectly allowing non-fixed ``freq`` when resampling on a :class:`TimedeltaIndex` (:issue:`51896`)
467+
- Bug in :meth:`DataFrame.resample` and :meth:`Series.resample` losing time zone when resampling empty data (:issue:`53664`)
456468
- Bug in :meth:`DataFrameGroupBy.idxmin`, :meth:`SeriesGroupBy.idxmin`, :meth:`DataFrameGroupBy.idxmax`, :meth:`SeriesGroupBy.idxmax` return wrong dtype when used on empty DataFrameGroupBy or SeriesGroupBy (:issue:`51423`)
457469
- Bug in weighted rolling aggregations when specifying ``min_periods=0`` (:issue:`51449`)
458470
- Bug in :meth:`DataFrame.groupby` and :meth:`Series.groupby`, where, when the index of the
@@ -472,6 +484,7 @@ Groupby/resample/rolling
472484

473485
Reshaping
474486
^^^^^^^^^
487+
- Bug in :func:`concat` coercing to ``object`` dtype when one column has ``pa.null()`` dtype (:issue:`53702`)
475488
- Bug in :func:`crosstab` when ``dropna=False`` would not keep ``np.nan`` in the result (:issue:`10772`)
476489
- Bug in :func:`merge_asof` raising ``KeyError`` for extension dtypes (:issue:`52904`)
477490
- Bug in :func:`merge_asof` raising ``ValueError`` for data backed by read-only ndarrays (:issue:`53513`)
@@ -511,6 +524,7 @@ Metadata
511524

512525
Other
513526
^^^^^
527+
- Bug in :class:`DataFrame` and :class:`Series` raising for data of complex dtype when ``NaN`` values are present (:issue:`53627`)
514528
- Bug in :class:`FloatingArray.__contains__` with ``NaN`` item incorrectly returning ``False`` when ``NaN`` values are present (:issue:`52840`)
515529
- Bug in :func:`api.interchange.from_dataframe` when converting an empty DataFrame object (:issue:`53155`)
516530
- Bug in :func:`assert_almost_equal` now throwing assertion error for two unequal sets (:issue:`51727`)

pandas/_libs/tslibs/nattype.pyx

+123-8
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,16 @@ cdef class _NaT(datetime):
256256

257257
def to_datetime64(self) -> np.datetime64:
258258
"""
259-
Return a numpy.datetime64 object with 'ns' precision.
259+
Return a numpy.datetime64 object with same precision.
260+
261+
Examples
262+
--------
263+
>>> ts = pd.Timestamp(year=2023, month=1, day=1,
264+
... hour=10, second=15)
265+
>>> ts
266+
Timestamp('2023-01-01 10:00:15')
267+
>>> ts.to_datetime64()
268+
numpy.datetime64('2023-01-01T10:00:15.000000')
260269
"""
261270
return np.datetime64("NaT", "ns")
262271

@@ -429,6 +438,14 @@ class NaTType(_NaT):
429438
Return the day of the week represented by the date.
430439
431440
Monday == 0 ... Sunday == 6.
441+
442+
Examples
443+
--------
444+
>>> ts = pd.Timestamp('2023-01-01')
445+
>>> ts
446+
Timestamp('2023-01-01 00:00:00')
447+
>>> ts.weekday()
448+
6
432449
""",
433450
)
434451
isoweekday = _make_nan_func(
@@ -514,13 +531,6 @@ class NaTType(_NaT):
514531
""",
515532
)
516533
# _nat_methods
517-
utctimetuple = _make_error_func("utctimetuple", datetime)
518-
timetz = _make_error_func("timetz", datetime)
519-
timetuple = _make_error_func("timetuple", datetime)
520-
time = _make_error_func("time", datetime)
521-
toordinal = _make_error_func("toordinal", datetime)
522-
tzname = _make_error_func("tzname", datetime)
523-
utcoffset = _make_error_func("utcoffset", datetime)
524534

525535
# "fromisocalendar" was introduced in 3.8
526536
fromisocalendar = _make_error_func("fromisocalendar", datetime)
@@ -570,7 +580,106 @@ class NaTType(_NaT):
570580
datetime.date(2023, 1, 1)
571581
"""
572582
)
583+
utctimetuple = _make_error_func(
584+
"utctimetuple",
585+
"""
586+
Return UTC time tuple, compatible with time.localtime().
587+
588+
Examples
589+
--------
590+
>>> ts = pd.Timestamp('2023-01-01 10:00:00', tz='Europe/Brussels')
591+
>>> ts
592+
Timestamp('2023-01-01 10:00:00+0100', tz='Europe/Brussels')
593+
>>> ts.utctimetuple()
594+
time.struct_time(tm_year=2023, tm_mon=1, tm_mday=1, tm_hour=9,
595+
tm_min=0, tm_sec=0, tm_wday=6, tm_yday=1, tm_isdst=0)
596+
"""
597+
)
598+
utcoffset = _make_error_func(
599+
"utcoffset",
600+
"""
601+
Return utc offset.
602+
603+
Examples
604+
--------
605+
>>> ts = pd.Timestamp('2023-01-01 10:00:00', tz='Europe/Brussels')
606+
>>> ts
607+
Timestamp('2023-01-01 10:00:00+0100', tz='Europe/Brussels')
608+
>>> ts.utcoffset()
609+
datetime.timedelta(seconds=3600)
610+
"""
611+
)
612+
tzname = _make_error_func(
613+
"tzname",
614+
"""
615+
Return time zone name.
616+
617+
Examples
618+
--------
619+
>>> ts = pd.Timestamp('2023-01-01 10:00:00', tz='Europe/Brussels')
620+
>>> ts
621+
Timestamp('2023-01-01 10:00:00+0100', tz='Europe/Brussels')
622+
>>> ts.tzname()
623+
'CET'
624+
"""
625+
)
626+
time = _make_error_func(
627+
"time",
628+
"""
629+
Return time object with same time but with tzinfo=None.
630+
631+
Examples
632+
--------
633+
>>> ts = pd.Timestamp('2023-01-01 10:00:00')
634+
>>> ts
635+
Timestamp('2023-01-01 10:00:00')
636+
>>> ts.time()
637+
datetime.time(10, 0)
638+
""",
639+
)
640+
timetuple = _make_error_func(
641+
"timetuple",
642+
"""
643+
Return time tuple, compatible with time.localtime().
644+
645+
Examples
646+
--------
647+
>>> ts = pd.Timestamp('2023-01-01 10:00:00')
648+
>>> ts
649+
Timestamp('2023-01-01 10:00:00')
650+
>>> ts.timetuple()
651+
time.struct_time(tm_year=2023, tm_mon=1, tm_mday=1,
652+
tm_hour=10, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=1, tm_isdst=-1)
653+
"""
654+
)
655+
timetz = _make_error_func(
656+
"timetz",
657+
"""
658+
Return time object with same time and tzinfo.
659+
660+
Examples
661+
--------
662+
>>> ts = pd.Timestamp('2023-01-01 10:00:00', tz='Europe/Brussels')
663+
>>> ts
664+
Timestamp('2023-01-01 10:00:00+0100', tz='Europe/Brussels')
665+
>>> ts.timetz()
666+
datetime.time(10, 0, tzinfo=<DstTzInfo 'Europe/Brussels' CET+1:00:00 STD>)
667+
"""
668+
)
669+
toordinal = _make_error_func(
670+
"toordinal",
671+
"""
672+
Return proleptic Gregorian ordinal. January 1 of year 1 is day 1.
573673
674+
Examples
675+
--------
676+
>>> ts = pd.Timestamp('2023-01-01 10:00:50')
677+
>>> ts
678+
Timestamp('2023-01-01 10:00:50')
679+
>>> ts.toordinal()
680+
738521
681+
"""
682+
)
574683
ctime = _make_error_func(
575684
"ctime",
576685
"""
@@ -612,6 +721,12 @@ class NaTType(_NaT):
612721
Timestamp.strptime(string, format)
613722
614723
Function is not implemented. Use pd.to_datetime().
724+
725+
Examples
726+
--------
727+
>>> pd.Timestamp.strptime("2023-01-01", "%d/%m/%y")
728+
Traceback (most recent call last):
729+
NotImplementedError
615730
""",
616731
)
617732

pandas/_libs/tslibs/period.pyx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1917,7 +1917,8 @@ cdef class _Period(PeriodMixin):
19171917
Parameters
19181918
----------
19191919
freq : str, BaseOffset
1920-
The desired frequency.
1920+
The desired frequency. If passing a `str`, it needs to be a
1921+
valid :ref:`period alias <timeseries.period_aliases>`.
19211922
how : {'E', 'S', 'end', 'start'}, default 'end'
19221923
Start or end of the timespan.
19231924

0 commit comments

Comments
 (0)