Skip to content

Commit 00c0f12

Browse files
authored
Merge branch 'main' into cow_putmask
2 parents bdde4df + fdd7163 commit 00c0f12

File tree

18 files changed

+116
-145
lines changed

18 files changed

+116
-145
lines changed

.github/workflows/python-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
run: |
7474
python --version
7575
python -m pip install --upgrade pip setuptools wheel
76-
python -m pip install -i https://pypi.anaconda.org/scipy-wheels-nightly/simple numpy
76+
python -m pip install --extra-index-url https://pypi.anaconda.org/scipy-wheels-nightly/simple numpy
7777
python -m pip install git+https://github.com/nedbat/coveragepy.git
7878
python -m pip install versioneer[toml]
7979
python -m pip install python-dateutil pytz cython hypothesis==6.52.1 pytest>=6.2.5 pytest-xdist pytest-cov pytest-asyncio>=0.17

doc/scripts/eval_performance.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pandas import DataFrame
77

88
setup_common = """from pandas import DataFrame
9+
import numpy as np
910
df = DataFrame(np.random.randn(%d, 3), columns=list('abc'))
1011
%s"""
1112

doc/source/whatsnew/v1.5.3.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ Bug fixes
3838

3939
Other
4040
~~~~~
41+
42+
.. note::
43+
44+
If you are using :meth:`DataFrame.to_sql`, :func:`read_sql`, :func:`read_sql_table`, or :func:`read_sql_query` with SQLAlchemy 1.4.46 or greater,
45+
you may see a ``sqlalchemy.exc.RemovedIn20Warning``. These warnings can be safely ignored for the SQLAlchemy 1.4.x releases
46+
as pandas works toward compatibility with SQLAlchemy 2.0.
47+
4148
- Reverted deprecation (:issue:`45324`) of behavior of :meth:`Series.__getitem__` and :meth:`Series.__setitem__` slicing with an integer :class:`Index`; this will remain positional (:issue:`49612`)
4249
-
4350

doc/source/whatsnew/v2.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ Other API changes
515515
- Default value of ``dtype`` in :func:`get_dummies` is changed to ``bool`` from ``uint8`` (:issue:`45848`)
516516
- :meth:`DataFrame.astype`, :meth:`Series.astype`, and :meth:`DatetimeIndex.astype` casting datetime64 data to any of "datetime64[s]", "datetime64[ms]", "datetime64[us]" will return an object with the given resolution instead of coercing back to "datetime64[ns]" (:issue:`48928`)
517517
- :meth:`DataFrame.astype`, :meth:`Series.astype`, and :meth:`DatetimeIndex.astype` casting timedelta64 data to any of "timedelta64[s]", "timedelta64[ms]", "timedelta64[us]" will return an object with the given resolution instead of coercing to "float64" dtype (:issue:`48963`)
518+
- :meth:`DatetimeIndex.astype`, :meth:`TimedeltaIndex.astype`, :meth:`PeriodIndex.astype` :meth:`Series.astype`, :meth:`DataFrame.astype` with ``datetime64``, ``timedelta64`` or :class:`PeriodDtype` dtypes no longer allow converting to integer dtypes other than "int64", do ``obj.astype('int64', copy=False).astype(dtype)`` instead (:issue:`49715`)
518519
- :meth:`Index.astype` now allows casting from ``float64`` dtype to datetime-like dtypes, matching :class:`Series` behavior (:issue:`49660`)
519520
- Passing data with dtype of "timedelta64[s]", "timedelta64[ms]", or "timedelta64[us]" to :class:`TimedeltaIndex`, :class:`Series`, or :class:`DataFrame` constructors will now retain that dtype instead of casting to "timedelta64[ns]"; timedelta64 data with lower resolution will be cast to the lowest supported resolution "timedelta64[s]" (:issue:`49014`)
520521
- Passing ``dtype`` of "timedelta64[s]", "timedelta64[ms]", or "timedelta64[us]" to :class:`TimedeltaIndex`, :class:`Series`, or :class:`DataFrame` constructors will now retain that dtype instead of casting to "timedelta64[ns]"; passing a dtype with lower resolution for :class:`Series` or :class:`DataFrame` will be cast to the lowest supported resolution "timedelta64[s]" (:issue:`49014`)

pandas/core/arrays/datetimelike.py

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
is_period_dtype,
9797
is_string_dtype,
9898
is_timedelta64_dtype,
99-
is_unsigned_integer_dtype,
10099
pandas_dtype,
101100
)
102101
from pandas.core.dtypes.dtypes import (
@@ -468,39 +467,10 @@ def astype(self, dtype, copy: bool = True):
468467
# we deliberately ignore int32 vs. int64 here.
469468
# See https://github.com/pandas-dev/pandas/issues/24381 for more.
470469
values = self.asi8
471-
472-
if is_unsigned_integer_dtype(dtype):
473-
# Again, we ignore int32 vs. int64
474-
values = values.view("uint64")
475-
if dtype != np.uint64:
476-
# GH#45034
477-
warnings.warn(
478-
f"The behavior of .astype from {self.dtype} to {dtype} is "
479-
"deprecated. In a future version, this astype will return "
480-
"exactly the specified dtype instead of uint64, and will "
481-
"raise if that conversion overflows.",
482-
FutureWarning,
483-
stacklevel=find_stack_level(),
484-
)
485-
elif (self.asi8 < 0).any():
486-
# GH#45034
487-
warnings.warn(
488-
f"The behavior of .astype from {self.dtype} to {dtype} is "
489-
"deprecated. In a future version, this astype will "
490-
"raise if the conversion overflows, as it did in this "
491-
"case with negative int64 values.",
492-
FutureWarning,
493-
stacklevel=find_stack_level(),
494-
)
495-
elif dtype != np.int64:
496-
# GH#45034
497-
warnings.warn(
498-
f"The behavior of .astype from {self.dtype} to {dtype} is "
499-
"deprecated. In a future version, this astype will return "
500-
"exactly the specified dtype instead of int64, and will "
501-
"raise if that conversion overflows.",
502-
FutureWarning,
503-
stacklevel=find_stack_level(),
470+
if dtype != np.int64:
471+
raise TypeError(
472+
f"Converting from {self.dtype} to {dtype} is not supported. "
473+
"Do obj.astype('int64').astype(dtype) instead"
504474
)
505475

506476
if copy:

pandas/core/dtypes/astype.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,6 @@ def astype_array(values: ArrayLike, dtype: DtypeObj, copy: bool = False) -> Arra
171171
-------
172172
ndarray or ExtensionArray
173173
"""
174-
if (
175-
values.dtype.kind in ["m", "M"]
176-
and dtype.kind in ["i", "u"]
177-
and isinstance(dtype, np.dtype)
178-
and dtype.itemsize != 8
179-
):
180-
# TODO(2.0) remove special case once deprecation on DTA/TDA is enforced
181-
msg = rf"cannot astype a datetimelike from [{values.dtype}] to [{dtype}]"
182-
raise TypeError(msg)
183-
184174
if is_dtype_equal(values.dtype, dtype):
185175
if copy:
186176
return values.copy()

pandas/core/dtypes/common.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,11 @@ def is_any_int_dtype(arr_or_dtype) -> bool:
638638
>>> is_any_int_dtype(pd.Index([1, 2.])) # float
639639
False
640640
"""
641-
return _is_dtype_type(arr_or_dtype, classes(np.integer, np.timedelta64))
641+
return _is_dtype_type(
642+
arr_or_dtype, classes(np.integer, np.timedelta64)
643+
) or _is_dtype(
644+
arr_or_dtype, lambda typ: isinstance(typ, ExtensionDtype) and typ.kind in "iu"
645+
)
642646

643647

644648
def is_integer_dtype(arr_or_dtype) -> bool:

pandas/tests/arrays/period/test_astype.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,13 @@ def test_astype_int(dtype):
1414
# Period/Datetime/Timedelta astype
1515
arr = period_array(["2000", "2001", None], freq="D")
1616

17-
if np.dtype(dtype).kind == "u":
18-
expected_dtype = np.dtype("uint64")
19-
warn1 = FutureWarning
20-
else:
21-
expected_dtype = np.dtype("int64")
22-
warn1 = None
23-
24-
msg_overflow = "will raise if the conversion overflows"
25-
with tm.assert_produces_warning(warn1, match=msg_overflow):
26-
expected = arr.astype(expected_dtype)
27-
28-
warn = None if dtype == expected_dtype else FutureWarning
29-
msg = " will return exactly the specified dtype"
30-
if warn is None and warn1 is not None:
31-
warn = warn1
32-
msg = msg_overflow
33-
with tm.assert_produces_warning(warn, match=msg):
34-
result = arr.astype(dtype)
35-
36-
assert result.dtype == expected_dtype
17+
if np.dtype(dtype) != np.int64:
18+
with pytest.raises(TypeError, match=r"Do obj.astype\('int64'\)"):
19+
arr.astype(dtype)
20+
return
21+
22+
result = arr.astype(dtype)
23+
expected = arr._ndarray.view("i8")
3724
tm.assert_numpy_array_equal(result, expected)
3825

3926

pandas/tests/arrays/test_datetimes.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -377,20 +377,13 @@ def test_astype_copies(self, dtype, other):
377377
def test_astype_int(self, dtype):
378378
arr = DatetimeArray._from_sequence([pd.Timestamp("2000"), pd.Timestamp("2001")])
379379

380-
if np.dtype(dtype).kind == "u":
381-
expected_dtype = np.dtype("uint64")
382-
else:
383-
expected_dtype = np.dtype("int64")
384-
expected = arr.astype(expected_dtype)
385-
386-
warn = None
387-
if dtype != expected_dtype:
388-
warn = FutureWarning
389-
msg = " will return exactly the specified dtype"
390-
with tm.assert_produces_warning(warn, match=msg):
391-
result = arr.astype(dtype)
380+
if np.dtype(dtype) != np.int64:
381+
with pytest.raises(TypeError, match=r"Do obj.astype\('int64'\)"):
382+
arr.astype(dtype)
383+
return
392384

393-
assert result.dtype == expected_dtype
385+
result = arr.astype(dtype)
386+
expected = arr._ndarray.view("i8")
394387
tm.assert_numpy_array_equal(result, expected)
395388

396389
def test_astype_to_sparse_dt64(self):

pandas/tests/arrays/test_timedeltas.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,13 @@ class TestTimedeltaArray:
190190
def test_astype_int(self, dtype):
191191
arr = TimedeltaArray._from_sequence([Timedelta("1H"), Timedelta("2H")])
192192

193-
if np.dtype(dtype).kind == "u":
194-
expected_dtype = np.dtype("uint64")
195-
else:
196-
expected_dtype = np.dtype("int64")
197-
expected = arr.astype(expected_dtype)
198-
199-
warn = None
200-
if dtype != expected_dtype:
201-
warn = FutureWarning
202-
msg = " will return exactly the specified dtype"
203-
with tm.assert_produces_warning(warn, match=msg):
204-
result = arr.astype(dtype)
205-
206-
assert result.dtype == expected_dtype
193+
if np.dtype(dtype) != np.int64:
194+
with pytest.raises(TypeError, match=r"Do obj.astype\('int64'\)"):
195+
arr.astype(dtype)
196+
return
197+
198+
result = arr.astype(dtype)
199+
expected = arr._ndarray.view("i8")
207200
tm.assert_numpy_array_equal(result, expected)
208201

209202
def test_setitem_clears_freq(self):

0 commit comments

Comments
 (0)