Skip to content

Commit a9a46d6

Browse files
committed
Merge branch 'fix-cartesian-product' of https://github.com/shoyer/pandas into shoyer-fix-cartesian-product
2 parents 5a3076a + 2e47bd6 commit a9a46d6

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

doc/source/release.rst

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ Bug Fixes
170170
depending on the order of dictionary keys and values (:issue:`5338`).
171171
- Perf issue in concatting with empty objects (:issue:`3259`)
172172
- Clarify sorting of ``sym_diff`` on ``Index``es with ``NaN``s (:isssue:`6444`)
173+
- Regression in ``MultiIndex.from_product`` with a ``DatetimeIndex`` as input (:issue:`6439`)
173174

174175
pandas 0.13.1
175176
-------------

pandas/tools/tests/test_util.py

+9
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+
from pandas import date_range, Index
910
import pandas.util.testing as tm
1011
from pandas.tools.util import cartesian_product
1112

@@ -23,6 +24,14 @@ 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+
# make sure that the ordering on datetimeindex is consistent
30+
x = date_range('2000-01-01', periods=2)
31+
result = [Index(y).day for y in cartesian_product([x, x])]
32+
expected = [np.array([1, 1, 2, 2]), np.array([1, 2, 1, 2])]
33+
assert_equal(result, expected)
34+
2635

2736
class TestLocaleUtils(tm.TestCase):
2837

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)