Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_assign_expr_binary():
DT = dt.Frame(A=range(5))
DT["B"] = f.A / 2
assert_equals(DT, dt.Frame(A=range(5), B=[0, 0.5, 1.0, 1.5, 2.0]))
def test_assign_2d_nparray(numpy):
arr = numpy.array([[1, 2], [3, 4], [5, 6]], dtype=numpy.int32)
DT = dt.Frame(A=range(3))
DT[:, ["B", "C"]] = arr
assert_equals(DT, dt.Frame(A=[0, 1, 2], B=[1, 3, 5], C=[2, 4, 6]))
def test_first_dt_groupby():
df_in = dt.Frame([9, 8, 2, 3, None, None, 3, 0, 5, 5, 8, None, 1])
df_reduce = df_in[:, first(f.C0), "C0"]
assert_equals(df_reduce, dt.Frame([[None, 0, 1, 2, 3, 5, 8, 9],
[None, 0, 1, 2, 3, 5, 8, 9]],
names=["C0", "C1"]))
def test_assign_wrong_nrows():
DT = dt.Frame(A=[3, 4, 5], B=['a', 't', 'k'])
with pytest.raises(ValueError):
DT[:, "D"] = dt.Frame(range(5))
assert DT.shape == (3, 2)
with pytest.raises(ValueError):
DT[:, "D"] = dt.Frame() # 0 rows
def test_first_dt_integer_large(numpy):
n = 12345678
a_in = numpy.random.randint(2**20, size=n, dtype=numpy.int32)
df_in = dt.Frame(a_in)
df_reduce = df_in[:, first(f.C0)]
assert_equals(df_reduce, dt.Frame(C0=[a_in[0]]))
def test_update_multiple_dependents():
DT = dt.Frame(A=range(5))
DT[:, update(B=f.A + 1, A=f.A + 2, D=f.A + 3)]
assert_equals(DT, dt.Frame(A=range(2, 7), B=range(1, 6), D=range(3, 8)))
def test_cov_small_frame():
D1 = dt.Frame(A=[1], B=[2])[:, cov(f.A, f.B)]
D2 = dt.Frame(A=[], B=[])[:, cov(f.A, f.B)]
assert_equals(D1, dt.Frame([None], stype=dt.float64))
assert_equals(D2, dt.Frame([None], stype=dt.float64))
def test_assign_frame_to_filtered_rows():
DT = dt.Frame(A=range(5))
DT[f.A < 3, "A"] = dt.Frame([4, 5, 7])
assert_equals(DT, dt.Frame(A=[4, 5, 7, 3, 4]))
def test_assign_downcasts(st1, st2):
DT = dt.Frame(A=range(5), stype=st1)
assert DT.stype == st1
DT[:2, 0] = dt.Frame([-1, None], stype=st2)
assert_equals(DT, dt.Frame(A=[-1, None, 2, 3, 4], stype=st1))
def test_assign_single_row_frame2():
DT = dt.Frame(A=[0, 1, 2], B=[3, 4, 5])
DT[:, ("C", "D")] = dt.Frame([[7], [8]])
assert_equals(DT, dt.Frame(A=[0, 1, 2], B=[3, 4, 5], C=[7]*3, D=[8]*3))