<p dir="auto">This was fun to debug.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [1]: import pandas as pd

In [2]: 0 in pd.Int64Index([0, 0, 1])
Out[2]: True

In [3]: 0 in pd.Int64Index([0, 1, 0])
Out[3]: True

In [4]: 0 in pd.Int64Index([0, 0, -1])
Out[4]: True

In [5]: pd.Timestamp(0) in pd.DatetimeIndex([0, 1, -1])
Out[5]: True

In [6]: pd.Timestamp(0) in pd.DatetimeIndex([0, 1, 0])
Out[6]: False   # BAD

In [7]: pd.Timestamp(0) in pd.DatetimeIndex([0, 0, 1])
Out[7]: True

In [8]: pd.Timestamp(0) in pd.DatetimeIndex([0, 0, -1])
Out[8]: False   # BAD"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">1</span>]: <span class="pl-s1">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>

<span class="pl-v">In</span> [<span class="pl-c1">2</span>]: <span class="pl-c1">0</span> <span class="pl-c1">in</span> <span class="pl-s1">pd</span>.<span class="pl-v">Int64Index</span>([<span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">1</span>])
<span class="pl-v">Out</span>[<span class="pl-c1">2</span>]: <span class="pl-c1">True</span>

<span class="pl-v">In</span> [<span class="pl-c1">3</span>]: <span class="pl-c1">0</span> <span class="pl-c1">in</span> <span class="pl-s1">pd</span>.<span class="pl-v">Int64Index</span>([<span class="pl-c1">0</span>, <span class="pl-c1">1</span>, <span class="pl-c1">0</span>])
<span class="pl-v">Out</span>[<span class="pl-c1">3</span>]: <span class="pl-c1">True</span>

<span class="pl-v">In</span> [<span class="pl-c1">4</span>]: <span class="pl-c1">0</span> <span class="pl-c1">in</span> <span class="pl-s1">pd</span>.<span class="pl-v">Int64Index</span>([<span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">-</span><span class="pl-c1">1</span>])
<span class="pl-v">Out</span>[<span class="pl-c1">4</span>]: <span class="pl-c1">True</span>

<span class="pl-v">In</span> [<span class="pl-c1">5</span>]: <span class="pl-s1">pd</span>.<span class="pl-v">Timestamp</span>(<span class="pl-c1">0</span>) <span class="pl-c1">in</span> <span class="pl-s1">pd</span>.<span class="pl-v">DatetimeIndex</span>([<span class="pl-c1">0</span>, <span class="pl-c1">1</span>, <span class="pl-c1">-</span><span class="pl-c1">1</span>])
<span class="pl-v">Out</span>[<span class="pl-c1">5</span>]: <span class="pl-c1">True</span>

<span class="pl-v">In</span> [<span class="pl-c1">6</span>]: <span class="pl-s1">pd</span>.<span class="pl-v">Timestamp</span>(<span class="pl-c1">0</span>) <span class="pl-c1">in</span> <span class="pl-s1">pd</span>.<span class="pl-v">DatetimeIndex</span>([<span class="pl-c1">0</span>, <span class="pl-c1">1</span>, <span class="pl-c1">0</span>])
<span class="pl-v">Out</span>[<span class="pl-c1">6</span>]: <span class="pl-c1">False</span>   <span class="pl-c"># BAD</span>

<span class="pl-v">In</span> [<span class="pl-c1">7</span>]: <span class="pl-s1">pd</span>.<span class="pl-v">Timestamp</span>(<span class="pl-c1">0</span>) <span class="pl-c1">in</span> <span class="pl-s1">pd</span>.<span class="pl-v">DatetimeIndex</span>([<span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">1</span>])
<span class="pl-v">Out</span>[<span class="pl-c1">7</span>]: <span class="pl-c1">True</span>

<span class="pl-v">In</span> [<span class="pl-c1">8</span>]: <span class="pl-s1">pd</span>.<span class="pl-v">Timestamp</span>(<span class="pl-c1">0</span>) <span class="pl-c1">in</span> <span class="pl-s1">pd</span>.<span class="pl-v">DatetimeIndex</span>([<span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">-</span><span class="pl-c1">1</span>])
<span class="pl-v">Out</span>[<span class="pl-c1">8</span>]: <span class="pl-c1">False</span>   <span class="pl-c"># BAD</span></pre></div>
<p dir="auto">TimedeltaIndex is also broken.</p>
<p dir="auto">The problem is in <a href="https://github.com/pydata/pandas/blob/v0.15.2/pandas/tseries/base.py#L68"><code class="notranslate">DatetimeIndexOpsMixin.__contains__</code></a>, which checks the type of <code class="notranslate">idx.get_loc(key)</code> to determine whether the key was found in the index.  If the index contains duplicate entries and is not monotonic increasing (for some reason, monotonic decreasing doesn't cut it), <code class="notranslate">get_loc</code> eventually falls back to <a href="https://github.com/pydata/pandas/blob/v0.15.2/pandas/index.pyx#L376"><code class="notranslate">Int64Engine._maybe_get_bool_indexer</code></a>, which returns an ndarray of bools if the key is duplicated.  Since the original <code class="notranslate">__contains__</code> method is looking for scalars or slices, it reports that the duplicated entry is not present.</p>
<h4 dir="auto">Code Sample</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="result = pd.Series(1., pd.date_range('20170101','20181231',freq='D')).resample('B').last().to_period()

print result.index[0]
# Period('2016-12-30', 'B')

pd.Period('20170101', freq='B')
# Period('2017-01-02', 'B')"><pre class="notranslate"><span class="pl-s1">result</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">Series</span>(<span class="pl-c1">1.</span>, <span class="pl-s1">pd</span>.<span class="pl-en">date_range</span>(<span class="pl-s">'20170101'</span>,<span class="pl-s">'20181231'</span>,<span class="pl-s1">freq</span><span class="pl-c1">=</span><span class="pl-s">'D'</span>)).<span class="pl-en">resample</span>(<span class="pl-s">'B'</span>).<span class="pl-en">last</span>().<span class="pl-en">to_period</span>()

<span class="pl-k">print</span> <span class="pl-s1">result</span>.<span class="pl-s1">index</span>[<span class="pl-c1">0</span>]
<span class="pl-c"># Period('2016-12-30', 'B')</span>

<span class="pl-s1">pd</span>.<span class="pl-v">Period</span>(<span class="pl-s">'20170101'</span>, <span class="pl-s1">freq</span><span class="pl-c1">=</span><span class="pl-s">'B'</span>)
<span class="pl-c"># Period('2017-01-02', 'B')</span></pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">when i have daily data that spans weekends (e.g., 1/1/2017 which is a Sunday) and try to get the last available value for a BusinessDay, the data falls back to the Friday period.  This is inconsistent with the timestamp of Sunday belonging to the Monday BusinessDay period (e.g., <code class="notranslate">pd.Period('20170101', 'B')</code> goes to 1/2/2017).</p>
<h4 dir="auto">Expected Output</h4>
<p dir="auto">I would expect that the <code class="notranslate">result.index[0]</code> above would return <code class="notranslate">Period('2017-01-02', 'B')</code></p>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.12.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-36-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: None.None
<p dir="auto">pandas: 0.19.2<br>
nose: 1.3.7<br>
pip: 9.0.1<br>
setuptools: 34.3.0<br>
Cython: 0.24<br>
numpy: 1.12.0<br>
scipy: 0.18.1<br>
statsmodels: 0.6.1<br>
xarray: 0.9.1<br>
IPython: 4.1.1<br>
sphinx: None<br>
patsy: 0.4.1<br>
dateutil: 2.6.0<br>
pytz: 2016.10<br>
blosc: None<br>
bottleneck: 1.2.0<br>
tables: None<br>
numexpr: 2.5<br>
matplotlib: 1.5.1<br>
openpyxl: 2.3.3<br>
xlrd: 0.9.4<br>
xlwt: 1.0.0<br>
xlsxwriter: None<br>
lxml: 3.5.0<br>
bs4: 4.5.1<br>
html5lib: None<br>
httplib2: 0.9.2<br>
apiclient: None<br>
sqlalchemy: 1.0.12<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.8<br>
boto: 2.45.0<br>
pandas_datareader: None</p>
</details>