DatetimeIndex union fails in 0.19rc1 when constructed from differences in DatetimeIndexes · Issue #14323 · pandas-dev/pandas (original) (raw)
When constructing a union of 2 DatetimeIndex objects that themselves were constructed from differences from a third DatetimeIndex, the union operator is ignored. This appears to be new behavior in 0.19rc1; the code functioned correctly under 0.18.1.
x = pd.DatetimeIndex(['20160923', '20160924'])
y = pd.DatetimeIndex(['20160923', '20160925'])
z = pd.date_range("20160921", "20160930")
a = z.difference(x)
b = z.difference(y)
In [59]: a.union(b)
Out[59]:
DatetimeIndex(['2016-09-21', '2016-09-22', '2016-09-25', '2016-09-26',
'2016-09-27', '2016-09-28', '2016-09-29', '2016-09-30'],
dtype='datetime64[ns]', freq='D')
In [60]: a.union(b).difference(a)
Out[60]: Index([], dtype='object')
Expected Output
a.union(b) should contain 2016-09-24
('2016-09-24' exists in b, since it was in z and not in y,
and thus '2016-09-24' should be in a.union(b)).
In [59]: a.union(b)
Out[59]:
DatetimeIndex(['2016-09-21', '2016-09-22', '2016-09-24', '2016-09-25',
'2016-09-26', '2016-09-27', '2016-09-28', '2016-09-29',
'2016-09-30'],
dtype='datetime64[ns]', freq=None, tz=None)
In [60]: a.union(b).difference(a)
Out[60]: DatetimeIndex(['2016-09-24'], dtype='datetime64[ns]', freq=None, tz=None)
Output of pd.show_versions()
## INSTALLED VERSIONS
commit: None
python: 2.7.11.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 62 Stepping 4, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.19.0rc1+0.g497a3bc.dirty
nose: 1.3.7
pip: 8.1.2
setuptools: 27.2.0
Cython: 0.24.1
numpy: 1.11.1
scipy: 0.18.1
statsmodels: 0.6.1
xarray: 0.8.2
IPython: 5.1.0
sphinx: 1.4.6
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.6.1
blosc: None
bottleneck: 1.1.0
tables: 3.2.2
numexpr: 2.6.1
matplotlib: 1.5.3
openpyxl: 2.3.2
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.3
lxml: 3.6.4
bs4: 4.5.1
html5lib: None
httplib2: 0.9.2
apiclient: 1.4.2
sqlalchemy: 1.0.13
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.42.0
pandas_datareader: 0.2.1