Skip to content

Commit 580773d

Browse files
committed
np
1 parent fa4e26b commit 580773d

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

doc/source/whatsnew/v1.5.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ Other enhancements
278278
- :meth:`DatetimeIndex.astype` now supports casting timezone-naive indexes to ``datetime64[s]``, ``datetime64[ms]``, and ``datetime64[us]``, and timezone-aware indexes to the corresponding ``datetime64[unit, tzname]`` dtypes (:issue:`47579`)
279279
- :class:`Series` reducers (e.g. ``min``, ``max``, ``sum``, ``mean``) will now successfully operate when the dtype is numeric and ``numeric_only=True`` is provided; previously this would raise a ``NotImplementedError`` (:issue:`47500`)
280280
- :meth:`RangeIndex.union` now can return a :class:`RangeIndex` instead of a :class:`Int64Index` if the resulting values are equally spaced (:issue:`47557`, :issue:`43885`)
281-
- :meth:`DataFrame.compare` now accepts an argument ``suffixes`` to allow the user to specify the suffixes of both left and right DataFrame which are being compared. This is by default ``'self'`` and ``'other'`` (:issue:`44354`)
281+
- :meth:`DataFrame.compare` now accepts an argument ``result_names`` to allow the user to specify the names of both left and right DataFrame which are being compared. This is by default ``'self'`` and ``'other'`` (:issue:`44354`)
282282

283283
.. ---------------------------------------------------------------------------
284284
.. _whatsnew_150.notable_bug_fixes:

pandas/core/frame.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -7776,9 +7776,9 @@ def __rdivmod__(self, other) -> tuple[DataFrame, DataFrame]:
77767776
0 a c NaN NaN
77777777
2 NaN NaN 3.0 4.0
77787778
7779-
Assign suffixes
7779+
Assign result_names
77807780
7781-
>>> df.compare(df2, suffixes=("left", "right"))
7781+
>>> df.compare(df2, result_names=("left", "right"))
77827782
col1 col3
77837783
left right left right
77847784
0 a c NaN NaN
@@ -7831,14 +7831,14 @@ def compare(
78317831
align_axis: Axis = 1,
78327832
keep_shape: bool = False,
78337833
keep_equal: bool = False,
7834-
suffixes: Suffixes = ("self", "other"),
7834+
result_names: Suffixes = ("self", "other"),
78357835
) -> DataFrame:
78367836
return super().compare(
78377837
other=other,
78387838
align_axis=align_axis,
78397839
keep_shape=keep_shape,
78407840
keep_equal=keep_equal,
7841-
suffixes=suffixes,
7841+
result_names=result_names,
78427842
)
78437843

78447844
def combine(

pandas/core/generic.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -8971,7 +8971,7 @@ def compare(
89718971
align_axis: Axis = 1,
89728972
keep_shape: bool_t = False,
89738973
keep_equal: bool_t = False,
8974-
suffixes: Suffixes = ("self", "other"),
8974+
result_names: Suffixes = ("self", "other"),
89758975
):
89768976
from pandas.core.reshape.concat import concat
89778977

@@ -8996,18 +8996,18 @@ def compare(
89968996
else:
89978997
self = self[mask]
89988998
other = other[mask]
8999-
if not isinstance(suffixes, tuple):
8999+
if not isinstance(result_names, tuple):
90009000
raise TypeError(
9001-
f"Passing 'suffixes' as a {type(suffixes)} is not "
9002-
"supported. Provide 'suffixes' as a tuple instead."
9001+
f"Passing 'result_names' as a {type(result_names)} is not "
9002+
"supported. Provide 'result_names' as a tuple instead."
90039003
)
90049004

90059005
if align_axis in (1, "columns"): # This is needed for Series
90069006
axis = 1
90079007
else:
90089008
axis = self._get_axis_number(align_axis)
90099009

9010-
diff = concat([self, other], axis=axis, keys=suffixes)
9010+
diff = concat([self, other], axis=axis, keys=result_names)
90119011

90129012
if axis >= self.ndim:
90139013
# No need to reorganize data if stacking on new axis

pandas/core/series.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3237,14 +3237,14 @@ def compare(
32373237
align_axis: Axis = 1,
32383238
keep_shape: bool = False,
32393239
keep_equal: bool = False,
3240-
suffixes: Suffixes = ("self", "other"),
3240+
result_names: Suffixes = ("self", "other"),
32413241
) -> DataFrame | Series:
32423242
return super().compare(
32433243
other=other,
32443244
align_axis=align_axis,
32453245
keep_shape=keep_shape,
32463246
keep_equal=keep_equal,
3247-
suffixes=suffixes,
3247+
result_names=result_names,
32483248
)
32493249

32503250
def combine(self, other, func, fill_value=None) -> Series:

pandas/core/shared_docs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
If true, the result keeps values that are equal.
7777
Otherwise, equal values are shown as NaNs.
7878
79-
suffixes : tuple, default ('self', 'other')
79+
result_names : tuple, default ('self', 'other')
8080
Set the dataframes names in the comparison.
8181
8282
.. versionadded:: 1.5.0

pandas/tests/frame/methods/test_compare.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def test_compare_unaligned_objects():
182182
df1.compare(df2)
183183

184184

185-
def test_compare_suffixes():
185+
def test_compare_result_names():
186186
# 44354
187187
df1 = pd.DataFrame(
188188
{"col1": ["a", "b", "c"], "col2": [1.0, 2.0, np.nan], "col3": [1.0, 2.0, 3.0]},
@@ -194,7 +194,7 @@ def test_compare_suffixes():
194194
"col3": [1.0, 2.0, np.nan],
195195
},
196196
)
197-
result = df1.compare(df2, suffixes=("left", "right"))
197+
result = df1.compare(df2, result_names=("left", "right"))
198198
expected = pd.DataFrame(
199199
{
200200
("col1", "left"): {0: "a", 2: np.nan},

0 commit comments

Comments
 (0)