Skip to content

TST: Parameterize more tests #22061

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 1 commit into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
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
64 changes: 34 additions & 30 deletions pandas/tests/arrays/categorical/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,36 +256,40 @@ def test_constructor_with_generator(self):
cat = Categorical([0, 1, 2], categories=xrange(3))
tm.assert_categorical_equal(cat, exp)

def test_constructor_with_datetimelike(self):

# 12077
# constructor wwth a datetimelike and NaT

for dtl in [date_range('1995-01-01 00:00:00', periods=5, freq='s'),
date_range('1995-01-01 00:00:00', periods=5,
freq='s', tz='US/Eastern'),
timedelta_range('1 day', periods=5, freq='s')]:

s = Series(dtl)
c = Categorical(s)
expected = type(dtl)(s)
expected.freq = None
tm.assert_index_equal(c.categories, expected)
tm.assert_numpy_array_equal(c.codes, np.arange(5, dtype='int8'))

# with NaT
s2 = s.copy()
s2.iloc[-1] = NaT
c = Categorical(s2)
expected = type(dtl)(s2.dropna())
expected.freq = None
tm.assert_index_equal(c.categories, expected)

exp = np.array([0, 1, 2, 3, -1], dtype=np.int8)
tm.assert_numpy_array_equal(c.codes, exp)

result = repr(c)
assert 'NaT' in result
@pytest.mark.parametrize("dtl", [
date_range("1995-01-01 00:00:00", periods=5, freq="s"),
date_range("1995-01-01 00:00:00", periods=5,
freq="s", tz="US/Eastern"),
timedelta_range("1 day", periods=5, freq="s")
])
def test_constructor_with_datetimelike(self, dtl):
# see gh-12077
# constructor with a datetimelike and NaT

s = Series(dtl)
c = Categorical(s)

expected = type(dtl)(s)
expected.freq = None

tm.assert_index_equal(c.categories, expected)
tm.assert_numpy_array_equal(c.codes, np.arange(5, dtype="int8"))

# with NaT
s2 = s.copy()
s2.iloc[-1] = NaT
c = Categorical(s2)

expected = type(dtl)(s2.dropna())
expected.freq = None

tm.assert_index_equal(c.categories, expected)

exp = np.array([0, 1, 2, 3, -1], dtype=np.int8)
tm.assert_numpy_array_equal(c.codes, exp)

result = repr(c)
assert "NaT" in result

def test_constructor_from_index_series_datetimetz(self):
idx = date_range('2015-01-01 10:00', freq='D', periods=3,
Expand Down
31 changes: 12 additions & 19 deletions pandas/tests/dtypes/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,18 @@ def test_dtype_equal(name1, dtype1, name2, dtype2):
assert not com.is_dtype_equal(dtype1, dtype2)


def test_dtype_equal_strict():

# we are strict on kind equality
for dtype in [np.int8, np.int16, np.int32]:
assert not com.is_dtype_equal(np.int64, dtype)

for dtype in [np.float32]:
assert not com.is_dtype_equal(np.float64, dtype)

# strict w.r.t. PeriodDtype
assert not com.is_dtype_equal(PeriodDtype('D'), PeriodDtype('2D'))

# strict w.r.t. datetime64
assert not com.is_dtype_equal(
com.pandas_dtype('datetime64[ns, US/Eastern]'),
com.pandas_dtype('datetime64[ns, CET]'))

# see gh-15941: no exception should be raised
assert not com.is_dtype_equal(None, None)
@pytest.mark.parametrize("dtype1,dtype2", [
(np.int8, np.int64),
(np.int16, np.int64),
(np.int32, np.int64),
(np.float32, np.float64),
(PeriodDtype("D"), PeriodDtype("2D")), # PeriodType
(com.pandas_dtype("datetime64[ns, US/Eastern]"),
com.pandas_dtype("datetime64[ns, CET]")), # Datetime
(None, None) # gh-15941: no exception should be raised.
])
def test_dtype_equal_strict(dtype1, dtype2):
assert not com.is_dtype_equal(dtype1, dtype2)


def get_is_dtype_funcs():
Expand Down
Loading