Skip to content

Commit b067001

Browse files
authored
Merge branch 'main' into depr-change-stacklevel
2 parents 6e5e6aa + 986074b commit b067001

File tree

7 files changed

+147
-16
lines changed

7 files changed

+147
-16
lines changed

ci/code_checks.sh

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
146146
-i "pandas.Series.cat.rename_categories PR01,PR02" \
147147
-i "pandas.Series.cat.reorder_categories PR01,PR02" \
148148
-i "pandas.Series.cat.set_categories PR01,PR02" \
149-
-i "pandas.Series.div PR07" \
150149
-i "pandas.Series.dt.as_unit PR01,PR02" \
151150
-i "pandas.Series.dt.ceil PR01,PR02" \
152151
-i "pandas.Series.dt.components SA01" \
@@ -239,7 +238,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
239238
-i "pandas.Series.to_frame SA01" \
240239
-i "pandas.Series.to_markdown SA01" \
241240
-i "pandas.Series.to_string SA01" \
242-
-i "pandas.Series.truediv PR07" \
243241
-i "pandas.Series.update PR07,SA01" \
244242
-i "pandas.Series.var PR01,RT03,SA01" \
245243
-i "pandas.Timedelta PR07,SA01" \
@@ -290,7 +288,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
290288
-i "pandas.Timestamp.quarter SA01" \
291289
-i "pandas.Timestamp.replace PR07,SA01" \
292290
-i "pandas.Timestamp.resolution PR02,PR07,SA01" \
293-
-i "pandas.Timestamp.round SA01" \
294291
-i "pandas.Timestamp.second GL08" \
295292
-i "pandas.Timestamp.strptime PR01,SA01" \
296293
-i "pandas.Timestamp.time SA01" \
@@ -301,7 +298,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
301298
-i "pandas.Timestamp.to_julian_date SA01" \
302299
-i "pandas.Timestamp.to_numpy PR01" \
303300
-i "pandas.Timestamp.to_period PR01,SA01" \
304-
-i "pandas.Timestamp.to_pydatetime PR01,SA01" \
305301
-i "pandas.Timestamp.today SA01" \
306302
-i "pandas.Timestamp.toordinal SA01" \
307303
-i "pandas.Timestamp.tz SA01" \
@@ -548,7 +544,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
548544
-i "pandas.tseries.api.guess_datetime_format SA01" \
549545
-i "pandas.tseries.offsets.BDay PR02,SA01" \
550546
-i "pandas.tseries.offsets.BMonthBegin PR02" \
551-
-i "pandas.tseries.offsets.BMonthEnd PR02" \
552547
-i "pandas.tseries.offsets.BQuarterBegin PR02" \
553548
-i "pandas.tseries.offsets.BQuarterBegin.freqstr SA01" \
554549
-i "pandas.tseries.offsets.BQuarterBegin.is_on_offset GL08" \
@@ -609,7 +604,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
609604
-i "pandas.tseries.offsets.BusinessMonthBegin.nanos GL08" \
610605
-i "pandas.tseries.offsets.BusinessMonthBegin.normalize GL08" \
611606
-i "pandas.tseries.offsets.BusinessMonthBegin.rule_code GL08" \
612-
-i "pandas.tseries.offsets.BusinessMonthEnd PR02" \
613607
-i "pandas.tseries.offsets.BusinessMonthEnd.freqstr SA01" \
614608
-i "pandas.tseries.offsets.BusinessMonthEnd.is_on_offset GL08" \
615609
-i "pandas.tseries.offsets.BusinessMonthEnd.n GL08" \
@@ -754,7 +748,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
754748
-i "pandas.tseries.offsets.MonthBegin.nanos GL08" \
755749
-i "pandas.tseries.offsets.MonthBegin.normalize GL08" \
756750
-i "pandas.tseries.offsets.MonthBegin.rule_code GL08" \
757-
-i "pandas.tseries.offsets.MonthEnd PR02" \
758751
-i "pandas.tseries.offsets.MonthEnd.freqstr SA01" \
759752
-i "pandas.tseries.offsets.MonthEnd.is_on_offset GL08" \
760753
-i "pandas.tseries.offsets.MonthEnd.n GL08" \
@@ -799,7 +792,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
799792
-i "pandas.tseries.offsets.SemiMonthBegin.nanos GL08" \
800793
-i "pandas.tseries.offsets.SemiMonthBegin.normalize GL08" \
801794
-i "pandas.tseries.offsets.SemiMonthBegin.rule_code GL08" \
802-
-i "pandas.tseries.offsets.SemiMonthEnd PR02,SA01" \
795+
-i "pandas.tseries.offsets.SemiMonthEnd SA01" \
803796
-i "pandas.tseries.offsets.SemiMonthEnd.day_of_month GL08" \
804797
-i "pandas.tseries.offsets.SemiMonthEnd.freqstr SA01" \
805798
-i "pandas.tseries.offsets.SemiMonthEnd.is_on_offset GL08" \

doc/source/user_guide/indexing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,6 @@ Why does assignment fail when using chained indexing?
17111711
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17121712

17131713
:ref:`Copy-on-Write <copy_on_write>` is the new default with pandas 3.0.
1714-
This means than chained indexing will never work.
1714+
This means that chained indexing will never work.
17151715
See :ref:`this section <copy_on_write_chained_assignment>`
17161716
for more context.

pandas/_libs/tslibs/nattype.pyx

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,30 @@ class NaTType(_NaT):
882882
"""
883883
Convert a Timestamp object to a native Python datetime object.
884884
885-
If warn=True, issue a warning if nanoseconds is nonzero.
885+
This method is useful for when you need to utilize a pandas Timestamp
886+
object in contexts where native Python datetime objects are expected
887+
or required. The conversion discards the nanoseconds component, and a
888+
warning can be issued in such cases if desired.
889+
890+
Parameters
891+
----------
892+
warn : bool, default True
893+
If True, issues a warning when the timestamp includes nonzero
894+
nanoseconds, as these will be discarded during the conversion.
895+
896+
Returns
897+
-------
898+
datetime.datetime or NaT
899+
Returns a datetime.datetime object representing the timestamp,
900+
with year, month, day, hour, minute, second, and microsecond components.
901+
If the timestamp is NaT (Not a Time), returns NaT.
902+
903+
See Also
904+
--------
905+
datetime.datetime : The standard Python datetime class that this method
906+
returns.
907+
Timestamp.timestamp : Convert a Timestamp object to POSIX timestamp.
908+
Timestamp.to_datetime64 : Convert a Timestamp object to numpy.datetime64.
886909
887910
Examples
888911
--------
@@ -947,6 +970,12 @@ class NaTType(_NaT):
947970
"""
948971
Round the Timestamp to the specified resolution.
949972
973+
This method rounds the given Timestamp down to a specified frequency
974+
level. It is particularly useful in data analysis to normalize timestamps
975+
to regular frequency intervals. For instance, rounding to the nearest
976+
minute, hour, or day can help in time series comparisons or resampling
977+
operations.
978+
950979
Parameters
951980
----------
952981
freq : str
@@ -981,6 +1010,14 @@ timedelta}, default 'raise'
9811010
------
9821011
ValueError if the freq cannot be converted
9831012
1013+
See Also
1014+
--------
1015+
datetime.round : Similar behavior in native Python datetime module.
1016+
Timestamp.floor : Round the Timestamp downward to the nearest multiple
1017+
of the specified frequency.
1018+
Timestamp.ceil : Round the Timestamp upward to the nearest multiple of
1019+
the specified frequency.
1020+
9841021
Notes
9851022
-----
9861023
If the Timestamp has a timezone, rounding will take place relative to the

pandas/_libs/tslibs/offsets.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2939,7 +2939,7 @@ cdef class MonthEnd(MonthOffset):
29392939
29402940
MonthEnd goes to the next date which is an end of the month.
29412941
2942-
Parameters
2942+
Attributes
29432943
----------
29442944
n : int, default 1
29452945
The number of months represented.
@@ -3014,7 +3014,7 @@ cdef class BusinessMonthEnd(MonthOffset):
30143014
30153015
BusinessMonthEnd goes to the next date which is the last business day of the month.
30163016
3017-
Parameters
3017+
Attributes
30183018
----------
30193019
n : int, default 1
30203020
The number of months represented.
@@ -3222,7 +3222,7 @@ cdef class SemiMonthEnd(SemiMonthOffset):
32223222
"""
32233223
Two DateOffset's per month repeating on the last day of the month & day_of_month.
32243224
3225-
Parameters
3225+
Attributes
32263226
----------
32273227
n : int, default 1
32283228
The number of months represented.

pandas/_libs/tslibs/timestamps.pyx

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,30 @@ cdef class _Timestamp(ABCTimestamp):
11961196
"""
11971197
Convert a Timestamp object to a native Python datetime object.
11981198
1199-
If warn=True, issue a warning if nanoseconds is nonzero.
1199+
This method is useful for when you need to utilize a pandas Timestamp
1200+
object in contexts where native Python datetime objects are expected
1201+
or required. The conversion discards the nanoseconds component, and a
1202+
warning can be issued in such cases if desired.
1203+
1204+
Parameters
1205+
----------
1206+
warn : bool, default True
1207+
If True, issues a warning when the timestamp includes nonzero
1208+
nanoseconds, as these will be discarded during the conversion.
1209+
1210+
Returns
1211+
-------
1212+
datetime.datetime or NaT
1213+
Returns a datetime.datetime object representing the timestamp,
1214+
with year, month, day, hour, minute, second, and microsecond components.
1215+
If the timestamp is NaT (Not a Time), returns NaT.
1216+
1217+
See Also
1218+
--------
1219+
datetime.datetime : The standard Python datetime class that this method
1220+
returns.
1221+
Timestamp.timestamp : Convert a Timestamp object to POSIX timestamp.
1222+
Timestamp.to_datetime64 : Convert a Timestamp object to numpy.datetime64.
12001223
12011224
Examples
12021225
--------
@@ -2015,6 +2038,12 @@ class Timestamp(_Timestamp):
20152038
"""
20162039
Round the Timestamp to the specified resolution.
20172040
2041+
This method rounds the given Timestamp down to a specified frequency
2042+
level. It is particularly useful in data analysis to normalize timestamps
2043+
to regular frequency intervals. For instance, rounding to the nearest
2044+
minute, hour, or day can help in time series comparisons or resampling
2045+
operations.
2046+
20182047
Parameters
20192048
----------
20202049
freq : str
@@ -2049,6 +2078,14 @@ timedelta}, default 'raise'
20492078
------
20502079
ValueError if the freq cannot be converted
20512080
2081+
See Also
2082+
--------
2083+
datetime.round : Similar behavior in native Python datetime module.
2084+
Timestamp.floor : Round the Timestamp downward to the nearest multiple
2085+
of the specified frequency.
2086+
Timestamp.ceil : Round the Timestamp upward to the nearest multiple of
2087+
the specified frequency.
2088+
20522089
Notes
20532090
-----
20542091
If the Timestamp has a timezone, rounding will take place relative to the

pandas/core/series.py

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6122,8 +6122,65 @@ def rmul(self, other, level=None, fill_value=None, axis: Axis = 0) -> Series:
61226122
other, roperator.rmul, level=level, fill_value=fill_value, axis=axis
61236123
)
61246124

6125-
@Appender(ops.make_flex_doc("truediv", "series"))
61266125
def truediv(self, other, level=None, fill_value=None, axis: Axis = 0) -> Series:
6126+
"""
6127+
Return Floating division of series and other, \
6128+
element-wise (binary operator `truediv`).
6129+
6130+
Equivalent to ``series / other``, but with support to substitute a
6131+
fill_value for missing data in either one of the inputs.
6132+
6133+
Parameters
6134+
----------
6135+
other : Series or scalar value
6136+
Series with which to compute division.
6137+
level : int or name
6138+
Broadcast across a level, matching Index values on the
6139+
passed MultiIndex level.
6140+
fill_value : None or float value, default None (NaN)
6141+
Fill existing missing (NaN) values, and any new element needed for
6142+
successful Series alignment, with this value before computation.
6143+
If data in both corresponding Series locations is missing
6144+
the result of filling (at that location) will be missing.
6145+
axis : {0 or 'index'}
6146+
Unused. Parameter needed for compatibility with DataFrame.
6147+
6148+
Returns
6149+
-------
6150+
Series
6151+
The result of the operation.
6152+
6153+
See Also
6154+
--------
6155+
Series.rtruediv : Reverse of the Floating division operator, see
6156+
`Python documentation
6157+
<https://docs.python.org/3/reference/datamodel.html#emulating-numeric-types>`_
6158+
for more details.
6159+
6160+
Examples
6161+
--------
6162+
>>> a = pd.Series([1, 1, 1, np.nan], index=["a", "b", "c", "d"])
6163+
>>> a
6164+
a 1.0
6165+
b 1.0
6166+
c 1.0
6167+
d NaN
6168+
dtype: float64
6169+
>>> b = pd.Series([1, np.nan, 1, np.nan], index=["a", "b", "d", "e"])
6170+
>>> b
6171+
a 1.0
6172+
b NaN
6173+
d 1.0
6174+
e NaN
6175+
dtype: float64
6176+
>>> a.divide(b, fill_value=0)
6177+
a 1.0
6178+
b inf
6179+
c inf
6180+
d 0.0
6181+
e NaN
6182+
dtype: float64
6183+
"""
61276184
return self._flex_method(
61286185
other, operator.truediv, level=level, fill_value=fill_value, axis=axis
61296186
)

pandas/tests/generic/test_to_xarray.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
date_range,
1010
)
1111
import pandas._testing as tm
12+
from pandas.util.version import Version
1213

1314
pytest.importorskip("xarray")
1415

@@ -29,11 +30,17 @@ def df(self):
2930
}
3031
)
3132

32-
def test_to_xarray_index_types(self, index_flat, df, using_infer_string):
33+
def test_to_xarray_index_types(self, index_flat, df, using_infer_string, request):
3334
index = index_flat
3435
# MultiIndex is tested in test_to_xarray_with_multiindex
3536
if len(index) == 0:
3637
pytest.skip("Test doesn't make sense for empty index")
38+
import xarray
39+
40+
if Version(xarray.__version__) >= Version("2024.5"):
41+
request.applymarker(
42+
pytest.mark.xfail(reason="https://github.com/pydata/xarray/issues/9026")
43+
)
3744

3845
from xarray import Dataset
3946

0 commit comments

Comments
 (0)