8000 ENH: Hand numpy-like arrays with is_list_like by znicholls · Pull Request #39830 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

ENH: Hand numpy-like arrays with is_list_like #39830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
10f1bde
PERF: is_list_like
jbrockmendel Feb 16, 2021
b8856be
typo fixup
jbrockmendel Feb 16, 2021
60e1008
isort fixup
jbrockmendel Feb 16, 2021
dda6588
isort fixup
jbrockmendel Feb 16, 2021
f36b11a
CLN: Better method of determining read-only status of openpyxl worksh…
rhshadrach Feb 15, 2021
b758123
TYP: tidy comments for # type: ignore (#39794)
simonjayhawkins Feb 15, 2021
ecf44fd
TYP: np.ndarray does not yet accept type parameters (#39792)
simonjayhawkins Feb 15, 2021
b190231
TYP: fix mypy errors in pandas/core/arraylike.py (#39104)
ivanovmg Feb 15, 2021
d7705e8
typing refactor (#39812)
attack68 Feb 15, 2021
8f48f22
[ArrayManager] Indexing - implement iset (#39734)
jorisvandenbossche Feb 15, 2021
fd1c797
DEP: bump min version of openpyxl to 3.0.0 #39603 (#39702)
fangchenli Feb 15, 2021
cc6597e
REF: Dispatch TimedeltaBlock.fillna to TimedeltaArray (#39811)
jbrockmendel Feb 15, 2021
b5b970f
REF: put Block replace methods together (#39810)
jbrockmendel Feb 15, 2021
f16e5fb
move validate_rst_title_capitalization to pre-commit (#39779)
8000 MarcoGorelli Feb 15, 2021
c433dc3
API: transform behaves differently with 'ffill' on DataFrameGroupBy a…
ftrihardjo Feb 15, 2021
15ec5e3
TST: fixturize indexing intervalindex tests (#39803)
jbrockmendel Feb 15, 2021
d819f65
DOC: skip evaluation of code in v0.8.0 release notes (#39801)
afeld Feb 15, 2021
a1173dc
Regression in to_excel when setting duplicate column names (#39800)
phofl Feb 15, 2021
b77d3fa
DOC: Add reference to Text Extensions for Pandas project (#39783)
frreiss Feb 15, 2021
7238b95
REF: share DTBlock/TDBLok _maybe_coerce_values (#39815)
jbrockmendel Feb 15, 2021
5cbafe4
CI: upload coverage report to Codecov (#39822)
fangchenli Feb 15, 2021
f4de260
DOC: Ban mutation in UDF methods (#39762)
rhshadrach Feb 15, 2021
5092a07
CLN: remove redundant openpyxl type conversions (#39782)
ahawryluk Feb 15, 2021
6646f7c
TST/REF: split/collect large tests (#39789)
jbrockmendel Feb 15, 2021
46fb34c
CLN: Remove "how" return from agg (#39786)
rhshadrach Feb 15, 2021
126f406
DEPR: casting date to dt64 in maybe_promote (#39767)
jbrockmendel Feb 15, 2021
8a726f0
TST: split large tests (#39768)
jbrockmendel Feb 15, 2021
4ea0473
BUG: incorrectly accepting datetime64(nat) for dt64tz (#39769)
jbrockmendel Feb 16, 2021
6c13843
Update is_list_like
znicholls Feb 16, 2021
015e1e8
Add and pass tests
znicholls Feb 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TST: fixturize indexing intervalindex tests (#39803)
  • Loading branch information
jbrockmendel authored and znicholls committed Feb 17, 2021
commit 15ec5e318db9142e80d9ad0cf461e7e4240bc327
8 changes: 8 additions & 0 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,14 @@ def indexer_si(request):
return request.param


@pytest.fixture(params=[tm.setitem, tm.loc])
def indexer_sl(request):
"""
Parametrize over __setitem__, loc.__setitem__
"""
return request.param


@pytest.fixture
def using_array_manager(request):
"""
Expand Down
78 changes: 37 additions & 41 deletions pandas/tests/indexing/interval/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,87 +7,83 @@


class TestIntervalIndex:
def setup_method(self, method):
self.s = Series(np.arange(5), IntervalIndex.from_breaks(np.arange(6)))
@pytest.fixture
def series_with_interval_index(self):
return Series(np.arange(5), IntervalIndex.from_breaks(np.arange(6)))

def test_getitem_with_scalar(self):
def test_getitem_with_scalar(self, series_with_interval_index, indexer_sl):

s = self.s
ser = series_with_interval_index.copy()

expected = s.iloc[:3]
tm.assert_series_equal(expected, s[:3])
tm.assert_series_equal(expected, s[:2.5])
tm.assert_series_equal(expected, s[0.1:2.5])
expected = ser.iloc[:3]
tm.assert_series_equal(expected, indexer_sl(ser)[:3])
tm.assert_series_equal(expected, indexer_sl(ser)[:2.5])
tm.assert_series_equal(expected, indexer_sl(ser)[0.1:2.5])
if indexer_sl is tm.loc:
tm.assert_series_equal(expected, ser.loc[-1:3])

expected = s.iloc[1:4]
tm.assert_series_equal(expected, s[[1.5, 2.5, 3.5]])
tm.assert_series_equal(expected, s[[2, 3, 4]])
tm.assert_series_equal(expected, s[[1.5, 3, 4]])
expected = ser.iloc[1:4]
tm.assert_series_equal(expected, indexer_sl(ser)[[1.5, 2.5, 3.5]])
tm.assert_series_equal(expected, indexer_sl(ser)[[2, 3, 4]])
tm.assert_series_equal(expected, indexer_sl(ser)[[1.5, 3, 4]])

expected = s.iloc[2:5]
tm.assert_series_equal(expected, s[s >= 2])
expected = ser.iloc[2:5]
tm.assert_series_equal(expected, indexer_sl(ser)[ser >= 2])

@pytest.mark.parametrize("direction", ["increasing", "decreasing"])
def test_nonoverlapping_monotonic(self, direction, closed):
def test_nonoverlapping_monotonic(self, direction, closed, indexer_sl):
tpls = [(0, 1), (2, 3), (4, 5)]
if direction == "decreasing":
tpls = tpls[::-1]

idx = IntervalIndex.from_tuples(tpls, closed=closed)
s = Series(list("abc"), idx)
ser = Series(list("abc"), idx)

for key, expected in zip(idx.left, s):
for key, expected in zip(idx.left, ser):
if idx.closed_left:
assert s[key] == expected
assert s.loc[key] == expected
assert indexer_sl(ser)[key] == expected
else:
with pytest.raises(KeyError, match=str(key)):
s[key]
with pytest.raises(KeyError, match=str(key)):
s.loc[key]
indexer_sl(ser)[key]

for key, expected in zip(idx.right, s):
for key, expected in zip(idx.right, ser):
if idx.closed_right:
assert s[key] == expected
assert s.loc[key] == expected
assert indexer_sl(ser)[key] == expected
else:
with pytest.raises(KeyError, match=str(key)):
s[key]
with pytest.raises(KeyError, match=str(key)):
s.loc[key]
indexer_sl(ser)[key]

for key, expected in zip(idx.mid, s):
assert s[key] == expected
assert s.loc[key] == expected
for key, expected in zip(idx.mid, ser):
assert indexer_sl(ser)[key] == expected

def test_non_matching(self):
s = self.s
def test_non_matching(self, series_with_interval_index, indexer_sl):
ser = series_with_interval_index.copy()

# this is a departure from our current
# indexing scheme, but simpler
with pytest.raises(KeyError, match=r"^\[-1\]$"):
s.loc[[-1, 3, 4, 5]]
indexer_sl(ser)[[-1, 3, 4, 5]]

with pytest.raises(KeyError, match=r"^\[-1\]$"):
s.loc[[-1, 3]]
indexer_sl(ser)[[-1, 3]]

@pytest.mark.arm_slow
def test_large_series(self):
s = Series(
ser = Series(
np.arange(1000000), index=IntervalIndex.from_breaks(np.arange(1000001))
)

result1 = s.loc[:80000]
result2 = s.loc[0:80000]
result3 = s.loc[0:80000:1]
result1 = ser.loc[:80000]
result2 = ser.loc[0:80000]
result3 = ser.loc[0:80000:1]
tm.assert_series_equal(result1, result2)
tm.assert_series_equal(result1, result3)

def test_loc_getitem_frame(self):
# CategoricalIndex with IntervalIndex categories
df = DataFrame({"A": range(10)})
s = pd.cut(df.A, 5)
df["B"] = s
ser = pd.cut(df.A, 5)
df["B"] = ser
df = df.set_index("B")

result = df.loc[4]
Expand Down
Loading
0