Skip to content

Commit 80babf1

Browse files
authored
Merge branch 'main' into pylint-48855-C-type-disallowed-name
2 parents 7589322 + 83798f6 commit 80babf1

32 files changed

+144
-316
lines changed

.github/workflows/wheels.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
- [windows-2019, win_amd64]
5353
- [windows-2019, win32]
5454
# TODO: support PyPy?
55-
python: [["cp38", "3.8"], ["cp39", "3.9"], ["cp310", "3.10"], ["cp311", "3.11-dev"]]# "pp38", "pp39"]
55+
python: [["cp38", "3.8"], ["cp39", "3.9"], ["cp310", "3.10"], ["cp311", "3.11"]]# "pp38", "pp39"]
5656
env:
5757
IS_PUSH: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
5858
IS_SCHEDULE_DISPATCH: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
@@ -73,7 +73,7 @@ jobs:
7373
CIBW_BUILD: ${{ matrix.python[0] }}-${{ matrix.buildplat[1] }}
7474

7575
# Used to test the built wheels
76-
- uses: actions/setup-python@v3
76+
- uses: actions/setup-python@v4
7777
with:
7878
python-version: ${{ matrix.python[1] }}
7979

asv_bench/benchmarks/groupby.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ class String:
683683
def setup(self, dtype, method):
684684
cols = list("abcdefghjkl")
685685
self.df = DataFrame(
686-
np.random.randint(0, 100, size=(1_000_000, len(cols))),
686+
np.random.randint(0, 100, size=(10_000, len(cols))),
687687
columns=cols,
688688
dtype=dtype,
689689
)

doc/source/getting_started/install.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Instructions for installing from source,
2020
Python version support
2121
----------------------
2222

23-
Officially Python 3.8, 3.9 and 3.10.
23+
Officially Python 3.8, 3.9, 3.10 and 3.11.
2424

2525
Installing pandas
2626
-----------------

doc/source/whatsnew/v0.13.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ Enhancements
733733
734734
.. _scipy: http://www.scipy.org
735735
.. _documentation: http://docs.scipy.org/doc/scipy/reference/interpolate.html#univariate-interpolation
736-
.. _guide: http://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html
736+
.. _guide: https://docs.scipy.org/doc/scipy/tutorial/interpolate.html
737737

738738
- ``to_csv`` now takes a ``date_format`` keyword argument that specifies how
739739
output datetime objects should be formatted. Datetimes encountered in the

doc/source/whatsnew/v2.0.0.rst

+5
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ Other API changes
142142
- The ``other`` argument in :meth:`DataFrame.mask` and :meth:`Series.mask` now defaults to ``no_default`` instead of ``np.nan`` consistent with :meth:`DataFrame.where` and :meth:`Series.where`. Entries will be filled with the corresponding NULL value (``np.nan`` for numpy dtypes, ``pd.NA`` for extension dtypes). (:issue:`49111`)
143143
- When creating a :class:`Series` with a object-dtype :class:`Index` of datetime objects, pandas no longer silently converts the index to a :class:`DatetimeIndex` (:issue:`39307`, :issue:`23598`)
144144
- :meth:`Series.unique` with dtype "timedelta64[ns]" or "datetime64[ns]" now returns :class:`TimedeltaArray` or :class:`DatetimeArray` instead of ``numpy.ndarray`` (:issue:`49176`)
145+
- Passing strings that cannot be parsed as datetimes to :class:`Series` or :class:`DataFrame` with ``dtype="datetime64[ns]"`` will raise instead of silently ignoring the keyword and returning ``object`` dtype (:issue:`24435`)
145146
-
146147

147148
.. ---------------------------------------------------------------------------
@@ -182,6 +183,7 @@ Removal of prior version deprecations/changes
182183
- Removed deprecated argument ``null_color`` in :meth:`.Styler.highlight_null` (:issue:`49397`)
183184
- Enforced deprecation disallowing passing a timezone-aware :class:`Timestamp` and ``dtype="datetime64[ns]"`` to :class:`Series` or :class:`DataFrame` constructors (:issue:`41555`)
184185
- Enforced deprecation disallowing passing a sequence of timezone-aware values and ``dtype="datetime64[ns]"`` to to :class:`Series` or :class:`DataFrame` constructors (:issue:`41555`)
186+
- Enforced deprecation disallowing unit-less "datetime64" dtype in :meth:`Series.astype` and :meth:`DataFrame.astype` (:issue:`47844`)
185187
- Enforced deprecation disallowing using ``.astype`` to convert a ``datetime64[ns]`` :class:`Series`, :class:`DataFrame`, or :class:`DatetimeIndex` to timezone-aware dtype, use ``obj.tz_localize`` or ``ser.dt.tz_localize`` instead (:issue:`39258`)
186188
- Enforced deprecation disallowing using ``.astype`` to convert a timezone-aware :class:`Series`, :class:`DataFrame`, or :class:`DatetimeIndex` to timezone-naive ``datetime64[ns]`` dtype, use ``obj.tz_localize(None)`` or ``obj.tz_convert("UTC").tz_localize(None)`` instead (:issue:`39258`)
187189
- Removed Date parser functions :func:`~pandas.io.date_converters.parse_date_time`,
@@ -200,6 +202,7 @@ Removal of prior version deprecations/changes
200202
- Removed argument ``sort_columns`` in :meth:`DataFrame.plot` and :meth:`Series.plot` (:issue:`47563`)
201203
- Removed argument ``is_copy`` from :meth:`DataFrame.take` and :meth:`Series.take` (:issue:`30615`)
202204
- Removed argument ``kind`` from :meth:`Index.get_slice_bound`, :meth:`Index.slice_indexer` and :meth:`Index.slice_locs` (:issue:`41378`)
205+
- Removed argument ``datetime_is_numeric`` from :meth:`DataFrame.describe` and :meth:`Series.describe` as datetime data will always be summarized as numeric data (:issue:`34798`)
203206
- Disallow subclass-specific keywords (e.g. "freq", "tz", "names", "closed") in the :class:`Index` constructor (:issue:`38597`)
204207
- Removed argument ``inplace`` from :meth:`Categorical.remove_unused_categories` (:issue:`37918`)
205208
- Disallow passing non-round floats to :class:`Timestamp` with ``unit="M"`` or ``unit="Y"`` (:issue:`47266`)
@@ -276,13 +279,15 @@ Removal of prior version deprecations/changes
276279
- Removed the ``display.column_space`` option in favor of ``df.to_string(col_space=...)`` (:issue:`47280`)
277280
- Removed the deprecated method ``mad`` from pandas classes (:issue:`11787`)
278281
- Removed the deprecated method ``tshift`` from pandas classes (:issue:`11631`)
282+
- Changed behavior of empty data passed into :class:`Series`; the default dtype will be ``object`` instead of ``float64`` (:issue:`29405`)
279283
- Changed the behavior of :func:`to_datetime` with argument "now" with ``utc=False`` to match ``Timestamp("now")`` (:issue:`18705`)
280284
- Changed behavior of :class:`DataFrame` constructor given floating-point ``data`` and an integer ``dtype``, when the data cannot be cast losslessly, the floating point dtype is retained, matching :class:`Series` behavior (:issue:`41170`)
281285
- Changed behavior of :class:`DataFrame` constructor when passed a ``dtype`` (other than int) that the data cannot be cast to; it now raises instead of silently ignoring the dtype (:issue:`41733`)
282286
- Changed the behavior of :class:`Series` constructor, it will no longer infer a datetime64 or timedelta64 dtype from string entries (:issue:`41731`)
283287
- Changed behavior of :class:`Index` constructor when passed a ``SparseArray`` or ``SparseDtype`` to retain that dtype instead of casting to ``numpy.ndarray`` (:issue:`43930`)
284288
- Removed the deprecated ``base`` and ``loffset`` arguments from :meth:`pandas.DataFrame.resample`, :meth:`pandas.Series.resample` and :class:`pandas.Grouper`. Use ``offset`` or ``origin`` instead (:issue:`31809`)
285289
- Changed behavior of :meth:`DataFrame.any` and :meth:`DataFrame.all` with ``bool_only=True``; object-dtype columns with all-bool values will no longer be included, manually cast to ``bool`` dtype first (:issue:`46188`)
290+
- Changed behavior of comparison of a :class:`Timestamp` with a ``datetime.date`` object; these now compare as un-equal and raise on inequality comparisons, matching the ``datetime.datetime`` behavior (:issue:`36131`)
286291
- Enforced deprecation of silently dropping columns that raised a ``TypeError`` in :class:`Series.transform` and :class:`DataFrame.transform` when used with a list or dictionary (:issue:`43740`)
287292
-
288293

pandas/_libs/tslibs/timestamps.pyx

+6-8
Original file line numberDiff line numberDiff line change
@@ -364,15 +364,13 @@ cdef class _Timestamp(ABCTimestamp):
364364
# which incorrectly drops tz and normalizes to midnight
365365
# before comparing
366366
# We follow the stdlib datetime behavior of never being equal
367-
warnings.warn(
368-
"Comparison of Timestamp with datetime.date is deprecated in "
369-
"order to match the standard library behavior. "
370-
"In a future version these will be considered non-comparable. "
371-
"Use 'ts == pd.Timestamp(date)' or 'ts.date() == date' instead.",
372-
FutureWarning,
373-
stacklevel=find_stack_level(),
367+
if op == Py_EQ:
368+
return False
369+
elif op == Py_NE:
370+
return True
371+
raise TypeError("Cannot compare Timestamp with datetime.date. "
372+
"Use ts == pd.Timestamp(date) or ts.date() == date instead."
374373
)
375-
return NotImplemented
376374
else:
377375
return NotImplemented
378376

pandas/core/apply.py

+4-9
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@
5858
from pandas.core.algorithms import safe_sort
5959
from pandas.core.base import SelectionMixin
6060
import pandas.core.common as com
61-
from pandas.core.construction import (
62-
create_series_with_explicit_dtype,
63-
ensure_wrapped_if_datetimelike,
64-
)
61+
from pandas.core.construction import ensure_wrapped_if_datetimelike
6562

6663
if TYPE_CHECKING:
6764
from pandas import (
@@ -881,14 +878,12 @@ def wrap_results(self, results: ResType, res_index: Index) -> DataFrame | Series
881878

882879
# dict of scalars
883880

884-
# the default dtype of an empty Series will be `object`, but this
881+
# the default dtype of an empty Series is `object`, but this
885882
# code can be hit by df.mean() where the result should have dtype
886883
# float64 even if it's an empty Series.
887884
constructor_sliced = self.obj._constructor_sliced
888-
if constructor_sliced is Series:
889-
result = create_series_with_explicit_dtype(
890-
results, dtype_if_empty=np.float64
891-
)
885+
if len(results) == 0 and constructor_sliced is Series:
886+
result = constructor_sliced(results, dtype=np.float64)
892887
else:
893888
result = constructor_sliced(results)
894889
result.index = res_index

pandas/core/arrays/datetimes.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -683,15 +683,10 @@ def astype(self, dtype, copy: bool = True):
683683
and dtype != self.dtype
684684
and is_unitless(dtype)
685685
):
686-
# TODO(2.0): just fall through to dtl.DatetimeLikeArrayMixin.astype
687-
warnings.warn(
688-
"Passing unit-less datetime64 dtype to .astype is deprecated "
689-
"and will raise in a future version. Pass 'datetime64[ns]' instead",
690-
FutureWarning,
691-
stacklevel=find_stack_level(),
686+
raise TypeError(
687+
"Casting to unit-less dtype 'datetime64' is not supported. "
688+
"Pass e.g. 'datetime64[ns]' instead."
692689
)
693-
# unit conversion e.g. datetime64[s]
694-
return self._ndarray.astype(dtype)
695690

696691
elif is_period_dtype(dtype):
697692
return self.to_period(freq=dtype.freq)

pandas/core/base.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
from pandas.core.arraylike import OpsMixin
7272
from pandas.core.arrays import ExtensionArray
7373
from pandas.core.construction import (
74-
create_series_with_explicit_dtype,
7574
ensure_wrapped_if_datetimelike,
7675
extract_array,
7776
)
@@ -842,9 +841,12 @@ def _map_values(self, mapper, na_action=None):
842841
# expected to be pd.Series(np.nan, ...). As np.nan is
843842
# of dtype float64 the return value of this method should
844843
# be float64 as well
845-
mapper = create_series_with_explicit_dtype(
846-
mapper, dtype_if_empty=np.float64
847-
)
844+
from pandas import Series
845+
846+
if len(mapper) == 0:
847+
mapper = Series(mapper, dtype=np.float64)
848+
else:
849+
mapper = Series(mapper)
848850

849851
if isinstance(mapper, ABCSeries):
850852
if na_action not in (None, "ignore"):

pandas/core/construction.py

-60
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from typing import (
1010
TYPE_CHECKING,
11-
Any,
1211
Optional,
1312
Sequence,
1413
Union,
@@ -830,62 +829,3 @@ def _try_cast(
830829
subarr = np.array(arr, dtype=dtype, copy=copy)
831830

832831
return subarr
833-
834-
835-
def is_empty_data(data: Any) -> bool:
836-
"""
837-
Utility to check if a Series is instantiated with empty data,
838-
which does not contain dtype information.
839-
840-
Parameters
841-
----------
842-
data : array-like, Iterable, dict, or scalar value
843-
Contains data stored in Series.
844-
845-
Returns
846-
-------
847-
bool
848-
"""
849-
is_none = data is None
850-
is_list_like_without_dtype = is_list_like(data) and not hasattr(data, "dtype")
851-
is_simple_empty = is_list_like_without_dtype and not data
852-
return is_none or is_simple_empty
853-
854-
855-
def create_series_with_explicit_dtype(
856-
data: Any = None,
857-
index: ArrayLike | Index | None = None,
858-
dtype: Dtype | None = None,
859-
name: str | None = None,
860-
copy: bool = False,
861-
fastpath: bool = False,
862-
dtype_if_empty: Dtype = object,
863-
) -> Series:
864-
"""
865-
Helper to pass an explicit dtype when instantiating an empty Series.
866-
867-
This silences a DeprecationWarning described in GitHub-17261.
868-
869-
Parameters
870-
----------
871-
data : Mirrored from Series.__init__
872-
index : Mirrored from Series.__init__
873-
dtype : Mirrored from Series.__init__
874-
name : Mirrored from Series.__init__
875-
copy : Mirrored from Series.__init__
876-
fastpath : Mirrored from Series.__init__
877-
dtype_if_empty : str, numpy.dtype, or ExtensionDtype
878-
This dtype will be passed explicitly if an empty Series will
879-
be instantiated.
880-
881-
Returns
882-
-------
883-
Series
884-
"""
885-
from pandas.core.series import Series
886-
887-
if is_empty_data(data) and dtype is None:
888-
dtype = dtype_if_empty
889-
return Series(
890-
data=data, index=index, dtype=dtype, name=name, copy=copy, fastpath=fastpath
891-
)

0 commit comments

Comments
 (0)