Skip to content

TST/REF: share/split index tests #43905

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

Merged
merged 2 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions pandas/tests/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@


class DatetimeLike(Base):
def test_isin(self, simple_index):
index = simple_index[:4]
result = index.isin(index)
assert result.all()

result = index.isin(list(index))
assert result.all()

result = index.isin([index[2], 5])
expected = np.array([False, False, True, False])
tm.assert_numpy_array_equal(result, expected)

def test_argsort_matches_array(self, simple_index):
idx = simple_index
idx = idx.insert(1, pd.NaT)
Expand Down
12 changes: 0 additions & 12 deletions pandas/tests/indexes/datetimes/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,6 @@ def test_groupby_function_tuple_1677(self):
result = monthly_group.mean()
assert isinstance(result.index[0], tuple)

def test_isin(self):
index = tm.makeDateIndex(4)
result = index.isin(index)
assert result.all()

result = index.isin(list(index))
assert result.all()

tm.assert_almost_equal(
index.isin([index[2], 5]), np.array([False, False, True, False])
)

def assert_index_parameters(self, index):
assert index.freq == "40960N"
assert index.inferred_freq == "40960N"
Expand Down
18 changes: 11 additions & 7 deletions pandas/tests/indexes/datetimes/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,19 +485,23 @@ def test_get_loc(self):
with pytest.raises(InvalidIndexError, match=r"slice\(None, 2, None\)"):
idx.get_loc(slice(2))

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

def test_get_loc_time_obj(self):
# time indexing
idx = date_range("2000-01-01", periods=24, freq="H")
tm.assert_numpy_array_equal(
idx.get_loc(time(12)), np.array([12]), check_dtype=False
)
tm.assert_numpy_array_equal(
idx.get_loc(time(12, 30)), np.array([]), check_dtype=False
)

result = idx.get_loc(time(12))
expected = np.array([12])
tm.assert_numpy_array_equal(result, expected, check_dtype=False)

result = idx.get_loc(time(12, 30))
expected = np.array([])
tm.assert_numpy_array_equal(result, expected, check_dtype=False)

msg = "cannot yet lookup inexact labels when key is a time object"
with pytest.raises(NotImplementedError, match=msg):
with tm.assert_produces_warning(FutureWarning, match="deprecated"):
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/indexes/datetimes/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ def test_range_edges9(self):


class TestDatetime64:
def test_no_millisecond_field(self):
msg = "type object 'DatetimeIndex' has no attribute 'millisecond'"
with pytest.raises(AttributeError, match=msg):
DatetimeIndex.millisecond

msg = "'DatetimeIndex' object has no attribute 'millisecond'"
with pytest.raises(AttributeError, match=msg):
DatetimeIndex([]).millisecond

def test_datetimeindex_accessors(self):
dti_naive = date_range(freq="D", start=datetime(1998, 1, 1), periods=365)
# GH#13303
Expand Down
10 changes: 0 additions & 10 deletions pandas/tests/indexes/period/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from pandas._libs.tslibs.period import IncompatibleFrequency

from pandas import (
DatetimeIndex,
Index,
NaT,
Period,
Expand Down Expand Up @@ -49,15 +48,6 @@ def test_where(self):
# This is handled in test_indexing
pass

def test_no_millisecond_field(self):
msg = "type object 'DatetimeIndex' has no attribute 'millisecond'"
with pytest.raises(AttributeError, match=msg):
DatetimeIndex.millisecond

msg = "'DatetimeIndex' object has no attribute 'millisecond'"
with pytest.raises(AttributeError, match=msg):
DatetimeIndex([]).millisecond

def test_make_time_series(self):
index = period_range(freq="A", start="1/1/2001", end="12/1/2009")
series = Series(1, index=index)
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/indexes/timedeltas/test_pickle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from pandas import timedelta_range
import pandas._testing as tm


class TestPickle:
def test_pickle_after_set_freq(self):
tdi = timedelta_range("1 day", periods=4, freq="s")
tdi = tdi._with_freq(None)

res = tm.round_trip_pickle(tdi)
tm.assert_index_equal(res, tdi)
30 changes: 5 additions & 25 deletions pandas/tests/indexes/timedeltas/test_timedelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from pandas import (
Index,
Int64Index,
NaT,
Series,
Timedelta,
TimedeltaIndex,
date_range,
timedelta_range,
)
import pandas._testing as tm
Expand Down Expand Up @@ -42,26 +42,6 @@ def test_numeric_compat(self):
def test_shift(self):
pass # this is handled in test_arithmetic.py

def test_pickle_after_set_freq(self):
tdi = timedelta_range("1 day", periods=4, freq="s")
tdi = tdi._with_freq(None)

res = tm.round_trip_pickle(tdi)
tm.assert_index_equal(res, tdi)

def test_isin(self):

index = tm.makeTimedeltaIndex(4)
result = index.isin(index)
assert result.all()

result = index.isin(list(index))
assert result.all()

tm.assert_almost_equal(
index.isin([index[2], 5]), np.array([False, False, True, False])
)

def test_misc_coverage(self):

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

# series
td = Series(date_range("20130101", periods=4)) - Series(
date_range("20121201", periods=4)
scalar = Timedelta(days=31)
td = Series(
[scalar, scalar, scalar + timedelta(minutes=5, seconds=3), NaT],
dtype="m8[ns]",
)
td[2] += timedelta(minutes=5, seconds=3)
td[3] = np.nan

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