Skip to content

TST: Fixturize series/test_constructors.py #22965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions pandas/tests/series/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@
from pandas.util.testing import assert_series_equal
import pandas.util.testing as tm

from .common import TestData


class TestSeriesConstructors(TestData):
class TestSeriesConstructors():

def test_invalid_dtype(self):
# GH15520
Expand All @@ -50,23 +48,23 @@ def test_scalar_conversion(self):
assert int(Series([1.])) == 1
assert long(Series([1.])) == 1

def test_constructor(self):
assert self.ts.index.is_all_dates
def test_constructor(self, datetime_series, empty_series):
assert datetime_series.index.is_all_dates

# Pass in Series
derived = Series(self.ts)
derived = Series(datetime_series)
assert derived.index.is_all_dates

assert tm.equalContents(derived.index, self.ts.index)
assert tm.equalContents(derived.index, datetime_series.index)
# Ensure new index is not created
assert id(self.ts.index) == id(derived.index)
assert id(datetime_series.index) == id(derived.index)

# Mixed type Series
mixed = Series(['hello', np.NaN], index=[0, 1])
assert mixed.dtype == np.object_
assert mixed[1] is np.NaN

assert not self.empty.index.is_all_dates
assert not empty_series.index.is_all_dates
assert not Series({}).index.is_all_dates
pytest.raises(Exception, Series, np.random.randn(3, 3),
index=np.arange(3))
Expand Down Expand Up @@ -977,27 +975,27 @@ def test_fromDict(self):
series = Series(data, dtype=float)
assert series.dtype == np.float64

def test_fromValue(self):
def test_fromValue(self, datetime_series):

nans = Series(np.NaN, index=self.ts.index)
nans = Series(np.NaN, index=datetime_series.index)
assert nans.dtype == np.float_
assert len(nans) == len(self.ts)
assert len(nans) == len(datetime_series)

strings = Series('foo', index=self.ts.index)
strings = Series('foo', index=datetime_series.index)
assert strings.dtype == np.object_
assert len(strings) == len(self.ts)
assert len(strings) == len(datetime_series)

d = datetime.now()
dates = Series(d, index=self.ts.index)
dates = Series(d, index=datetime_series.index)
assert dates.dtype == 'M8[ns]'
assert len(dates) == len(self.ts)
assert len(dates) == len(datetime_series)

# GH12336
# Test construction of categorical series from value
categorical = Series(0, index=self.ts.index, dtype="category")
expected = Series(0, index=self.ts.index).astype("category")
categorical = Series(0, index=datetime_series.index, dtype="category")
expected = Series(0, index=datetime_series.index).astype("category")
assert categorical.dtype == 'category'
assert len(categorical) == len(self.ts)
assert len(categorical) == len(datetime_series)
tm.assert_series_equal(categorical, expected)

def test_constructor_dtype_timedelta64(self):
Expand Down