Skip to content

Commit

Permalink
Merge pull request #774 from AxFoundation/pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
[pre-commit.ci] pre-commit autoupdate
  • Loading branch information
dachengx authored Nov 14, 2023
2 parents f17619d + 0716ec6 commit c88daf8
Show file tree
Hide file tree
Showing 19 changed files with 96 additions and 114 deletions.
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
5c4a277fbb155529dc5cf06435f0d7419977d7dd
8e431b2f5827d3f9c69088bd68b432dc6d4d4769
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.11.0
hooks:
- id: black
args: [--safe, --line-length=100, --preview]
Expand All @@ -24,7 +24,7 @@ repos:
- id: docformatter

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
rev: v1.7.0
hooks:
- id: mypy
additional_dependencies: [
Expand Down
12 changes: 5 additions & 7 deletions strax/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,11 @@ def __init__(
# DeprecationWarning)

if (
sum(
[
self.default is not OMITTED,
self.default_factory is not OMITTED,
self.default_by_run is not OMITTED,
]
)
sum([
self.default is not OMITTED,
self.default_factory is not OMITTED,
self.default_by_run is not OMITTED,
])
> 1
):
raise RuntimeError(f"Tried to specify more than one default for option {self.name}.")
Expand Down
40 changes: 18 additions & 22 deletions strax/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,13 +613,11 @@ def _context_hash(self):
"""
base_hash_on_config = self.config.copy()
# Also take into account the versions of the plugins registered
base_hash_on_config.update(
{
data_type: (plugin.__version__, plugin.compressor, plugin.input_timeout)
for data_type, plugin in self._plugin_class_registry.items()
if not data_type.startswith("_temp_")
}
)
base_hash_on_config.update({
data_type: (plugin.__version__, plugin.compressor, plugin.input_timeout)
for data_type, plugin in self._plugin_class_registry.items()
if not data_type.startswith("_temp_")
})
return strax.deterministic_hash(base_hash_on_config)

def _plugins_are_cached(
Expand Down Expand Up @@ -723,9 +721,9 @@ def _get_plugins(

# Check all config options are taken by some registered plugin class
# (helps spot typos)
all_opts = set().union(
*[pc.takes_config.keys() for pc in self._plugin_class_registry.values()]
)
all_opts = set().union(*[
pc.takes_config.keys() for pc in self._plugin_class_registry.values()
])
for k in self.config:
if not (k in all_opts or k in self.context_config["free_options"]):
self.log.warning(f"Option {k} not taken by any registered plugin")
Expand Down Expand Up @@ -2219,18 +2217,16 @@ def provided_dtypes(self, runid="0"):
version
"""
hashes = set(
[
(
data_type,
self.key_for(runid, data_type).lineage_hash,
self.get_save_when(data_type),
plugin.__version__,
)
for plugin in self._plugin_class_registry.values()
for data_type in plugin.provides
]
)
hashes = set([
(
data_type,
self.key_for(runid, data_type).lineage_hash,
self.get_save_when(data_type),
plugin.__version__,
)
for plugin in self._plugin_class_registry.values()
for data_type in plugin.provides
])

return {
data_type: dict(hash=_hash, save_when=save_when.name, version=version)
Expand Down
1 change: 1 addition & 0 deletions strax/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
TODO: file numba issue.
"""

from typing import Optional, Tuple

import numpy as np
Expand Down
1 change: 1 addition & 0 deletions strax/io.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Read/write numpy arrays to/from compressed files or file-like objects."""

import os
import bz2

Expand Down
6 changes: 3 additions & 3 deletions strax/mailbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ def _can_fetch(self):

# If someone is still waiting for a message we already have
# (so they just haven't woken up yet), don't fetch a new message.
if len(self._mailbox) and any(
[x is not None and x <= self._lowest_msg_number for x in self._subscriber_waiting_for]
):
if len(self._mailbox) and any([
x is not None and x <= self._lowest_msg_number for x in self._subscriber_waiting_for
]):
return False

# Everyone is waiting for the new chunk or not at all.
Expand Down
12 changes: 5 additions & 7 deletions strax/plugins/merge_only_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ def infer_dtype(self):
+ str(deps_by_kind)
)

return strax.merged_dtype(
[
self.deps[d].dtype_for(d)
# Sorting is needed here to match what strax.Chunk does in merging
for d in sorted(self.depends_on)
]
)
return strax.merged_dtype([
self.deps[d].dtype_for(d)
# Sorting is needed here to match what strax.Chunk does in merging
for d in sorted(self.depends_on)
])

def compute(self, **kwargs):
return kwargs[list(kwargs.keys())[0]]
7 changes: 4 additions & 3 deletions strax/plugins/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
A 'plugin' is something that outputs an array and gets arrays from one or more other plugins.
"""

from enum import IntEnum
import inspect
import itertools
Expand Down Expand Up @@ -466,9 +467,9 @@ class IterDone(Exception):
inputs[d], back_to_buffer = inputs[d].split(
t=this_chunk_end, allow_early_split=True
)
self.input_buffer[d] = strax.Chunk.concatenate(
[back_to_buffer, self.input_buffer[d]]
)
self.input_buffer[d] = strax.Chunk.concatenate([
back_to_buffer, self.input_buffer[d]
])
max_passes_left -= 1
else:
raise RuntimeError(
Expand Down
1 change: 1 addition & 0 deletions strax/processing/data_reduction.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions to perform in-place pulse-level data reduction."""

import numpy as np
import numba
from enum import IntEnum
Expand Down
1 change: 1 addition & 0 deletions strax/processing/pulse_processing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Functions that perform processing on pulses (other than data reduction functions, which are in
data_reduction.py)"""

import typing as ty

import numpy as np
Expand Down
25 changes: 11 additions & 14 deletions strax/run_selection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Context methods dealing with run scanning and selection."""

import fnmatch
import re
import typing as ty
Expand Down Expand Up @@ -142,9 +143,9 @@ def scan_runs(
if isinstance(doc["source"], list):
doc["source"] = ",".join(doc["source"])

doc["tags"] = ",".join(
[t["name"] if isinstance(t, dict) else t for t in doc.get("tags", [])]
)
doc["tags"] = ",".join([
t["name"] if isinstance(t, dict) else t for t in doc.get("tags", [])
])

# Set a default livetime if we have start and stop
if (
Expand Down Expand Up @@ -524,17 +525,13 @@ def _tags_match(dsets, patterns, pattern_type, ignore_underscore):
patterns = [patterns]

for i, tags in enumerate(dsets.tags):
result[i] = any(
[
any(
[
_tag_match(tag, pattern, pattern_type, ignore_underscore)
for tag in tags.split(",")
for pattern in patterns
]
)
]
)
result[i] = any([
any([
_tag_match(tag, pattern, pattern_type, ignore_underscore)
for tag in tags.split(",")
for pattern in patterns
])
])

return result

Expand Down
1 change: 1 addition & 0 deletions strax/storage/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Please see the developer documentation for more details on strax' storage hierarchy.
"""

from ast import literal_eval
from concurrent.futures import wait
import logging
Expand Down
10 changes: 4 additions & 6 deletions strax/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,10 @@ def unpack_dtype(dtype):
@export
def remove_titles_from_dtype(dtype):
"""Return np.dtype with titles removed from fields."""
return np.dtype(
[
(fieldname[-1] if isinstance(fieldname, tuple) else fieldname, dt)
for fieldname, dt in unpack_dtype(np.dtype(dtype))
]
)
return np.dtype([
(fieldname[-1] if isinstance(fieldname, tuple) else fieldname, dt)
for fieldname, dt in unpack_dtype(np.dtype(dtype))
])


@export
Expand Down
14 changes: 6 additions & 8 deletions tests/test_corrections.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ def setUp(self):
def make_dummy_df():
"""Make a dummy pandas.dataframe()"""
dates = [datetime(2017, 1, 1), datetime(2021, 1, 1), datetime(2021, 9, 23)]
df = pd.DataFrame(
{
"ONLINE": [10.0, 10.0, 8.0],
"v1": [12.0, 12.0, 14.0],
"v2": [13.0, 14.0, np.nan],
"time": dates,
}
)
df = pd.DataFrame({
"ONLINE": [10.0, 10.0, 8.0],
"v1": [12.0, 12.0, 14.0],
"v2": [13.0, 14.0, np.nan],
"time": dates,
})

df["time"] = pd.to_datetime(df["time"], utc=True)
df = df.set_index("time")
Expand Down
4 changes: 1 addition & 3 deletions tests/test_general_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,7 @@ def test_raw_to_records(r):


@hypothesis.given(
hyp_numpy.arrays(
np.int64, 10**2, elements=hypothesis.strategies.integers(10**9, 5 * 10**9)
),
hyp_numpy.arrays(np.int64, 10**2, elements=hypothesis.strategies.integers(10**9, 5 * 10**9)),
hyp_numpy.arrays(np.int16, 10**2, elements=hypothesis.strategies.integers(-10, 10**3)),
)
@hypothesis.settings(deadline=None)
Expand Down
20 changes: 8 additions & 12 deletions tests/test_mongo_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,10 @@ def test_interrupt_iterator(self):
def test_allow_incomplete(self):
"""Test loading incomplete data."""
st_incomplete_allowed = self.st.new_context()
st_incomplete_allowed.set_context_config(
{
"allow_incomplete": True,
"forbid_creation_of": "*",
}
)
st_incomplete_allowed.set_context_config({
"allow_incomplete": True,
"forbid_creation_of": "*",
})
assert not self.is_stored_in_mongo
self.st.config["n_chunks"] = 3

Expand Down Expand Up @@ -193,12 +191,10 @@ def test_allow_incomplete_during_md_creation(self):
"""
st_incomplete_allowed = self.st.new_context()
st_incomplete_allowed.set_context_config(
{
"allow_incomplete": True,
"forbid_creation_of": "*",
}
)
st_incomplete_allowed.set_context_config({
"allow_incomplete": True,
"forbid_creation_of": "*",
})
assert not self.is_stored_in_mongo
self.st.config["n_chunks"] = 3

Expand Down
36 changes: 16 additions & 20 deletions tests/test_multi_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,11 @@ def test_save_when_per_provide_same_save_when(self):
def test_save_when_per_provide(self):
"""Tests if save when works properly in case of different save when per provided
data_type."""
_save_when = immutabledict(
{
"even_recs": strax.SaveWhen.NEVER,
"odd_recs": strax.SaveWhen.TARGET,
"rec_count": strax.SaveWhen.ALWAYS,
}
)
_save_when = immutabledict({
"even_recs": strax.SaveWhen.NEVER,
"odd_recs": strax.SaveWhen.TARGET,
"rec_count": strax.SaveWhen.ALWAYS,
})
p = self.mystrax._plugin_class_registry["rec_count"]
p.save_when = _save_when

Expand Down Expand Up @@ -207,13 +205,11 @@ def test_save_when_per_provide(self):

def test_save_per_provide_inlined(self):
"""Checks whether the plugin inlining works for different combinations."""
_save_when = immutabledict(
{
"even_recs": strax.SaveWhen.NEVER,
"odd_recs": strax.SaveWhen.TARGET,
"rec_count": strax.SaveWhen.ALWAYS,
}
)
_save_when = immutabledict({
"even_recs": strax.SaveWhen.NEVER,
"odd_recs": strax.SaveWhen.TARGET,
"rec_count": strax.SaveWhen.ALWAYS,
})
p = self.mystrax._plugin_class_registry["rec_count"]
p.save_when = _save_when

Expand Down Expand Up @@ -255,17 +251,17 @@ def test_double_dependency_notlazy(self):
def test_double_dependency_multiprocess(self):
"""Tests if double dependency of a plugin on another plugin leads to dead lock in
processing."""
self.mystrax.set_context_config(
{"timeout": 120, "allow_lazy": False, "allow_multiprocess": True}
)
self.mystrax.set_context_config({
"timeout": 120, "allow_lazy": False, "allow_multiprocess": True
})
self._test_double_dependency(max_workers=2)

def test_double_dependency_inline_plugins(self):
"""Tests if double dependency of a plugin on another plugin leads to dead lock in
processing."""
self.mystrax.set_context_config(
{"timeout": 120, "allow_lazy": False, "allow_multiprocess": True}
)
self.mystrax.set_context_config({
"timeout": 120, "allow_lazy": False, "allow_multiprocess": True
})
self._test_double_dependency(max_workers=2, make_data_type="zipped_records_classified")
self.mystrax.is_stored(run_id, "even_recs_classified")

Expand Down
Loading

0 comments on commit c88daf8

Please sign in to comment.