Skip to content

BUG: DatetimeIndex.get_indexer wrong result on mixed-type argument #33741

@batterseapower

Description

@batterseapower
  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of pandas.
  • (optional) I have confirmed this bug exists on the master branch of pandas.

Code Sample, a copy-pastable example

import datetime
import pandas as pd

dates = pd.bdate_range('2020-04-20', '2020-04-25')
print(dates.get_indexer([datetime.date(2020, 4, 20), datetime.date(2020, 4, 21)]))
# [0, 1]
print(dates.get_indexer([pd.Timestamp('2020-04-20'), datetime.date(2020, 4, 21)]))
# [0, -1]

Problem description

As a general rule I would expect that index.get_indexer(as + bs) == np.concat([index.get_indexer(as), index.get_indexer(bs)]) for any lists as and bs, i.e. index.get_indexer operates elementwise. However in this case the type of a previous argument is surprisingly affecting the index that is assigned to a later one.

Expected Output

[0, 1] in both cases

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit : None python : 3.8.2.final.0 python-bits : 64 OS : Windows OS-release : 10 machine : AMD64 processor : Intel64 Family 6 Model 63 Stepping 2, GenuineIntel byteorder : little LC_ALL : None LANG : None LOCALE : English_United Kingdom.936

pandas : 1.0.3
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 46.1.3.post20200330
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexRelated to the Index class or subclassesIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions