Description
Code Sample, a copy-pastable example if possible
In [2]: pd.interval_range(start=0.5, periods=4)
Out[2]:
IntervalIndex([(0.5, 1.375], (1.375, 2.25], (2.25, 3.125], (3.125, 4.0]]
closed='right',
dtype='interval[float64]')
In [3]: pd.interval_range(end=4.5, periods=4)
Out[3]:
IntervalIndex([(0.5, 1.375], (1.375, 2.25], (2.25, 3.125], (3.125, 4.0]]
closed='right',
dtype='interval[float64]')
Problem description
In [2]
the default frequency should be 1 since freq
is not specified but instead is 0.875.
In [3]
the end=4.5
is not being set correctly, as well as having the same issue with freq
as [2]
.
This appears to be caused by overeager truncation logic for when start
/end
are both specified and inconsistent with freq
:
pandas/pandas/core/indexes/interval.py
Lines 1583 to 1585 in 172ab7a
Expected Output
I'd expect both outputs to be:
IntervalIndex([(0.5, 1.5], (1.5, 2.5], (2.5, 3.5], (3.5, 4.5]]
closed='right',
dtype='interval[float64]')
Output of pd.show_versions()
INSTALLED VERSIONS
commit: e6864b5
python: 3.6.1.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.24.0.dev0+12.ge6864b5
pytest: 3.1.2
pip: 9.0.1
setuptools: 39.0.1
Cython: 0.28.2
numpy: 1.13.3
scipy: 1.0.0
pyarrow: 0.6.0
xarray: 0.9.6
IPython: 6.1.0
sphinx: 1.5.6
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.4
feather: 0.4.0
matplotlib: 2.0.2
openpyxl: 2.4.8
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 0.9.8
lxml: 3.8.0
bs4: None
html5lib: 0.999
sqlalchemy: 1.1.13
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
fastparquet: 0.1.5
pandas_gbq: None
pandas_datareader: None