Skip to content

Commit e1f7599

Browse files
committed
Merge remote-tracking branch 'upstream/master' into apply_raw
2 parents de593d3 + bdb4a08 commit e1f7599

File tree

20 files changed

+424
-387
lines changed

20 files changed

+424
-387
lines changed

doc/source/whatsnew/v1.1.0.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ Numeric
234234
Conversion
235235
^^^^^^^^^^
236236
- Bug in :class:`Series` construction from NumPy array with big-endian ``datetime64`` dtype (:issue:`29684`)
237-
-
237+
- Bug in :class:`Timedelta` construction with large nanoseconds keyword value (:issue:`34202`)
238238
-
239239

240240
Strings
@@ -327,6 +327,7 @@ Reshaping
327327
- Bug in :func:`crosstab` when inputs are two Series and have tuple names, the output will keep dummy MultiIndex as columns. (:issue:`18321`)
328328
- :meth:`DataFrame.pivot` can now take lists for ``index`` and ``columns`` arguments (:issue:`21425`)
329329
- Bug in :func:`concat` where the resulting indices are not copied when ``copy=True`` (:issue:`29879`)
330+
- :meth:`Series.append` will now raise a ``TypeError`` when passed a DataFrame or a sequence containing Dataframe (:issue:`31413`)
330331
- :meth:`DataFrame.replace` and :meth:`Series.replace` will raise a ``TypeError`` if ``to_replace`` is not an expected type. Previously the ``replace`` would fail silently (:issue:`18634`)
331332

332333

@@ -349,7 +350,6 @@ Other
349350
instead of ``TypeError: Can only append a Series if ignore_index=True or if the Series has a name`` (:issue:`30871`)
350351
- Set operations on an object-dtype :class:`Index` now always return object-dtype results (:issue:`31401`)
351352
- Bug in :meth:`AbstractHolidayCalendar.holidays` when no rules were defined (:issue:`31415`)
352-
-
353353

354354
.. ---------------------------------------------------------------------------
355355

pandas/_libs/tslibs/timedeltas.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ class Timedelta(_Timedelta):
11981198

11991199
kwargs = {key: _to_py_int_float(kwargs[key]) for key in kwargs}
12001200

1201-
nano = np.timedelta64(kwargs.pop('nanoseconds', 0), 'ns')
1201+
nano = convert_to_timedelta64(kwargs.pop('nanoseconds', 0), 'ns')
12021202
try:
12031203
value = nano + convert_to_timedelta64(timedelta(**kwargs),
12041204
'ns')

pandas/_testing.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -706,11 +706,11 @@ def _get_ilevel_values(index, level):
706706
if isinstance(left, pd.PeriodIndex) or isinstance(right, pd.PeriodIndex):
707707
assert_attr_equal("freq", left, right, obj=obj)
708708
if isinstance(left, pd.IntervalIndex) or isinstance(right, pd.IntervalIndex):
709-
assert_interval_array_equal(left.values, right.values)
709+
assert_interval_array_equal(left._values, right._values)
710710

711711
if check_categorical:
712712
if is_categorical_dtype(left) or is_categorical_dtype(right):
713-
assert_categorical_equal(left.values, right.values, obj=f"{obj} category")
713+
assert_categorical_equal(left._values, right._values, obj=f"{obj} category")
714714

715715

716716
def assert_class_equal(left, right, exact: Union[bool, str] = True, obj="Input"):
@@ -883,7 +883,7 @@ def assert_interval_array_equal(left, right, exact="equiv", obj="IntervalArray")
883883
def assert_period_array_equal(left, right, obj="PeriodArray"):
884884
_check_isinstance(left, right, PeriodArray)
885885

886-
assert_numpy_array_equal(left._data, right._data, obj=f"{obj}.values")
886+
assert_numpy_array_equal(left._data, right._data, obj=f"{obj}._data")
887887
assert_attr_equal("freq", left, right, obj=obj)
888888

889889

@@ -1170,10 +1170,10 @@ def assert_series_equal(
11701170

11711171
# datetimelike may have different objects (e.g. datetime.datetime
11721172
# vs Timestamp) but will compare equal
1173-
if not Index(left.values).equals(Index(right.values)):
1173+
if not Index(left._values).equals(Index(right._values)):
11741174
msg = (
1175-
f"[datetimelike_compat=True] {left.values} "
1176-
f"is not equal to {right.values}."
1175+
f"[datetimelike_compat=True] {left._values} "
1176+
f"is not equal to {right._values}."
11771177
)
11781178
raise AssertionError(msg)
11791179
else:
@@ -1212,8 +1212,8 @@ def assert_series_equal(
12121212
if check_categorical:
12131213
if is_categorical_dtype(left) or is_categorical_dtype(right):
12141214
assert_categorical_equal(
1215-
left.values,
1216-
right.values,
1215+
left._values,
1216+
right._values,
12171217
obj=f"{obj} category",
12181218
check_category_order=check_category_order,
12191219
)

pandas/core/dtypes/cast.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1181,9 +1181,11 @@ def try_timedelta(v):
11811181
from pandas import to_timedelta
11821182

11831183
try:
1184-
return to_timedelta(v)._ndarray_values.reshape(shape)
1184+
td_values = to_timedelta(v)
11851185
except ValueError:
11861186
return v.reshape(shape)
1187+
else:
1188+
return np.asarray(td_values).reshape(shape)
11871189

11881190
inferred_type = lib.infer_datetimelike_array(ensure_object(v))
11891191

pandas/core/frame.py

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,8 @@
9494
)
9595
from pandas.core.dtypes.generic import (
9696
ABCDataFrame,
97-
ABCDatetimeIndex,
9897
ABCIndexClass,
9998
ABCMultiIndex,
100-
ABCPeriodIndex,
10199
ABCSeries,
102100
)
103101
from pandas.core.dtypes.missing import isna, notna
@@ -4582,7 +4580,7 @@ def drop_duplicates(
45824580
duplicated = self.duplicated(subset, keep=keep)
45834581

45844582
if inplace:
4585-
(inds,) = (-duplicated)._ndarray_values.nonzero()
4583+
(inds,) = np.asarray(-duplicated).nonzero()
45864584
new_data = self._data.take(inds)
45874585

45884586
if ignore_index:
@@ -8246,7 +8244,9 @@ def quantile(self, q=0.5, axis=0, numeric_only=True, interpolation="linear"):
82468244

82478245
return result
82488246

8249-
def to_timestamp(self, freq=None, how="start", axis=0, copy=True) -> "DataFrame":
8247+
def to_timestamp(
8248+
self, freq=None, how: str = "start", axis: Axis = 0, copy: bool = True
8249+
) -> "DataFrame":
82508250
"""
82518251
Cast to DatetimeIndex of timestamps, at *beginning* of period.
82528252
@@ -8266,23 +8266,16 @@ def to_timestamp(self, freq=None, how="start", axis=0, copy=True) -> "DataFrame"
82668266
-------
82678267
DataFrame with DatetimeIndex
82688268
"""
8269-
new_data = self._data
8270-
if copy:
8271-
new_data = new_data.copy()
8269+
new_obj = self.copy(deep=copy)
82728270

8273-
axis = self._get_axis_number(axis)
8274-
if axis == 0:
8275-
assert isinstance(self.index, (ABCDatetimeIndex, ABCPeriodIndex))
8276-
new_data.set_axis(1, self.index.to_timestamp(freq=freq, how=how))
8277-
elif axis == 1:
8278-
assert isinstance(self.columns, (ABCDatetimeIndex, ABCPeriodIndex))
8279-
new_data.set_axis(0, self.columns.to_timestamp(freq=freq, how=how))
8280-
else: # pragma: no cover
8281-
raise AssertionError(f"Axis must be 0 or 1. Got {axis}")
8271+
axis_name = self._get_axis_name(axis)
8272+
old_ax = getattr(self, axis_name)
8273+
new_ax = old_ax.to_timestamp(freq=freq, how=how)
82828274

8283-
return self._constructor(new_data)
8275+
setattr(new_obj, axis_name, new_ax)
8276+
return new_obj
82848277

8285-
def to_period(self, freq=None, axis=0, copy=True) -> "DataFrame":
8278+
def to_period(self, freq=None, axis: Axis = 0, copy: bool = True) -> "DataFrame":
82868279
"""
82878280
Convert DataFrame from DatetimeIndex to PeriodIndex.
82888281
@@ -8300,23 +8293,16 @@ def to_period(self, freq=None, axis=0, copy=True) -> "DataFrame":
83008293
83018294
Returns
83028295
-------
8303-
TimeSeries with PeriodIndex
8296+
DataFrame with PeriodIndex
83048297
"""
8305-
new_data = self._data
8306-
if copy:
8307-
new_data = new_data.copy()
8298+
new_obj = self.copy(deep=copy)
83088299

8309-
axis = self._get_axis_number(axis)
8310-
if axis == 0:
8311-
assert isinstance(self.index, ABCDatetimeIndex)
8312-
new_data.set_axis(1, self.index.to_period(freq=freq))
8313-
elif axis == 1:
8314-
assert isinstance(self.columns, ABCDatetimeIndex)
8315-
new_data.set_axis(0, self.columns.to_period(freq=freq))
8316-
else: # pragma: no cover
8317-
raise AssertionError(f"Axis must be 0 or 1. Got {axis}")
8300+
axis_name = self._get_axis_name(axis)
8301+
old_ax = getattr(self, axis_name)
8302+
new_ax = old_ax.to_period(freq=freq)
83188303

8319-
return self._constructor(new_data)
8304+
setattr(new_obj, axis_name, new_ax)
8305+
return new_obj
83208306

83218307
def isin(self, values) -> "DataFrame":
83228308
"""

0 commit comments

Comments
 (0)