Skip to content

Commit f401777

Browse files
committed
Fix formatting
1 parent 69182fb commit f401777

19 files changed

+86
-95
lines changed

PLAN.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This document tracks the plan to fix the remaining 56 ruff issues (excluding not
55
## 🔴 Priority 1: Critical Fixes (7 issues) - ✅ COMPLETED
66

77
### Immediate Action Required
8+
89
- [x] **Mutable Default Argument** (`convert_ephys.py:42`)
910
- Change `nwb_hw_channel_order=[]` to `nwb_hw_channel_order=None`
1011
- Add `if nwb_hw_channel_order is None: nwb_hw_channel_order = []` inside function
@@ -21,6 +22,7 @@ This document tracks the plan to fix the remaining 56 ruff issues (excluding not
2122
## 🟡 Priority 2: Code Quality (25 issues) - ✅ COMPLETED
2223

2324
### Quick Wins - Auto-fixable patterns
25+
2426
- [x] **Dictionary/List Inefficiencies** (11 issues)
2527
- Replace `key in dict.keys()` with `key in dict` (8 instances)
2628
- Replace `dict()` with `{}` literals (2 instances)
@@ -41,6 +43,7 @@ This document tracks the plan to fix the remaining 56 ruff issues (excluding not
4143
## 🟠 Priority 3: Style & Performance (9 issues remaining) - PARTIALLY COMPLETED
4244

4345
### Consider for future refactoring
46+
4447
- [ ] **Magic Numbers** (`convert_position.py` - 4 instances)
4548
- Extract constants: `MIN_TIMESTAMPS = 2`, `DEFAULT_TIMEOUT = 2000`, `MIN_TICKS = 100`
4649
- **Note**: These are context-specific values that may be better left as literals
@@ -60,14 +63,16 @@ This document tracks the plan to fix the remaining 56 ruff issues (excluding not
6063
## Progress Tracking
6164

6265
**Total Issues**: 56 (excluding notebooks)
66+
6367
- **Fixed**: 47 (7 Priority 1 + 37 Priority 2 + 3 Priority 3)
6468
- **Remaining**: 9 (4 magic numbers + 4 memory optimizations + 1 unused import)
6569

6670
**Estimated Timeline**:
71+
6772
- Phase 1 (Critical): 30 minutes
6873
- Phase 2 (Quality): 45 minutes
6974
- Phase 3 (Style): As needed during regular development
7075

7176
## Commit Strategy
7277

73-
Each priority level will be committed separately with detailed commit messages explaining the fixes applied.
78+
Each priority level will be committed separately with detailed commit messages explaining the fixes applied.

pyproject.toml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ extend-exclude = '''
8383
'''
8484

8585
[tool.pytest.ini_options]
86-
testpaths = ["src/trodes_to_nwb/tests", "src/trodes_to_nwb/tests/integration-tests"]
86+
testpaths = [
87+
"src/trodes_to_nwb/tests",
88+
"src/trodes_to_nwb/tests/integration-tests",
89+
]
8790
python_files = ["test_*.py"]
8891
python_classes = ["Test*"]
8992
python_functions = ["test_*"]
@@ -99,7 +102,7 @@ warn_return_any = true
99102
warn_unused_configs = true
100103
warn_redundant_casts = true
101104
warn_unused_ignores = true
102-
disallow_untyped_defs = false # Set to true gradually
105+
disallow_untyped_defs = false # Set to true gradually
103106
disallow_incomplete_defs = true
104107
check_untyped_defs = true
105108
disallow_untyped_decorators = true
@@ -125,26 +128,26 @@ line-length = 88
125128

126129
[tool.ruff.lint]
127130
select = [
128-
"E", # pycodestyle errors
129-
"W", # pycodestyle warnings
130-
"F", # pyflakes
131-
"B", # flake8-bugbear
132-
"I", # isort
133-
"UP", # pyupgrade
134-
"C4", # flake8-comprehensions
131+
"E", # pycodestyle errors
132+
"W", # pycodestyle warnings
133+
"F", # pyflakes
134+
"B", # flake8-bugbear
135+
"I", # isort
136+
"UP", # pyupgrade
137+
"C4", # flake8-comprehensions
135138
"SIM", # flake8-simplify
136-
"PL", # pylint
139+
"PL", # pylint
137140
]
138141
ignore = [
139-
"E501", # line too long, handled by black
142+
"E501", # line too long, handled by black
140143
"PLR0913", # too many arguments to function call
141144
"PLR0912", # too many branches
142145
"PLR0915", # too many statements
143146
"PLW2901", # redefined loop variable
144147
]
145148

146149
[tool.ruff.lint.per-file-ignores]
147-
"tests/**/*.py" = ["PLR2004"] # magic value used in comparison
150+
"tests/**/*.py" = ["PLR2004"] # magic value used in comparison
148151
"src/trodes_to_nwb/tests/**/*.py" = ["PLR2004"]
149152
"notebooks/**/*.py" = ["E402", "F401", "F821"] # notebook-specific ignores
150153

src/trodes_to_nwb/convert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import logging
99
from pathlib import Path
1010

11-
from dask.distributed import Client
1211
import nwbinspector
1312
import pandas as pd
13+
from dask.distributed import Client
1414
from pynwb import NWBHDF5IO
1515

1616
from trodes_to_nwb.convert_analog import add_analog_data

src/trodes_to_nwb/convert_analog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from xml.etree import ElementTree
44

5-
from hdmf.backends.hdf5 import H5DataIO
65
import numpy as np
76
import pynwb
7+
from hdmf.backends.hdf5 import H5DataIO
88
from pynwb import NWBFile
99

1010
from trodes_to_nwb import convert_rec_header

src/trodes_to_nwb/convert_dios.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ def _get_channel_name_map(metadata: dict) -> dict[str, str]:
3131
)
3232
channel_name_map[dio_event["description"]] = {
3333
"name": dio_event["name"],
34-
"comments": (
35-
dio_event.get("comments", "no comments")
36-
),
34+
"comments": (dio_event.get("comments", "no comments")),
3735
}
3836
return channel_name_map
3937

src/trodes_to_nwb/convert_ephys.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import logging
66
from warnings import warn
77

8+
import numpy as np
89
from hdmf.backends.hdf5 import H5DataIO
910
from hdmf.data_utils import GenericDataChunkIterator
10-
import numpy as np
1111
from pynwb import NWBFile
1212
from pynwb.ecephys import ElectricalSeries
1313

@@ -97,8 +97,7 @@ def __init__(
9797
assert all(neo_io.block_count() == 1 for neo_io in self.neo_io)
9898
assert all(neo_io.segment_count(0) == 1 for neo_io in self.neo_io)
9999
assert all(
100-
neo_io.signal_streams_count() == 4 - behavior_only
101-
for neo_io in self.neo_io
100+
neo_io.signal_streams_count() == 4 - behavior_only for neo_io in self.neo_io
102101
), (
103102
"Unexpected number of signal streams. "
104103
+ "Confirm whether behavior_only is set correctly for this recording"
@@ -132,10 +131,8 @@ def __init__(
132131
if (
133132
len(
134133
{
135-
136-
neo_io.signal_channels_count(stream_index=self.stream_index)
137-
for neo_io in self.neo_io
138-
134+
neo_io.signal_channels_count(stream_index=self.stream_index)
135+
for neo_io in self.neo_io
139136
}
140137
)
141138
> 1
@@ -222,7 +219,8 @@ def __init__(
222219
is_timestamps_sequential = np.all(np.diff(self.timestamps))
223220
if not is_timestamps_sequential:
224221
warn(
225-
"Timestamps are not sequential. This may cause problems with some software or data analysis.", stacklevel=2
222+
"Timestamps are not sequential. This may cause problems with some software or data analysis.",
223+
stacklevel=2,
226224
)
227225

228226
self.n_time = [
@@ -265,22 +263,20 @@ def _get_data(self, selection: tuple[slice]) -> np.ndarray:
265263
io_stream = np.argmin(i >= file_start_ind) - 1
266264
# get the data from that stream
267265
data.append(
268-
269-
self.neo_io[io_stream].get_analogsignal_chunk(
270-
block_index=self.block_index,
271-
seg_index=self.seg_index,
272-
i_start=int(i - file_start_ind[io_stream]),
273-
i_stop=int(
274-
min(
275-
time_index[-1] - file_start_ind[io_stream],
276-
self.n_time[io_stream],
277-
)
266+
self.neo_io[io_stream].get_analogsignal_chunk(
267+
block_index=self.block_index,
268+
seg_index=self.seg_index,
269+
i_start=int(i - file_start_ind[io_stream]),
270+
i_stop=int(
271+
min(
272+
time_index[-1] - file_start_ind[io_stream],
273+
self.n_time[io_stream],
278274
)
279-
+ 1,
280-
stream_index=self.stream_index,
281-
channel_ids=channel_ids,
282275
)
283-
276+
+ 1,
277+
stream_index=self.stream_index,
278+
channel_ids=channel_ids,
279+
)
284280
)
285281
i += min(
286282
self.n_time[io_stream]

src/trodes_to_nwb/convert_optogenetics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import os
33
from pathlib import Path
44

5+
import numpy as np
6+
import yaml
57
from ndx_franklab_novela import FrankLabOptogeneticEpochsTable
68
from ndx_optogenetics import (
79
ExcitationSource,
@@ -15,9 +17,7 @@
1517
OptogeneticVirusInjection,
1618
OptogeneticVirusInjections,
1719
)
18-
import numpy as np
1920
from pynwb import NWBFile
20-
import yaml
2121

2222
from trodes_to_nwb.tests.utils import data_path
2323

src/trodes_to_nwb/convert_position.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
import datetime
77
import logging
8-
from pathlib import Path
98
import re
109
import subprocess
10+
from pathlib import Path
1111
from typing import Any
1212

1313
import numpy as np

src/trodes_to_nwb/convert_rec_header.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ def validate_yaml_header_electrode_map(
120120
# find appropriate channel map metadata
121121
channel_map = None
122122
map_number = None
123-
for _, test_meta in enumerate(
124-
metadata["ntrode_electrode_group_channel_map"]
125-
):
123+
for _, test_meta in enumerate(metadata["ntrode_electrode_group_channel_map"]):
126124
if str(test_meta["ntrode_id"]) == ntrode_id:
127125
channel_map = test_meta
128126
break

src/trodes_to_nwb/convert_yaml.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
initial NWB file setup, subject info, device entries, electrode tables, etc.
44
"""
55

6-
from copy import deepcopy
7-
from datetime import datetime
86
import logging
97
import uuid
8+
from copy import deepcopy
9+
from datetime import datetime
1010
from xml.etree import ElementTree
1111

12+
import pandas as pd
13+
import pytz
14+
import yaml
1215
from hdmf.common.table import DynamicTable, VectorData
1316
from ndx_franklab_novela import (
1417
AssociatedFiles,
@@ -19,14 +22,11 @@
1922
Shank,
2023
ShanksElectrode,
2124
)
22-
import pandas as pd
2325
from pynwb import NWBFile
2426
from pynwb.file import ProcessingModule, Subject
25-
import pytz
26-
import yaml
2727

28-
from trodes_to_nwb import __version__
2928
import trodes_to_nwb.metadata_validation
29+
from trodes_to_nwb import __version__
3030

3131

3232
def load_metadata(

0 commit comments

Comments
 (0)