| @@ -1,7 +1,7 @@ |
|
|
| 1 |
1 |
# pylint: disable=E1103 |
| 2 |
2 |
|
| 3 |
3 |
import pytest |
| 4 |
|
-from datetime import datetime |
|
4 |
+from datetime import datetime, date |
| 5 |
5 |
from numpy.random import randn |
| 6 |
6 |
from numpy import nan |
| 7 |
7 |
import numpy as np |
| @@ -1515,6 +1515,27 @@ def test_self_join_multiple_categories(self): |
|
|
| 1515 |
1515 |
|
| 1516 |
1516 |
assert_frame_equal(result, df) |
| 1517 |
1517 |
|
|
1518 |
+def test_dtype_on_categorical_dates(self): |
|
1519 |
+# GH 16900 |
|
1520 |
+# dates should not be coerced to ints |
|
1521 |
+ |
|
1522 |
+df = pd.DataFrame( |
|
1523 |
+ [[date(2001, 1, 1), 1.1], |
|
1524 |
+ [date(2001, 1, 2), 1.3]], |
|
1525 |
+columns=['date', 'num2'] |
|
1526 |
+ ) |
|
1527 |
+df['date'] = df['date'].astype('category') |
|
1528 |
+ |
|
1529 |
+df2 = pd.DataFrame( |
|
1530 |
+ [[date(2001, 1, 1), 1.3], |
|
1531 |
+ [date(2001, 1, 3), 1.4]], |
|
1532 |
+columns=['date', 'num4'] |
|
1533 |
+ ) |
|
1534 |
+df2['date'] = df2['date'].astype('category') |
|
1535 |
+ |
|
1536 |
+result = pd.merge(df, df2, how='outer', on=['date']) |
|
1537 |
+assert result['date'].dtype == 'category' |
|
1538 |
+ |
| 1518 |
1539 |
|
| 1519 |
1540 |
@pytest.fixture |
| 1520 |
1541 |
def left_df(): |