Skip to content

Commit

Permalink
Run formatter and fix failing tests after branch update
Browse files Browse the repository at this point in the history
  • Loading branch information
simicd committed Jan 19, 2023
1 parent 6804cf4 commit 8d0a2e4
Showing 1 changed file with 61 additions and 33 deletions.
94 changes: 61 additions & 33 deletions datafusion/tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ def df():
pa.array(["Hello", "World", "!"]),
pa.array([4, 5, 6]),
pa.array(["hello ", " world ", " !"]),
pa.array([datetime(2022, 12, 31), datetime(2027, 6, 26), datetime(2020, 7, 2)])
pa.array(
[
datetime(2022, 12, 31),
datetime(2027, 6, 26),
datetime(2020, 7, 2),
]
),
],
names=["a", "b", "c", "d"],
)
Expand Down Expand Up @@ -130,11 +136,17 @@ def test_math_functions():
)
np.testing.assert_array_less(result.column(10), np.ones_like(values))
np.testing.assert_array_almost_equal(result.column(11), np.arctan(values))
np.testing.assert_array_almost_equal(result.column(12), np.arctan2(values, 1.1))
np.testing.assert_array_almost_equal(
result.column(12), np.arctan2(values, 1.1)
)
np.testing.assert_array_almost_equal(result.column(13), np.ceil(values))
np.testing.assert_array_almost_equal(result.column(14), np.floor(values))
np.testing.assert_array_almost_equal(result.column(15), np.power(values, 3))
np.testing.assert_array_almost_equal(result.column(16), np.power(values, 4))
np.testing.assert_array_almost_equal(
result.column(15), np.power(values, 3)
)
np.testing.assert_array_almost_equal(
result.column(16), np.power(values, 4)
)
np.testing.assert_array_almost_equal(result.column(17), np.round(values))
np.testing.assert_array_almost_equal(result.column(18), np.sqrt(values))
np.testing.assert_array_almost_equal(result.column(19), np.sign(values))
Expand Down Expand Up @@ -175,7 +187,9 @@ def test_string_functions(df):
result = df.collect()
assert len(result) == 1
result = result[0]
assert result.column(0) == pa.array([72, 87, 33], type=pa.int32()) # H = 72; W = 87; ! = 33
assert result.column(0) == pa.array(
[72, 87, 33], type=pa.int32()
) # H = 72; W = 87; ! = 33
assert result.column(1) == pa.array([40, 40, 8], type=pa.int32())
assert result.column(2) == pa.array(["World", "World", "World"])
assert result.column(3) == pa.array([5, 5, 1], type=pa.int32())
Expand Down Expand Up @@ -214,7 +228,15 @@ def test_string_functions(df):
def test_hash_functions(df):
exprs = [
f.digest(column("a"), literal(m))
for m in ("md5", "sha224", "sha256", "sha384", "sha512", "blake2s", "blake3")
for m in (
"md5",
"sha224",
"sha256",
"sha384",
"sha512",
"blake2s",
"blake3",
)
]
df = df.select(
*exprs,
Expand All @@ -236,18 +258,9 @@ def test_hash_functions(df):
)
assert result.column(1) == pa.array(
[
b(
"4149DA18AA8BFC2B1E382C6C2655"
"6D01A92C261B6436DAD5E3BE3FCC"
),
b(
"12972632B6D3B6AA52BD6434552F"
"08C1303D56B817119406466E9236"
),
b(
"6641A7E8278BCD49E476E7ACAE15"
"8F4105B2952D22AEB2E0B9A231A0"
),
b("4149DA18AA8BFC2B1E382C6C26556D01A92C261B6436DAD5E3BE3FCC"),
b("12972632B6D3B6AA52BD6434552F08C1303D56B817119406466E9236"),
b("6641A7E8278BCD49E476E7ACAE158F4105B2952D22AEB2E0B9A231A0"),
]
)
assert result.column(2) == pa.array(
Expand Down Expand Up @@ -339,34 +352,49 @@ def test_hash_functions(df):
),
]
)
assert result.column(7) == result.column(1) # SHA-224
assert result.column(8) == result.column(2) # SHA-256
assert result.column(9) == result.column(3) # SHA-384
assert result.column(10) == result.column(4) # SHA-512
assert result.column(7) == result.column(1) # SHA-224
assert result.column(8) == result.column(2) # SHA-256
assert result.column(9) == result.column(3) # SHA-384
assert result.column(10) == result.column(4) # SHA-512


def test_temporal_functions(df):
df = df.select(
f.date_part(literal("month"), column("d")),
f.datepart(literal("year"), column("d")),
f.date_trunc(literal("month"), column("d")),
f.date_trunc(literal("day"), column("d")),
f.datetrunc(literal("day"), column("d")),
f.from_unixtime(literal(1673383974)),
f.to_timestamp(literal("2023-09-07 05:06:14.523952")),
f.to_timestamp_seconds(literal("2023-09-07 05:06:14.523952")),
f.to_timestamp_millis(literal("2023-09-07 05:06:14.523952")),
f.to_timestamp_micros(literal("2023-09-07 05:06:14.523952")),
# f.now(),
)
result = df.collect()
assert len(result) == 1
result = result[0]
assert result.column(0) == pa.array([12, 6, 7], type=pa.int32())
assert result.column(1) == pa.array([2022, 2027, 2020], type=pa.int32())
assert result.column(2) == pa.array([datetime(2022, 12, 1), datetime(2027, 6, 1), datetime(2020, 7, 1)], type=pa.timestamp("ns"))
assert result.column(3) == pa.array([datetime(2022, 12, 31), datetime(2027, 6, 26), datetime(2020, 7, 2)], type=pa.timestamp("ns"))
assert result.column(4) == pa.array([datetime(2023, 1, 10, 20, 52, 54)] * 3, type=pa.timestamp("s"))
assert result.column(5) == pa.array([datetime(2023, 9, 7, 5, 6, 14, 523952)] * 3, type=pa.timestamp("ns"))
assert result.column(6) == pa.array([datetime(2023, 9, 7, 5, 6, 14)] * 3, type=pa.timestamp("s"))
assert result.column(7) == pa.array([datetime(2023, 9, 7, 5, 6, 14, 523000)] * 3, type=pa.timestamp("ms"))
assert result.column(8) == pa.array([datetime(2023, 9, 7, 5, 6, 14, 523952)] * 3, type=pa.timestamp("us"))
assert result.column(0) == pa.array([12, 6, 7], type=pa.float64())
assert result.column(1) == pa.array([2022, 2027, 2020], type=pa.float64())
assert result.column(2) == pa.array(
[datetime(2022, 12, 1), datetime(2027, 6, 1), datetime(2020, 7, 1)],
type=pa.timestamp("ns"),
)
assert result.column(3) == pa.array(
[datetime(2022, 12, 31), datetime(2027, 6, 26), datetime(2020, 7, 2)],
type=pa.timestamp("ns"),
)
assert result.column(4) == pa.array(
[datetime(2023, 1, 10, 20, 52, 54)] * 3, type=pa.timestamp("s")
)
assert result.column(5) == pa.array(
[datetime(2023, 9, 7, 5, 6, 14, 523952)] * 3, type=pa.timestamp("ns")
)
assert result.column(6) == pa.array(
[datetime(2023, 9, 7, 5, 6, 14)] * 3, type=pa.timestamp("s")
)
assert result.column(7) == pa.array(
[datetime(2023, 9, 7, 5, 6, 14, 523000)] * 3, type=pa.timestamp("ms")
)
assert result.column(8) == pa.array(
[datetime(2023, 9, 7, 5, 6, 14, 523952)] * 3, type=pa.timestamp("us")
)

0 comments on commit 8d0a2e4

Please sign in to comment.