Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#805)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/psf/black: 24.1.1 → 24.2.0](psf/black@24.1.1...24.2.0)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Dacheng Xu <[email protected]>
  • Loading branch information
pre-commit-ci[bot] and dachengx authored Feb 15, 2024
1 parent 882b545 commit 8b601ed
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
- id: check-added-large-files

- repo: https://github.com/psf/black
rev: 24.1.1
rev: 24.2.0
hooks:
- id: black
args: [--safe, --line-length=100, --preview]
Expand Down
12 changes: 7 additions & 5 deletions strax/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,13 @@ 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
34 changes: 19 additions & 15 deletions strax/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,11 +634,13 @@ def _context_hash(self):
"""
self._base_hash_on_config = self.config.copy()
# Also take into account the versions of the plugins registered
self._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_")
})
self._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(self._base_hash_on_config)

def _plugins_are_cached(
Expand Down Expand Up @@ -2324,16 +2326,18 @@ 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
12 changes: 7 additions & 5 deletions strax/plugins/merge_only_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ 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]]
18 changes: 11 additions & 7 deletions strax/run_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,13 +525,17 @@ 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
10 changes: 6 additions & 4 deletions strax/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,12 @@ 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: 8 additions & 6 deletions tests/test_corrections.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ 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
10 changes: 6 additions & 4 deletions tests/test_down_chunk_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ def test_down_chunking(self):
_chunks_are_downsampled = len(chunks_records) * 2 == len(chunks_records_down_chunked)
assert _chunks_are_downsampled

_chunks_are_continues = np.all([
chunks_records_down_chunked[i]["end"] == chunks_records_down_chunked[i + 1]["start"]
for i in range(len(chunks_records_down_chunked) - 1)
])
_chunks_are_continues = np.all(
[
chunks_records_down_chunked[i]["end"] == chunks_records_down_chunked[i + 1]["start"]
for i in range(len(chunks_records_down_chunked) - 1)
]
)
assert _chunks_are_continues

def test_down_chunking_multi_processing(self):
Expand Down
20 changes: 12 additions & 8 deletions tests/test_mongo_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ 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 @@ -191,10 +193,12 @@ 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
24 changes: 14 additions & 10 deletions tests/test_multi_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,13 @@ 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 @@ -205,11 +207,13 @@ 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

0 comments on commit 8b601ed

Please sign in to comment.