Skip to content

Commit b947e6a

Browse files
committed
resolve conflict in pandas/tests/resample/test_base.py
2 parents b0bd2d8 + af83376 commit b947e6a

35 files changed

+500
-678
lines changed

doc/source/whatsnew/v2.1.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ Reshaping
491491
- Bug in :func:`merge_asof` raising ``KeyError`` for extension dtypes (:issue:`52904`)
492492
- Bug in :func:`merge_asof` raising ``ValueError`` for data backed by read-only ndarrays (:issue:`53513`)
493493
- Bug in :meth:`DataFrame.agg` and :meth:`Series.agg` on non-unique columns would return incorrect type when dist-like argument passed in (:issue:`51099`)
494+
- Bug in :meth:`DataFrame.combine_first` ignoring other's columns if ``other`` is empty (:issue:`53792`)
494495
- Bug in :meth:`DataFrame.idxmin` and :meth:`DataFrame.idxmax`, where the axis dtype would be lost for empty frames (:issue:`53265`)
495496
- Bug in :meth:`DataFrame.merge` not merging correctly when having ``MultiIndex`` with single level (:issue:`52331`)
496497
- Bug in :meth:`DataFrame.stack` losing extension dtypes when columns is a :class:`MultiIndex` and frame contains mixed dtypes (:issue:`45740`)

pandas/_libs/groupby.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ def group_skew(
950950
isna_entry = _treat_as_na(val, False)
951951

952952
if not isna_entry:
953-
# Based on RunningSats::Push from
953+
# Based on RunningStats::Push from
954954
# https://www.johndcook.com/blog/skewness_kurtosis/
955955
n1 = nobs[lab, j]
956956
n = n1 + 1

pandas/_libs/tslibs/timedeltas.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ cdef _timedelta_from_value_and_reso(cls, int64_t value, NPY_DATETIMEUNIT reso):
974974
"Only resolutions 's', 'ms', 'us', 'ns' are supported."
975975
)
976976

977-
td_base._value= value
977+
td_base._value = value
978978
td_base._is_populated = 0
979979
td_base._creso = reso
980980
return td_base

pandas/core/arrays/arrow/array.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -1131,13 +1131,7 @@ def take(
11311131
it's called by :meth:`Series.reindex`, or any other method
11321132
that causes realignment, with a `fill_value`.
11331133
"""
1134-
# TODO: Remove once we got rid of the (indices < 0) check
1135-
if not is_array_like(indices):
1136-
indices_array = np.asanyarray(indices)
1137-
else:
1138-
# error: Incompatible types in assignment (expression has type
1139-
# "Sequence[int]", variable has type "ndarray")
1140-
indices_array = indices # type: ignore[assignment]
1134+
indices_array = np.asanyarray(indices)
11411135

11421136
if len(self._pa_array) == 0 and (indices_array >= 0).any():
11431137
raise IndexError("cannot do a non-empty take")

pandas/core/arrays/sparse/array.py

+10-14
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
maybe_box_datetimelike,
4343
)
4444
from pandas.core.dtypes.common import (
45-
is_array_like,
4645
is_bool_dtype,
4746
is_integer,
4847
is_list_like,
@@ -428,19 +427,16 @@ def __init__(
428427
# Union[int, Sequence[int]]], List[Any], _DTypeDict, Tuple[Any, Any]]]"
429428
data = np.array([], dtype=dtype) # type: ignore[arg-type]
430429

431-
if not is_array_like(data):
432-
try:
433-
# probably shared code in sanitize_series
434-
435-
data = sanitize_array(data, index=None)
436-
except ValueError:
437-
# NumPy may raise a ValueError on data like [1, []]
438-
# we retry with object dtype here.
439-
if dtype is None:
440-
dtype = np.dtype(object)
441-
data = np.atleast_1d(np.asarray(data, dtype=dtype))
442-
else:
443-
raise
430+
try:
431+
data = sanitize_array(data, index=None)
432+
except ValueError:
433+
# NumPy may raise a ValueError on data like [1, []]
434+
# we retry with object dtype here.
435+
if dtype is None:
436+
dtype = np.dtype(object)
437+
data = np.atleast_1d(np.asarray(data, dtype=dtype))
438+
else:
439+
raise
444440

445441
if copy:
446442
# TODO: avoid double copy when dtype forces cast.

pandas/core/dtypes/dtypes.py

-11
Original file line numberDiff line numberDiff line change
@@ -1666,17 +1666,6 @@ def _check_fill_value(self):
16661666
FutureWarning,
16671667
stacklevel=find_stack_level(),
16681668
)
1669-
elif isinstance(self.subtype, CategoricalDtype):
1670-
# TODO: is this even supported? It is reached in
1671-
# test_dtype_sparse_with_fill_value_not_present_in_data
1672-
if self.subtype.categories is None or val not in self.subtype.categories:
1673-
warnings.warn(
1674-
"Allowing arbitrary scalar fill_value in SparseDtype is "
1675-
"deprecated. In a future version, the fill_value must be "
1676-
"a valid value for the SparseDtype.subtype.",
1677-
FutureWarning,
1678-
stacklevel=find_stack_level(),
1679-
)
16801669
else:
16811670
dummy = np.empty(0, dtype=self.subtype)
16821671
dummy = ensure_wrapped_if_datetimelike(dummy)

pandas/core/frame.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -673,9 +673,9 @@ def __init__(
673673
manager = get_option("mode.data_manager")
674674

675675
# GH47215
676-
if index is not None and isinstance(index, set):
676+
if isinstance(index, set):
677677
raise ValueError("index cannot be a set")
678-
if columns is not None and isinstance(columns, set):
678+
if isinstance(columns, set):
679679
raise ValueError("columns cannot be a set")
680680

681681
if copy is None:
@@ -8344,7 +8344,13 @@ def combiner(x, y):
83448344

83458345
return expressions.where(mask, y_values, x_values)
83468346

8347-
combined = self.combine(other, combiner, overwrite=False)
8347+
if len(other) == 0:
8348+
combined = self.reindex(
8349+
self.columns.append(other.columns.difference(self.columns)), axis=1
8350+
)
8351+
combined = combined.astype(other.dtypes)
8352+
else:
8353+
combined = self.combine(other, combiner, overwrite=False)
83488354

83498355
dtypes = {
83508356
col: find_common_type([self.dtypes[col], other.dtypes[col]])

pandas/core/generic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
AlignJoin,
4848
AnyArrayLike,
4949
ArrayLike,
50+
Axes,
5051
Axis,
5152
AxisInt,
5253
CompressionOptions,
@@ -271,7 +272,7 @@ def __init__(self, data: Manager) -> None:
271272
def _init_mgr(
272273
cls,
273274
mgr: Manager,
274-
axes,
275+
axes: dict[Literal["index", "columns"], Axes | None],
275276
dtype: DtypeObj | None = None,
276277
copy: bool_t = False,
277278
) -> Manager:
@@ -3995,7 +3996,6 @@ class max_speed
39953996
):
39963997
return self.copy(deep=None)
39973998
elif self.ndim == 1:
3998-
# TODO: be consistent here for DataFrame vs Series
39993999
raise TypeError(
40004000
f"{type(self).__name__}.take requires a sequence of integers, "
40014001
"not slice."

pandas/core/indexes/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4192,7 +4192,7 @@ def _convert_slice_indexer(self, key: slice, kind: Literal["loc", "getitem"]):
41924192

41934193
# TODO(GH#50617): once Series.__[gs]etitem__ is removed we should be able
41944194
# to simplify this.
4195-
if isinstance(self.dtype, np.dtype) and self.dtype.kind == "f":
4195+
if lib.is_np_dtype(self.dtype, "f"):
41964196
# We always treat __getitem__ slicing as label-based
41974197
# translate to locations
41984198
return self.slice_indexer(start, stop, step)

pandas/core/internals/blocks.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def make_block_same_class(
233233
values,
234234
placement: BlockPlacement | None = None,
235235
refs: BlockValuesRefs | None = None,
236-
) -> Block:
236+
) -> Self:
237237
"""Wrap given values in a block of same type as self."""
238238
# Pre-2.0 we called ensure_wrapped_if_datetimelike because fastparquet
239239
# relied on it, as of 2.0 the caller is responsible for this.
@@ -503,6 +503,7 @@ def convert(
503503
# ---------------------------------------------------------------------
504504
# Array-Like Methods
505505

506+
@final
506507
@cache_readonly
507508
def dtype(self) -> DtypeObj:
508509
return self.values.dtype
@@ -559,7 +560,7 @@ def to_native_types(self, na_rep: str = "nan", quoting=None, **kwargs) -> Block:
559560
return self.make_block(result)
560561

561562
@final
562-
def copy(self, deep: bool = True) -> Block:
563+
def copy(self, deep: bool = True) -> Self:
563564
"""copy constructor"""
564565
values = self.values
565566
refs: BlockValuesRefs | None
@@ -1499,7 +1500,8 @@ def quantile(
14991500
result = ensure_block_shape(result, ndim=2)
15001501
return new_block_2d(result, placement=self._mgr_locs)
15011502

1502-
def round(self, decimals: int, using_cow: bool = False) -> Block:
1503+
@final
1504+
def round(self, decimals: int, using_cow: bool = False) -> Self:
15031505
"""
15041506
Rounds the values.
15051507
If the block is not of an integer or float dtype, nothing happens.
@@ -1765,9 +1767,7 @@ def putmask(self, mask, new, using_cow: bool = False) -> list[Block]:
17651767

17661768
if using_cow and self.refs.has_reference():
17671769
values = values.copy()
1768-
self = self.make_block_same_class( # type: ignore[assignment]
1769-
values.T if values.ndim == 2 else values
1770-
)
1770+
self = self.make_block_same_class(values.T if values.ndim == 2 else values)
17711771

17721772
try:
17731773
# Caller is responsible for ensuring matching lengths

pandas/core/internals/concat.py

+9
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,15 @@ def _concat_homogeneous_fastpath(
254254
"""
255255
# assumes
256256
# all(_is_homogeneous_mgr(mgr, first_dtype) for mgr, _ in in mgrs_indexers)
257+
258+
if all(not indexers for _, indexers in mgrs_indexers):
259+
# https://github.com/pandas-dev/pandas/pull/52685#issuecomment-1523287739
260+
arrs = [mgr.blocks[0].values.T for mgr, _ in mgrs_indexers]
261+
arr = np.concatenate(arrs).T
262+
bp = libinternals.BlockPlacement(slice(shape[0]))
263+
nb = new_block_2d(arr, bp)
264+
return nb
265+
257266
arr = np.empty(shape, dtype=first_dtype)
258267

259268
if first_dtype == np.float64:

pandas/core/internals/managers.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -939,8 +939,7 @@ def take(
939939
-------
940940
BlockManager
941941
"""
942-
assert isinstance(indexer, np.ndarray), type(indexer)
943-
assert indexer.dtype == np.intp, indexer.dtype
942+
# Caller is responsible for ensuring indexer annotation is accurate
944943

945944
n = self.shape[axis]
946945
indexer = maybe_convert_indices(indexer, n, verify=verify)

pandas/core/missing.py

-2
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,6 @@ def interpolate_array_2d(
311311
limit_direction: str = "forward",
312312
limit_area: str | None = None,
313313
fill_value: Any | None = None,
314-
coerce: bool = False,
315-
downcast: str | None = None,
316314
**kwargs,
317315
) -> None:
318316
"""

0 commit comments

Comments
 (0)