Skip to content

Commit 2e47bd6

Browse files
committed
BUG FIX: cartesian_product now converts all arguments to ndarrays
Fixes GitHub issue pandas-dev#6439.
1 parent 7e2f7bc commit 2e47bd6

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pandas/tools/tests/test_util.py

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import numpy as np
77
from numpy.testing import assert_equal
88

9+
import pandas
910
import pandas.util.testing as tm
1011
from pandas.tools.util import cartesian_product
1112

@@ -23,6 +24,13 @@ def test_simple(self):
2324
np.array([ 1, 22, 1, 22, 1, 22])]
2425
assert_equal(result, expected)
2526

27+
def test_datetimeindex(self):
28+
# regression test for GitHub issue #6439
29+
x = pandas.date_range('2000-01-01', periods=2)
30+
result = [pandas.Index(y).day for y in cartesian_product([x, x])]
31+
expected = [np.array([1, 1, 2, 2]), np.array([1, 2, 1, 2])]
32+
assert_equal(result, expected)
33+
2634

2735
class TestLocaleUtils(tm.TestCase):
2836

pandas/tools/util.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def cartesian_product(X):
2929

3030
b = cumprodX[-1] / cumprodX
3131

32-
return [np.tile(np.repeat(x, b[i]),
32+
return [np.tile(np.repeat(np.asarray(x), b[i]),
3333
np.product(a[i]))
3434
for i, x in enumerate(X)]
3535

0 commit comments

Comments
 (0)