Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5ee1f8b
Switch ruff from select to extend-select
jenshnielsen Mar 31, 2026
abf56fb
Fix FURB105
jenshnielsen Mar 31, 2026
d77b9b4
Fix LOG009
jenshnielsen Mar 31, 2026
789decc
Fix SIM210
jenshnielsen Mar 31, 2026
55ba48a
Fix SIM113
jenshnielsen Mar 31, 2026
a30c522
Fix SIM103
jenshnielsen Mar 31, 2026
886f932
Fix SIM905
jenshnielsen Mar 31, 2026
dc83bac
Fix SIM114
jenshnielsen Mar 31, 2026
19451a5
Fix SIM201
jenshnielsen Mar 31, 2026
e49fc19
Fix SIM222
jenshnielsen Mar 31, 2026
4aac40c
Fix SIM117
jenshnielsen Mar 31, 2026
916e389
Fix SIM102
jenshnielsen Mar 31, 2026
ec31347
Fix FLY002
jenshnielsen Mar 31, 2026
a7252c7
Fix PERF402
jenshnielsen Mar 31, 2026
f88f688
Fix PERF102
jenshnielsen Mar 31, 2026
e2f29cf
Fix TRY201
jenshnielsen Mar 31, 2026
877964e
Enable FURB166
jenshnielsen Mar 31, 2026
d15701f
Fix B016
jenshnielsen Mar 31, 2026
bca8047
Fix C409
jenshnielsen Mar 31, 2026
910997a
Fix PIE808
jenshnielsen Mar 31, 2026
a97cdd1
Fix B010
jenshnielsen Mar 31, 2026
799e4ca
Fix B033
jenshnielsen Mar 31, 2026
0cb8326
Implement B008
jenshnielsen Mar 31, 2026
b982271
Implement B023
jenshnielsen Mar 31, 2026
5e5de2c
Implement C400
jenshnielsen Mar 31, 2026
7687572
Implement C419
jenshnielsen Mar 31, 2026
c2fdb09
Implement C405
jenshnielsen Mar 31, 2026
93ce880
Implement C408 and C414
jenshnielsen Mar 31, 2026
3b56b58
Implement B009
jenshnielsen Mar 31, 2026
63cb6cc
Implement B017
jenshnielsen Mar 31, 2026
ea86384
Implement PT014
jenshnielsen Apr 1, 2026
62e2c42
Implement LOG015
jenshnielsen Apr 1, 2026
212577b
Implement PT031
jenshnielsen Apr 1, 2026
e899a11
Implement PIE790
jenshnielsen Apr 1, 2026
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
8 changes: 4 additions & 4 deletions benchmarking/benchmarks/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class Adding5Params:
timer = time.perf_counter

def __init__(self):
self.parameters = list()
self.values = list()
self.parameters = []
self.values = []
self.experiment = None
self.runner = None
self.datasaver = None
Expand Down Expand Up @@ -116,8 +116,8 @@ def teardown(self, bench_param):
shutil.rmtree(self.tmpdir)
self.tmpdir = None

self.parameters = list()
self.values = list()
self.parameters = []
self.values = []

def time_test(self, bench_param):
"""Adding data for 5 parameters"""
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/DataSet/Accessing-data-in-DataSet.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@
" print(f\"DataFrame for parameter {parameter_name}\")\n",
" print(\"-----------------------------\")\n",
" print(f\"{df.head()!r}\")\n",
" print(\"\")"
" print()"
]
},
{
Expand Down
10 changes: 2 additions & 8 deletions docs/examples/DataSet/Offline Plotting Tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -669,17 +669,11 @@
"\n",
"\n",
"def no_x(xv):\n",
" if xv > 0 and xv < 3:\n",
" return True\n",
" else:\n",
" return False\n",
" return bool(xv > 0 and xv < 3)\n",
"\n",
"\n",
"def no_t(tv):\n",
" if tv > 0 and tv < 450:\n",
" return True\n",
" else:\n",
" return False\n",
" return bool(tv > 0 and tv < 450)\n",
"\n",
"\n",
"with meas.run() as datasaver:\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1742,9 +1742,8 @@
}
],
"source": [
"with qcodes.logger.console_level(\"DEBUG\"):\n",
" with qcodes.logger.filter_instrument(dac):\n",
" dond(set_only_sweep, dmm.v1, dmm.v2)"
"with qcodes.logger.console_level(\"DEBUG\"), qcodes.logger.filter_instrument(dac):\n",
" dond(set_only_sweep, dmm.v1, dmm.v2)"
]
},
{
Expand Down Expand Up @@ -1802,9 +1801,8 @@
}
],
"source": [
"with qcodes.logger.console_level(\"DEBUG\"):\n",
" with qcodes.logger.filter_instrument(dac):\n",
" dond(set_and_get_sweep, dmm.v1, dmm.v2)"
"with qcodes.logger.console_level(\"DEBUG\"), qcodes.logger.filter_instrument(dac):\n",
" dond(set_and_get_sweep, dmm.v1, dmm.v2)"
]
},
{
Expand Down
4 changes: 1 addition & 3 deletions docs/examples/basic_examples/Configuring_QCoDeS.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,7 @@
],
"source": [
"print(\n",
" \"\\n\".join(\n",
" [qc.config.home_file_name, qc.config.env_file_name, qc.config.cwd_file_name]\n",
" )\n",
" f\"{qc.config.home_file_name}\\n{qc.config.env_file_name}\\n{qc.config.cwd_file_name}\"\n",
")"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand All @@ -191,7 +191,7 @@
"source": [
"try:\n",
" s46.A2(\"close\")\n",
" raise (\"We should not be here\")\n",
" raise RuntimeError(\"We should not be here\")\n",
"except KeithleyS46LockAcquisitionError as e:\n",
" print(e)"
]
Expand All @@ -216,7 +216,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand All @@ -230,7 +230,7 @@
"source": [
"try:\n",
" s46.A1(\"close\")\n",
" raise (\"We should not be here\")\n",
" raise RuntimeError(\"We should not be here\")\n",
"except KeithleyS46LockAcquisitionError as e:\n",
" print(e)"
]
Expand All @@ -246,7 +246,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand All @@ -260,7 +260,7 @@
"source": [
"try:\n",
" s46.B2(\"close\")\n",
" raise (\"We should not be here\")\n",
" raise RuntimeError(\"We should not be here\")\n",
"except KeithleyS46LockAcquisitionError as e:\n",
" print(e)"
]
Expand Down
5 changes: 2 additions & 3 deletions docs/examples/logging/logfile_parsing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@
"source": [
"# put the 30MB into a zip file\n",
"filepath = os.path.join(os.getcwd(), \"static\", \"pythonlog.zip\")\n",
"with ZipFile(filepath) as z:\n",
" with z.open(\"pythonlog.log\", \"r\") as f:\n",
" my_log = [line.decode() for line in f]"
"with ZipFile(filepath) as z, z.open(\"pythonlog.log\", \"r\") as f:\n",
" my_log = [line.decode() for line in f]"
]
},
{
Expand Down
26 changes: 13 additions & 13 deletions docs/examples/logging/logging_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,8 @@
],
"source": [
"driver.cartesian((0, 0, 0))\n",
"with logger.console_level(\"DEBUG\"):\n",
" with logger.filter_instrument(mag_x):\n",
" driver.cartesian((0, 0, 1))"
"with logger.console_level(\"DEBUG\"), logger.filter_instrument(mag_x):\n",
" driver.cartesian((0, 0, 1))"
]
},
{
Expand Down Expand Up @@ -330,9 +329,8 @@
],
"source": [
"driver.cartesian((0, 0, 0))\n",
"with logger.console_level(\"DEBUG\"):\n",
" with logger.filter_instrument((mag_x, mag_y)):\n",
" driver.cartesian((0, 0, 1))"
"with logger.console_level(\"DEBUG\"), logger.filter_instrument((mag_x, mag_y)):\n",
" driver.cartesian((0, 0, 1))"
]
},
{
Expand Down Expand Up @@ -360,7 +358,7 @@
"metadata": {},
"outputs": [],
"source": [
"with logger.console_level(logging.WARN):\n",
"with logger.console_level(logging.WARNING):\n",
" driver.cartesian((0, 0, 0))\n",
" with capture_dataframe(level=\"DEBUG\") as (handler, get_dataframe):\n",
" driver.cartesian((0, 0, 1))\n",
Expand Down Expand Up @@ -1197,7 +1195,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1319,12 +1317,14 @@
}
],
"source": [
"with logger.console_level(logging.WARN):\n",
"with logger.console_level(logging.WARNING):\n",
" driver.cartesian((0, 0, 0))\n",
" with capture_dataframe(level=\"DEBUG\") as (handler, get_dataframe):\n",
" with logger.filter_instrument(mag_x, handler=handler):\n",
" driver.cartesian((0, 0, 1))\n",
" df = get_dataframe()\n",
" with (\n",
" capture_dataframe(level=\"DEBUG\") as (handler, get_dataframe),\n",
" logger.filter_instrument(mag_x, handler=handler),\n",
" ):\n",
" driver.cartesian((0, 0, 1))\n",
" df = get_dataframe()\n",
"df"
]
},
Expand Down
12 changes: 10 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ explicit-preview-rules = true
# TID253 banned-module-level-imports
# W pydocstyle
# PLx pylint
select = [
# extend-select = [
extend-select = [
"E", "F", "PT025", "UP", "RUF", "YTT", "INP",
"I", "G", "ISC", "TID253", "NPY", "PLE",
"PLR", "PLC", "PLW", "W",
Expand All @@ -260,7 +261,14 @@ select = [
# PLxxxx are pylint lints that generate a fair amount of warnings
# it may be worth fixing some or these in the future
# PYI036 disable until https://github.com/astral-sh/ruff/issues/9794 is fixed
ignore = ["E501", "G004", "PLR2004", "PLR0913", "PLR0911", "PLR0912", "PLR0915", "PLW0602", "PLW0603", "PLW2901", "PYI036"]
ignore = ["E501", "G004", "PLR2004", "PLR0913", "PLR0911", "PLR0912", "PLR0915", "PLW0602", "PLW0603", "PLW2901", "PYI036",
"B018",
"SIM118", # explicitly allowing keys() is fine
"DTZ007", "DTZ005", "BLE001", "S110",
"N999", "PIE804",
"DTZ006",
"TRY002", "TRY004" # these would require changing exception types
]

# we want to explicitly use the micro symbol
# not the greek letter
Expand Down
13 changes: 6 additions & 7 deletions src/qcodes/dataset/data_set_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,7 @@ def _merge_data_single_param(
)
elif new_values is not None or shape is not None:
(merged_data, new_write_status) = _create_new_data_dict(new_values, shape)
elif existing_values is not None:
merged_data = existing_values
new_write_status = single_tree_write_status
elif shape is None and new_values is None:
elif existing_values is not None or (shape is None and new_values is None):
merged_data = existing_values
new_write_status = single_tree_write_status
else:
Expand Down Expand Up @@ -444,11 +441,13 @@ def _insert_into_data_dict(
data[j] = np.atleast_1d(new_values[i])
return data, None
else:
if existing_values.dtype.kind in ("U", "S"):
if (
existing_values.dtype.kind in ("U", "S")
and new_values.dtype.itemsize > existing_values.dtype.itemsize
):
# string type arrays may be too small for the new data
# read so rescale if needed.
if new_values.dtype.itemsize > existing_values.dtype.itemsize:
existing_values = existing_values.astype(new_values.dtype)
existing_values = existing_values.astype(new_values.dtype)
n_values = new_values.size
new_write_status = write_status + n_values
if new_write_status > existing_values.size:
Expand Down
12 changes: 7 additions & 5 deletions src/qcodes/dataset/data_set_in_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,11 +614,13 @@ def add_metadata(self, tag: str, metadata: Any) -> None:

def _add_to_dyn_column_if_in_db(self, tag: str, data: Any) -> None:
if self._dataset_is_in_runs_table():
with contextlib.closing(
conn_from_dbpath_or_conn(conn=None, path_to_db=self._path_to_db)
) as conn:
with atomic(conn) as aconn:
add_data_to_dynamic_columns(aconn, self.run_id, {tag: data})
with (
contextlib.closing(
conn_from_dbpath_or_conn(conn=None, path_to_db=self._path_to_db)
) as conn,
atomic(conn) as aconn,
):
add_data_to_dynamic_columns(aconn, self.run_id, {tag: data})

@property
def metadata(self) -> dict[str, Any]:
Expand Down
9 changes: 4 additions & 5 deletions src/qcodes/dataset/descriptions/detect_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,10 @@ def _get_shape_of_step(step: int | np.integer[Any] | Sized | npt.NDArray) -> int


def _param_is_array_like(meas_param: ParameterBase) -> bool:
if isinstance(meas_param, (ArrayParameter, ParameterWithSetpoints)):
return True
elif isinstance(meas_param.vals, Arrays):
return True
return False
is_array_like = isinstance(
meas_param, (ArrayParameter, ParameterWithSetpoints)
) or isinstance(meas_param.vals, Arrays)
return is_array_like


def _get_shape_of_arrayparam(param: ParameterBase) -> tuple[int, ...]:
Expand Down
4 changes: 1 addition & 3 deletions src/qcodes/dataset/descriptions/rundescriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ def __eq__(self, other: object) -> bool:
return False
if self.interdeps != other.interdeps:
return False
if self.shapes != other.shapes:
return False
return True
return self.shapes == other.shapes

def __repr__(self) -> str:
return f"RunDescriber({self.interdeps}, Shapes: {self._shapes})"
4 changes: 1 addition & 3 deletions src/qcodes/dataset/descriptions/versioning/v0.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def __eq__(self, other: object) -> bool:
return False
ours = sorted(self.paramspecs, key=lambda ps: ps.name)
theirs = sorted(other.paramspecs, key=lambda ps: ps.name)
if not ours == theirs:
return False
return True
return ours == theirs

def _to_dict(self) -> InterDependenciesDict:
"""
Expand Down
2 changes: 1 addition & 1 deletion src/qcodes/dataset/dond/do2d_retrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def do2d_retrace(
after_inner_actions: ActionsT = (),
measurement_name: str = "",
exp: Experiment | None = None,
additional_setpoints: Sequence[ParameterBase] = tuple(),
additional_setpoints: Sequence[ParameterBase] = (),
show_progress: bool | None = None,
) -> tuple[DataSetProtocol, DataSetProtocol]:
"""
Expand Down
7 changes: 3 additions & 4 deletions src/qcodes/dataset/dond/do_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def do2d(
flush_columns: bool = False,
do_plot: bool | None = None,
use_threads: bool | None = None,
additional_setpoints: Sequence[ParameterBase] = tuple(),
additional_setpoints: Sequence[ParameterBase] = (),
show_progress: bool | None = None,
log_info: str | None = None,
break_condition: BreakConditionT | None = None,
Expand Down Expand Up @@ -214,9 +214,8 @@ def do2d(
*additional_setpoints_data,
)

if callable(break_condition):
if break_condition():
raise BreakConditionInterrupt("Break condition was met.")
if callable(break_condition) and break_condition():
raise BreakConditionInterrupt("Break condition was met.")

for action in after_inner_actions:
action()
Expand Down
Loading
Loading