Skip to content

Commit d452842

Browse files
committed
Merge remote-tracking branch 'upstream/master' into extensiontyping
2 parents c9795a5 + 1f5e358 commit d452842

File tree

155 files changed

+3402
-1229
lines changed

Some content is hidden

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

155 files changed

+3402
-1229
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ jobs:
178178
pytest pandas/tests/indexing/multiindex/test_setitem.py::TestMultiIndexSetItem::test_frame_setitem_multi_column
179179
180180
pytest pandas/tests/api/
181+
pytest pandas/tests/arrays/
181182
pytest pandas/tests/base/
182183
pytest pandas/tests/computation/
183184
pytest pandas/tests/config/

asv_bench/benchmarks/reshape.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,42 @@ def time_unstack(self):
5353
self.df.unstack(1)
5454

5555

56+
class ReshapeExtensionDtype:
57+
58+
params = ["datetime64[ns, US/Pacific]", "Period[s]"]
59+
param_names = ["dtype"]
60+
61+
def setup(self, dtype):
62+
lev = pd.Index(list("ABCDEFGHIJ"))
63+
ri = pd.Index(range(1000))
64+
mi = MultiIndex.from_product([lev, ri], names=["foo", "bar"])
65+
66+
index = date_range("2016-01-01", periods=10000, freq="s", tz="US/Pacific")
67+
if dtype == "Period[s]":
68+
index = index.tz_localize(None).to_period("s")
69+
70+
ser = pd.Series(index, index=mi)
71+
df = ser.unstack("bar")
72+
# roundtrips -> df.stack().equals(ser)
73+
74+
self.ser = ser
75+
self.df = df
76+
77+
def time_stack(self, dtype):
78+
self.df.stack()
79+
80+
def time_unstack_fast(self, dtype):
81+
# last level -> doesnt have to make copies
82+
self.ser.unstack("bar")
83+
84+
def time_unstack_slow(self, dtype):
85+
# first level -> must make copies
86+
self.ser.unstack("foo")
87+
88+
def time_transpose(self, dtype):
89+
self.df.T
90+
91+
5692
class Unstack:
5793

5894
params = ["int", "category"]

doc/source/user_guide/window.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ The following formula is used to compute exponentially weighted mean with an inp
581581

582582
.. math::
583583
584-
y_t = \frac{\sum_{i=0}^t 0.5^\frac{t_{t} - t_{i}}{\lambda} x_{t-i}}{0.5^\frac{t_{t} - t_{i}}{\lambda}},
584+
y_t = \frac{\sum_{i=0}^t 0.5^\frac{t_{t} - t_{i}}{\lambda} x_{t-i}}{\sum_{i=0}^t 0.5^\frac{t_{t} - t_{i}}{\lambda}},
585585
586586
587587
ExponentialMovingWindow also has an ``ignore_na`` argument, which determines how

doc/source/whatsnew/v1.3.0.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ Other enhancements
140140
- :meth:`pandas.read_stata` and :class:`StataReader` support reading data from compressed files.
141141
- Add support for parsing ``ISO 8601``-like timestamps with negative signs to :meth:`pandas.Timedelta` (:issue:`37172`)
142142
- Add support for unary operators in :class:`FloatingArray` (:issue:`38749`)
143+
- :class:`RangeIndex` can now be constructed by passing a ``range`` object directly e.g. ``pd.RangeIndex(range(3))`` (:issue:`12067`)
143144
- :meth:`round` being enabled for the nullable integer and floating dtypes (:issue:`38844`)
145+
- :meth:`pandas.read_csv` and :meth:`pandas.read_json` expose the argument ``encoding_errors`` to control how encoding errors are handled (:issue:`39450`)
144146

145147
.. ---------------------------------------------------------------------------
146148
@@ -437,6 +439,7 @@ Timezones
437439
Numeric
438440
^^^^^^^
439441
- Bug in :meth:`DataFrame.quantile`, :meth:`DataFrame.sort_values` causing incorrect subsequent indexing behavior (:issue:`38351`)
442+
- Bug in :meth:`DataFrame.sort_values` raising an :class:`IndexError` for empty ``by`` (:issue:`40258`)
440443
- Bug in :meth:`DataFrame.select_dtypes` with ``include=np.number`` now retains numeric ``ExtensionDtype`` columns (:issue:`35340`)
441444
- Bug in :meth:`DataFrame.mode` and :meth:`Series.mode` not keeping consistent integer :class:`Index` for empty input (:issue:`33321`)
442445
- Bug in :meth:`DataFrame.rank` with ``np.inf`` and mixture of ``np.nan`` and ``np.inf`` (:issue:`32593`)
@@ -534,6 +537,7 @@ I/O
534537
- :meth:`read_sql` returned an empty generator if ``chunksize`` was no-zero and the query returned no results. Now returns a generator with a single empty dataframe (:issue:`34411`)
535538
- Bug in :func:`read_hdf` returning unexpected records when filtering on categorical string columns using ``where`` parameter (:issue:`39189`)
536539
- Bug in :func:`read_sas` raising ``ValueError`` when ``datetimes`` were null (:issue:`39725`)
540+
- Bug in :func:`read_excel` dropping empty values from single-column spreadsheets (:issue:`39808`)
537541

538542
Period
539543
^^^^^^
@@ -570,6 +574,7 @@ Groupby/resample/rolling
570574
- Bug in :meth:`DataFrameGroupBy.sample` where column selection was not applied to sample result (:issue:`39928`)
571575
- Bug in :class:`core.window.ewm.ExponentialMovingWindow` when calling ``__getitem__`` would incorrectly raise a ``ValueError`` when providing ``times`` (:issue:`40164`)
572576
- Bug in :class:`core.window.ewm.ExponentialMovingWindow` when calling ``__getitem__`` would not retain ``com``, ``span``, ``alpha`` or ``halflife`` attributes (:issue:`40164`)
577+
- :class:`core.window.ewm.ExponentialMovingWindow` now raises a ``NotImplementedError`` when specifying ``times`` with ``adjust=False`` due to an incorrect calculation (:issue:`40098`)
573578

574579
Reshaping
575580
^^^^^^^^^
@@ -586,7 +591,7 @@ Reshaping
586591
- Bug in :meth:`DataFrame.append` returning incorrect dtypes with combinations of ``datetime64`` and ``timedelta64`` dtypes (:issue:`39574`)
587592
- Bug in :meth:`DataFrame.pivot_table` returning a ``MultiIndex`` for a single value when operating on and empty ``DataFrame`` (:issue:`13483`)
588593
- Allow :class:`Index` to be passed to the :func:`numpy.all` function (:issue:`40180`)
589-
-
594+
- Bug in :meth:`DataFrame.stack` not preserving ``CategoricalDtype`` in a ``MultiIndex`` (:issue:`36991`)
590595

591596
Sparse
592597
^^^^^^
@@ -608,7 +613,7 @@ Other
608613
- Bug in :func:`pandas.api.types.infer_dtype` not recognizing Series, Index or array with a period dtype (:issue:`23553`)
609614
- Bug in :func:`pandas.api.types.infer_dtype` raising an error for general :class:`.ExtensionArray` objects. It will now return ``"unknown-array"`` instead of raising (:issue:`37367`)
610615
- Bug in constructing a :class:`Series` from a list and a :class:`PandasDtype` (:issue:`39357`)
611-
- Bug in :class:`Styler` which caused CSS to duplicate on multiple renders. (:issue:`39395`)
616+
- Bug in :class:`Styler` which caused CSS to duplicate on multiple renders. (:issue:`39395`, :issue:`40334`)
612617
- ``inspect.getmembers(Series)`` no longer raises an ``AbstractMethodError`` (:issue:`38782`)
613618
- Bug in :meth:`Series.where` with numeric dtype and ``other = None`` not casting to ``nan`` (:issue:`39761`)
614619
- :meth:`Index.where` behavior now mirrors :meth:`Index.putmask` behavior, i.e. ``index.where(mask, other)`` matches ``index.putmask(~mask, other)`` (:issue:`39412`)

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ channels:
33
- conda-forge
44
dependencies:
55
# required
6-
- numpy>=1.16.5, <1.20 # gh-39513
6+
- numpy>=1.16.5
77
- python=3
88
- python-dateutil>=2.7.3
99
- pytz

pandas/_libs/algos_common_helper.pxi.in

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def ensure_platform_int(object arr):
1818
if (<ndarray>arr).descr.type_num == PLATFORM_INT:
1919
return arr
2020
else:
21-
return arr.astype(np.intp)
21+
# equiv: arr.astype(np.intp)
22+
return cnp.PyArray_Cast(<ndarray>arr, PLATFORM_INT)
2223
else:
2324
return np.array(arr, dtype=np.intp)
2425

@@ -28,7 +29,8 @@ def ensure_object(object arr):
2829
if (<ndarray>arr).descr.type_num == NPY_OBJECT:
2930
return arr
3031
else:
31-
return arr.astype(np.object_)
32+
# equiv: arr.astype(object)
33+
return cnp.PyArray_Cast(<ndarray>arr, NPY_OBJECT)
3234
else:
3335
return np.array(arr, dtype=np.object_)
3436

pandas/_libs/algos_take_helper.pxi.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,10 @@ ctypedef fused take_t:
230230
object
231231

232232

233-
cdef _take_2d(ndarray[take_t, ndim=2] values, object idx):
233+
cdef _take_2d(ndarray[take_t, ndim=2] values, ndarray[intp_t, ndim=2] idx):
234234
cdef:
235235
Py_ssize_t i, j, N, K
236-
ndarray[Py_ssize_t, ndim=2, cast=True] indexer = idx
236+
ndarray[intp_t, ndim=2, cast=True] indexer = idx
237237
ndarray[take_t, ndim=2] result
238238

239239
N, K = (<object>values).shape

0 commit comments

Comments
 (0)