Skip to content

Commit e26a13b

Browse files
Daniel SaxtonDaniel Saxton
Daniel Saxton
authored and
Daniel Saxton
committed
Merge branch 'master' into qcut-null-int
2 parents 5694ab6 + bfb80fa commit e26a13b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+301
-347
lines changed

doc/source/whatsnew/v1.0.1.rst

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ including other versions of pandas.
1515

1616
Bug fixes
1717
~~~~~~~~~
18-
18+
- Bug in :meth:`GroupBy.apply` was raising ``TypeError`` if called with function which returned a non-pandas non-scalar object (e.g. a list) (:issue:`31441`)
1919

2020
Categorical
2121
^^^^^^^^^^^
@@ -25,8 +25,8 @@ Categorical
2525

2626
Datetimelike
2727
^^^^^^^^^^^^
28-
-
29-
-
28+
- Fixed regression in :meth:`to_datetime` when parsing non-nanosecond resolution datetimes (:issue:`31491`)
29+
- Fixed bug in :meth:`to_datetime` raising when ``cache=True`` and out-of-bound values are present (:issue:`31491`)
3030

3131
Timedelta
3232
^^^^^^^^^
@@ -68,8 +68,11 @@ Interval
6868
Indexing
6969
^^^^^^^^
7070

71+
- Fixed regression when indexing a ``Series`` or ``DataFrame`` indexed by ``DatetimeIndex`` with a slice containg a :class:`datetime.date` (:issue:`31501`)
72+
- Fixed regression in :class:`DataFrame` setting values with a slice (e.g. ``df[-4:] = 1``) indexing by label instead of position (:issue:`31469`)
7173
-
7274
-
75+
- Bug where assigning to a :class:`Series` using a IntegerArray / BooleanArray as a mask would raise ``TypeError`` (:issue:`31446`)
7376

7477
Missing
7578
^^^^^^^

pandas/_libs/groupby.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ def group_rank(float64_t[:, :] out,
11431143
# Update out only when there is a transition of values or labels.
11441144
# When a new value or group is encountered, go back #dups steps(
11451145
# the number of occurrence of current value) and assign the ranks
1146-
# based on the the starting index of the current group (grp_start)
1146+
# based on the starting index of the current group (grp_start)
11471147
# and the current index
11481148
if (i == N - 1 or
11491149
(masked_vals[_as[i]] != masked_vals[_as[i+1]]) or

pandas/_libs/reduction.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,9 @@ def apply_frame_axis0(object frame, object f, object names,
501501

502502
if not is_scalar(piece):
503503
# Need to copy data to avoid appending references
504-
if hasattr(piece, "copy"):
504+
try:
505505
piece = piece.copy(deep="all")
506-
else:
506+
except (TypeError, AttributeError):
507507
piece = copy(piece)
508508

509509
results.append(piece)

pandas/conftest.py

+10
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,16 @@ def tick_classes(request):
868868
)
869869

870870

871+
@pytest.fixture
872+
def datetime_series():
873+
"""
874+
Fixture for Series of floats with DatetimeIndex
875+
"""
876+
s = tm.makeTimeSeries()
877+
s.name = "ts"
878+
return s
879+
880+
871881
@pytest.fixture
872882
def float_frame():
873883
"""

pandas/core/algorithms.py

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
is_categorical_dtype,
3030
is_complex_dtype,
3131
is_datetime64_any_dtype,
32+
is_datetime64_dtype,
3233
is_datetime64_ns_dtype,
3334
is_extension_array_dtype,
3435
is_float_dtype,
@@ -191,6 +192,11 @@ def _reconstruct_data(values, dtype, original):
191192
if isinstance(original, ABCIndexClass):
192193
values = values.astype(object, copy=False)
193194
elif dtype is not None:
195+
if is_datetime64_dtype(dtype):
196+
dtype = "datetime64[ns]"
197+
elif is_timedelta64_dtype(dtype):
198+
dtype = "timedelta64[ns]"
199+
194200
values = values.astype(dtype, copy=False)
195201

196202
return values

pandas/core/arrays/boolean.py

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from pandas.core.dtypes.missing import isna, notna
2727

2828
from pandas.core import nanops, ops
29+
from pandas.core.indexers import check_array_indexer
2930

3031
from .masked import BaseMaskedArray
3132

@@ -382,6 +383,7 @@ def __setitem__(self, key, value):
382383
value = value[0]
383384
mask = mask[0]
384385

386+
key = check_array_indexer(self, key)
385387
self._data[key] = value
386388
self._mask[key] = mask
387389

pandas/core/arrays/categorical.py

+2
Original file line numberDiff line numberDiff line change
@@ -2073,6 +2073,8 @@ def __setitem__(self, key, value):
20732073

20742074
lindexer = self.categories.get_indexer(rvalue)
20752075
lindexer = self._maybe_coerce_indexer(lindexer)
2076+
2077+
key = check_array_indexer(self, key)
20762078
self._codes[key] = lindexer
20772079

20782080
def _reverse_indexer(self) -> Dict[Hashable, np.ndarray]:

pandas/core/arrays/datetimelike.py

+2
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,8 @@ def __setitem__(
601601
f"or array of those. Got '{type(value).__name__}' instead."
602602
)
603603
raise TypeError(msg)
604+
605+
key = check_array_indexer(self, key)
604606
self._data[key] = value
605607
self._maybe_clear_freq()
606608

pandas/core/arrays/integer.py

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from pandas.core.dtypes.missing import isna
2626

2727
from pandas.core import nanops, ops
28+
from pandas.core.indexers import check_array_indexer
2829
from pandas.core.ops import invalid_comparison
2930
from pandas.core.ops.common import unpack_zerodim_and_defer
3031
from pandas.core.tools.numeric import to_numeric
@@ -425,6 +426,7 @@ def __setitem__(self, key, value):
425426
value = value[0]
426427
mask = mask[0]
427428

429+
key = check_array_indexer(self, key)
428430
self._data[key] = value
429431
self._mask[key] = mask
430432

pandas/core/arrays/interval.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ def __setitem__(self, key, value):
541541
msg = f"'value' should be an interval type, got {type(value)} instead."
542542
raise TypeError(msg)
543543

544+
key = check_array_indexer(self, key)
544545
# Need to ensure that left and right are updated atomically, so we're
545546
# forced to copy, update the copy, and swap in the new values.
546547
left = self.left.copy(deep=True)
@@ -729,11 +730,11 @@ def _shallow_copy(self, left=None, right=None, closed=None):
729730
Parameters
730731
----------
731732
left : array-like
732-
Values to be used for the left-side of the the intervals.
733+
Values to be used for the left-side of the intervals.
733734
If None, the existing left and right values will be used.
734735
735736
right : array-like
736-
Values to be used for the right-side of the the intervals.
737+
Values to be used for the right-side of the intervals.
737738
If None and left is IntervalArray-like, the left and right
738739
of the IntervalArray-like will be used.
739740

pandas/core/arrays/numpy_.py

+1
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ def __getitem__(self, item):
262262
def __setitem__(self, key, value) -> None:
263263
value = extract_array(value, extract_numpy=True)
264264

265+
key = check_array_indexer(self, key)
265266
scalar_key = lib.is_scalar(key)
266267
scalar_value = lib.is_scalar(value)
267268

pandas/core/arrays/period.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from pandas.core.dtypes.dtypes import PeriodDtype
3434
from pandas.core.dtypes.generic import (
3535
ABCIndexClass,
36+
ABCPeriod,
3637
ABCPeriodArray,
3738
ABCPeriodIndex,
3839
ABCSeries,
@@ -960,8 +961,8 @@ def _get_ordinal_range(start, end, periods, freq, mult=1):
960961
if end is not None:
961962
end = Period(end, freq)
962963

963-
is_start_per = isinstance(start, Period)
964-
is_end_per = isinstance(end, Period)
964+
is_start_per = isinstance(start, ABCPeriod)
965+
is_end_per = isinstance(end, ABCPeriod)
965966

966967
if is_start_per and is_end_per and start.freq != end.freq:
967968
raise ValueError("start and end must have same freq")

pandas/core/arrays/string_.py

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from pandas.core import ops
1616
from pandas.core.arrays import PandasArray
1717
from pandas.core.construction import extract_array
18+
from pandas.core.indexers import check_array_indexer
1819
from pandas.core.missing import isna
1920

2021
if TYPE_CHECKING:
@@ -238,6 +239,7 @@ def __setitem__(self, key, value):
238239
# extract_array doesn't extract PandasArray subclasses
239240
value = value._ndarray
240241

242+
key = check_array_indexer(self, key)
241243
scalar_key = lib.is_scalar(key)
242244
scalar_value = lib.is_scalar(value)
243245
if scalar_key and not scalar_value:

pandas/core/frame.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -2937,8 +2937,11 @@ def __setitem__(self, key, value):
29372937
self._set_item(key, value)
29382938

29392939
def _setitem_slice(self, key, value):
2940+
# NB: we can't just use self.loc[key] = value because that
2941+
# operates on labels and we need to operate positional for
2942+
# backwards-compat, xref GH#31469
29402943
self._check_setitem_copy()
2941-
self.loc[key] = value
2944+
self.loc._setitem_with_indexer(key, value)
29422945

29432946
def _setitem_array(self, key, value):
29442947
# also raises Exception if object array with NA values

pandas/core/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2681,7 +2681,7 @@ def to_clipboard(
26812681
... # 0,1,2,3
26822682
... # 1,4,5,6
26832683
2684-
We can omit the the index by passing the keyword `index` and setting
2684+
We can omit the index by passing the keyword `index` and setting
26852685
it to false.
26862686
26872687
>>> df.to_clipboard(sep=',', index=False)

0 commit comments

Comments
 (0)