Skip to content
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

Closes #2768: Verify that all test files pass flake8 #2769

Merged
merged 6 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 6 additions & 3 deletions PROTO_tests/tests/bitops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def test_bigint_bitops(self):
# every elem has one more set bit, so popcount increases by one and parity swaps/is XORed by 1
pop_ans += 1
par_ans = par_ans ^ 1
# clz_ans will be max_bits - 201 for all indices since that's the first nonzero bit everywhere now
# clz_ans will be max_bits - 201 for all indices since that's the
# first nonzero bit everywhere now
# ctz_ans is unchanged other than first position which previously had no set bits
ctz_ans[0] = 200
for max_bits in [201, 256]:
Expand Down Expand Up @@ -100,7 +101,8 @@ def test_bigint_bitops(self):
bi.max_bits = max_bits
# base_clz plus the amount that max_bits exceeds the bits used to store the bigint
clz_ans = base_clz + (max_bits - 192)
# except for the first position doesn't have any set bits, so we want the 128 bits after accounted
# except for the first position doesn't have any set bits,
# so we want the 128 bits after accounted
clz_ans[0] += 128

assert pop_ans.to_list() == bi.popcount().to_list()
Expand All @@ -113,7 +115,8 @@ def test_bigint_bitops(self):
bi = ak.bigint_from_uint_arrays([edge_case, edge_case, edge_case])

pop_ans = ak.popcount(edge_case) * 3
# parity is the same as edge cases, because anything XORed with itself becomes zero so (x ^ x ^ x) = x
# parity is the same as edge cases,
# because anything XORed with itself becomes zero so (x ^ x ^ x) = x
par_ans = ak.parity(edge_case)
base_clz = ak.clz(edge_case)
ctz_ans = ak.ctz(edge_case)
Expand Down
10 changes: 8 additions & 2 deletions PROTO_tests/tests/client_dtypes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ def test_is_ipv4(self):
ipv4 = ak.IPv4(ak.array(x))
assert ak.is_ipv4(ipv4).to_list() == [True] * prob_size

x = [random.getrandbits(64) if i < prob_size / 2 else random.getrandbits(32) for i in range(prob_size)]
x = [
random.getrandbits(64) if i < prob_size / 2 else random.getrandbits(32)
for i in range(prob_size)
]
ans = ak.is_ipv4(ak.array(x, ak.uint64))
assert ans.to_list() == [i >= prob_size / 2 for i in range(prob_size)]

Expand All @@ -169,7 +172,10 @@ def test_is_ipv6(self):

assert ak.is_ipv6(high, low).to_list() == [True] * prob_size

x = [random.getrandbits(64) if i < prob_size / 2 else random.getrandbits(32) for i in range(prob_size)]
x = [
random.getrandbits(64) if i < prob_size / 2 else random.getrandbits(32)
for i in range(prob_size)
]
ans = ak.is_ipv6(ak.array(x, ak.uint64))
assert ans.to_list() == [i < prob_size / 2 for i in range(prob_size)]

Expand Down
2 changes: 1 addition & 1 deletion PROTO_tests/tests/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_get_mem_used(self):
"""
try:
config = ak.client.get_config()
a = ak.ones(1024 * 1024 * config["numLocales"])
a = ak.ones(1024 * 1024 * config["numLocales"]) # noqa: F841
mem_used = ak.client.get_mem_used()
except Exception as e:
raise AssertionError(e)
Expand Down
28 changes: 17 additions & 11 deletions PROTO_tests/tests/datetime_test.py
stress-tess marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,11 @@ def test_op_types(self, verbose=pytest.verbose):
r_is_supported,
return_type,
) in build_op_table().items():
fcvec = vectors[firstclass]
pdfcvec = pdvectors[firstclass]
fcsca = scalars[firstclass]
scvec = vectors[secondclass]
pdscvec = pdvectors[secondclass]
scsca = scalars[secondclass]
fcvec = vectors[firstclass] # noqa: F841
pdfcvec = pdvectors[firstclass] # noqa: F841
scvec = vectors[secondclass] # noqa: F841
pdscvec = pdvectors[secondclass] # noqa: F841
scsca = scalars[secondclass] # noqa: F841
if not is_supported:
with pytest.raises(TypeError):
eval(f"fcvec {op} scvec")
Expand Down Expand Up @@ -153,7 +152,8 @@ def test_op_types(self, verbose=pytest.verbose):
except AssertionError as e:
if verbose:
print(
f"arkouda vs pandas discrepancy in {firstclass.__name__} {op} {secondclass.__name__}:\n {ret} {pdret}"
f"arkouda vs pandas discrepancy in {firstclass.__name__}"
f" {op} {secondclass.__name__}:\n {ret} {pdret}"
)
raise e

Expand Down Expand Up @@ -188,7 +188,8 @@ def test_op_types(self, verbose=pytest.verbose):
except TypeError:
if verbose:
print(
f"Pandas does not support {secondclass.__name__}(scalar) {op} {firstclass.__name__}"
f"Pandas does not support {secondclass.__name__}(scalar) "
f"{op} {firstclass.__name__}"
)
metrics["ak_yes_pd_no"] += 1
compare_flag = False
Expand All @@ -198,7 +199,8 @@ def test_op_types(self, verbose=pytest.verbose):
except AttributeError:
if verbose:
print(
f"Unexpected pandas return: {secondclass}(scalar) {op} {firstclass} -> {type(pdret)}: {pdret}"
f"Unexpected pandas return: {secondclass}(scalar) "
f"{op} {firstclass} -> {type(pdret)}: {pdret}"
)
if verbose:
print(f"{metrics.items()}")
Expand Down Expand Up @@ -327,10 +329,14 @@ def test_woy_boundary(self):
# https://github.com/pandas-dev/pandas/blob/main/pandas/tests/scalar/timestamp/test_timestamp.py
for date in "2013-12-31", "2008-12-28", "2009-12-31", "2010-01-01", "2010-01-03":
ak_week = ak.Datetime(ak.date_range(date, periods=10, freq="w")).week.to_list()
pd_week = pd.Series(pd.date_range(date, periods=10, freq="w")).dt.isocalendar().week.to_list()
pd_week = (
pd.Series(pd.date_range(date, periods=10, freq="w")).dt.isocalendar().week.to_list()
)
assert ak_week == pd_week

for date in "2000-01-01", "2005-01-01":
ak_week = ak.Datetime(ak.date_range(date, periods=10, freq="d")).week.to_list()
pd_week = pd.Series(pd.date_range(date, periods=10, freq="d")).dt.isocalendar().week.to_list()
pd_week = (
pd.Series(pd.date_range(date, periods=10, freq="d")).dt.isocalendar().week.to_list()
)
assert ak_week == pd_week
1 change: 0 additions & 1 deletion PROTO_tests/tests/extrema_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def test_extrema_edge_cases(self, dtype):
if (arg_max_k != -1).all():
assert np.allclose(pda[arg_max_k].to_ndarray(), non_nan_sorted[-K:], equal_nan=True)


@pytest.mark.parametrize("dtype", NUMERIC_TYPES)
def test_argmin_and_argmax(self, dtype):
np_arr = make_np_arrays(1000, dtype)
Expand Down
4 changes: 2 additions & 2 deletions PROTO_tests/tests/groupby_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_pandas_equivalency(self, size, levels, op):
akkeys, akvals = akg.count() if op == "count" else akg.aggregate(akdf[vname], op)
except Exception as E:
print("Arkouda error: ", E)
continue # skip check
continue # skip check
if do_check:
if op.startswith("arg"):
pdextrema = df[vname][pdvals]
Expand Down Expand Up @@ -474,7 +474,7 @@ def test_uint64_aggregate(self):
assert u_group_sums.to_list() == i_group_sums.to_list()

# verify the multidim unsigned version doesnt break
multi_gu = ak.GroupBy([u, u])
ak.GroupBy([u, u])

u_data = ak.array(np.array([3, 4, 3, 1, 1, 4, 3, 4, 1, 4], dtype=np.uint64))
i_data = ak.array([3, 4, 3, 1, 1, 4, 3, 4, 1, 4])
Expand Down
2 changes: 1 addition & 1 deletion PROTO_tests/tests/io_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ def test_snapshot(self):
# delete variables and verify no longer in the namespace
del v
with pytest.raises(NameError):
assert not v
assert not v # noqa: F821

# restore the variables
data = ak.restore(f"{tmp_dirname}/snapshot_test")
Expand Down
59 changes: 22 additions & 37 deletions PROTO_tests/tests/message_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from arkouda.message import MessageFormat, MessageType, ReplyMessage, RequestMessage
import pytest
import json
from arkouda.client import _json_args_to_str

import pytest

import arkouda as ak
from arkouda.client import _json_args_to_str
from arkouda.message import MessageFormat, MessageType, ReplyMessage, RequestMessage


class TestMessage:
Expand Down Expand Up @@ -38,6 +40,7 @@ def test_request_msg(self):
msgNonDupe = RequestMessage(
user="user1", token="token", cmd="connect", format=MessageFormat.BINARY
)
min_msg = RequestMessage(user="user1", cmd="connect")

assert "user1" == msg.user
assert "token" == msg.token
Expand All @@ -47,40 +50,22 @@ def test_request_msg(self):
assert msg == msgDupe
assert msg != msgNonDupe

assert (
"RequestMessage(user='user1', token='token', cmd='connect', format=STRING, args=None, size=-1)"
== str(msg)
rep_msg = (
"RequestMessage(user='user1', token={}, cmd='connect', format=STRING, args=None, size=-1)"
)

assert (
"RequestMessage(user='user1', token='token', cmd='connect', format=STRING, args=None, size=-1)"
== repr(msg)
assert rep_msg.format("'token'") == str(msg)
assert rep_msg.format("'token'") == repr(msg)
assert rep_msg.format("None") == str(min_msg)
assert rep_msg.format("None") == repr(min_msg)

dict_msg = (
'{{"user": "user1", "token": {}, "cmd": "connect", "format": "STRING", "args": "",'
' "size": -1}}'
)

assert (
'{"user": "user1", "token": "token", "cmd": "connect", "format": "STRING", "args": "", "size": -1}'
== json.dumps(msg.asdict())
)

assert dict_msg.format('"token"') == json.dumps(msg.asdict())
assert dict_msg.format('""') == json.dumps(min_msg.asdict())
assert json.loads(json.dumps(msg.asdict())) == msg.asdict()

min_msg = RequestMessage(user="user1", cmd="connect")

assert (
"RequestMessage(user='user1', token=None, cmd='connect', format=STRING, args=None, size=-1)"
== str(min_msg)
)

assert (
"RequestMessage(user='user1', token=None, cmd='connect', format=STRING, args=None, size=-1)"
== repr(min_msg)
)

assert (
'{"user": "user1", "token": "", "cmd": "connect", "format": "STRING", "args": "", "size": -1}'
== json.dumps(min_msg.asdict())
)

def test_reply_msg(self):
msg = ReplyMessage(msg="normal result", msgType=MessageType.NORMAL, user="user")
msgDupe = ReplyMessage(msg="normal result", msgType=MessageType.NORMAL, user="user")
Expand Down Expand Up @@ -175,17 +160,17 @@ def test_list_arg(self, dtype):
assert args == expected

def test_list_addl_str(self):
l = ["abc", "def", "l", "mn", "op"]
size, args = _json_args_to_str({"str_list": l})
string_list = ["abc", "def", "l", "mn", "op"]
size, args = _json_args_to_str({"str_list": string_list})

expected = json.dumps(
[
json.dumps(
{
"key": "str_list",
"objType": "LIST",
"dtype": ak.resolve_scalar_dtype(l[0]),
"val": json.dumps(l),
"dtype": ak.resolve_scalar_dtype(string_list[0]),
"val": json.dumps(string_list),
}
),
]
Expand Down
12 changes: 8 additions & 4 deletions PROTO_tests/tests/operator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ def do_op(lt, rt, ls, rs, isarkouda, oper):
continue
for lscalar, rscalar in ((False, False), (False, True), (True, False)):
tests += 1
expression = f'{ltype}({("array", "scalar")[lscalar]}) {op} {rtype}({("array", "scalar")[rscalar]})'
expression = (
f'{ltype}({("array", "scalar")[lscalar]}) '
f'{op} {rtype}({("array", "scalar")[rscalar]})'
)
try:
npres = do_op(ltype, rtype, lscalar, rscalar, False, op)
except TypeError: # numpy doesn't implement operation
Expand Down Expand Up @@ -171,7 +174,6 @@ def do_op(lt, rt, ls, rs, isarkouda, oper):
print(f" Value mismatches: {len(valueerrors)} / {nboth}")
if verbose:
print("\n".join(map(": ".join, valueerrors)))
return matches == nboth

@pytest.mark.parametrize("dtype", NUMERIC_TYPES)
def test_pdarray_and_scalar_ops(self, dtype):
Expand Down Expand Up @@ -549,9 +551,11 @@ def test_str_repr(self):
assert ak.array([1.1, 2.3, 5]).__repr__() in answers

answers = [
"array([0 0.52631578947368418 1.0526315789473684 ... 8.9473684210526319 9.473684210526315 10])",
"array([0 0.52631578947368418 1.0526315789473684 ... 8.9473684210526319 "
"9.473684210526315 10])",
"array([0 0.5 1.1 ... 8.9 9.5 10])",
"array([0.00000000000000000 0.52631578947368418 1.0526315789473684 ... 8.9473684210526319 9.473684210526315 10.00000000000000000])",
"array([0.00000000000000000 0.52631578947368418 1.0526315789473684 ... 8.9473684210526319 "
"9.473684210526315 10.00000000000000000])",
stress-tess marked this conversation as resolved.
Show resolved Hide resolved
stress-tess marked this conversation as resolved.
Show resolved Hide resolved
]
assert ak.linspace(0, 10, 20).__repr__() in answers
assert "array([False False False])" == ak.isnan(ak.array([1.1, 2.3, 5])).__repr__()
Expand Down
10 changes: 5 additions & 5 deletions PROTO_tests/tests/pdarray_creation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,19 +717,19 @@ def randint_randomness(self, size):
trials = 20

for x in range(trials):
l = ak.randint(min_val, max_val, size)
l_median = statistics.median(l.to_ndarray())
l_int = ak.randint(min_val, max_val, size)
l_median = statistics.median(l_int.to_ndarray())

runs, n1, n2 = 0, 0, 0

# Checking for start of new run
for i in range(len(l)):
for i in range(len(l_int)):
# no. of runs
if (l[i] >= l_median > l[i - 1]) or (l[i] < l_median <= l[i - 1]):
if (l_int[i] >= l_median > l_int[i - 1]) or (l_int[i] < l_median <= l_int[i - 1]):
runs += 1

# no. of positive values
if (l[i]) >= l_median:
if (l_int[i]) >= l_median:
n1 += 1
# no. of negative values
else:
Expand Down
12 changes: 4 additions & 8 deletions PROTO_tests/tests/stats_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,10 @@ def test_divmod(self):
# Boolean where argument
truth = ak.arange(10) % 2 == 0
ak_div_truth, ak_mod_truth = ak.divmod(self.x, self.y, where=truth)
assert (
ak_div_truth.to_list()
== [(self.x[i] // self.y[i]) if truth[i] else self.x[i] for i in range(10)],
)
assert (
ak_mod_truth.to_list()
== [(self.x[i] % self.y[i]) if truth[i] else self.x[i] for i in range(10)],
)
div_ans = [(self.x[i] // self.y[i]) if truth[i] else self.x[i] for i in range(10)]
mod_ans = [(self.x[i] % self.y[i]) if truth[i] else self.x[i] for i in range(10)]
assert ak_div_truth.to_list() == div_ans
assert ak_mod_truth.to_list() == mod_ans

# Edge cases in the numerator
edge_case = [-np.inf, -7.0, -0.0, np.nan, 0.0, 7.0, np.inf]
Expand Down
Loading