Skip to content

Commit 41c96a2

Browse files
committed
Merge branch 'main' of https://github.com/pandas-dev/pandas into bug_empty_contructor_dtype
2 parents ad0260c + 34177d6 commit 41c96a2

File tree

10 files changed

+216
-50
lines changed

10 files changed

+216
-50
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,8 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
7777
-i "pandas.DataFrame.plot PR02,SA01" \
7878
-i "pandas.Grouper PR02" \
7979
-i "pandas.Index PR07" \
80-
-i "pandas.IntervalIndex.is_non_overlapping_monotonic SA01" \
8180
-i "pandas.IntervalIndex.left GL08" \
82-
-i "pandas.IntervalIndex.length GL08" \
8381
-i "pandas.IntervalIndex.set_closed RT03,SA01" \
84-
-i "pandas.IntervalIndex.to_tuples RT03,SA01" \
8582
-i "pandas.MultiIndex PR01" \
8683
-i "pandas.MultiIndex.append PR07,SA01" \
8784
-i "pandas.MultiIndex.copy PR07,RT03,SA01" \
@@ -144,9 +141,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
144141
-i "pandas.RangeIndex.start SA01" \
145142
-i "pandas.RangeIndex.step SA01" \
146143
-i "pandas.RangeIndex.stop SA01" \
147-
-i "pandas.Series.add PR07" \
148144
-i "pandas.Series.case_when RT03" \
149-
-i "pandas.Series.cat PR07" \
150145
-i "pandas.Series.cat.add_categories PR01,PR02" \
151146
-i "pandas.Series.cat.as_ordered PR01" \
152147
-i "pandas.Series.cat.as_unordered PR01" \
@@ -274,7 +269,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
274269
-i "pandas.TimedeltaIndex.nanoseconds SA01" \
275270
-i "pandas.TimedeltaIndex.seconds SA01" \
276271
-i "pandas.TimedeltaIndex.to_pytimedelta RT03,SA01" \
277-
-i "pandas.Timestamp.asm8 SA01" \
278272
-i "pandas.Timestamp.astimezone SA01" \
279273
-i "pandas.Timestamp.ceil SA01" \
280274
-i "pandas.Timestamp.combine PR01,SA01" \
@@ -289,7 +283,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
289283
-i "pandas.Timestamp.hour GL08" \
290284
-i "pandas.Timestamp.is_leap_year SA01" \
291285
-i "pandas.Timestamp.isocalendar SA01" \
292-
-i "pandas.Timestamp.isoformat SA01" \
293286
-i "pandas.Timestamp.isoweekday SA01" \
294287
-i "pandas.Timestamp.max PR02" \
295288
-i "pandas.Timestamp.microsecond GL08" \
@@ -305,7 +298,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
305298
-i "pandas.Timestamp.resolution PR02,PR07,SA01" \
306299
-i "pandas.Timestamp.round SA01" \
307300
-i "pandas.Timestamp.second GL08" \
308-
-i "pandas.Timestamp.strftime SA01" \
309301
-i "pandas.Timestamp.strptime PR01,SA01" \
310302
-i "pandas.Timestamp.time SA01" \
311303
-i "pandas.Timestamp.timestamp SA01" \
@@ -328,9 +320,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
328320
-i "pandas.Timestamp.utcoffset SA01" \
329321
-i "pandas.Timestamp.utctimetuple SA01" \
330322
-i "pandas.Timestamp.value GL08" \
331-
-i "pandas.Timestamp.week SA01" \
332323
-i "pandas.Timestamp.weekday SA01" \
333-
-i "pandas.Timestamp.weekofyear SA01" \
334324
-i "pandas.Timestamp.year GL08" \
335325
-i "pandas.api.extensions.ExtensionArray._from_sequence_of_strings SA01" \
336326
-i "pandas.api.extensions.ExtensionArray._hash_pandas_object RT03,SA01" \
@@ -402,13 +392,11 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
402392
-i "pandas.arrays.DatetimeArray SA01" \
403393
-i "pandas.arrays.FloatingArray SA01" \
404394
-i "pandas.arrays.IntegerArray SA01" \
405-
-i "pandas.arrays.IntervalArray.is_non_overlapping_monotonic SA01" \
406395
-i "pandas.arrays.IntervalArray.left SA01" \
407396
-i "pandas.arrays.IntervalArray.length SA01" \
408397
-i "pandas.arrays.IntervalArray.mid SA01" \
409398
-i "pandas.arrays.IntervalArray.right SA01" \
410399
-i "pandas.arrays.IntervalArray.set_closed RT03,SA01" \
411-
-i "pandas.arrays.IntervalArray.to_tuples RT03,SA01" \
412400
-i "pandas.arrays.NumpyExtensionArray SA01" \
413401
-i "pandas.arrays.SparseArray PR07,SA01" \
414402
-i "pandas.arrays.TimedeltaArray PR07,SA01" \

doc/source/whatsnew/v3.0.0.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ Datetimelike
384384
- Bug in :func:`date_range` where the last valid timestamp would sometimes not be produced (:issue:`56134`)
385385
- Bug in :func:`date_range` where using a negative frequency value would not include all points between the start and end values (:issue:`56382`)
386386
- Bug in :func:`tseries.api.guess_datetime_format` would fail to infer time format when "%Y" == "%H%M" (:issue:`57452`)
387+
- Bug in :meth:`DatetimeIndex.is_year_start` and :meth:`DatetimeIndex.is_quarter_start` does not raise on Custom business days frequencies bigger then "1C" (:issue:`58664`)
388+
- Bug in :meth:`DatetimeIndex.is_year_start` and :meth:`DatetimeIndex.is_quarter_start` returning ``False`` on double-digit frequencies (:issue:`58523`)
387389
- Bug in setting scalar values with mismatched resolution into arrays with non-nanosecond ``datetime64``, ``timedelta64`` or :class:`DatetimeTZDtype` incorrectly truncating those scalars (:issue:`56410`)
388390

389391
Timedelta
@@ -421,7 +423,6 @@ Interval
421423
Indexing
422424
^^^^^^^^
423425
- Bug in :meth:`DataFrame.__getitem__` returning modified columns when called with ``slice`` in Python 3.12 (:issue:`57500`)
424-
- Bug in :meth:`DatetimeIndex.is_year_start` and :meth:`DatetimeIndex.is_quarter_start` returning ``False`` on double-digit frequencies (:issue:`58523`)
425426
-
426427

427428
Missing

pandas/_libs/tslibs/fields.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def get_start_end_field(
253253
# month of year. Other offsets use month, startingMonth as ending
254254
# month of year.
255255

256-
if freq_name.lstrip("B")[0:2] in ["MS", "QS", "YS"]:
256+
if freq_name.lstrip("B")[0:2] in ["MS", "QS", "YS"]:
257257
end_month = 12 if month_kw == 1 else month_kw - 1
258258
start_month = month_kw
259259
else:

pandas/_libs/tslibs/nattype.pyx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,12 @@ class NaTType(_NaT):
692692
See strftime documentation for more information on the format string:
693693
https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior.
694694
695+
See Also
696+
--------
697+
Timestamp.isoformat : Return the time formatted according to ISO 8601.
698+
pd.to_datetime : Convert argument to datetime.
699+
Period.strftime : Format a single Period.
700+
695701
Examples
696702
--------
697703
>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548651')

pandas/_libs/tslibs/timestamps.pyx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,11 @@ cdef class _Timestamp(ABCTimestamp):
902902
-------
903903
int
904904

905+
See Also
906+
--------
907+
Timestamp.weekday : Return the day of the week.
908+
Timestamp.quarter : Return the quarter of the year.
909+
905910
Examples
906911
--------
907912
>>> ts = pd.Timestamp(2020, 3, 14)
@@ -1008,6 +1013,12 @@ cdef class _Timestamp(ABCTimestamp):
10081013
-------
10091014
str
10101015

1016+
See Also
1017+
--------
1018+
Timestamp.strftime : Return a formatted string.
1019+
Timestamp.isocalendar : Return a tuple containing ISO year, week number and
1020+
weekday.
1021+
10111022
Examples
10121023
--------
10131024
>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548651')
@@ -1150,6 +1161,12 @@ cdef class _Timestamp(ABCTimestamp):
11501161
"""
11511162
Return numpy datetime64 format in nanoseconds.
11521163

1164+
See Also
1165+
--------
1166+
numpy.datetime64 : Numpy datatype for dates and times with high precision.
1167+
Timestamp.to_numpy : Convert the Timestamp to a NumPy datetime64.
1168+
to_datetime : Convert argument to datetime.
1169+
11531170
Examples
11541171
--------
11551172
>>> ts = pd.Timestamp(2020, 3, 14, 15)
@@ -1543,6 +1560,12 @@ class Timestamp(_Timestamp):
15431560
See strftime documentation for more information on the format string:
15441561
https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior.
15451562
1563+
See Also
1564+
--------
1565+
Timestamp.isoformat : Return the time formatted according to ISO 8601.
1566+
pd.to_datetime : Convert argument to datetime.
1567+
Period.strftime : Format a single Period.
1568+
15461569
Examples
15471570
--------
15481571
>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548651')

pandas/core/arrays/categorical.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2847,6 +2847,7 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
28472847
Parameters
28482848
----------
28492849
data : Series or CategoricalIndex
2850+
The object to which the categorical accessor is attached.
28502851
28512852
See Also
28522853
--------

pandas/core/arrays/interval.py

Lines changed: 91 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,10 +1509,54 @@ def set_closed(self, closed: IntervalClosedType) -> Self:
15091509
"""
15101510

15111511
@property
1512-
@Appender(
1513-
_interval_shared_docs["is_non_overlapping_monotonic"] % _shared_docs_kwargs
1514-
)
15151512
def is_non_overlapping_monotonic(self) -> bool:
1513+
"""
1514+
Return a boolean whether the IntervalArray/IntervalIndex\
1515+
is non-overlapping and monotonic.
1516+
1517+
Non-overlapping means (no Intervals share points), and monotonic means
1518+
either monotonic increasing or monotonic decreasing.
1519+
1520+
See Also
1521+
--------
1522+
overlaps : Check if two IntervalIndex objects overlap.
1523+
1524+
Examples
1525+
--------
1526+
For arrays:
1527+
1528+
>>> interv_arr = pd.arrays.IntervalArray([pd.Interval(0, 1), pd.Interval(1, 5)])
1529+
>>> interv_arr
1530+
<IntervalArray>
1531+
[(0, 1], (1, 5]]
1532+
Length: 2, dtype: interval[int64, right]
1533+
>>> interv_arr.is_non_overlapping_monotonic
1534+
True
1535+
1536+
>>> interv_arr = pd.arrays.IntervalArray(
1537+
... [pd.Interval(0, 1), pd.Interval(-1, 0.1)]
1538+
... )
1539+
>>> interv_arr
1540+
<IntervalArray>
1541+
[(0.0, 1.0], (-1.0, 0.1]]
1542+
Length: 2, dtype: interval[float64, right]
1543+
>>> interv_arr.is_non_overlapping_monotonic
1544+
False
1545+
1546+
For Interval Index:
1547+
1548+
>>> interv_idx = pd.interval_range(start=0, end=2)
1549+
>>> interv_idx
1550+
IntervalIndex([(0, 1], (1, 2]], dtype='interval[int64, right]')
1551+
>>> interv_idx.is_non_overlapping_monotonic
1552+
True
1553+
1554+
>>> interv_idx = pd.interval_range(start=0, end=2, closed="both")
1555+
>>> interv_idx
1556+
IntervalIndex([[0, 1], [1, 2]], dtype='interval[int64, both]')
1557+
>>> interv_idx.is_non_overlapping_monotonic
1558+
False
1559+
"""
15161560
# must be increasing (e.g., [0, 1), [1, 2), [2, 3), ... )
15171561
# or decreasing (e.g., [-1, 0), [-2, -1), [-3, -2), ...)
15181562
# we already require left <= right
@@ -1624,39 +1668,51 @@ def __arrow_array__(self, type=None):
16241668
"""
16251669
)
16261670

1627-
@Appender(
1628-
_interval_shared_docs["to_tuples"]
1629-
% {
1630-
"return_type": (
1631-
"ndarray (if self is IntervalArray) or Index (if self is IntervalIndex)"
1632-
),
1633-
"examples": textwrap.dedent(
1634-
"""\
1635-
1636-
Examples
1637-
--------
1638-
For :class:`pandas.IntervalArray`:
1639-
1640-
>>> idx = pd.arrays.IntervalArray.from_tuples([(0, 1), (1, 2)])
1641-
>>> idx
1642-
<IntervalArray>
1643-
[(0, 1], (1, 2]]
1644-
Length: 2, dtype: interval[int64, right]
1645-
>>> idx.to_tuples()
1646-
array([(0, 1), (1, 2)], dtype=object)
1647-
1648-
For :class:`pandas.IntervalIndex`:
1649-
1650-
>>> idx = pd.interval_range(start=0, end=2)
1651-
>>> idx
1652-
IntervalIndex([(0, 1], (1, 2]], dtype='interval[int64, right]')
1653-
>>> idx.to_tuples()
1654-
Index([(0, 1), (1, 2)], dtype='object')
1655-
"""
1656-
),
1657-
}
1658-
)
16591671
def to_tuples(self, na_tuple: bool = True) -> np.ndarray:
1672+
"""
1673+
Return an ndarray (if self is IntervalArray) or Index \
1674+
(if self is IntervalIndex) of tuples of the form (left, right).
1675+
1676+
Parameters
1677+
----------
1678+
na_tuple : bool, default True
1679+
If ``True``, return ``NA`` as a tuple ``(nan, nan)``. If ``False``,
1680+
just return ``NA`` as ``nan``.
1681+
1682+
Returns
1683+
-------
1684+
ndarray or Index
1685+
An ndarray of tuples representing the intervals
1686+
if `self` is an IntervalArray.
1687+
An Index of tuples representing the intervals
1688+
if `self` is an IntervalIndex.
1689+
1690+
See Also
1691+
--------
1692+
IntervalArray.to_list : Convert IntervalArray to a list of tuples.
1693+
IntervalArray.to_numpy : Convert IntervalArray to a numpy array.
1694+
IntervalArray.unique : Find unique intervals in an IntervalArray.
1695+
1696+
Examples
1697+
--------
1698+
For :class:`pandas.IntervalArray`:
1699+
1700+
>>> idx = pd.arrays.IntervalArray.from_tuples([(0, 1), (1, 2)])
1701+
>>> idx
1702+
<IntervalArray>
1703+
[(0, 1], (1, 2]]
1704+
Length: 2, dtype: interval[int64, right]
1705+
>>> idx.to_tuples()
1706+
array([(0, 1), (1, 2)], dtype=object)
1707+
1708+
For :class:`pandas.IntervalIndex`:
1709+
1710+
>>> idx = pd.interval_range(start=0, end=2)
1711+
>>> idx
1712+
IntervalIndex([(0, 1], (1, 2]], dtype='interval[int64, right]')
1713+
>>> idx.to_tuples()
1714+
Index([(0, 1), (1, 2)], dtype='object')
1715+
"""
16601716
tuples = com.asarray_tuplesafe(zip(self._left, self._right))
16611717
if not na_tuple:
16621718
# GH 18756

pandas/core/indexes/interval.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,34 @@ def mid(self) -> Index:
924924

925925
@property
926926
def length(self) -> Index:
927+
"""
928+
Calculate the length of each interval in the IntervalIndex.
929+
930+
This method returns a new Index containing the lengths of each interval
931+
in the IntervalIndex. The length of an interval is defined as the difference
932+
between its end and its start.
933+
934+
Returns
935+
-------
936+
Index
937+
An Index containing the lengths of each interval.
938+
939+
See Also
940+
--------
941+
Interval.length : Return the length of the Interval.
942+
943+
Examples
944+
--------
945+
>>> intervals = pd.IntervalIndex.from_arrays(
946+
... [1, 2, 3], [4, 5, 6], closed="right"
947+
... )
948+
>>> intervals.length
949+
Index([3, 3, 3], dtype='int64')
950+
951+
>>> intervals = pd.IntervalIndex.from_tuples([(1, 5), (6, 10), (11, 15)])
952+
>>> intervals.length
953+
Index([4, 4, 4], dtype='int64')
954+
"""
927955
return Index(self._data.length, copy=False)
928956

929957
# --------------------------------------------------------------------

0 commit comments

Comments
 (0)