|
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,42 @@ 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([]) |
| 86 | + empty2 = Series(input_class()) |
85 | 87 |
|
86 |
| - # the are Index() and RangeIndex() which don't compare type equal |
| 88 | + # these are Index() and RangeIndex() which don't compare type equal |
87 | 89 | # but are just .equals
|
88 | 90 | assert_series_equal(empty, empty2, check_index_type=False)
|
89 | 91 |
|
90 |
| - empty = Series(index=lrange(10)) |
91 |
| - empty2 = Series(np.nan, index=lrange(10)) |
92 |
| - assert_series_equal(empty, empty2) |
| 92 | + # With explicit dtype: |
| 93 | + empty = Series(dtype='float64') |
| 94 | + empty2 = Series(input_class(), dtype='float64') |
| 95 | + assert_series_equal(empty, empty2, check_index_type=False) |
| 96 | + |
| 97 | + # GH 18515 : with dtype=category: |
| 98 | + empty = Series(dtype='category') |
| 99 | + empty2 = Series(input_class(), dtype='category') |
| 100 | + assert_series_equal(empty, empty2, check_index_type=False) |
| 101 | + |
| 102 | + if input_class is not list: |
| 103 | + # With index: |
| 104 | + empty = Series(index=lrange(10)) |
| 105 | + empty2 = Series(input_class(), index=lrange(10)) |
| 106 | + assert_series_equal(empty, empty2) |
| 107 | + |
| 108 | + # With index and dtype float64: |
| 109 | + empty = Series(np.nan, index=lrange(10)) |
| 110 | + empty2 = Series(input_class(), index=lrange(10), dtype='float64') |
| 111 | + assert_series_equal(empty, empty2) |
| 112 | + |
| 113 | + @pytest.mark.parametrize('input_arg', [np.nan, float('nan')]) |
| 114 | + def test_constructor_nan(self, input_arg): |
| 115 | + empty = Series(dtype='float64', index=lrange(10)) |
| 116 | + empty2 = Series(input_arg, index=lrange(10)) |
| 117 | + |
| 118 | + assert_series_equal(empty, empty2, check_index_type=False) |
93 | 119 |
|
94 | 120 | def test_constructor_series(self):
|
95 | 121 | index1 = ['d', 'b', 'a', 'c']
|
|
0 commit comments