Skip to content

pd.merge_asof with empty datetime index column in right dataframe breaks in 0.24.0 #25059

Closed
@philngo

Description

@philngo

Code Sample, a copy-pastable example if possible

The following breaks in 0.24.0 but worked in 0.23.4:

import pandas as pd
print(pd.__version__)
empty_index = pd.to_datetime([], utc=True)
index_df1 = pd.DataFrame({'index_col': empty_index}, index=empty_index)
index_temp = pd.date_range(start='2017-01-01', periods=10, freq='H', tz="utc")
df1 = pd.DataFrame({'temp': 1.0}, index=index_temp)
pd.merge_asof(left=df1, right=index_df1, left_index=True, right_index=True)

Problem description

0.24.0:

>>> import pandas as pd
>>> print(pd.__version__)
0.24.0
>>> empty_index = pd.to_datetime([], utc=True)
>>> index_df1 = pd.DataFrame({'index_col': empty_index}, index=empty_index)
>>> index_temp = pd.date_range(start='2017-01-01', periods=10, freq='H', tz="utc")
>>> df1 = pd.DataFrame({'temp': 1.0}, index=index_temp)
>>> pd.merge_asof(left=df1, right=index_df1, left_index=True, right_index=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/philngo/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pandas/core/reshape/merge.py", line 462, in merge_asof
    return op.get_result()
  File "/Users/philngo/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pandas/core/reshape/merge.py", line 1280, in get_result
    concat_axis=0, copy=self.copy)
  File "/Users/philngo/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pandas/core/internals/managers.py", line 2061, in concatenate_block_managers
    concatenate_join_units(join_units, concat_axis, copy=copy),
  File "/Users/philngo/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pandas/core/internals/concat.py", line 240, in concatenate_join_units
    for ju in join_units]
  File "/Users/philngo/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pandas/core/internals/concat.py", line 240, in <listcomp>
    for ju in join_units]
  File "/Users/philngo/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pandas/core/internals/concat.py", line 223, in get_reindexed_values
    fill_value=fill_value)
  File "/Users/philngo/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pandas/core/algorithms.py", line 1579, in take_nd
    return arr.take(indexer, fill_value=fill_value, allow_fill=allow_fill)
  File "/Users/philngo/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pandas/core/arrays/datetimelike.py", line 589, in take
    fill_value = self._validate_fill_value(fill_value)
  File "/Users/philngo/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pandas/core/arrays/datetimes.py", line 656, in _validate_fill_value
    "Got '{got}'.".format(got=fill_value))
ValueError: 'fill_value' should be a Timestamp. Got '-9223372036854775808'.

The behavior in 0.24.0 might make sense - I don't know if there was some underlying decision about why the above shouldn't be allowed - but since it worked in 0.23.4 I figured I would check here to see if it was an unintended regression. That's my suspicion, but if it is intended, maybe it would be worth catching the error a bit earlier and giving a better error message?

Expected Output

0.23.4:

>>> import pandas as pd
>>> print(pd.__version__)
0.23.4
>>> import pandas as pd
>>> empty_index = pd.to_datetime([], utc=True)
>>> index_df1 = pd.DataFrame({'index_col': empty_index}, index=empty_index)
>>> index_temp = pd.date_range(start='2017-01-01', periods=10, freq='H', tz="utc")
>>> df1 = pd.DataFrame({'temp': 1.0}, index=index_temp)
>>> pd.merge_asof(left=df1, right=index_df1, left_index=True, right_index=True)
                           temp index_col
2017-01-01 00:00:00+00:00   1.0       NaT
2017-01-01 01:00:00+00:00   1.0       NaT
2017-01-01 02:00:00+00:00   1.0       NaT
2017-01-01 03:00:00+00:00   1.0       NaT
2017-01-01 04:00:00+00:00   1.0       NaT
2017-01-01 05:00:00+00:00   1.0       NaT
2017-01-01 06:00:00+00:00   1.0       NaT
2017-01-01 07:00:00+00:00   1.0       NaT
2017-01-01 08:00:00+00:00   1.0       NaT
2017-01-01 09:00:00+00:00   1.0       NaT

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions