Skip to content

BUG: pandas.tools.util.cartesian_product doesn't work on DatetimeIndex objects #6439

Closed
@shoyer

Description

@shoyer

This breaks the new pandas.MultiIndex.from_product function when one of the product arrays is DatetimeIndex. Observe:

>>> import pandas as pd
>>> from pandas.tools.util import cartesian_product
>>> x, y = cartesian_product([[1, 2], pd.date_range('2000-01-01', periods=2)])
>>> print x
[1 1 2 2]
>>> print y.values
['1999-12-31T16:00:00.000000000-0800' '1999-12-31T16:00:00.000000000-0800'
 '2000-01-01T16:00:00.000000000-0800' '2000-01-01T16:00:00.000000000-0800']

If cartesian_product was working properly, the dates should actually be [1999, 2000, 1999, 2000].

The simple fix would be to convert everything into a numpy array before calculating the cartesian product.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions