Skip to content

REF: Parametrize test #28515

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
Sep 19, 2019
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
43 changes: 22 additions & 21 deletions pandas/tests/internals/test_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,32 +528,33 @@ def test_as_array_datetime_tz(self):
assert mgr.get("g").dtype == "datetime64[ns, CET]"
assert mgr.as_array().dtype == "object"

def test_astype(self):
@pytest.mark.parametrize("t", ["float16", "float32", "float64", "int32", "int64"])
def test_astype(self, t):
# coerce all
mgr = create_mgr("c: f4; d: f2; e: f8")
for t in ["float16", "float32", "float64", "int32", "int64"]:
t = np.dtype(t)
tmgr = mgr.astype(t)
assert tmgr.get("c").dtype.type == t
assert tmgr.get("d").dtype.type == t
assert tmgr.get("e").dtype.type == t

t = np.dtype(t)
tmgr = mgr.astype(t)
assert tmgr.get("c").dtype.type == t
assert tmgr.get("d").dtype.type == t
assert tmgr.get("e").dtype.type == t

# mixed
mgr = create_mgr("a,b: object; c: bool; d: datetime; e: f4; f: f2; g: f8")
for t in ["float16", "float32", "float64", "int32", "int64"]:
t = np.dtype(t)
tmgr = mgr.astype(t, errors="ignore")
assert tmgr.get("c").dtype.type == t
assert tmgr.get("e").dtype.type == t
assert tmgr.get("f").dtype.type == t
assert tmgr.get("g").dtype.type == t

assert tmgr.get("a").dtype.type == np.object_
assert tmgr.get("b").dtype.type == np.object_
if t != np.int64:
assert tmgr.get("d").dtype.type == np.datetime64
else:
assert tmgr.get("d").dtype.type == t

t = np.dtype(t)
tmgr = mgr.astype(t, errors="ignore")
assert tmgr.get("c").dtype.type == t
assert tmgr.get("e").dtype.type == t
assert tmgr.get("f").dtype.type == t
assert tmgr.get("g").dtype.type == t

assert tmgr.get("a").dtype.type == np.object_
assert tmgr.get("b").dtype.type == np.object_
if t != np.int64:
assert tmgr.get("d").dtype.type == np.datetime64
else:
assert tmgr.get("d").dtype.type == t

def test_convert(self):
def _compare(old_mgr, new_mgr):
Expand Down