Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: DatetimeIndex.union gives wrong result with "datetime64[us]" #59036

Closed
2 of 3 tasks
tehunter opened this issue Jun 17, 2024 · 0 comments · Fixed by #59037
Closed
2 of 3 tasks

BUG: DatetimeIndex.union gives wrong result with "datetime64[us]" #59036

tehunter opened this issue Jun 17, 2024 · 0 comments · Fixed by #59037
Labels
Bug datetime.date stdlib datetime.date support Index Related to the Index class or subclasses Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@tehunter
Copy link
Contributor

tehunter commented Jun 17, 2024

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

l1 = pd.DatetimeIndex(['2024-05-11', '2024-05-12'], dtype='datetime64[us]', name='Date', freq='D')
l2 = pd.DatetimeIndex(['2024-05-13'], dtype='datetime64[us]', name='Date', freq='D')

print(l1.union(l2))
# Returns DatetimeIndex(['2024-05-11', '2024-05-13', '2027-02-05'], dtype='datetime64[us]', name='Date', freq='D')

Issue Description

DatetimeIndex.union is returning an incorrect result. Since this method is used by MultiIndex.concat, it leads to unexpected errors when combining several MultiIndex DataFrames/Series that have a datetime64[us] level.

Expected Behavior

DatetimeIndex(['2024-05-11', '2024-05-12', '2024-05-13'], dtype='datetime64[us]', name='Date', freq=None)

Installed Versions

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.11.9.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22631
machine : AMD64
processor : Intel64 Family 6 Model 141 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252

pandas : 2.2.2
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.9.0
setuptools : 69.5.1
pip : 24.0
Cython : None
pytest : 7.4.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.2.0
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.4
IPython : 8.25.0
pandas_datareader : None
adbc-driver-sqlite : None
bs4 : None
bottleneck : 1.3.8
dataframe-api-compat : None
fastparquet : None
fsspec : 2024.6.0
gcsfs : None
matplotlib : None
numba : 0.59.1
numexpr : 2.10.0
odfpy : None
openpyxl : 3.1.3
pandas_gbq : None
pyarrow : 16.1.0
pyreadstat : 1.2.7
python-calamine : None
pyxlsb : 1.0.10
s3fs : None
scipy : None
sqlalchemy : 2.0.30
tables : None
tabulate : 0.9.0
xarray : None
xlrd : 2.0.1
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None

@tehunter tehunter added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 17, 2024
@rhshadrach rhshadrach added Index Related to the Index class or subclasses datetime.date stdlib datetime.date support labels Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug datetime.date stdlib datetime.date support Index Related to the Index class or subclasses Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants