Skip to content

Commit 83f6352

Browse files
Merge remote-tracking branch 'upstream/main' into bisect
2 parents 2633bf9 + e12b318 commit 83f6352

Some content is hidden

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

84 files changed

+1258
-859
lines changed

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ repos:
9393
types: [python]
9494
stages: [manual]
9595
additional_dependencies: &pyright_dependencies
96-
96+
9797
- id: pyright_reportGeneralTypeIssues
9898
name: pyright reportGeneralTypeIssues
9999
entry: pyright --skipunannotated -p pyright_reportGeneralTypeIssues.json
@@ -230,7 +230,7 @@ repos:
230230
language: python
231231
additional_dependencies:
232232
- flake8==4.0.1
233-
- flake8-pyi==22.5.1
233+
- flake8-pyi==22.7.0
234234
- id: future-annotations
235235
name: import annotations from __future__
236236
entry: 'from __future__ import annotations'

doc/source/ecosystem.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ A good implementation for Python users is `has2k1/plotnine <https://github.com/h
161161
`IPython Vega <https://github.com/vega/ipyvega>`__ leverages `Vega
162162
<https://github.com/vega/vega>`__ to create plots within Jupyter Notebook.
163163

164-
`Plotly <https://poltly.com/python>`__
164+
`Plotly <https://plotly.com/python>`__
165165
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
166166

167-
`Plotly’s <https://poltly.com/>`__ `Python API <https://poltly.com/python/>`__ enables interactive figures and web shareability. Maps, 2D, 3D, and live-streaming graphs are rendered with WebGL and `D3.js <https://d3js.org/>`__. The library supports plotting directly from a pandas DataFrame and cloud-based collaboration. Users of `matplotlib, ggplot for Python, and Seaborn <https://poltly.com/python/matplotlib-to-plotly-tutorial/>`__ can convert figures into interactive web-based plots. Plots can be drawn in `IPython Notebooks <https://plotly.com/ipython-notebooks/>`__ , edited with R or MATLAB, modified in a GUI, or embedded in apps and dashboards. Plotly is free for unlimited sharing, and has `offline <https://poltly.com/python/offline/>`__, or `on-premise <https://poltly.com/product/enterprise/>`__ accounts for private use.
167+
`Plotly’s <https://plotly.com/>`__ `Python API <https://plotly.com/python/>`__ enables interactive figures and web shareability. Maps, 2D, 3D, and live-streaming graphs are rendered with WebGL and `D3.js <https://d3js.org/>`__. The library supports plotting directly from a pandas DataFrame and cloud-based collaboration. Users of `matplotlib, ggplot for Python, and Seaborn <https://plotly.com/python/matplotlib-to-plotly-tutorial/>`__ can convert figures into interactive web-based plots. Plots can be drawn in `IPython Notebooks <https://plotly.com/ipython-notebooks/>`__ , edited with R or MATLAB, modified in a GUI, or embedded in apps and dashboards. Plotly is free for unlimited sharing, and has `offline <https://plotly.com/python/offline/>`__, or `on-premise <https://plotly.com/product/enterprise/>`__ accounts for private use.
168168

169169
`Lux <https://github.com/lux-org/lux>`__
170170
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

doc/source/user_guide/sparse.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ have no replacement.
266266

267267
.. _sparse.scipysparse:
268268

269-
Interaction with scipy.sparse
270-
-----------------------------
269+
Interaction with *scipy.sparse*
270+
-------------------------------
271271

272272
Use :meth:`DataFrame.sparse.from_spmatrix` to create a :class:`DataFrame` with sparse values from a sparse matrix.
273273

doc/source/user_guide/timeseries.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ We subtract the epoch (midnight at January 1, 1970 UTC) and then floor divide by
388388
389389
.. _timeseries.origin:
390390

391-
Using the ``origin`` Parameter
391+
Using the ``origin`` parameter
392392
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
393393

394394
Using the ``origin`` parameter, one can specify an alternative starting point for creation
@@ -1523,7 +1523,7 @@ or calendars with additional rules.
15231523
15241524
.. _timeseries.advanced_datetime:
15251525

1526-
Time series-related instance methods
1526+
Time Series-related instance methods
15271527
------------------------------------
15281528

15291529
Shifting / lagging
@@ -2601,7 +2601,7 @@ Transform nonexistent times to ``NaT`` or shift the times.
26012601
26022602
.. _timeseries.timezone_series:
26032603

2604-
Time zone series operations
2604+
Time zone Series operations
26052605
~~~~~~~~~~~~~~~~~~~~~~~~~~~
26062606

26072607
A :class:`Series` with time zone **naive** values is

doc/source/user_guide/visualization.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{{ header }}
44

55
*******************
6-
Chart Visualization
6+
Chart visualization
77
*******************
88

99
This section demonstrates visualization through charting. For information on
@@ -1746,7 +1746,7 @@ Andrews curves charts:
17461746
17471747
plt.close("all")
17481748
1749-
Plotting directly with matplotlib
1749+
Plotting directly with Matplotlib
17501750
---------------------------------
17511751

17521752
In some situations it may still be preferable or necessary to prepare plots

doc/source/user_guide/window.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{{ header }}
44

55
********************
6-
Windowing Operations
6+
Windowing operations
77
********************
88

99
pandas contains a compact set of APIs for performing windowing operations - an operation that performs
@@ -490,7 +490,7 @@ For all supported aggregation functions, see :ref:`api.functions_expanding`.
490490

491491
.. _window.exponentially_weighted:
492492

493-
Exponentially Weighted window
493+
Exponentially weighted window
494494
-----------------------------
495495

496496
An exponentially weighted window is similar to an expanding window but with each prior point

doc/source/whatsnew/v1.5.0.rst

+2
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,7 @@ Missing
914914
^^^^^^^
915915
- Bug in :meth:`Series.fillna` and :meth:`DataFrame.fillna` with ``downcast`` keyword not being respected in some cases where there are no NA values present (:issue:`45423`)
916916
- Bug in :meth:`Series.fillna` and :meth:`DataFrame.fillna` with :class:`IntervalDtype` and incompatible value raising instead of casting to a common (usually object) dtype (:issue:`45796`)
917+
- Bug in :meth:`Series.map` not respecting ``na_action`` argument if mapper is a ``dict`` or :class:`Series` (:issue:`47527`)
917918
- Bug in :meth:`DataFrame.interpolate` with object-dtype column not returning a copy with ``inplace=False`` (:issue:`45791`)
918919
- Bug in :meth:`DataFrame.dropna` allows to set both ``how`` and ``thresh`` incompatible arguments (:issue:`46575`)
919920
- Bug in :meth:`DataFrame.fillna` ignored ``axis`` when :class:`DataFrame` is single block (:issue:`47713`)
@@ -1026,6 +1027,7 @@ Reshaping
10261027
Sparse
10271028
^^^^^^
10281029
- Bug in :meth:`Series.where` and :meth:`DataFrame.where` with ``SparseDtype`` failing to retain the array's ``fill_value`` (:issue:`45691`)
1030+
- Bug in :meth:`SparseArray.unique` fails to keep original elements order (:issue:`47809`)
10291031
-
10301032

10311033
ExtensionArray

environment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,4 @@ dependencies:
127127
# build the interactive terminal
128128
- jupyterlab >=3.4,<4
129129
- pip:
130-
- jupyterlite==0.1.0b9
130+
- jupyterlite==0.1.0b10

pandas/_libs/algos.pyi

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
from typing import Any
42

53
import numpy as np

pandas/_libs/interval.pyi

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
from typing import (
42
Any,
53
Generic,
@@ -84,7 +82,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
8482
self: Interval[_OrderableTimesT], key: _OrderableTimesT
8583
) -> bool: ...
8684
@overload
87-
def __contains__(self: Interval[_OrderableScalarT], key: int | float) -> bool: ...
85+
def __contains__(self: Interval[_OrderableScalarT], key: float) -> bool: ...
8886
@overload
8987
def __add__(
9088
self: Interval[_OrderableTimesT], y: Timedelta
@@ -94,7 +92,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
9492
self: Interval[int], y: _OrderableScalarT
9593
) -> Interval[_OrderableScalarT]: ...
9694
@overload
97-
def __add__(self: Interval[float], y: int | float) -> Interval[float]: ...
95+
def __add__(self: Interval[float], y: float) -> Interval[float]: ...
9896
@overload
9997
def __radd__(
10098
self: Interval[_OrderableTimesT], y: Timedelta
@@ -104,7 +102,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
104102
self: Interval[int], y: _OrderableScalarT
105103
) -> Interval[_OrderableScalarT]: ...
106104
@overload
107-
def __radd__(self: Interval[float], y: int | float) -> Interval[float]: ...
105+
def __radd__(self: Interval[float], y: float) -> Interval[float]: ...
108106
@overload
109107
def __sub__(
110108
self: Interval[_OrderableTimesT], y: Timedelta
@@ -114,7 +112,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
114112
self: Interval[int], y: _OrderableScalarT
115113
) -> Interval[_OrderableScalarT]: ...
116114
@overload
117-
def __sub__(self: Interval[float], y: int | float) -> Interval[float]: ...
115+
def __sub__(self: Interval[float], y: float) -> Interval[float]: ...
118116
@overload
119117
def __rsub__(
120118
self: Interval[_OrderableTimesT], y: Timedelta
@@ -124,31 +122,31 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
124122
self: Interval[int], y: _OrderableScalarT
125123
) -> Interval[_OrderableScalarT]: ...
126124
@overload
127-
def __rsub__(self: Interval[float], y: int | float) -> Interval[float]: ...
125+
def __rsub__(self: Interval[float], y: float) -> Interval[float]: ...
128126
@overload
129127
def __mul__(
130128
self: Interval[int], y: _OrderableScalarT
131129
) -> Interval[_OrderableScalarT]: ...
132130
@overload
133-
def __mul__(self: Interval[float], y: int | float) -> Interval[float]: ...
131+
def __mul__(self: Interval[float], y: float) -> Interval[float]: ...
134132
@overload
135133
def __rmul__(
136134
self: Interval[int], y: _OrderableScalarT
137135
) -> Interval[_OrderableScalarT]: ...
138136
@overload
139-
def __rmul__(self: Interval[float], y: int | float) -> Interval[float]: ...
137+
def __rmul__(self: Interval[float], y: float) -> Interval[float]: ...
140138
@overload
141139
def __truediv__(
142140
self: Interval[int], y: _OrderableScalarT
143141
) -> Interval[_OrderableScalarT]: ...
144142
@overload
145-
def __truediv__(self: Interval[float], y: int | float) -> Interval[float]: ...
143+
def __truediv__(self: Interval[float], y: float) -> Interval[float]: ...
146144
@overload
147145
def __floordiv__(
148146
self: Interval[int], y: _OrderableScalarT
149147
) -> Interval[_OrderableScalarT]: ...
150148
@overload
151-
def __floordiv__(self: Interval[float], y: int | float) -> Interval[float]: ...
149+
def __floordiv__(self: Interval[float], y: float) -> Interval[float]: ...
152150
def overlaps(self: Interval[_OrderableT], other: Interval[_OrderableT]) -> bool: ...
153151

154152
def intervals_to_interval_bounds(

pandas/_libs/join.pyi

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def asof_join_backward_on_X_by_Y(
5555
left_by_values: np.ndarray, # by_t[:]
5656
right_by_values: np.ndarray, # by_t[:]
5757
allow_exact_matches: bool = ...,
58-
tolerance: np.number | int | float | None = ...,
58+
tolerance: np.number | float | None = ...,
5959
use_hashtable: bool = ...,
6060
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
6161
def asof_join_forward_on_X_by_Y(
@@ -64,7 +64,7 @@ def asof_join_forward_on_X_by_Y(
6464
left_by_values: np.ndarray, # by_t[:]
6565
right_by_values: np.ndarray, # by_t[:]
6666
allow_exact_matches: bool = ...,
67-
tolerance: np.number | int | float | None = ...,
67+
tolerance: np.number | float | None = ...,
6868
use_hashtable: bool = ...,
6969
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
7070
def asof_join_nearest_on_X_by_Y(
@@ -73,6 +73,6 @@ def asof_join_nearest_on_X_by_Y(
7373
left_by_values: np.ndarray, # by_t[:]
7474
right_by_values: np.ndarray, # by_t[:]
7575
allow_exact_matches: bool = ...,
76-
tolerance: np.number | int | float | None = ...,
76+
tolerance: np.number | float | None = ...,
7777
use_hashtable: bool = ...,
7878
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...

pandas/_libs/json.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def dumps(
1212
date_unit: str = ...,
1313
iso_dates: bool = ...,
1414
default_handler: None
15-
| Callable[[Any], str | int | float | bool | list | dict | None] = ...,
15+
| Callable[[Any], str | float | bool | list | dict | None] = ...,
1616
) -> str: ...
1717
def loads(
1818
s: str,

pandas/_libs/tslibs/np_datetime.pxd

+7
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,10 @@ cdef bint cmp_dtstructs(npy_datetimestruct* left, npy_datetimestruct* right, int
109109
cdef get_implementation_bounds(
110110
NPY_DATETIMEUNIT reso, npy_datetimestruct *lower, npy_datetimestruct *upper
111111
)
112+
113+
cdef int64_t convert_reso(
114+
int64_t value,
115+
NPY_DATETIMEUNIT from_reso,
116+
NPY_DATETIMEUNIT to_reso,
117+
bint round_ok,
118+
) except? -1

pandas/_libs/tslibs/np_datetime.pyx

+63-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
cimport cython
22
from cpython.datetime cimport (
3+
PyDateTime_CheckExact,
34
PyDateTime_DATE_GET_HOUR,
45
PyDateTime_DATE_GET_MICROSECOND,
56
PyDateTime_DATE_GET_MINUTE,
@@ -229,7 +230,13 @@ def py_td64_to_tdstruct(int64_t td64, NPY_DATETIMEUNIT unit):
229230

230231

231232
cdef inline void pydatetime_to_dtstruct(datetime dt, npy_datetimestruct *dts):
232-
dts.year = PyDateTime_GET_YEAR(dt)
233+
if PyDateTime_CheckExact(dt):
234+
dts.year = PyDateTime_GET_YEAR(dt)
235+
else:
236+
# We use dt.year instead of PyDateTime_GET_YEAR because with Timestamp
237+
# we override year such that PyDateTime_GET_YEAR is incorrect.
238+
dts.year = dt.year
239+
233240
dts.month = PyDateTime_GET_MONTH(dt)
234241
dts.day = PyDateTime_GET_DAY(dt)
235242
dts.hour = PyDateTime_DATE_GET_HOUR(dt)
@@ -541,5 +548,59 @@ cdef int64_t get_conversion_factor(NPY_DATETIMEUNIT from_unit, NPY_DATETIMEUNIT
541548
return 1000 * get_conversion_factor(NPY_DATETIMEUNIT.NPY_FR_fs, to_unit)
542549
elif from_unit == NPY_DATETIMEUNIT.NPY_FR_fs:
543550
return 1000 * get_conversion_factor(NPY_DATETIMEUNIT.NPY_FR_as, to_unit)
551+
552+
553+
cdef int64_t convert_reso(
554+
int64_t value,
555+
NPY_DATETIMEUNIT from_reso,
556+
NPY_DATETIMEUNIT to_reso,
557+
bint round_ok,
558+
) except? -1:
559+
cdef:
560+
int64_t res_value, mult, div, mod
561+
562+
if from_reso == to_reso:
563+
return value
564+
565+
elif to_reso < from_reso:
566+
# e.g. ns -> us, no risk of overflow, but can be lossy rounding
567+
mult = get_conversion_factor(to_reso, from_reso)
568+
div, mod = divmod(value, mult)
569+
if mod > 0 and not round_ok:
570+
raise ValueError("Cannot losslessly convert units")
571+
572+
# Note that when mod > 0, we follow np.timedelta64 in always
573+
# rounding down.
574+
res_value = div
575+
576+
elif (
577+
from_reso == NPY_FR_Y
578+
or from_reso == NPY_FR_M
579+
or to_reso == NPY_FR_Y
580+
or to_reso == NPY_FR_M
581+
):
582+
# Converting by multiplying isn't _quite_ right bc the number of
583+
# seconds in a month/year isn't fixed.
584+
res_value = _convert_reso_with_dtstruct(value, from_reso, to_reso)
585+
544586
else:
545-
raise ValueError(from_unit, to_unit)
587+
# e.g. ns -> us, risk of overflow, but no risk of lossy rounding
588+
mult = get_conversion_factor(from_reso, to_reso)
589+
with cython.overflowcheck(True):
590+
# Note: caller is responsible for re-raising as OutOfBoundsTimedelta
591+
res_value = value * mult
592+
593+
return res_value
594+
595+
596+
cdef int64_t _convert_reso_with_dtstruct(
597+
int64_t value,
598+
NPY_DATETIMEUNIT from_unit,
599+
NPY_DATETIMEUNIT to_unit,
600+
) except? -1:
601+
cdef:
602+
npy_datetimestruct dts
603+
604+
pandas_datetime_to_datetimestruct(value, from_unit, &dts)
605+
check_dts_bounds(&dts, to_unit)
606+
return npy_datetimestruct_to_datetime(to_unit, &dts)

pandas/_libs/tslibs/offsets.pyi

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
from datetime import (
42
datetime,
53
timedelta,

pandas/_libs/tslibs/timedeltas.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Timedelta(timedelta):
8686
cls: type[_S],
8787
value=...,
8888
unit: str = ...,
89-
**kwargs: int | float | np.integer | np.floating,
89+
**kwargs: float | np.integer | np.floating,
9090
) -> _S: ...
9191
# GH 46171
9292
# While Timedelta can return pd.NaT, having the constructor return
@@ -123,7 +123,7 @@ class Timedelta(timedelta):
123123
@overload # type: ignore[override]
124124
def __floordiv__(self, other: timedelta) -> int: ...
125125
@overload
126-
def __floordiv__(self, other: int | float) -> Timedelta: ...
126+
def __floordiv__(self, other: float) -> Timedelta: ...
127127
@overload
128128
def __floordiv__(
129129
self, other: npt.NDArray[np.timedelta64]

0 commit comments

Comments
 (0)