Skip to content

Commit b9a6885

Browse files
authored
Merge branch 'master' into cln-arith
2 parents 75fae8d + 7f1c3b1 commit b9a6885

25 files changed

+637
-524
lines changed

doc/source/user_guide/merging.rst

+141-155
Large diffs are not rendered by default.

doc/source/whatsnew/v1.1.4.rst

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Fixed regressions
1818
- Fixed regression where attempting to mutate a :class:`DateOffset` object would no longer raise an ``AttributeError`` (:issue:`36940`)
1919
- Fixed regression where :meth:`DataFrame.agg` would fail with :exc:`TypeError` when passed positional arguments to be passed on to the aggregation function (:issue:`36948`).
2020
- Fixed regression in :class:`RollingGroupby` with ``sort=False`` not being respected (:issue:`36889`)
21+
- Fixed regression in :meth:`Series.astype` converting ``None`` to ``"nan"`` when casting to string (:issue:`36904`)
2122

2223
.. ---------------------------------------------------------------------------
2324

doc/source/whatsnew/v1.2.0.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ Numeric
363363
- Bug in :class:`IntegerArray` multiplication with ``timedelta`` and ``np.timedelta64`` objects (:issue:`36870`)
364364
- Bug in :meth:`DataFrame.diff` with ``datetime64`` dtypes including ``NaT`` values failing to fill ``NaT`` results correctly (:issue:`32441`)
365365
- Bug in :class:`IntervalArray` comparisons with :class:`Series` not returning :class:`Series` (:issue:`36908`)
366+
- Bug in :class:`DataFrame` arithmetic ops incorrectly accepting keyword arguments (:issue:`36843`)
366367

367368
Conversion
368369
^^^^^^^^^^
@@ -476,7 +477,7 @@ Other
476477

477478
- Bug in :meth:`DataFrame.replace` and :meth:`Series.replace` incorrectly raising ``AssertionError`` instead of ``ValueError`` when invalid parameter combinations are passed (:issue:`36045`)
478479
- Bug in :meth:`DataFrame.replace` and :meth:`Series.replace` with numeric values and string ``to_replace`` (:issue:`34789`)
479-
- Fixed metadata propagation in the :class:`Series.dt` accessor (:issue:`28283`)
480+
- Fixed metadata propagation in the :class:`Series.dt` and :class:`Series.str` accessors (:issue:`28283`)
480481
- Bug in :meth:`Index.union` behaving differently depending on whether operand is a :class:`Index` or other list-like (:issue:`36384`)
481482
- Passing an array with 2 or more dimensions to the :class:`Series` constructor now raises the more specific ``ValueError``, from a bare ``Exception`` previously (:issue:`35744`)
482483

pandas/_libs/reduction.pyx

+24-38
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from copy import copy
22

3-
from cython import Py_ssize_t
4-
53
from libc.stdlib cimport free, malloc
64

75
import numpy as np
@@ -11,14 +9,14 @@ from numpy cimport int64_t, ndarray
119

1210
cnp.import_array()
1311

14-
from pandas._libs cimport util
12+
from pandas._libs.util cimport is_array, set_array_not_contiguous
1513

1614
from pandas._libs.lib import is_scalar, maybe_convert_objects
1715

1816

1917
cpdef check_result_array(object obj, Py_ssize_t cnt):
2018

21-
if (util.is_array(obj) or
19+
if (is_array(obj) or
2220
(isinstance(obj, list) and len(obj) == cnt) or
2321
getattr(obj, 'shape', None) == (cnt,)):
2422
raise ValueError('Must produce aggregated value')
@@ -33,7 +31,7 @@ cdef class _BaseGrouper:
3331
if (dummy.dtype != self.arr.dtype
3432
and values.dtype != self.arr.dtype):
3533
raise ValueError('Dummy array must be same dtype')
36-
if util.is_array(values) and not values.flags.contiguous:
34+
if is_array(values) and not values.flags.contiguous:
3735
# e.g. Categorical has no `flags` attribute
3836
values = values.copy()
3937
index = dummy.index.values
@@ -106,7 +104,7 @@ cdef class SeriesBinGrouper(_BaseGrouper):
106104
self.f = f
107105

108106
values = series.values
109-
if util.is_array(values) and not values.flags.c_contiguous:
107+
if is_array(values) and not values.flags.c_contiguous:
110108
# e.g. Categorical has no `flags` attribute
111109
values = values.copy('C')
112110
self.arr = values
@@ -204,7 +202,7 @@ cdef class SeriesGrouper(_BaseGrouper):
204202
self.f = f
205203

206204
values = series.values
207-
if util.is_array(values) and not values.flags.c_contiguous:
205+
if is_array(values) and not values.flags.c_contiguous:
208206
# e.g. Categorical has no `flags` attribute
209207
values = values.copy('C')
210208
self.arr = values
@@ -288,9 +286,9 @@ cpdef inline extract_result(object res, bint squeeze=True):
288286
res = res._values
289287
if squeeze and res.ndim == 1 and len(res) == 1:
290288
res = res[0]
291-
if hasattr(res, 'values') and util.is_array(res.values):
289+
if hasattr(res, 'values') and is_array(res.values):
292290
res = res.values
293-
if util.is_array(res):
291+
if is_array(res):
294292
if res.ndim == 0:
295293
res = res.item()
296294
elif squeeze and res.ndim == 1 and len(res) == 1:
@@ -304,7 +302,7 @@ cdef class Slider:
304302
"""
305303
cdef:
306304
ndarray values, buf
307-
Py_ssize_t stride, orig_len, orig_stride
305+
Py_ssize_t stride
308306
char *orig_data
309307

310308
def __init__(self, ndarray values, ndarray buf):
@@ -316,11 +314,9 @@ cdef class Slider:
316314

317315
self.values = values
318316
self.buf = buf
319-
self.stride = values.strides[0]
320317

318+
self.stride = values.strides[0]
321319
self.orig_data = self.buf.data
322-
self.orig_len = self.buf.shape[0]
323-
self.orig_stride = self.buf.strides[0]
324320

325321
self.buf.data = self.values.data
326322
self.buf.strides[0] = self.stride
@@ -333,10 +329,8 @@ cdef class Slider:
333329
self.buf.shape[0] = end - start
334330

335331
cdef reset(self):
336-
337-
self.buf.shape[0] = self.orig_len
338332
self.buf.data = self.orig_data
339-
self.buf.strides[0] = self.orig_stride
333+
self.buf.shape[0] = 0
340334

341335

342336
class InvalidApply(Exception):
@@ -408,39 +402,34 @@ cdef class BlockSlider:
408402
"""
409403
Only capable of sliding on axis=0
410404
"""
411-
412-
cdef public:
413-
object frame, dummy, index
414-
int nblocks
415-
Slider idx_slider
416-
list blocks
417-
418405
cdef:
406+
object frame, dummy, index, block
407+
list blk_values
408+
ndarray values
409+
Slider idx_slider
419410
char **base_ptrs
411+
int nblocks
412+
Py_ssize_t i
420413

421414
def __init__(self, object frame):
422-
cdef:
423-
Py_ssize_t i
424-
object b
425-
426415
self.frame = frame
427416
self.dummy = frame[:0]
428417
self.index = self.dummy.index
429418

430-
self.blocks = [b.values for b in self.dummy._mgr.blocks]
419+
self.blk_values = [block.values for block in self.dummy._mgr.blocks]
431420

432-
for x in self.blocks:
433-
util.set_array_not_contiguous(x)
421+
for values in self.blk_values:
422+
set_array_not_contiguous(values)
434423

435-
self.nblocks = len(self.blocks)
424+
self.nblocks = len(self.blk_values)
436425
# See the comment in indexes/base.py about _index_data.
437426
# We need this for EA-backed indexes that have a reference to a 1-d
438427
# ndarray like datetime / timedelta / period.
439428
self.idx_slider = Slider(
440429
self.frame.index._index_data, self.dummy.index._index_data)
441430

442-
self.base_ptrs = <char**>malloc(sizeof(char*) * len(self.blocks))
443-
for i, block in enumerate(self.blocks):
431+
self.base_ptrs = <char**>malloc(sizeof(char*) * self.nblocks)
432+
for i, block in enumerate(self.blk_values):
444433
self.base_ptrs[i] = (<ndarray>block).data
445434

446435
def __dealloc__(self):
@@ -450,10 +439,9 @@ cdef class BlockSlider:
450439
cdef:
451440
ndarray arr
452441
Py_ssize_t i
453-
454442
# move blocks
455443
for i in range(self.nblocks):
456-
arr = self.blocks[i]
444+
arr = self.blk_values[i]
457445

458446
# axis=1 is the frame's axis=0
459447
arr.data = self.base_ptrs[i] + arr.strides[1] * start
@@ -470,10 +458,8 @@ cdef class BlockSlider:
470458
cdef:
471459
ndarray arr
472460
Py_ssize_t i
473-
474-
# reset blocks
475461
for i in range(self.nblocks):
476-
arr = self.blocks[i]
462+
arr = self.blk_values[i]
477463

478464
# axis=1 is the frame's axis=0
479465
arr.data = self.base_ptrs[i]

pandas/core/arrays/categorical.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,8 @@ def as_ordered(self, inplace=False):
723723
724724
Returns
725725
-------
726-
Categorical
727-
Ordered Categorical.
726+
Categorical or None
727+
Ordered Categorical or None if ``inplace=True``.
728728
"""
729729
inplace = validate_bool_kwarg(inplace, "inplace")
730730
return self.set_ordered(True, inplace=inplace)
@@ -741,8 +741,8 @@ def as_unordered(self, inplace=False):
741741
742742
Returns
743743
-------
744-
Categorical
745-
Unordered Categorical.
744+
Categorical or None
745+
Unordered Categorical or None if ``inplace=True``.
746746
"""
747747
inplace = validate_bool_kwarg(inplace, "inplace")
748748
return self.set_ordered(False, inplace=inplace)
@@ -848,8 +848,7 @@ def rename_categories(self, new_categories, inplace=False):
848848
Returns
849849
-------
850850
cat : Categorical or None
851-
With ``inplace=False``, the new categorical is returned.
852-
With ``inplace=True``, there is no return value.
851+
Categorical with removed categories or None if ``inplace=True``.
853852
854853
Raises
855854
------
@@ -917,7 +916,8 @@ def reorder_categories(self, new_categories, ordered=None, inplace=False):
917916
918917
Returns
919918
-------
920-
cat : Categorical with reordered categories or None if inplace.
919+
cat : Categorical or None
920+
Categorical with removed categories or None if ``inplace=True``.
921921
922922
Raises
923923
------
@@ -957,7 +957,8 @@ def add_categories(self, new_categories, inplace=False):
957957
958958
Returns
959959
-------
960-
cat : Categorical with new categories added or None if inplace.
960+
cat : Categorical or None
961+
Categorical with new categories added or None if ``inplace=True``.
961962
962963
Raises
963964
------
@@ -1007,7 +1008,8 @@ def remove_categories(self, removals, inplace=False):
10071008
10081009
Returns
10091010
-------
1010-
cat : Categorical with removed categories or None if inplace.
1011+
cat : Categorical or None
1012+
Categorical with removed categories or None if ``inplace=True``.
10111013
10121014
Raises
10131015
------
@@ -1054,7 +1056,8 @@ def remove_unused_categories(self, inplace=False):
10541056
10551057
Returns
10561058
-------
1057-
cat : Categorical with unused categories dropped or None if inplace.
1059+
cat : Categorical or None
1060+
Categorical with unused categories dropped or None if ``inplace=True``.
10581061
10591062
See Also
10601063
--------

0 commit comments

Comments
 (0)