Skip to content

Commit 8b6bffa

Browse files
author
MomIsBestFriend
committed
Merge remote-tracking branch 'upstream/master' into STY-repr-batch-3
2 parents a7b1439 + 6b189d7 commit 8b6bffa

File tree

6 files changed

+33
-4
lines changed

6 files changed

+33
-4
lines changed

ci/deps/travis-36-cov.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ dependencies:
2727
- numexpr
2828
- numpy=1.15.*
2929
- odfpy
30-
- openpyxl
30+
- openpyxl<=3.0.1
31+
# https://github.com/pandas-dev/pandas/pull/30009 openpyxl 3.0.2 broke
3132
- pandas-gbq
3233
# https://github.com/pydata/pandas-gbq/issues/271
3334
- google-cloud-bigquery<=1.11

doc/source/whatsnew/v1.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ Numeric
661661
- Bug in :class:`UInt64Index` precision loss while constructing from a list with values in the ``np.uint64`` range (:issue:`29526`)
662662
- Bug in :class:`NumericIndex` construction that caused indexing to fail when integers in the ``np.uint64`` range were used (:issue:`28023`)
663663
- Bug in :class:`NumericIndex` construction that caused :class:`UInt64Index` to be casted to :class:`Float64Index` when integers in the ``np.uint64`` range were used to index a :class:`DataFrame` (:issue:`28279`)
664+
- Bug in :meth:`Series.interpolate` when using method=`index` with an unsorted index, would previously return incorrect results. (:issue:`21037`)
664665

665666
Conversion
666667
^^^^^^^^^^

pandas/core/arrays/numpy_.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numbers
2+
from typing import Union
23

34
import numpy as np
45
from numpy.lib.mixins import NDArrayOperatorsMixin
@@ -117,11 +118,12 @@ class PandasArray(ExtensionArray, ExtensionOpsMixin, NDArrayOperatorsMixin):
117118
# pandas internals, which turns off things like block consolidation.
118119
_typ = "npy_extension"
119120
__array_priority__ = 1000
121+
_ndarray: np.ndarray
120122

121123
# ------------------------------------------------------------------------
122124
# Constructors
123125

124-
def __init__(self, values, copy=False):
126+
def __init__(self, values: Union[np.ndarray, "PandasArray"], copy: bool = False):
125127
if isinstance(values, type(self)):
126128
values = values._ndarray
127129
if not isinstance(values, np.ndarray):

pandas/core/missing.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,11 @@ def interpolate_1d(
278278
inds = lib.maybe_convert_objects(inds)
279279
else:
280280
inds = xvalues
281-
result[invalid] = np.interp(inds[invalid], inds[valid], yvalues[valid])
281+
# np.interp requires sorted X values, #21037
282+
indexer = np.argsort(inds[valid])
283+
result[invalid] = np.interp(
284+
inds[invalid], inds[valid][indexer], yvalues[valid][indexer]
285+
)
282286
result[preserve_nans] = np.nan
283287
return result
284288

pandas/tests/io/excel/test_openpyxl.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
from distutils.version import LooseVersion
12
import os
23

34
import numpy as np
45
import pytest
56

7+
from pandas.compat import PY37, is_platform_mac
8+
69
import pandas as pd
710
from pandas import DataFrame
811
import pandas.util.testing as tm
@@ -13,6 +16,8 @@
1316

1417
pytestmark = pytest.mark.parametrize("ext", [".xlsx"])
1518

19+
openpyxl_gt301 = LooseVersion(openpyxl.__version__) > LooseVersion("3.0.1")
20+
1621

1722
def test_to_excel_styleconverter(ext):
1823
from openpyxl import styles
@@ -81,6 +86,9 @@ def test_write_cells_merge_styled(ext):
8186
assert xcell_a2.font == openpyxl_sty_merged
8287

8388

89+
@pytest.mark.xfail(
90+
openpyxl_gt301 and PY37 and is_platform_mac(), reason="broken change in openpyxl"
91+
)
8492
@pytest.mark.parametrize(
8593
"mode,expected", [("w", ["baz"]), ("a", ["foo", "bar", "baz"])]
8694
)
@@ -107,7 +115,9 @@ def test_write_append_mode(ext, mode, expected):
107115
assert wb2.worksheets[index]["A1"].value == cell_value
108116

109117

110-
@pytest.mark.xfail(openpyxl.__version__ > "3.0.1", reason="broken change in openpyxl")
118+
@pytest.mark.xfail(
119+
openpyxl_gt301 and PY37 and is_platform_mac(), reason="broken change in openpyxl"
120+
)
111121
def test_to_excel_with_openpyxl_engine(ext, tmpdir):
112122
# GH 29854
113123
# TODO: Fix this once newer version of openpyxl fixes the bug

pandas/tests/series/test_missing.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,3 +1649,14 @@ def test_interpolate_timedelta_index(self, interp_methods_ind):
16491649
pytest.skip(
16501650
"This interpolation method is not supported for Timedelta Index yet."
16511651
)
1652+
1653+
@pytest.mark.parametrize(
1654+
"ascending, expected_values",
1655+
[(True, [1, 2, 3, 9, 10]), (False, [10, 9, 3, 2, 1])],
1656+
)
1657+
def test_interpolate_unsorted_index(self, ascending, expected_values):
1658+
# GH 21037
1659+
ts = pd.Series(data=[10, 9, np.nan, 2, 1], index=[10, 9, 3, 2, 1])
1660+
result = ts.sort_index(ascending=ascending).interpolate(method="index")
1661+
expected = pd.Series(data=expected_values, index=expected_values, dtype=float)
1662+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)