|
1 |
| -from collections import deque |
| 1 | +from collections import OrderedDict, deque |
2 | 2 | import datetime as dt
|
3 | 3 | from datetime import datetime
|
4 | 4 | from decimal import Decimal
|
|
18 | 18 | from pandas import (
|
19 | 19 | Categorical, DataFrame, DatetimeIndex, Index, MultiIndex, Series,
|
20 | 20 | Timestamp, concat, date_range, isna, read_csv)
|
| 21 | +import pandas.core.common as com |
21 | 22 | from pandas.tests.extension.decimal import to_decimal
|
22 | 23 | from pandas.util import testing as tm
|
23 | 24 | from pandas.util.testing import assert_frame_equal, makeCustomDataframe as mkdf
|
@@ -1162,7 +1163,7 @@ def test_concat_dict(self):
|
1162 | 1163 | 'baz': DataFrame(np.random.randn(4, 3)),
|
1163 | 1164 | 'qux': DataFrame(np.random.randn(4, 3))}
|
1164 | 1165 |
|
1165 |
| - sorted_keys = sorted(frames) |
| 1166 | + sorted_keys = com.dict_keys_to_ordered_list(frames) |
1166 | 1167 |
|
1167 | 1168 | result = concat(frames)
|
1168 | 1169 | expected = concat([frames[k] for k in sorted_keys], keys=sorted_keys)
|
@@ -2370,6 +2371,14 @@ def test_concat_different_extension_dtypes_upcasts(self):
|
2370 | 2371 | ], dtype=object)
|
2371 | 2372 | tm.assert_series_equal(result, expected)
|
2372 | 2373 |
|
| 2374 | + def test_concat_odered_dict(self): |
| 2375 | + # GH 21510 |
| 2376 | + expected = pd.concat([pd.Series(range(3)), pd.Series(range(4))], |
| 2377 | + keys=['First', 'Another']) |
| 2378 | + result = pd.concat(OrderedDict([('First', pd.Series(range(3))), |
| 2379 | + ('Another', pd.Series(range(4)))])) |
| 2380 | + tm.assert_series_equal(result, expected) |
| 2381 | + |
2373 | 2382 |
|
2374 | 2383 | @pytest.mark.parametrize('pdt', [pd.Series, pd.DataFrame])
|
2375 | 2384 | @pytest.mark.parametrize('dt', np.sctypes['float'])
|
|
0 commit comments