Skip to content

Commit 1582c42

Browse files
committed
TST: test and whatsnew for pandas-dev#18515
1 parent dc4c76e commit 1582c42

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

doc/source/whatsnew/v0.22.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Other API Changes
6868

6969
- :func:`Series.astype` and :func:`Index.astype` with an incompatible dtype will now raise a ``TypeError`` rather than a ``ValueError`` (:issue:`18231`)
7070
- ``Series`` construction with an ``object`` dtyped tz-aware datetime and ``dtype=object`` specified, will now return an ``object`` dtyped ``Series``, previously this would infer the datetime dtype (:issue:`18231`)
71+
- A :class:`Series` of ``dtype=category`` constructed from an empty ``dict`` will now have categories of ``dtype=object`` rather than ``dtype=float64``, consistently with the case in which an empty list is passed (:issue:`18515`)
7172
- ``NaT`` division with :class:`datetime.timedelta` will now return ``NaN`` instead of raising (:issue:`17876`)
7273
- All-NaN levels in a ``MultiIndex`` are now assigned ``float`` rather than ``object`` dtype, promoting consistency with ``Index`` (:issue:`17929`).
7374
- :class:`Timestamp` will no longer silently ignore unused or invalid ``tz`` or ``tzinfo`` keyword arguments (:issue:`17690`)

pandas/tests/series/test_constructors.py

+32-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55

66
from datetime import datetime, timedelta
7+
from collections import OrderedDict
78

89
from numpy import nan
910
import numpy as np
@@ -79,17 +80,42 @@ def test_constructor(self):
7980
m = MultiIndex.from_arrays([[1, 2], [3, 4]])
8081
pytest.raises(NotImplementedError, Series, m)
8182

82-
def test_constructor_empty(self):
83+
@pytest.mark.parametrize('input_class', [list, dict, OrderedDict])
84+
def test_constructor_empty(self, input_class):
8385
empty = Series()
84-
empty2 = Series([])
86+
empty2 = Series(input_class())
8587

86-
# the are Index() and RangeIndex() which don't compare type equal
88+
# these are Index() and RangeIndex() which don't compare type equal
8789
# but are just .equals
8890
assert_series_equal(empty, empty2, check_index_type=False)
8991

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)
93119

94120
def test_constructor_series(self):
95121
index1 = ['d', 'b', 'a', 'c']

0 commit comments

Comments
 (0)