def test_find_index(self): index = date_range('2000-01-01', periods=5000) series = Series(np.arange(len(index)), index=index, name='test') df = DataFrame(series) assert_equal(find_index(series, '2000-01-01'), 0) assert_equal(find_index(series, series.index[0]), 0) assert_equal(find_index(series, series.index[3000]), 3000) assert_equal(find_index(series, series.index[3000].to_datetime()), 3000) found_loc =find_index(series, np.datetime64(series.index[3000].to_datetime())) assert_equal(found_loc, 3000) assert_raises(ValueError, find_index, series, 'bad-date') assert_raises(ValueError, find_index, series, '1900-01-01') assert_equal(find_index(df, '2000-01-01'), 0) assert_equal(find_index(df, df.index[0]), 0) assert_equal(find_index(df, df.index[3000]), 3000) assert_equal(find_index(df, df.index[3000].to_datetime()), 3000) found_loc =find_index(df, np.datetime64(df.index[3000].to_datetime())) assert_equal(found_loc, 3000) assert_raises(ValueError, find_index, df, 'bad-date') assert_raises(ValueError, find_index, df, '1900-01-01')
def test_find_index(): index = date_range("2000-01-01", periods=5000) series = Series(np.arange(len(index)), index=index, name="test") df = DataFrame(series) assert_equal(find_index(series, "2000-01-01"), 0) assert_equal(find_index(series, series.index[0]), 0) assert_equal(find_index(series, series.index[3000]), 3000) assert_equal(find_index(series, series.index[3000].to_pydatetime()), 3000) npy_date = np.datetime64(series.index[3000].to_pydatetime()) found_loc = find_index(series, npy_date) assert_equal(found_loc, 3000) with pytest.raises(ValueError): find_index(series, "bad-date") with pytest.raises(ValueError): find_index(series, "1900-01-01") assert_equal(find_index(df, "2000-01-01"), 0) assert_equal(find_index(df, df.index[0]), 0) assert_equal(find_index(df, df.index[3000]), 3000) assert_equal(find_index(df, df.index[3000].to_pydatetime()), 3000) found_loc = find_index(df, np.datetime64(df.index[3000].to_pydatetime())) assert_equal(found_loc, 3000) with pytest.raises(ValueError): find_index(df, "bad-date") with pytest.raises(ValueError): find_index(df, "1900-01-01") idx = find_index(df, 1) assert idx == 1