Skip to content

Commit 2ee312d

Browse files
resolve merge conflicts
2 parents f83d9f3 + 4fb853f commit 2ee312d

File tree

19 files changed

+489
-427
lines changed

19 files changed

+489
-427
lines changed

asv_bench/benchmarks/rolling.py

+19
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,25 @@ def peakmem_rolling(self, constructor, window, dtype, method):
2525
getattr(self.roll, method)()
2626

2727

28+
class Apply:
29+
params = (
30+
["DataFrame", "Series"],
31+
[10, 1000],
32+
["int", "float"],
33+
[sum, np.sum, lambda x: np.sum(x) + 5],
34+
[True, False],
35+
)
36+
param_names = ["contructor", "window", "dtype", "function", "raw"]
37+
38+
def setup(self, constructor, window, dtype, function, raw):
39+
N = 10 ** 5
40+
arr = (100 * np.random.random(N)).astype(dtype)
41+
self.roll = getattr(pd, constructor)(arr).rolling(window)
42+
43+
def time_rolling(self, constructor, window, dtype, function, raw):
44+
self.roll.apply(function, raw=raw)
45+
46+
2847
class ExpandingMethods:
2948

3049
params = (

doc/source/whatsnew/v1.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ Plotting
263263
- Bug in :meth:`DataFrame.plot` when ``kind='box'`` and data contains datetime or timedelta data. These types are now automatically dropped (:issue:`22799`)
264264
- Bug in :meth:`DataFrame.plot.line` and :meth:`DataFrame.plot.area` produce wrong xlim in x-axis (:issue:`27686`, :issue:`25160`, :issue:`24784`)
265265
- Bug where :meth:`DataFrame.boxplot` would not accept a `color` parameter like `DataFrame.plot.box` (:issue:`26214`)
266+
- Bug in the ``xticks`` argument being ignored for :meth:`DataFrame.plot.bar` (:issue:`14119`)
266267
- :func:`set_option` now validates that the plot backend provided to ``'plotting.backend'`` implements the backend when the option is set, rather than when a plot is created (:issue:`28163`)
267268

268269
Groupby/resample/rolling

pandas/core/algorithms.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
is_period_dtype,
4040
is_scalar,
4141
is_signed_integer_dtype,
42-
is_sparse,
4342
is_timedelta64_dtype,
4443
is_unsigned_integer_dtype,
4544
needs_i8_conversion,
@@ -743,7 +742,7 @@ def value_counts(
743742

744743
else:
745744

746-
if is_extension_array_dtype(values) or is_sparse(values):
745+
if is_extension_array_dtype(values):
747746

748747
# handle Categorical and sparse,
749748
result = Series(values)._values.value_counts(dropna=dropna)
@@ -1623,7 +1622,7 @@ def take_nd(
16231622
out : ndarray or None, default None
16241623
Optional output array, must be appropriate type to hold input and
16251624
fill_value together, if indexer has any -1 value entries; call
1626-
_maybe_promote to determine this type for any fill_value
1625+
maybe_promote to determine this type for any fill_value
16271626
fill_value : any, default np.nan
16281627
Fill value to replace -1 values with
16291628
mask_info : tuple of (ndarray, boolean)
@@ -1644,9 +1643,7 @@ def take_nd(
16441643
if is_extension_array_dtype(arr):
16451644
return arr.take(indexer, fill_value=fill_value, allow_fill=allow_fill)
16461645

1647-
if is_sparse(arr):
1648-
arr = arr.to_dense()
1649-
elif isinstance(arr, (ABCIndexClass, ABCSeries)):
1646+
if isinstance(arr, (ABCIndexClass, ABCSeries)):
16501647
arr = arr._values
16511648

16521649
arr = np.asarray(arr)

pandas/core/construction.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import numpy as np
1010
import numpy.ma as ma
1111

12-
from pandas._libs import lib, tslibs
12+
from pandas._libs import lib
1313
from pandas._libs.tslibs import IncompatibleFrequency, OutOfBoundsDatetime
1414

1515
from pandas.core.dtypes.cast import (
@@ -36,7 +36,7 @@
3636
is_timedelta64_ns_dtype,
3737
pandas_dtype,
3838
)
39-
from pandas.core.dtypes.dtypes import ExtensionDtype, registry
39+
from pandas.core.dtypes.dtypes import CategoricalDtype, ExtensionDtype, registry
4040
from pandas.core.dtypes.generic import (
4141
ABCExtensionArray,
4242
ABCIndexClass,
@@ -275,7 +275,7 @@ def array(
275275
if inferred_dtype == "period":
276276
try:
277277
return period_array(data, copy=copy)
278-
except tslibs.IncompatibleFrequency:
278+
except IncompatibleFrequency:
279279
# We may have a mixture of frequencies.
280280
# We choose to return an ndarray, rather than raising.
281281
pass
@@ -365,7 +365,9 @@ def extract_array(obj, extract_numpy=False):
365365
return obj
366366

367367

368-
def sanitize_array(data, index, dtype=None, copy=False, raise_cast_failure=False):
368+
def sanitize_array(
369+
data, index, dtype=None, copy: bool = False, raise_cast_failure: bool = False
370+
):
369371
"""
370372
Sanitize input data to an ndarray, copy if specified, coerce to the
371373
dtype if specified.
@@ -486,13 +488,19 @@ def sanitize_array(data, index, dtype=None, copy=False, raise_cast_failure=False
486488
return subarr
487489

488490

489-
def _try_cast(arr, dtype, copy, raise_cast_failure):
491+
def _try_cast(
492+
arr,
493+
dtype: Optional[Union[np.dtype, "ExtensionDtype"]],
494+
copy: bool,
495+
raise_cast_failure: bool,
496+
):
490497
"""
491498
Convert input to numpy ndarray and optionally cast to a given dtype.
492499
493500
Parameters
494501
----------
495-
arr : array-like
502+
arr : ndarray, list, tuple, iterator (catchall)
503+
Excludes: ExtensionArray, Series, Index.
496504
dtype : np.dtype, ExtensionDtype or None
497505
copy : bool
498506
If False, don't copy the data if not needed.
@@ -528,11 +536,13 @@ def _try_cast(arr, dtype, copy, raise_cast_failure):
528536
if is_categorical_dtype(dtype):
529537
# We *do* allow casting to categorical, since we know
530538
# that Categorical is the only array type for 'category'.
539+
dtype = cast(CategoricalDtype, dtype)
531540
subarr = dtype.construct_array_type()(
532541
arr, dtype.categories, ordered=dtype._ordered
533542
)
534543
elif is_extension_array_dtype(dtype):
535544
# create an extension array from its dtype
545+
dtype = cast(ExtensionDtype, dtype)
536546
array_type = dtype.construct_array_type()._from_sequence
537547
subarr = array_type(arr, dtype=dtype, copy=copy)
538548
elif dtype is not None and raise_cast_failure:

pandas/core/dtypes/cast.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1311,9 +1311,8 @@ def construct_1d_ndarray_preserving_na(values, dtype=None, copy=False):
13111311
>>> np.array([1.0, 2.0, None], dtype='str')
13121312
array(['1.0', '2.0', 'None'], dtype='<U4')
13131313
1314-
>>> construct_1d_ndarray_preserving_na([1.0, 2.0, None], dtype='str')
1315-
1316-
1314+
>>> construct_1d_ndarray_preserving_na([1.0, 2.0, None], dtype=np.dtype('str'))
1315+
array(['1.0', '2.0', None], dtype=object)
13171316
"""
13181317
subarr = np.array(values, dtype=dtype, copy=copy)
13191318

pandas/core/dtypes/common.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,8 @@ def is_dtype_equal(source, target):
890890

891891

892892
def is_any_int_dtype(arr_or_dtype) -> bool:
893-
"""Check whether the provided array or dtype is of an integer dtype.
893+
"""
894+
Check whether the provided array or dtype is of an integer dtype.
894895
895896
In this function, timedelta64 instances are also considered "any-integer"
896897
type objects and will return True.

pandas/core/frame.py

+5-18
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ class DataFrame(NDFrame):
315315
316316
.. versionchanged:: 0.25.0
317317
If data is a list of dicts, column order follows insertion-order
318-
Python 3.6 and later.
318+
for Python 3.6 and later.
319319
320320
index : Index or array-like
321321
Index to use for resulting frame. Will default to RangeIndex if
@@ -5272,7 +5272,7 @@ def _arith_op(left, right):
52725272
with np.errstate(all="ignore"):
52735273
res_values = _arith_op(this.values, other.values)
52745274
new_data = dispatch_fill_zeros(func, this.values, other.values, res_values)
5275-
return this._construct_result(other, new_data, _arith_op)
5275+
return this._construct_result(new_data)
52765276

52775277
def _combine_match_index(self, other, func, level=None):
52785278
left, right = self.align(other, join="outer", axis=0, level=level, copy=False)
@@ -5285,44 +5285,31 @@ def _combine_match_index(self, other, func, level=None):
52855285
# fastpath --> operate directly on values
52865286
with np.errstate(all="ignore"):
52875287
new_data = func(left.values.T, right.values).T
5288-
return left._construct_result(other, new_data, func)
5288+
return left._construct_result(new_data)
52895289

52905290
def _combine_match_columns(self, other: Series, func, level=None):
52915291
left, right = self.align(other, join="outer", axis=1, level=level, copy=False)
52925292
# at this point we have `left.columns.equals(right.index)`
52935293
new_data = ops.dispatch_to_series(left, right, func, axis="columns")
5294-
return left._construct_result(right, new_data, func)
5295-
5296-
def _combine_const(self, other, func):
5297-
# scalar other or np.ndim(other) == 0
5298-
new_data = ops.dispatch_to_series(self, other, func)
5299-
return self._construct_result(other, new_data, func)
5294+
return left._construct_result(new_data)
53005295

5301-
def _construct_result(self, other, result, func):
5296+
def _construct_result(self, result) -> "DataFrame":
53025297
"""
53035298
Wrap the result of an arithmetic, comparison, or logical operation.
53045299
53055300
Parameters
53065301
----------
5307-
other : object
53085302
result : DataFrame
5309-
func : binary operator
53105303
53115304
Returns
53125305
-------
53135306
DataFrame
5314-
5315-
Notes
5316-
-----
5317-
`func` is included for compat with SparseDataFrame signature, is not
5318-
needed here.
53195307
"""
53205308
out = self._constructor(result, index=self.index, copy=False)
53215309
# Pin columns instead of passing to constructor for compat with
53225310
# non-unique columns case
53235311
out.columns = self.columns
53245312
return out
5325-
# TODO: finalize? we do for SparseDataFrame
53265313

53275314
def combine(self, other, func, fill_value=None, overwrite=True):
53285315
"""

pandas/core/internals/blocks.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2128,7 +2128,8 @@ def _can_hold_na(self):
21282128
return True
21292129

21302130
def _maybe_coerce_values(self, values):
2131-
"""Input validation for values passed to __init__. Ensure that
2131+
"""
2132+
Input validation for values passed to __init__. Ensure that
21322133
we have datetime64ns, coercing if necessary.
21332134
21342135
Parameters

0 commit comments

Comments
 (0)