Skip to content

Commit 2cc339a

Browse files
authored
CLN: misplaced indexing tests (#44375)
1 parent aad39a8 commit 2cc339a

File tree

9 files changed

+67
-69
lines changed

9 files changed

+67
-69
lines changed

pandas/tests/arithmetic/test_datetime64.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,39 @@ def test_dt64arr_timestamp_equality(self, box_with_array):
359359
expected = tm.box_expected([False, False, False], xbox)
360360
tm.assert_equal(result, expected)
361361

362+
@pytest.mark.parametrize(
363+
"datetimelike",
364+
[
365+
Timestamp("20130101"),
366+
datetime(2013, 1, 1),
367+
np.datetime64("2013-01-01T00:00", "ns"),
368+
],
369+
)
370+
@pytest.mark.parametrize(
371+
"op,expected",
372+
[
373+
(operator.lt, [True, False, False, False]),
374+
(operator.le, [True, True, False, False]),
375+
(operator.eq, [False, True, False, False]),
376+
(operator.gt, [False, False, False, True]),
377+
],
378+
)
379+
def test_dt64_compare_datetime_scalar(self, datetimelike, op, expected):
380+
# GH#17965, test for ability to compare datetime64[ns] columns
381+
# to datetimelike
382+
ser = Series(
383+
[
384+
Timestamp("20120101"),
385+
Timestamp("20130101"),
386+
np.nan,
387+
Timestamp("20130103"),
388+
],
389+
name="A",
390+
)
391+
result = op(ser, datetimelike)
392+
expected = Series(expected, name="A")
393+
tm.assert_series_equal(result, expected)
394+
362395

363396
class TestDatetimeIndexComparisons:
364397

pandas/tests/indexes/datetimes/test_partial_slicing.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
""" test partial slicing on Series/Frame """
22

33
from datetime import datetime
4-
import operator
54

65
import numpy as np
76
import pytest
@@ -412,40 +411,6 @@ def test_loc_datetime_length_one(self):
412411
result = df.loc["2016-10-01T00:00:00":]
413412
tm.assert_frame_equal(result, df)
414413

415-
@pytest.mark.parametrize(
416-
"datetimelike",
417-
[
418-
Timestamp("20130101"),
419-
datetime(2013, 1, 1),
420-
np.datetime64("2013-01-01T00:00", "ns"),
421-
],
422-
)
423-
@pytest.mark.parametrize(
424-
"op,expected",
425-
[
426-
(operator.lt, [True, False, False, False]),
427-
(operator.le, [True, True, False, False]),
428-
(operator.eq, [False, True, False, False]),
429-
(operator.gt, [False, False, False, True]),
430-
],
431-
)
432-
def test_selection_by_datetimelike(self, datetimelike, op, expected):
433-
# GH issue #17965, test for ability to compare datetime64[ns] columns
434-
# to datetimelike
435-
df = DataFrame(
436-
{
437-
"A": [
438-
Timestamp("20120101"),
439-
Timestamp("20130101"),
440-
np.nan,
441-
Timestamp("20130103"),
442-
]
443-
}
444-
)
445-
result = op(df.A, datetimelike)
446-
expected = Series(expected, name="A")
447-
tm.assert_series_equal(result, expected)
448-
449414
@pytest.mark.parametrize(
450415
"start",
451416
[

pandas/tests/indexes/period/test_indexing.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ def test_getitem_seconds(self):
205205
# GH7116
206206
# these show deprecations as we are trying
207207
# to slice with non-integer indexers
208+
# FIXME: don't leave commented-out
208209
# with pytest.raises(IndexError):
209210
# idx[v]
210211
continue
@@ -814,12 +815,6 @@ def test_get_value(self):
814815
result2 = idx2.get_value(input2, p1)
815816
tm.assert_series_equal(result2, expected2)
816817

817-
def test_loc_str(self):
818-
# https://github.com/pandas-dev/pandas/issues/33964
819-
index = period_range(start="2000", periods=20, freq="B")
820-
series = Series(range(20), index=index)
821-
assert series.loc["2000-01-14"] == 9
822-
823818
@pytest.mark.parametrize("freq", ["H", "D"])
824819
def test_get_value_datetime_hourly(self, freq):
825820
# get_loc and get_value should treat datetime objects symmetrically

pandas/tests/indexes/period/test_period.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,18 +211,18 @@ def _check_all_fields(self, periodindex):
211211
]
212212

213213
periods = list(periodindex)
214-
s = Series(periodindex)
214+
ser = Series(periodindex)
215215

216216
for field in fields:
217217
field_idx = getattr(periodindex, field)
218218
assert len(periodindex) == len(field_idx)
219219
for x, val in zip(periods, field_idx):
220220
assert getattr(x, field) == val
221221

222-
if len(s) == 0:
222+
if len(ser) == 0:
223223
continue
224224

225-
field_s = getattr(s.dt, field)
225+
field_s = getattr(ser.dt, field)
226226
assert len(periodindex) == len(field_s)
227227
for x, val in zip(periods, field_s):
228228
assert getattr(x, field) == val

pandas/tests/indexes/timedeltas/test_ops.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import numpy as np
21
import pytest
32

43
from pandas import (
5-
Series,
64
TimedeltaIndex,
75
timedelta_range,
86
)
@@ -30,15 +28,6 @@ def test_nonunique_contains(self):
3028
):
3129
assert idx[0] in idx
3230

33-
def test_unknown_attribute(self):
34-
# see gh-9680
35-
tdi = timedelta_range(start=0, periods=10, freq="1s")
36-
ts = Series(np.random.normal(size=10), index=tdi)
37-
assert "foo" not in ts.__dict__.keys()
38-
msg = "'Series' object has no attribute 'foo'"
39-
with pytest.raises(AttributeError, match=msg):
40-
ts.foo
41-
4231
def test_infer_freq(self, freq_sample):
4332
# GH#11018
4433
idx = timedelta_range("1", freq=freq_sample, periods=10)

pandas/tests/indexing/test_loc.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2941,3 +2941,9 @@ def test_loc_set_multiple_items_in_multiple_new_columns(self):
29412941
)
29422942

29432943
tm.assert_frame_equal(df, expected)
2944+
2945+
def test_getitem_loc_str_periodindex(self):
2946+
# GH#33964
2947+
index = pd.period_range(start="2000", periods=20, freq="B")
2948+
series = Series(range(20), index=index)
2949+
assert series.loc["2000-01-14"] == 9

pandas/tests/series/indexing/test_indexing.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -377,17 +377,3 @@ def test_frozenset_index():
377377
assert s[idx1] == 2
378378
s[idx1] = 3
379379
assert s[idx1] == 3
380-
381-
382-
def test_boolean_index():
383-
# GH18579
384-
s1 = Series([1, 2, 3], index=[4, 5, 6])
385-
s2 = Series([1, 3, 2], index=s1 == 2)
386-
tm.assert_series_equal(Series([1, 3, 2], [False, True, False]), s2)
387-
388-
389-
def test_index_ndim_gt_1_raises():
390-
# GH18579
391-
df = DataFrame([[1, 2], [3, 4], [5, 6]], index=[3, 6, 9])
392-
with pytest.raises(ValueError, match="Index data must be 1-dimensional"):
393-
Series([1, 3, 2], index=df)

pandas/tests/series/test_api.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,12 @@ def test_inspect_getmembers(self):
182182
ser = Series(dtype=object)
183183
with tm.assert_produces_warning(None):
184184
inspect.getmembers(ser)
185+
186+
def test_unknown_attribute(self):
187+
# GH#9680
188+
tdi = pd.timedelta_range(start=0, periods=10, freq="1s")
189+
ser = Series(np.random.normal(size=10), index=tdi)
190+
assert "foo" not in ser.__dict__.keys()
191+
msg = "'Series' object has no attribute 'foo'"
192+
with pytest.raises(AttributeError, match=msg):
193+
ser.foo

pandas/tests/series/test_constructors.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ def test_constructor(self, datetime_series):
154154
with pytest.raises(NotImplementedError, match=msg):
155155
Series(m)
156156

157+
def test_constructor_index_ndim_gt_1_raises(self):
158+
# GH#18579
159+
df = DataFrame([[1, 2], [3, 4], [5, 6]], index=[3, 6, 9])
160+
with pytest.raises(ValueError, match="Index data must be 1-dimensional"):
161+
Series([1, 3, 2], index=df)
162+
157163
@pytest.mark.parametrize("input_class", [list, dict, OrderedDict])
158164
def test_constructor_empty(self, input_class):
159165
with tm.assert_produces_warning(FutureWarning):
@@ -276,6 +282,15 @@ def test_constructor_list_like(self):
276282
result = Series(obj, index=[0, 1, 2])
277283
tm.assert_series_equal(result, expected)
278284

285+
def test_constructor_boolean_index(self):
286+
# GH#18579
287+
s1 = Series([1, 2, 3], index=[4, 5, 6])
288+
289+
index = s1 == 2
290+
result = Series([1, 3, 2], index=index)
291+
expected = Series([1, 3, 2], index=[False, True, False])
292+
tm.assert_series_equal(result, expected)
293+
279294
@pytest.mark.parametrize("dtype", ["bool", "int32", "int64", "float64"])
280295
def test_constructor_index_dtype(self, dtype):
281296
# GH 17088

0 commit comments

Comments
 (0)