Skip to content

Commit ec548c2

Browse files
authored
Make add_segmentation kwarg only (#1687)
1 parent b630a43 commit ec548c2

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Removals, Deprecations and Changes
44
* Removed deprecated wrapper functions from `roiextractors_pending_deprecation.py` (March 2026 deadline): `add_imaging_plane_to_nwbfile`, `add_image_segmentation_to_nwbfile`, `add_photon_series_to_nwbfile`, `add_plane_segmentation_to_nwbfile`, `add_background_plane_segmentation_to_nwbfile`, `add_background_fluorescence_traces_to_nwbfile`, `add_summary_images_to_nwbfile`. [PR #1680](https://github.com/catalystneuro/neuroconv/pull/1680)
55
* Added `*args` positional argument deprecation to `add_imaging_to_nwbfile` to enforce keyword-only arguments. Will be enforced on or after September 2026. [PR #1680](https://github.com/catalystneuro/neuroconv/pull/1680)
6+
* Added `*args` positional argument deprecation to `add_segmentation_to_nwbfile` to enforce keyword-only arguments. Will be enforced on or after September 2026. [PR #1687](https://github.com/catalystneuro/neuroconv/pull/1687)
67
* Removed the deprecated `staging` parameter from `automatic_dandi_upload`. Use `sandbox` instead. [PR #1678](https://github.com/catalystneuro/neuroconv/pull/1678)
78
* Removed the deprecated `container_name` parameter from `ImageInterface.add_to_nwbfile` and `DeepLabCutInterface.add_to_nwbfile`. Use `metadata_key` in `__init__` instead. [PR #1678](https://github.com/catalystneuro/neuroconv/pull/1678)
89
* Removed the deprecated `time_series_name` parameter from `add_recording_as_time_series_to_nwbfile`. Use `metadata_key` instead. [PR #1678](https://github.com/catalystneuro/neuroconv/pull/1678)

src/neuroconv/tools/roiextractors/roiextractors.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,6 +1911,7 @@ def add_segmentation_to_nwbfile(
19111911
segmentation_extractor: SegmentationExtractor,
19121912
nwbfile: NWBFile,
19131913
metadata: dict | None = None,
1914+
*args, # TODO: change to * (keyword only) on or after September 2026
19141915
plane_segmentation_name: str | None = None,
19151916
background_plane_segmentation_name: str | None = None,
19161917
include_background_segmentation: bool = False,
@@ -1950,6 +1951,45 @@ def add_segmentation_to_nwbfile(
19501951
NWBFile
19511952
The NWBFile with the added segmentation data.
19521953
"""
1954+
# TODO: Remove this block in September 2026 or after when positional arguments are no longer supported.
1955+
if args:
1956+
parameter_names = [
1957+
"plane_segmentation_name",
1958+
"background_plane_segmentation_name",
1959+
"include_background_segmentation",
1960+
"include_roi_centroids",
1961+
"include_roi_acceptance",
1962+
"mask_type",
1963+
"iterator_options",
1964+
]
1965+
num_positional_args_before_args = 3 # segmentation_extractor, nwbfile, metadata
1966+
if len(args) > len(parameter_names):
1967+
raise TypeError(
1968+
f"add_segmentation_to_nwbfile() takes at most {len(parameter_names) + num_positional_args_before_args} positional arguments but "
1969+
f"{len(args) + num_positional_args_before_args} were given. "
1970+
"Note: Positional arguments are deprecated and will be removed in September 2026 or after. Please use keyword arguments."
1971+
)
1972+
positional_values = dict(zip(parameter_names, args))
1973+
passed_as_positional = list(positional_values.keys())
1974+
warnings.warn(
1975+
f"Passing arguments positionally to add_segmentation_to_nwbfile is deprecated "
1976+
f"and will be removed in September 2026 or after. "
1977+
f"The following arguments were passed positionally: {passed_as_positional}. "
1978+
"Please use keyword arguments instead.",
1979+
FutureWarning,
1980+
stacklevel=2,
1981+
)
1982+
plane_segmentation_name = positional_values.get("plane_segmentation_name", plane_segmentation_name)
1983+
background_plane_segmentation_name = positional_values.get(
1984+
"background_plane_segmentation_name", background_plane_segmentation_name
1985+
)
1986+
include_background_segmentation = positional_values.get(
1987+
"include_background_segmentation", include_background_segmentation
1988+
)
1989+
include_roi_centroids = positional_values.get("include_roi_centroids", include_roi_centroids)
1990+
include_roi_acceptance = positional_values.get("include_roi_acceptance", include_roi_acceptance)
1991+
mask_type = positional_values.get("mask_type", mask_type)
1992+
iterator_options = positional_values.get("iterator_options", iterator_options)
19531993

19541994
# Add device:
19551995
_add_devices_to_nwbfile_old_list_format(nwbfile=nwbfile, metadata=metadata)

0 commit comments

Comments
 (0)