TST: Fixturize series/test_constructors.py (#22965) · pandas-dev/pandas@4c78b97 (original) (raw)
`@@ -26,10 +26,8 @@
`
26
26
`from pandas.util.testing import assert_series_equal
`
27
27
`import pandas.util.testing as tm
`
28
28
``
29
``
`-
from .common import TestData
`
30
29
``
31
``
-
32
``
`-
class TestSeriesConstructors(TestData):
`
``
30
`+
class TestSeriesConstructors():
`
33
31
``
34
32
`def test_invalid_dtype(self):
`
35
33
`# GH15520
`
`@@ -50,23 +48,23 @@ def test_scalar_conversion(self):
`
50
48
`assert int(Series([1.])) == 1
`
51
49
`assert long(Series([1.])) == 1
`
52
50
``
53
``
`-
def test_constructor(self):
`
54
``
`-
assert self.ts.index.is_all_dates
`
``
51
`+
def test_constructor(self, datetime_series, empty_series):
`
``
52
`+
assert datetime_series.index.is_all_dates
`
55
53
``
56
54
`# Pass in Series
`
57
``
`-
derived = Series(self.ts)
`
``
55
`+
derived = Series(datetime_series)
`
58
56
`assert derived.index.is_all_dates
`
59
57
``
60
``
`-
assert tm.equalContents(derived.index, self.ts.index)
`
``
58
`+
assert tm.equalContents(derived.index, datetime_series.index)
`
61
59
`# Ensure new index is not created
`
62
``
`-
assert id(self.ts.index) == id(derived.index)
`
``
60
`+
assert id(datetime_series.index) == id(derived.index)
`
63
61
``
64
62
`# Mixed type Series
`
65
63
`mixed = Series(['hello', np.NaN], index=[0, 1])
`
66
64
`assert mixed.dtype == np.object_
`
67
65
`assert mixed[1] is np.NaN
`
68
66
``
69
``
`-
assert not self.empty.index.is_all_dates
`
``
67
`+
assert not empty_series.index.is_all_dates
`
70
68
`assert not Series({}).index.is_all_dates
`
71
69
`pytest.raises(Exception, Series, np.random.randn(3, 3),
`
72
70
`index=np.arange(3))
`
`@@ -977,27 +975,27 @@ def test_fromDict(self):
`
977
975
`series = Series(data, dtype=float)
`
978
976
`assert series.dtype == np.float64
`
979
977
``
980
``
`-
def test_fromValue(self):
`
``
978
`+
def test_fromValue(self, datetime_series):
`
981
979
``
982
``
`-
nans = Series(np.NaN, index=self.ts.index)
`
``
980
`+
nans = Series(np.NaN, index=datetime_series.index)
`
983
981
`assert nans.dtype == np.float_
`
984
``
`-
assert len(nans) == len(self.ts)
`
``
982
`+
assert len(nans) == len(datetime_series)
`
985
983
``
986
``
`-
strings = Series('foo', index=self.ts.index)
`
``
984
`+
strings = Series('foo', index=datetime_series.index)
`
987
985
`assert strings.dtype == np.object_
`
988
``
`-
assert len(strings) == len(self.ts)
`
``
986
`+
assert len(strings) == len(datetime_series)
`
989
987
``
990
988
`d = datetime.now()
`
991
``
`-
dates = Series(d, index=self.ts.index)
`
``
989
`+
dates = Series(d, index=datetime_series.index)
`
992
990
`assert dates.dtype == 'M8[ns]'
`
993
``
`-
assert len(dates) == len(self.ts)
`
``
991
`+
assert len(dates) == len(datetime_series)
`
994
992
``
995
993
`# GH12336
`
996
994
`# Test construction of categorical series from value
`
997
``
`-
categorical = Series(0, index=self.ts.index, dtype="category")
`
998
``
`-
expected = Series(0, index=self.ts.index).astype("category")
`
``
995
`+
categorical = Series(0, index=datetime_series.index, dtype="category")
`
``
996
`+
expected = Series(0, index=datetime_series.index).astype("category")
`
999
997
`assert categorical.dtype == 'category'
`
1000
``
`-
assert len(categorical) == len(self.ts)
`
``
998
`+
assert len(categorical) == len(datetime_series)
`
1001
999
`tm.assert_series_equal(categorical, expected)
`
1002
1000
``
1003
1001
`def test_constructor_dtype_timedelta64(self):
`