Skip to content

Commit 950b695

Browse files
committed
Merge remote-tracking branch 'upstream/master' into excel-fixture-cleanup
2 parents e7dea6c + 9a67ff4 commit 950b695

File tree

10 files changed

+49
-2
lines changed

10 files changed

+49
-2
lines changed

.github/FUNDING.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
custom: https://pandas.pydata.org/donate.html

asv_bench/benchmarks/index_object.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def time_get_loc(self):
188188

189189
class IntervalIndexMethod:
190190
# GH 24813
191-
params = [10**3, 10**5, 10**7]
191+
params = [10**3, 10**5]
192192

193193
def setup(self, N):
194194
left = np.append(np.arange(N), np.array(0))

doc/source/whatsnew/v0.25.0.rst

+3
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ Performance Improvements
513513
- Improved performance of :meth:`IntervalIndex.intersection` (:issue:`24813`)
514514
- Improved performance of :meth:`read_csv` by faster concatenating date columns without extra conversion to string for integer/float zero and float ``NaN``; by faster checking the string for the possibility of being a date (:issue:`25754`)
515515
- Improved performance of :attr:`IntervalIndex.is_unique` by removing conversion to ``MultiIndex`` (:issue:`24813`)
516+
- Restored performance of :meth:`DatetimeIndex.__iter__` by re-enabling specialized code path (:issue:`26702`)
516517

517518
.. _whatsnew_0250.bug_fixes:
518519

@@ -539,13 +540,15 @@ Datetimelike
539540
- Bug in adding :class:`DateOffset` with nonzero month to :class:`DatetimeIndex` would raise ``ValueError`` (:issue:`26258`)
540541
- Bug in :func:`to_datetime` which raises unhandled ``OverflowError`` when called with mix of invalid dates and ``NaN`` values with ``format='%Y%m%d'`` and ``error='coerce'`` (:issue:`25512`)
541542
- Bug in :func:`to_datetime` which raises ``TypeError`` for ``format='%Y%m%d'`` when called for invalid integer dates with length >= 6 digits with ``errors='ignore'``
543+
- Bug when comparing a :class:`PeriodIndex` against a zero-dimensional numpy array (:issue:`26689`)
542544

543545
Timedelta
544546
^^^^^^^^^
545547

546548
- Bug in :func:`TimedeltaIndex.intersection` where for non-monotonic indices in some cases an empty ``Index`` was returned when in fact an intersection existed (:issue:`25913`)
547549
- Bug with comparisons between :class:`Timedelta` and ``NaT`` raising ``TypeError`` (:issue:`26039`)
548550
- Bug when adding or subtracting a :class:`BusinessHour` to a :class:`Timestamp` with the resulting time landing in a following or prior day respectively (:issue:`26381`)
551+
- Bug when comparing a :class:`TimedeltaIndex` against a zero-dimensional numpy array (:issue:`26689`)
549552

550553
Timezones
551554
^^^^^^^^^

pandas/core/arrays/period.py

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import numpy as np
66

7+
from pandas._libs import lib
78
from pandas._libs.tslibs import (
89
NaT, NaTType, frequencies as libfrequencies, iNaT, period as libperiod)
910
from pandas._libs.tslibs.fields import isleapyear_arr
@@ -51,6 +52,7 @@ def _period_array_cmp(cls, op):
5152
def wrapper(self, other):
5253
op = getattr(self.asi8, opname)
5354

55+
other = lib.item_from_zerodim(other)
5456
if isinstance(other, (ABCDataFrame, ABCSeries, ABCIndexClass)):
5557
return NotImplemented
5658

pandas/core/arrays/timedeltas.py

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def _td_array_cmp(cls, op):
6262
nat_result = opname == '__ne__'
6363

6464
def wrapper(self, other):
65+
other = lib.item_from_zerodim(other)
6566
if isinstance(other, (ABCDataFrame, ABCSeries, ABCIndexClass)):
6667
return NotImplemented
6768

pandas/core/indexes/datetimes.py

+2
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ def _join_i8_wrapper(joinf, **kwargs):
243243
_is_numeric_dtype = False
244244
_infer_as_myclass = True
245245

246+
# Use faster implementation given we know we have DatetimeArrays
247+
__iter__ = DatetimeArray.__iter__
246248
# some things like freq inference make use of these attributes.
247249
_bool_ops = DatetimeArray._bool_ops
248250
_object_ops = DatetimeArray._object_ops

pandas/tests/arithmetic/test_datetime64.py

+12
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def assert_all(obj):
3737
# ------------------------------------------------------------------
3838
# Comparisons
3939

40+
4041
class TestDatetime64DataFrameComparison:
4142
@pytest.mark.parametrize('timestamps', [
4243
[pd.Timestamp('2012-01-01 13:00:00+00:00')] * 2,
@@ -338,6 +339,17 @@ def test_comparison_tzawareness_compat(self, op):
338339

339340
class TestDatetimeIndexComparisons:
340341

342+
# TODO: parametrize over box
343+
def test_compare_zerodim(self, tz_naive_fixture):
344+
# Test comparison with zero-dimensional array is unboxed
345+
tz = tz_naive_fixture
346+
dti = date_range('20130101', periods=3, tz=tz)
347+
348+
other = np.array(dti.to_numpy()[0])
349+
result = dti <= other
350+
expected = np.array([True, False, False])
351+
tm.assert_numpy_array_equal(result, expected)
352+
341353
# TODO: moved from tests.indexes.test_base; parametrize and de-duplicate
342354
@pytest.mark.parametrize("op", [
343355
operator.eq, operator.ne, operator.gt, operator.lt,

pandas/tests/arithmetic/test_period.py

+10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222

2323
class TestPeriodIndexComparisons:
2424

25+
# TODO: parameterize over boxes
26+
def test_compare_zerodim(self):
27+
# GH#26689 make sure we unbox zero-dimensional arrays
28+
pi = pd.period_range('2000', periods=4)
29+
other = np.array(pi.to_numpy()[0])
30+
31+
result = pi <= other
32+
expected = np.array([True, False, False, False])
33+
tm.assert_numpy_array_equal(result, expected)
34+
2535
@pytest.mark.parametrize("other", ["2017", 2017])
2636
def test_eq(self, other):
2737
idx = PeriodIndex(['2017', '2017', '2018'], freq="D")

pandas/tests/arithmetic/test_timedelta64.py

+13
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ def get_upcast_box(box, vector):
3333
class TestTimedelta64ArrayComparisons:
3434
# TODO: All of these need to be parametrized over box
3535

36+
def test_compare_timedelta64_zerodim(self):
37+
# GH#26689 should unbox when comparing with zerodim array
38+
tdi = pd.timedelta_range('2H', periods=4)
39+
other = np.array(tdi.to_numpy()[0])
40+
41+
res = tdi <= other
42+
expected = np.array([True, False, False, False])
43+
tm.assert_numpy_array_equal(res, expected)
44+
45+
with pytest.raises(TypeError):
46+
# zero-dim of wrong dtype should still raise
47+
tdi >= np.array(4)
48+
3649
def test_compare_timedelta_series(self):
3750
# regresssion test for GH#5963
3851
s = pd.Series([timedelta(days=1), timedelta(days=2)])

pandas/tests/plotting/test_frame.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,10 @@ def test_line_area_stacked(self):
800800
with pytest.raises(ValueError):
801801
mixed_df.plot(stacked=True)
802802

803-
_check_plot_works(df.plot, kind=kind, logx=True, stacked=True)
803+
# Use an index with strictly positive values, preventing
804+
# matplotlib from warning about ignoring xlim
805+
df2 = df.set_index(df.index + 1)
806+
_check_plot_works(df2.plot, kind=kind, logx=True, stacked=True)
804807

805808
def test_line_area_nan_df(self):
806809
values1 = [1, 2, np.nan, 3]

0 commit comments

Comments
 (0)