From 2e47bd6900d88434f2dffbf6b3365881f512db99 Mon Sep 17 00:00:00 2001 From: Stephan Hoyer Date: Sun, 23 Feb 2014 10:19:44 -0800 Subject: [PATCH] BUG FIX: cartesian_product now converts all arguments to ndarrays Fixes GitHub issue #6439. --- pandas/tools/tests/test_util.py | 8 ++++++++ pandas/tools/util.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pandas/tools/tests/test_util.py b/pandas/tools/tests/test_util.py index 36cfb4870a8fe..f022d97c02395 100644 --- a/pandas/tools/tests/test_util.py +++ b/pandas/tools/tests/test_util.py @@ -6,6 +6,7 @@ import numpy as np from numpy.testing import assert_equal +import pandas import pandas.util.testing as tm from pandas.tools.util import cartesian_product @@ -23,6 +24,13 @@ def test_simple(self): np.array([ 1, 22, 1, 22, 1, 22])] assert_equal(result, expected) + def test_datetimeindex(self): + # regression test for GitHub issue #6439 + x = pandas.date_range('2000-01-01', periods=2) + result = [pandas.Index(y).day for y in cartesian_product([x, x])] + expected = [np.array([1, 1, 2, 2]), np.array([1, 2, 1, 2])] + assert_equal(result, expected) + class TestLocaleUtils(tm.TestCase): diff --git a/pandas/tools/util.py b/pandas/tools/util.py index f6a64affc3e01..6dbefc4b70930 100644 --- a/pandas/tools/util.py +++ b/pandas/tools/util.py @@ -29,7 +29,7 @@ def cartesian_product(X): b = cumprodX[-1] / cumprodX - return [np.tile(np.repeat(x, b[i]), + return [np.tile(np.repeat(np.asarray(x), b[i]), np.product(a[i])) for i, x in enumerate(X)]