Skip to content

Commit 5757a4b

Browse files
authored
Merge branch 'master' into 31988_ReadPickle
2 parents cdb6096 + ac3056f commit 5757a4b

29 files changed

+1073
-900
lines changed

Diff for: doc/source/development/code_style.rst

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ pandas code style guide
99
.. contents:: Table of contents:
1010
:local:
1111

12+
*pandas* follows the `PEP8 <https://www.python.org/dev/peps/pep-0008/>`_
13+
standard and uses `Black <https://black.readthedocs.io/en/stable/>`_
14+
and `Flake8 <https://flake8.pycqa.org/en/latest/>`_ to ensure a
15+
consistent code format throughout the project. For details see the
16+
:ref:`contributing guide to pandas<contributing.code-formatting>`.
17+
1218
Patterns
1319
========
1420

Diff for: doc/source/whatsnew/v1.0.2.rst

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Fixed regressions
2020
- Fixed regression in :meth:`pandas.core.groupby.RollingGroupby.apply` where the ``raw`` parameter was ignored (:issue:`31754`)
2121
- Fixed regression in :meth:`rolling(..).corr() <pandas.core.window.Rolling.corr>` when using a time offset (:issue:`31789`)
2222
- Fixed regression where :func:`read_pickle` raised a ``UnicodeDecodeError`` when reading a py27 pickle with :class:`MultiIndex` column (:issue:`31988`).
23+
- Fixed regression in :class:`DataFrame` arithmetic operations with mis-matched columns (:issue:`31623`)
24+
-
2325

2426
.. ---------------------------------------------------------------------------
2527
@@ -31,6 +33,7 @@ Bug fixes
3133
**Categorical**
3234

3335
- Fixed bug where :meth:`Categorical.from_codes` improperly raised a ``ValueError`` when passed nullable integer codes. (:issue:`31779`)
36+
- Bug in :class:`Categorical` that would ignore or crash when calling :meth:`Series.replace` with a list-like ``to_replace`` (:issue:`31720`)
3437

3538
**I/O**
3639

Diff for: environment.yml

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dependencies:
2626

2727
# documentation
2828
- gitpython # obtain contributors from git for whatsnew
29+
- gitdb2=2.0.6 # GH-32060
2930
- sphinx
3031

3132
# documentation (jupyter notebooks)

Diff for: pandas/_libs/algos.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1173,12 +1173,12 @@ ctypedef fused out_t:
11731173

11741174
@cython.boundscheck(False)
11751175
@cython.wraparound(False)
1176-
def diff_2d(ndarray[diff_t, ndim=2] arr,
1177-
ndarray[out_t, ndim=2] out,
1176+
def diff_2d(diff_t[:, :] arr,
1177+
out_t[:, :] out,
11781178
Py_ssize_t periods, int axis):
11791179
cdef:
11801180
Py_ssize_t i, j, sx, sy, start, stop
1181-
bint f_contig = arr.flags.f_contiguous
1181+
bint f_contig = arr.is_f_contig()
11821182

11831183
# Disable for unsupported dtype combinations,
11841184
# see https://github.com/cython/cython/issues/2646

Diff for: pandas/_libs/hashing.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import cython
55
from libc.stdlib cimport malloc, free
66

77
import numpy as np
8-
from numpy cimport uint8_t, uint32_t, uint64_t, import_array
8+
from numpy cimport ndarray, uint8_t, uint32_t, uint64_t, import_array
99
import_array()
1010

1111
from pandas._libs.util cimport is_nan
@@ -15,7 +15,7 @@ DEF dROUNDS = 4
1515

1616

1717
@cython.boundscheck(False)
18-
def hash_object_array(object[:] arr, object key, object encoding='utf8'):
18+
def hash_object_array(ndarray[object] arr, object key, object encoding='utf8'):
1919
"""
2020
Parameters
2121
----------

Diff for: pandas/_libs/tslibs/conversion.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def ensure_timedelta64ns(arr: ndarray, copy: bool=True):
152152

153153
@cython.boundscheck(False)
154154
@cython.wraparound(False)
155-
def datetime_to_datetime64(object[:] values):
155+
def datetime_to_datetime64(ndarray[object] values):
156156
"""
157157
Convert ndarray of datetime-like objects to int64 array representing
158158
nanosecond timestamps.

Diff for: pandas/_libs/window/aggregations.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ cdef:
5656
cdef inline int int_max(int a, int b): return a if a >= b else b
5757
cdef inline int int_min(int a, int b): return a if a <= b else b
5858

59-
cdef inline bint is_monotonic_start_end_bounds(
59+
cdef bint is_monotonic_start_end_bounds(
6060
ndarray[int64_t, ndim=1] start, ndarray[int64_t, ndim=1] end
6161
):
6262
return is_monotonic(start, False)[0] and is_monotonic(end, False)[0]

Diff for: pandas/_testing.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,7 @@ def assert_series_equal(
10741074
check_exact=False,
10751075
check_datetimelike_compat=False,
10761076
check_categorical=True,
1077+
check_category_order=True,
10771078
obj="Series",
10781079
):
10791080
"""
@@ -1108,6 +1109,10 @@ def assert_series_equal(
11081109
Compare datetime-like which is comparable ignoring dtype.
11091110
check_categorical : bool, default True
11101111
Whether to compare internal Categorical exactly.
1112+
check_category_order : bool, default True
1113+
Whether to compare category order of internal Categoricals
1114+
1115+
.. versionadded:: 1.0.2
11111116
obj : str, default 'Series'
11121117
Specify object name being compared, internally used to show appropriate
11131118
assertion message.
@@ -1210,7 +1215,12 @@ def assert_series_equal(
12101215

12111216
if check_categorical:
12121217
if is_categorical_dtype(left) or is_categorical_dtype(right):
1213-
assert_categorical_equal(left.values, right.values, obj=f"{obj} category")
1218+
assert_categorical_equal(
1219+
left.values,
1220+
right.values,
1221+
obj=f"{obj} category",
1222+
check_category_order=check_category_order,
1223+
)
12141224

12151225

12161226
# This could be refactored to use the NDFrame.equals method

Diff for: pandas/core/arrays/categorical.py

+21-9
Original file line numberDiff line numberDiff line change
@@ -2441,18 +2441,30 @@ def replace(self, to_replace, value, inplace: bool = False):
24412441
"""
24422442
inplace = validate_bool_kwarg(inplace, "inplace")
24432443
cat = self if inplace else self.copy()
2444-
if to_replace in cat.categories:
2445-
if isna(value):
2446-
cat.remove_categories(to_replace, inplace=True)
2447-
else:
2444+
2445+
# build a dict of (to replace -> value) pairs
2446+
if is_list_like(to_replace):
2447+
# if to_replace is list-like and value is scalar
2448+
replace_dict = {replace_value: value for replace_value in to_replace}
2449+
else:
2450+
# if both to_replace and value are scalar
2451+
replace_dict = {to_replace: value}
2452+
2453+
# other cases, like if both to_replace and value are list-like or if
2454+
# to_replace is a dict, are handled separately in NDFrame
2455+
for replace_value, new_value in replace_dict.items():
2456+
if replace_value in cat.categories:
2457+
if isna(new_value):
2458+
cat.remove_categories(replace_value, inplace=True)
2459+
continue
24482460
categories = cat.categories.tolist()
2449-
index = categories.index(to_replace)
2450-
if value in cat.categories:
2451-
value_index = categories.index(value)
2461+
index = categories.index(replace_value)
2462+
if new_value in cat.categories:
2463+
value_index = categories.index(new_value)
24522464
cat._codes[cat._codes == index] = value_index
2453-
cat.remove_categories(to_replace, inplace=True)
2465+
cat.remove_categories(replace_value, inplace=True)
24542466
else:
2455-
categories[index] = value
2467+
categories[index] = new_value
24562468
cat.rename_categories(categories, inplace=True)
24572469
if not inplace:
24582470
return cat

0 commit comments

Comments
 (0)