Skip to content

Commit 2a2186d

Browse files
committed
Merge remote-tracking branch 'upstream/main' into clip-corr-edge-cases
2 parents c83ccaf + 78acf94 commit 2a2186d

File tree

11 files changed

+41
-199
lines changed

11 files changed

+41
-199
lines changed

Diff for: doc/source/user_guide/basics.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ of elements to display is five, but you may pass a custom number.
3636
Attributes and underlying data
3737
------------------------------
3838

39-
pandas objects have a number of attributes enabling you to access the metadata
39+
pandas objects have a number of attributes enabling you to access the metadata.
4040

4141
* **shape**: gives the axis dimensions of the object, consistent with ndarray
4242
* Axis labels
@@ -59,7 +59,7 @@ NumPy's type system to add support for custom arrays
5959
(see :ref:`basics.dtypes`).
6060

6161
To get the actual data inside a :class:`Index` or :class:`Series`, use
62-
the ``.array`` property
62+
the ``.array`` property.
6363

6464
.. ipython:: python
6565
@@ -88,18 +88,18 @@ NumPy doesn't have a dtype to represent timezone-aware datetimes, so there
8888
are two possibly useful representations:
8989

9090
1. An object-dtype :class:`numpy.ndarray` with :class:`Timestamp` objects, each
91-
with the correct ``tz``
91+
with the correct ``tz``.
9292
2. A ``datetime64[ns]`` -dtype :class:`numpy.ndarray`, where the values have
93-
been converted to UTC and the timezone discarded
93+
been converted to UTC and the timezone discarded.
9494

95-
Timezones may be preserved with ``dtype=object``
95+
Timezones may be preserved with ``dtype=object``:
9696

9797
.. ipython:: python
9898
9999
ser = pd.Series(pd.date_range("2000", periods=2, tz="CET"))
100100
ser.to_numpy(dtype=object)
101101
102-
Or thrown away with ``dtype='datetime64[ns]'``
102+
Or thrown away with ``dtype='datetime64[ns]'``:
103103

104104
.. ipython:: python
105105

Diff for: doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ Groupby/resample/rolling
772772
- Bug in :meth:`.DataFrameGroupBy.quantile` when ``interpolation="nearest"`` is inconsistent with :meth:`DataFrame.quantile` (:issue:`47942`)
773773
- Bug in :meth:`.Resampler.interpolate` on a :class:`DataFrame` with non-uniform sampling and/or indices not aligning with the resulting resampled index would result in wrong interpolation (:issue:`21351`)
774774
- Bug in :meth:`DataFrame.ewm` and :meth:`Series.ewm` when passed ``times`` and aggregation functions other than mean (:issue:`51695`)
775+
- Bug in :meth:`DataFrame.resample` changing index type to :class:`MultiIndex` when the dataframe is empty and using an upsample method (:issue:`55572`)
775776
- Bug in :meth:`DataFrameGroupBy.agg` that raises ``AttributeError`` when there is dictionary input and duplicated columns, instead of returning a DataFrame with the aggregation of all duplicate columns. (:issue:`55041`)
776777
- Bug in :meth:`DataFrameGroupBy.apply` and :meth:`SeriesGroupBy.apply` for empty data frame with ``group_keys=False`` still creating output index using group keys. (:issue:`60471`)
777778
- Bug in :meth:`DataFrameGroupBy.apply` that was returning a completely empty DataFrame when all return values of ``func`` were ``None`` instead of returning an empty DataFrame with the original columns and dtypes. (:issue:`57775`)

Diff for: pandas/_libs/tslibs/period.pyx

+2-5
Original file line numberDiff line numberDiff line change
@@ -1752,9 +1752,6 @@ cdef class _Period(PeriodMixin):
17521752
def __cinit__(self, int64_t ordinal, BaseOffset freq):
17531753
self.ordinal = ordinal
17541754
self.freq = freq
1755-
# Note: this is more performant than PeriodDtype.from_date_offset(freq)
1756-
# because from_date_offset cannot be made a cdef method (until cython
1757-
# supported cdef classmethods)
17581755
self._dtype = PeriodDtypeBase(freq._period_dtype_code, freq.n)
17591756

17601757
@classmethod
@@ -1913,7 +1910,7 @@ cdef class _Period(PeriodMixin):
19131910

19141911
Parameters
19151912
----------
1916-
freq : str, BaseOffset
1913+
freq : str, DateOffset
19171914
The target frequency to convert the Period object to.
19181915
If a string is provided,
19191916
it must be a valid :ref:`period alias <timeseries.period_aliases>`.
@@ -2599,7 +2596,7 @@ cdef class _Period(PeriodMixin):
25992596
26002597
Parameters
26012598
----------
2602-
freq : str, BaseOffset
2599+
freq : str, DateOffset
26032600
Frequency to use for the returned period.
26042601
26052602
See Also

Diff for: pandas/core/resample.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -507,22 +507,12 @@ def _wrap_result(self, result):
507507
"""
508508
Potentially wrap any results.
509509
"""
510-
# GH 47705
511-
obj = self.obj
512-
if (
513-
isinstance(result, ABCDataFrame)
514-
and len(result) == 0
515-
and not isinstance(result.index, PeriodIndex)
516-
):
517-
result = result.set_index(
518-
_asfreq_compat(obj.index[:0], freq=self.freq), append=True
519-
)
520-
521510
if isinstance(result, ABCSeries) and self._selection is not None:
522511
result.name = self._selection
523512

524513
if isinstance(result, ABCSeries) and result.empty:
525514
# When index is all NaT, result is empty but index is not
515+
obj = self.obj
526516
result.index = _asfreq_compat(obj.index[:0], freq=self.freq)
527517
result.name = getattr(obj, "name", None)
528518

@@ -1756,6 +1746,17 @@ def func(x):
17561746
return x.apply(f, *args, **kwargs)
17571747

17581748
result = self._groupby.apply(func)
1749+
1750+
# GH 47705
1751+
if (
1752+
isinstance(result, ABCDataFrame)
1753+
and len(result) == 0
1754+
and not isinstance(result.index, PeriodIndex)
1755+
):
1756+
result = result.set_index(
1757+
_asfreq_compat(self.obj.index[:0], freq=self.freq), append=True
1758+
)
1759+
17591760
return self._wrap_result(result)
17601761

17611762
_upsample = _apply

Diff for: pandas/tests/resample/test_base.py

+18
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,24 @@ def test_resample_size_empty_dataframe(freq, index):
438438
tm.assert_series_equal(result, expected)
439439

440440

441+
@pytest.mark.parametrize("index", [DatetimeIndex([]), TimedeltaIndex([])])
442+
@pytest.mark.parametrize("freq", ["D", "h"])
443+
@pytest.mark.parametrize(
444+
"method", ["ffill", "bfill", "nearest", "asfreq", "interpolate", "mean"]
445+
)
446+
def test_resample_apply_empty_dataframe(index, freq, method):
447+
# GH#55572
448+
empty_frame_dti = DataFrame(index=index)
449+
450+
rs = empty_frame_dti.resample(freq)
451+
result = rs.apply(getattr(rs, method))
452+
453+
expected_index = _asfreq_compat(empty_frame_dti.index, freq)
454+
expected = DataFrame([], index=expected_index)
455+
456+
tm.assert_frame_equal(result, expected)
457+
458+
441459
@pytest.mark.parametrize(
442460
"index",
443461
[

Diff for: web/pandas/config.yml

-20
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,6 @@ sponsors:
146146
url: https://numfocus.org/
147147
logo: static/img/partners/numfocus.svg
148148
kind: numfocus
149-
- name: "Two Sigma"
150-
url: https://www.twosigma.com/
151-
logo: static/img/partners/two_sigma.svg
152-
kind: partner
153-
description: "Jeff Reback"
154-
- name: "Voltron Data"
155-
url: https://voltrondata.com/
156-
logo: static/img/partners/voltron_data.svg
157-
kind: partner
158-
description: "Joris Van den Bossche"
159149
- name: "Coiled"
160150
url: https://www.coiled.io
161151
logo: static/img/partners/coiled.svg
@@ -171,21 +161,11 @@ sponsors:
171161
logo: static/img/partners/nvidia.svg
172162
kind: partner
173163
description: "Matthew Roeschke"
174-
- name: "Intel"
175-
url: https://www.intel.com/
176-
logo: /static/img/partners/intel.svg
177-
kind: partner
178-
description: "Brock Mendel"
179164
- name: "Tidelift"
180165
url: https://tidelift.com
181166
logo: static/img/partners/tidelift.svg
182167
kind: regular
183168
description: "<i>pandas</i> is part of the <a href=\"https://tidelift.com/subscription/pkg/pypi-pandas?utm_source=pypi-pandas&utm_medium=referral&utm_campaign=readme\">Tidelift subscription</a>. You can support pandas by becoming a Tidelift subscriber."
184-
- name: "Chan Zuckerberg Initiative"
185-
url: https://chanzuckerberg.com/
186-
logo: static/img/partners/czi.svg
187-
kind: regular
188-
description: "<i>pandas</i> is funded by the Essential Open Source Software for Science program of the Chan Zuckerberg Initiative. The funding is used for general maintenance, improve extension types, and a efficient string type."
189169
- name: "Bodo"
190170
url: https://www.bodo.ai/
191171
logo: static/img/partners/bodo.svg

Diff for: web/pandas/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ <h5>With the support of:</h5>
4646
{% for row in sponsors.active | batch(6, "") %}
4747
<div class="row mx-auto h-100">
4848
{% for company in row %}
49-
<div class="col-6 col-md-2">
49+
<div class="col-6 col-md-2 d-flex align-items-center justify-content-center">
5050
{% if company %}
5151
<a href="{{ company.url }}" target="_blank">
52-
<img class="img-fluid img-thumbnail py-5 mx-auto" alt="{{ company.name }}" src="{{ base_url }}{{ company.logo }}"/>
52+
<img class="img-fluid w-100" alt="{{ company.name }}" src="{{ base_url }}{{ company.logo }}"/>
5353
</a>
5454
{% endif %}
5555
</div>

0 commit comments

Comments
 (0)