/usr/local/lib64/python3.6/site-packages/pandas/tests/series/methods
NameSizeModeActions
__pycache__/-0755rm
test_align.py53590644editdlrm
test_append.py96000644editdlrm
test_argsort.py22490644editdlrm
test_asfreq.py36160644editdlrm
test_asof.py55150644editdlrm
test_astype.py26280644editdlrm
test_at_time.py26290644editdlrm
test_autocorr.py9990644editdlrm
test_between.py11970644editdlrm
test_between_time.py50860644editdlrm
test_clip.py33840644editdlrm
test_combine.py6270644editdlrm
test_combine_first.py34110644editdlrm
test_compare.py37340644editdlrm
test_convert_dtypes.py99140644editdlrm
test_count.py11230644editdlrm
test_cov_corr.py52150644editdlrm
test_describe.py46400644editdlrm
test_diff.py23310644editdlrm
test_drop.py29860644editdlrm
test_droplevel.py6290644editdlrm
test_drop_duplicates.py68500644editdlrm
test_duplicated.py9960644editdlrm
test_equals.py12950644editdlrm
test_explode.py35380644editdlrm
test_fillna.py65130644editdlrm
test_first_and_last.py20420644editdlrm
test_head_tail.py3430644editdlrm
test_interpolate.py277570644editdlrm
test_isin.py34450644editdlrm
test_nlargest.py71210644editdlrm
test_pct_change.py29680644editdlrm
test_quantile.py68100644editdlrm
test_rank.py202870644editdlrm
test_reindex_like.py12450644editdlrm
test_rename.py33780644editdlrm
test_rename_axis.py15030644editdlrm
test_replace.py155590644editdlrm
test_reset_index.py46360644editdlrm
test_round.py19700644editdlrm
test_searchsorted.py21210644editdlrm
test_shift.py125950644editdlrm
test_sort_index.py122770644editdlrm
test_sort_values.py79810644editdlrm
test_to_dict.py7420644editdlrm
test_to_period.py17550644editdlrm
test_to_timestamp.py26160644editdlrm
test_truncate.py55570644editdlrm
test_tz_convert.py10080644editdlrm
test_tz_localize.py31080644editdlrm
test_unstack.py42080644editdlrm
test_update.py42130644editdlrm
test_value_counts.py81360644editdlrm
__init__.py2250644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/pandas/tests/series/methods/test_asof.py (5515B)
import numpy as np import pytest from pandas._libs.tslibs import IncompatibleFrequency from pandas import Series, Timestamp, date_range, isna, notna, offsets import pandas._testing as tm class TestSeriesAsof: def test_basic(self): # array or list or dates N = 50 rng = date_range("1/1/1990", periods=N, freq="53s") ts = Series(np.random.randn(N), index=rng) ts.iloc[15:30] = np.nan dates = date_range("1/1/1990", periods=N * 3, freq="25s") result = ts.asof(dates) assert notna(result).all() lb = ts.index[14] ub = ts.index[30] result = ts.asof(list(dates)) assert notna(result).all() lb = ts.index[14] ub = ts.index[30] mask = (result.index >= lb) & (result.index < ub) rs = result[mask] assert (rs == ts[lb]).all() val = result[result.index[result.index >= ub][0]] assert ts[ub] == val def test_scalar(self): N = 30 rng = date_range("1/1/1990", periods=N, freq="53s") ts = Series(np.arange(N), index=rng) ts.iloc[5:10] = np.NaN ts.iloc[15:20] = np.NaN val1 = ts.asof(ts.index[7]) val2 = ts.asof(ts.index[19]) assert val1 == ts[4] assert val2 == ts[14] # accepts strings val1 = ts.asof(str(ts.index[7])) assert val1 == ts[4] # in there result = ts.asof(ts.index[3]) assert result == ts[3] # no as of value d = ts.index[0] - offsets.BDay() assert np.isnan(ts.asof(d)) def test_with_nan(self): # basic asof test rng = date_range("1/1/2000", "1/2/2000", freq="4h") s = Series(np.arange(len(rng)), index=rng) r = s.resample("2h").mean() result = r.asof(r.index) expected = Series( [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6.0], index=date_range("1/1/2000", "1/2/2000", freq="2h"), ) tm.assert_series_equal(result, expected) r.iloc[3:5] = np.nan result = r.asof(r.index) expected = Series( [0, 0, 1, 1, 1, 1, 3, 3, 4, 4, 5, 5, 6.0], index=date_range("1/1/2000", "1/2/2000", freq="2h"), ) tm.assert_series_equal(result, expected) r.iloc[-3:] = np.nan result = r.asof(r.index) expected = Series( [0, 0, 1, 1, 1, 1, 3, 3, 4, 4, 4, 4, 4.0], index=date_range("1/1/2000", "1/2/2000", freq="2h"), ) tm.assert_series_equal(result, expected) def test_periodindex(self): from pandas import PeriodIndex, period_range # array or list or dates N = 50 rng = period_range("1/1/1990", periods=N, freq="H") ts = Series(np.random.randn(N), index=rng) ts.iloc[15:30] = np.nan dates = date_range("1/1/1990", periods=N * 3, freq="37min") result = ts.asof(dates) assert notna(result).all() lb = ts.index[14] ub = ts.index[30] result = ts.asof(list(dates)) assert notna(result).all() lb = ts.index[14] ub = ts.index[30] pix = PeriodIndex(result.index.values, freq="H") mask = (pix >= lb) & (pix < ub) rs = result[mask] assert (rs == ts[lb]).all() ts.iloc[5:10] = np.nan ts.iloc[15:20] = np.nan val1 = ts.asof(ts.index[7]) val2 = ts.asof(ts.index[19]) assert val1 == ts[4] assert val2 == ts[14] # accepts strings val1 = ts.asof(str(ts.index[7])) assert val1 == ts[4] # in there assert ts.asof(ts.index[3]) == ts[3] # no as of value d = ts.index[0].to_timestamp() - offsets.BDay() assert isna(ts.asof(d)) # Mismatched freq msg = "Input has different freq" with pytest.raises(IncompatibleFrequency, match=msg): ts.asof(rng.asfreq("D")) def test_errors(self): s = Series( [1, 2, 3], index=[Timestamp("20130101"), Timestamp("20130103"), Timestamp("20130102")], ) # non-monotonic assert not s.index.is_monotonic with pytest.raises(ValueError, match="requires a sorted index"): s.asof(s.index[0]) # subset with Series N = 10 rng = date_range("1/1/1990", periods=N, freq="53s") s = Series(np.random.randn(N), index=rng) with pytest.raises(ValueError, match="not valid for Series"): s.asof(s.index[0], subset="foo") def test_all_nans(self): # GH 15713 # series is all nans result = Series([np.nan]).asof([0]) expected = Series([np.nan]) tm.assert_series_equal(result, expected) # testing non-default indexes N = 50 rng = date_range("1/1/1990", periods=N, freq="53s") dates = date_range("1/1/1990", periods=N * 3, freq="25s") result = Series(np.nan, index=rng).asof(dates) expected = Series(np.nan, index=dates) tm.assert_series_equal(result, expected) # testing scalar input date = date_range("1/1/1990", periods=N * 3, freq="25s")[0] result = Series(np.nan, index=rng).asof(date) assert isna(result) # test name is propagated result = Series(np.nan, index=[1, 2, 3, 4], name="test").asof([4, 5]) expected = Series(np.nan, index=[4, 5], name="test") tm.assert_series_equal(result, expected)