|
4 | 4 | import pytest |
5 | 5 |
|
6 | 6 | from datetime import datetime, timedelta |
| 7 | +from collections import OrderedDict |
7 | 8 |
|
8 | 9 | from numpy import nan |
9 | 10 | import numpy as np |
@@ -79,17 +80,34 @@ def test_constructor(self): |
79 | 80 | m = MultiIndex.from_arrays([[1, 2], [3, 4]]) |
80 | 81 | pytest.raises(NotImplementedError, Series, m) |
81 | 82 |
|
82 | | - def test_constructor_empty(self): |
| 83 | + @pytest.mark.parametrize('input_class', [list, dict, OrderedDict]) |
| 84 | + def test_constructor_empty(self, input_class): |
83 | 85 | empty = Series() |
84 | | - empty2 = Series([]) |
85 | | - |
86 | | - # the are Index() and RangeIndex() which don't compare type equal |
| 86 | + empty2 = Series(input_class()) |
| 87 | + # these are Index() and RangeIndex() which don't compare type equal |
87 | 88 | # but are just .equals |
88 | 89 | assert_series_equal(empty, empty2, check_index_type=False) |
89 | 90 |
|
90 | | - empty = Series(index=lrange(10)) |
91 | | - empty2 = Series(np.nan, index=lrange(10)) |
92 | | - assert_series_equal(empty, empty2) |
| 91 | + # With explicit dtype: |
| 92 | + empty = Series(dtype='float64') |
| 93 | + empty2 = Series(input_class(), dtype='float64') |
| 94 | + assert_series_equal(empty, empty2, check_index_type=False) |
| 95 | + |
| 96 | + # GH 18515 : with dtype=category: |
| 97 | + empty = Series(dtype='category') |
| 98 | + empty2 = Series(input_class(), dtype='category') |
| 99 | + assert_series_equal(empty, empty2, check_index_type=False) |
| 100 | + |
| 101 | + if input_class is not list: |
| 102 | + # With index: |
| 103 | + empty = Series(index=lrange(10)) |
| 104 | + empty2 = Series(input_class(), index=lrange(10)) |
| 105 | + assert_series_equal(empty, empty2) |
| 106 | + |
| 107 | + # With index and dtype float64: |
| 108 | + empty = Series(np.nan, index=lrange(10)) |
| 109 | + empty2 = Series(input_class(), index=lrange(10), dtype='float64') |
| 110 | + assert_series_equal(empty, empty2) |
93 | 111 |
|
94 | 112 | def test_constructor_series(self): |
95 | 113 | index1 = ['d', 'b', 'a', 'c'] |
|
0 commit comments