Skip to content

Commit 34e87e8

Browse files
jbrockmendelgasparitiago
authored andcommitted
TST/REF: share/split index tests (pandas-dev#43905)
1 parent 22bcbaf commit 34e87e8

File tree

7 files changed

+48
-54
lines changed

7 files changed

+48
-54
lines changed

pandas/tests/indexes/datetimelike.py

+12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99

1010

1111
class DatetimeLike(Base):
12+
def test_isin(self, simple_index):
13+
index = simple_index[:4]
14+
result = index.isin(index)
15+
assert result.all()
16+
17+
result = index.isin(list(index))
18+
assert result.all()
19+
20+
result = index.isin([index[2], 5])
21+
expected = np.array([False, False, True, False])
22+
tm.assert_numpy_array_equal(result, expected)
23+
1224
def test_argsort_matches_array(self, simple_index):
1325
idx = simple_index
1426
idx = idx.insert(1, pd.NaT)

pandas/tests/indexes/datetimes/test_datetime.py

-12
Original file line numberDiff line numberDiff line change
@@ -154,18 +154,6 @@ def test_groupby_function_tuple_1677(self):
154154
result = monthly_group.mean()
155155
assert isinstance(result.index[0], tuple)
156156

157-
def test_isin(self):
158-
index = tm.makeDateIndex(4)
159-
result = index.isin(index)
160-
assert result.all()
161-
162-
result = index.isin(list(index))
163-
assert result.all()
164-
165-
tm.assert_almost_equal(
166-
index.isin([index[2], 5]), np.array([False, False, True, False])
167-
)
168-
169157
def assert_index_parameters(self, index):
170158
assert index.freq == "40960N"
171159
assert index.inferred_freq == "40960N"

pandas/tests/indexes/datetimes/test_indexing.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -485,19 +485,23 @@ def test_get_loc(self):
485485
with pytest.raises(InvalidIndexError, match=r"slice\(None, 2, None\)"):
486486
idx.get_loc(slice(2))
487487

488-
idx = pd.to_datetime(["2000-01-01", "2000-01-04"])
488+
idx = DatetimeIndex(["2000-01-01", "2000-01-04"])
489489
assert idx.get_loc("2000-01-02", method="nearest") == 0
490490
assert idx.get_loc("2000-01-03", method="nearest") == 1
491491
assert idx.get_loc("2000-01", method="nearest") == slice(0, 2)
492492

493+
def test_get_loc_time_obj(self):
493494
# time indexing
494495
idx = date_range("2000-01-01", periods=24, freq="H")
495-
tm.assert_numpy_array_equal(
496-
idx.get_loc(time(12)), np.array([12]), check_dtype=False
497-
)
498-
tm.assert_numpy_array_equal(
499-
idx.get_loc(time(12, 30)), np.array([]), check_dtype=False
500-
)
496+
497+
result = idx.get_loc(time(12))
498+
expected = np.array([12])
499+
tm.assert_numpy_array_equal(result, expected, check_dtype=False)
500+
501+
result = idx.get_loc(time(12, 30))
502+
expected = np.array([])
503+
tm.assert_numpy_array_equal(result, expected, check_dtype=False)
504+
501505
msg = "cannot yet lookup inexact labels when key is a time object"
502506
with pytest.raises(NotImplementedError, match=msg):
503507
with tm.assert_produces_warning(FutureWarning, match="deprecated"):

pandas/tests/indexes/datetimes/test_misc.py

+9
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ def test_range_edges9(self):
156156

157157

158158
class TestDatetime64:
159+
def test_no_millisecond_field(self):
160+
msg = "type object 'DatetimeIndex' has no attribute 'millisecond'"
161+
with pytest.raises(AttributeError, match=msg):
162+
DatetimeIndex.millisecond
163+
164+
msg = "'DatetimeIndex' object has no attribute 'millisecond'"
165+
with pytest.raises(AttributeError, match=msg):
166+
DatetimeIndex([]).millisecond
167+
159168
def test_datetimeindex_accessors(self):
160169
dti_naive = date_range(freq="D", start=datetime(1998, 1, 1), periods=365)
161170
# GH#13303

pandas/tests/indexes/period/test_period.py

-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from pandas._libs.tslibs.period import IncompatibleFrequency
55

66
from pandas import (
7-
DatetimeIndex,
87
Index,
98
NaT,
109
Period,
@@ -49,15 +48,6 @@ def test_where(self):
4948
# This is handled in test_indexing
5049
pass
5150

52-
def test_no_millisecond_field(self):
53-
msg = "type object 'DatetimeIndex' has no attribute 'millisecond'"
54-
with pytest.raises(AttributeError, match=msg):
55-
DatetimeIndex.millisecond
56-
57-
msg = "'DatetimeIndex' object has no attribute 'millisecond'"
58-
with pytest.raises(AttributeError, match=msg):
59-
DatetimeIndex([]).millisecond
60-
6151
def test_make_time_series(self):
6252
index = period_range(freq="A", start="1/1/2001", end="12/1/2009")
6353
series = Series(1, index=index)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from pandas import timedelta_range
2+
import pandas._testing as tm
3+
4+
5+
class TestPickle:
6+
def test_pickle_after_set_freq(self):
7+
tdi = timedelta_range("1 day", periods=4, freq="s")
8+
tdi = tdi._with_freq(None)
9+
10+
res = tm.round_trip_pickle(tdi)
11+
tm.assert_index_equal(res, tdi)

pandas/tests/indexes/timedeltas/test_timedelta.py

+5-25
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
from pandas import (
88
Index,
99
Int64Index,
10+
NaT,
1011
Series,
1112
Timedelta,
1213
TimedeltaIndex,
13-
date_range,
1414
timedelta_range,
1515
)
1616
import pandas._testing as tm
@@ -42,26 +42,6 @@ def test_numeric_compat(self):
4242
def test_shift(self):
4343
pass # this is handled in test_arithmetic.py
4444

45-
def test_pickle_after_set_freq(self):
46-
tdi = timedelta_range("1 day", periods=4, freq="s")
47-
tdi = tdi._with_freq(None)
48-
49-
res = tm.round_trip_pickle(tdi)
50-
tm.assert_index_equal(res, tdi)
51-
52-
def test_isin(self):
53-
54-
index = tm.makeTimedeltaIndex(4)
55-
result = index.isin(index)
56-
assert result.all()
57-
58-
result = index.isin(list(index))
59-
assert result.all()
60-
61-
tm.assert_almost_equal(
62-
index.isin([index[2], 5]), np.array([False, False, True, False])
63-
)
64-
6545
def test_misc_coverage(self):
6646

6747
rng = timedelta_range("1 day", periods=5)
@@ -140,11 +120,11 @@ def test_freq_conversion(self):
140120
# doc example
141121

142122
# series
143-
td = Series(date_range("20130101", periods=4)) - Series(
144-
date_range("20121201", periods=4)
123+
scalar = Timedelta(days=31)
124+
td = Series(
125+
[scalar, scalar, scalar + timedelta(minutes=5, seconds=3), NaT],
126+
dtype="m8[ns]",
145127
)
146-
td[2] += timedelta(minutes=5, seconds=3)
147-
td[3] = np.nan
148128

149129
result = td / np.timedelta64(1, "D")
150130
expected = Series([31, 31, (31 * 86400 + 5 * 60 + 3) / 86400.0, np.nan])

0 commit comments

Comments
 (0)