<p dir="auto">pd.date_range() handles closed intervals correctly for daily time series but incorrectly for monthly.</p>
<p dir="auto">In this example, notice how freq='D' gives 4 days while freq='M' gives 3 months, dropping the final 2017-07-31:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="pd.date_range(start='2017-01-04', end='2017-01-07', freq='D', closed=None)
# DatetimeIndex(['2017-01-04', '2017-01-05', '2017-01-06', '2017-01-07'], dtype='datetime64[ns]', freq='D')

pd.date_range(start='2017-04', end='2017-07', freq='M', closed=None)
# DatetimeIndex(['2017-04-30', '2017-05-31', '2017-06-30'], dtype='datetime64[ns]', freq='M')"><pre class="notranslate"><span class="pl-s1">pd</span>.<span class="pl-en">date_range</span>(<span class="pl-s1">start</span><span class="pl-c1">=</span><span class="pl-s">'2017-01-04'</span>, <span class="pl-s1">end</span><span class="pl-c1">=</span><span class="pl-s">'2017-01-07'</span>, <span class="pl-s1">freq</span><span class="pl-c1">=</span><span class="pl-s">'D'</span>, <span class="pl-s1">closed</span><span class="pl-c1">=</span><span class="pl-c1">None</span>)
<span class="pl-c"># DatetimeIndex(['2017-01-04', '2017-01-05', '2017-01-06', '2017-01-07'], dtype='datetime64[ns]', freq='D')</span>

<span class="pl-s1">pd</span>.<span class="pl-en">date_range</span>(<span class="pl-s1">start</span><span class="pl-c1">=</span><span class="pl-s">'2017-04'</span>, <span class="pl-s1">end</span><span class="pl-c1">=</span><span class="pl-s">'2017-07'</span>, <span class="pl-s1">freq</span><span class="pl-c1">=</span><span class="pl-s">'M'</span>, <span class="pl-s1">closed</span><span class="pl-c1">=</span><span class="pl-c1">None</span>)
<span class="pl-c"># DatetimeIndex(['2017-04-30', '2017-05-31', '2017-06-30'], dtype='datetime64[ns]', freq='M')</span></pre></div>
<p dir="auto">This is with pandas 0.19.2. Here is my output for pd.show_versions():</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 3.6.0.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-71-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.19.2
nose: None
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.11.3
scipy: 0.18.1
statsmodels: None
xarray: None
IPython: 5.2.2
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 2.0.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.5
boto: None
pandas_datareader: None"><pre class="notranslate"><code class="notranslate">pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 3.6.0.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-71-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.19.2
nose: None
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.11.3
scipy: 0.18.1
statsmodels: None
xarray: None
IPython: 5.2.2
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 2.0.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.5
boto: None
pandas_datareader: None
</code></pre></div>
<p dir="auto"><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="23671684" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/5637" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/5637/hovercard" href="https://github.com/pandas-dev/pandas/issues/5637">#5637</a> has some examples as well</p>
<p dir="auto">When the end date in <code class="notranslate">date_range</code> is not a valid business day it appears that <code class="notranslate">date_range</code> first sets it to a valid date <em>before</em> deciding whether to return the last date depending on whether the interval is closed or open on the right. This results in the date range being incorrectly truncated when the interval is open-right - e.g.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [22]: for d in pd.date_range('20-Mar-2014', '23-Mar-2014', freq='D'):
    ...:     print d.strftime('%a %d-%b-%Y')
    ...:     
Thu 20-Mar-2014
Fri 21-Mar-2014
Sat 22-Mar-2014
Sun 23-Mar-2014

In [23]: pd.date_range('20-Mar-2014', '23-Mar-2014', freq='B')
Out[23]: 
&lt;class 'pandas.tseries.index.DatetimeIndex'&gt;
[2014-03-20, 2014-03-21]
Length: 2, Freq: B, Timezone: None

In [24]: # should return all valid business days &lt;= '23-Mar-2014'
    ...: pd.date_range('20-Mar-2014', '23-Mar-2014', freq='B', closed='left')
&lt;class 'pandas.tseries.index.DatetimeIndex'&gt;
[2014-03-20]
Length: 1, Freq: B, Timezone: None"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">22</span>]: <span class="pl-s1">for</span> <span class="pl-s1">d</span> <span class="pl-c1">in</span> <span class="pl-s1">pd</span>.<span class="pl-en">date_range</span>(<span class="pl-s">'20-Mar-2014'</span>, <span class="pl-s">'23-Mar-2014'</span>, <span class="pl-s1">freq</span><span class="pl-c1">=</span><span class="pl-s">'D'</span>):
    ...:     <span class="pl-k">print</span> <span class="pl-s1">d</span>.<span class="pl-en">strftime</span>(<span class="pl-s">'%a %d-%b-%Y'</span>)
    ...:     
<span class="pl-v">Thu</span> <span class="pl-c1">20</span><span class="pl-c1">-</span><span class="pl-v">Mar</span><span class="pl-c1">-</span><span class="pl-c1">2014</span>
<span class="pl-v">Fri</span> <span class="pl-c1">21</span><span class="pl-c1">-</span><span class="pl-v">Mar</span><span class="pl-c1">-</span><span class="pl-c1">2014</span>
<span class="pl-v">Sat</span> <span class="pl-c1">22</span><span class="pl-c1">-</span><span class="pl-v">Mar</span><span class="pl-c1">-</span><span class="pl-c1">2014</span>
<span class="pl-v">Sun</span> <span class="pl-c1">23</span><span class="pl-c1">-</span><span class="pl-v">Mar</span><span class="pl-c1">-</span><span class="pl-c1">2014</span>

<span class="pl-v">In</span> [<span class="pl-c1">23</span>]: <span class="pl-s1">pd</span>.<span class="pl-en">date_range</span>(<span class="pl-s">'20-Mar-2014'</span>, <span class="pl-s">'23-Mar-2014'</span>, <span class="pl-s1">freq</span><span class="pl-c1">=</span><span class="pl-s">'B'</span>)
<span class="pl-v">Out</span>[<span class="pl-c1">23</span>]:<span class="pl-s1"></span> 
<span class="pl-c1">&lt;</span><span class="pl-s1">class</span> <span class="pl-s">'pandas.tseries.index.DatetimeIndex'</span><span class="pl-c1">&gt;</span>
[<span class="pl-c1">2014</span><span class="pl-c1">-</span><span class="pl-c1">03</span><span class="pl-c1">-</span><span class="pl-c1">20</span>, <span class="pl-c1">2014</span><span class="pl-c1">-</span><span class="pl-c1">03</span><span class="pl-c1">-</span><span class="pl-c1">21</span>]
<span class="pl-v">Length</span>: <span class="pl-c1">2</span>, <span class="pl-v">Freq</span>: <span class="pl-v">B</span>, <span class="pl-v">Timezone</span>: <span class="pl-c1">None</span>

<span class="pl-v">In</span> [<span class="pl-c1">24</span>]: <span class="pl-c"># should return all valid business days &lt;= '23-Mar-2014'</span>
    ...: <span class="pl-s1">pd</span>.<span class="pl-en">date_range</span>(<span class="pl-s">'20-Mar-2014'</span>, <span class="pl-s">'23-Mar-2014'</span>, <span class="pl-s1">freq</span><span class="pl-c1">=</span><span class="pl-s">'B'</span>, <span class="pl-s1">closed</span><span class="pl-c1">=</span><span class="pl-s">'left'</span>)
<span class="pl-c1">&lt;</span><span class="pl-k">class</span> <span class="pl-s">'pandas.tseries.index.DatetimeIndex'</span><span class="pl-c1">&gt;</span>
[<span class="pl-c1">2014</span><span class="pl-c1">-</span><span class="pl-c1">03</span><span class="pl-c1">-</span><span class="pl-c1">20</span>]
<span class="pl-v">Length</span>: <span class="pl-c1">1</span>, <span class="pl-v">Freq</span>: <span class="pl-v">B</span>, <span class="pl-v">Timezone</span>: <span class="pl-c1">None</span></pre></div>