Skip to content

Commit 0fca392

Browse files
committed
Merge remote-tracking branch 'upstream/master' into shiny-new-feature
2 parents 9b6657d + 6b189d7 commit 0fca392

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

ci/deps/travis-36-cov.yaml

+2-1
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

+1
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/missing.py

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

pandas/tests/io/excel/test_openpyxl.py

+11-1
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

+11
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)