Skip to content

Commit

Permalink
fix flake8 error variable declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
jaketrookman committed Sep 19, 2023
1 parent 494ce09 commit ed01c94
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 60 deletions.
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
11 changes: 5 additions & 6 deletions PROTO_tests/tests/datetime_test.py
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
2 changes: 1 addition & 1 deletion PROTO_tests/tests/groupby_test.py
Original file line number Diff line number Diff line change
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])
multi_gu = ak.GroupBy([u, u]) # noqa: F841

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
8 changes: 4 additions & 4 deletions PROTO_tests/tests/message_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,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
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
14 changes: 6 additions & 8 deletions PROTO_tests/tests/stats_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,12 @@ 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)],
)
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)
]

# Edge cases in the numerator
edge_case = [-np.inf, -7.0, -0.0, np.nan, 0.0, 7.0, np.inf]
Expand Down
50 changes: 28 additions & 22 deletions PROTO_tests/tests/string_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def setup_class(self):

@staticmethod
def base_words(size):
base_words1 = ak.random_strings_uniform(1, 10, size//4, characters="printable")
base_words2 = ak.random_strings_lognormal(2, 0.25, size//4, characters="printable")
base_words1 = ak.random_strings_uniform(1, 10, size // 4, characters="printable")
base_words2 = ak.random_strings_lognormal(2, 0.25, size // 4, characters="printable")
base_words = ak.concatenate((base_words1, base_words2))
np_base_words = np.hstack((base_words1.to_ndarray(), base_words2.to_ndarray()))

Expand Down Expand Up @@ -104,10 +104,10 @@ def test_groupby(self, size):
lengths = np.diff(np.hstack((g.segments.to_ndarray(), np.array([g.length]))))
for uk, s, l in zip(g.unique_keys.to_ndarray(), g.segments.to_ndarray(), lengths):
# All values in group should equal key
assert (permStrings[s: s + l] == uk).all()
assert (permStrings[s : s + l] == uk).all()
# Key should not appear anywhere outside of group
assert not (permStrings[:s] == uk).any()
assert not (permStrings[s + l:] == uk).any()
assert not (permStrings[s + l :] == uk).any()

@pytest.mark.parametrize("size", pytest.prob_size)
def test_index(self, size):
Expand Down Expand Up @@ -135,10 +135,12 @@ def test_slice(self, size):
strings = self.get_strings(size, base_words)
test_strings = strings.to_ndarray()
cat = ak.Categorical(strings)
assert self.compare_strings(strings[size // 4: size // 3].to_ndarray(),
test_strings[size // 4: size // 3])
assert self.compare_strings(cat[size // 4: size // 3].to_ndarray(),
test_strings[size // 4: size // 3])
assert self.compare_strings(
strings[size // 4 : size // 3].to_ndarray(), test_strings[size // 4 : size // 3]
)
assert self.compare_strings(
cat[size // 4 : size // 3].to_ndarray(), test_strings[size // 4 : size // 3]
)

@pytest.mark.parametrize("size", pytest.prob_size)
def test_pdarray_index(self, size):
Expand Down Expand Up @@ -250,8 +252,8 @@ def test_ends_with_delimiter_match(self):

@pytest.mark.parametrize("size", pytest.prob_size)
def test_error_handling(self, size):
stringsOne = ak.random_strings_uniform(1, 10, size//4, characters="printable")
stringsTwo = ak.random_strings_uniform(1, 10, size//4, characters="printable")
stringsOne = ak.random_strings_uniform(1, 10, size // 4, characters="printable")
stringsTwo = ak.random_strings_uniform(1, 10, size // 4, characters="printable")

with pytest.raises(TypeError):
stringsOne.lstick(stringsTwo, delimiter=1)
Expand Down Expand Up @@ -415,21 +417,25 @@ def test_stick(self, size):
delim = self.delim(np_base_words)
self._stick_help(strings, test_strings, base_words, delim, size)
self._stick_help(strings, test_strings, base_words, np.str_(delim), size)
self._stick_help(
strings, test_strings, base_words, str.encode(str(delim)), size
)
self._stick_help(strings, test_strings, base_words, str.encode(str(delim)), size)

# Test gremlins delimiters
g = self._get_ak_gremlins(size)
self._stick_help(g.gremlins_strings, g.gremlins_test_strings, g.gremlins_base_words, " ", size+3)
self._stick_help(g.gremlins_strings, g.gremlins_test_strings, g.gremlins_base_words, "", size+3)
self._stick_help(g.gremlins_strings, g.gremlins_test_strings, g.gremlins_base_words, '"', size+3)
self._stick_help(
g.gremlins_strings, g.gremlins_test_strings, g.gremlins_base_words, " ", size + 3
)
self._stick_help(
g.gremlins_strings, g.gremlins_test_strings, g.gremlins_base_words, "", size + 3
)
self._stick_help(
g.gremlins_strings, g.gremlins_test_strings, g.gremlins_base_words, '"', size + 3
)

def test_str_output(self):
strings = ak.array(["string {}".format(i) for i in range(0, 101)])
assert (
"['string 0', 'string 1', 'string 2', ... , 'string 98', 'string 99', 'string 100']" ==
str(strings),
"['string 0', 'string 1', 'string 2', ... , 'string 98', "
"'string 99', 'string 100']" == str(strings)
)

def test_flatten(self):
Expand Down Expand Up @@ -571,15 +577,15 @@ def test_get_fixes(self):
assert [x[0:n] for x in a if len(x) >= n] == prefix.to_list()

suffix, origin = strings.get_suffixes(n, return_origins=True, proper=True)
assert [x[len(x)-n:] for x in a if len(x) > n] == suffix.to_list()
assert [x[len(x) - n :] for x in a if len(x) > n] == suffix.to_list()
assert [True if len(x) >= n else False for x in a]

suffix, origin = strings.get_suffixes(n, return_origins=True, proper=False)
assert [x[len(x) - n:] for x in a if len(x) >= n] == suffix.to_list()
assert [x[len(x) - n :] for x in a if len(x) >= n] == suffix.to_list()
assert [True if len(x) >= n else False for x in a]

suffix = strings.get_suffixes(n, return_origins=False, proper=False)
assert [x[len(x) - n:] for x in a if len(x) >= n] == suffix.to_list()
assert [x[len(x) - n :] for x in a if len(x) >= n] == suffix.to_list()

def test_encoding(self):
idna_strings = ak.array(["Bücher.example", "ドメイン.テスト", "домен.испытание", "Königsgäßchen"])
Expand Down Expand Up @@ -611,7 +617,7 @@ def test_encoding(self):
# using the below assertion due to a bug in `Strings.to_ndarray`. See issue #1828
assert ["münchen", "zürich", "", "", "example.com"] == result.to_list()

a3 = ak.random_strings_uniform(1, 10, 100//4, characters="printable")
a3 = ak.random_strings_uniform(1, 10, 100 // 4, characters="printable")
assert (a3 == a3.encode("ascii").decode("ascii")).all()

def test_idna_utf16(self):
Expand Down
24 changes: 12 additions & 12 deletions PROTO_tests/tests/symbol_table_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,38 +721,38 @@ def test_attach_weak_binding(self, dtype):
str(a)

def test_symentry_cleanup(self):
pda = self.make_pdarray(ak.int64, 10)
pda = self.make_pdarray(ak.int64, 10) # noqa: F841
assert len(ak.list_symbol_table()) > 0
pda = None
pda = None # noqa: F841
assert len(ak.list_symbol_table()) == 0

s = self.make_pdarray(ak.str_, 10)
s = self.make_pdarray(ak.str_, 10) # noqa: F841
assert len(ak.list_symbol_table()) > 0
s = None
s = None # noqa: F841
assert len(ak.list_symbol_table()) == 0

cat = ak.Categorical(self.make_pdarray(ak.str_, 10))
cat = ak.Categorical(self.make_pdarray(ak.str_, 10)) # noqa: F841
assert len(ak.list_symbol_table()) > 0
cat = None
cat = None # noqa: F841
assert len(ak.list_symbol_table()) == 0

seg = ak.SegArray(ak.arange(0, 10, 2), self.make_pdarray(ak.float64, 10))
seg = ak.SegArray(ak.arange(0, 10, 2), self.make_pdarray(ak.float64, 10)) # noqa: F841
assert len(ak.list_symbol_table()) > 0
seg = None
seg = None # noqa: F841
assert len(ak.list_symbol_table()) == 0

g = ak.GroupBy(
g = ak.GroupBy( # noqa: F841
[
self.make_pdarray(ak.int64, 10),
self.make_pdarray(ak.str_, 10),
ak.Categorical(self.make_pdarray(ak.str_, 10)),
]
)
assert len(ak.list_symbol_table()) > 0
g = None
g = None # noqa: F841
assert len(ak.list_symbol_table()) == 0

d = ak.DataFrame(
d = ak.DataFrame( # noqa: F841
{
"pda": self.make_pdarray(ak.int64, 10),
"s": self.make_pdarray(ak.str_, 10),
Expand All @@ -761,5 +761,5 @@ def test_symentry_cleanup(self):
}
)
assert len(ak.list_symbol_table()) > 0
d = None
d = None # noqa: F841
assert len(ak.list_symbol_table()) == 0

0 comments on commit ed01c94

Please sign in to comment.