Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update deprecations #2011

Merged
merged 24 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0dce442
update deprecated classes and methods
stephprince Dec 17, 2024
71dd68b
update deprecation warnings
stephprince Dec 18, 2024
1d0ed92
update tests for deprecated classes and functions
stephprince Dec 18, 2024
93ae7a1
fix warnings and formatting
stephprince Dec 18, 2024
01be0fb
add scratch tests and deprecations
stephprince Dec 18, 2024
7b4e197
keep function behavior for deprecation warnings
stephprince Dec 18, 2024
478454e
update CHANGELOG.md
stephprince Dec 18, 2024
095ce84
add tests for deprecations
stephprince Dec 18, 2024
c62ebd4
update scratch tutorial
stephprince Dec 18, 2024
d2934b6
skip deprecated gallery examples
stephprince Dec 18, 2024
e885275
Merge branch 'dev' into deprecation-errors
stephprince Dec 19, 2024
190bd72
Merge branch 'dev' into deprecation-errors
stephprince Dec 21, 2024
de32f40
update CHANGELOG.md
stephprince Dec 21, 2024
fe6a0f5
remove old icephys tutorial
stephprince Dec 21, 2024
f971a1a
add pynwb 4.0 deprecation info
stephprince Dec 21, 2024
363d1fa
add error on new pass on construct method
stephprince Dec 21, 2024
bb2d82d
remove warnings on construct for deprecations
stephprince Dec 21, 2024
7ec06b0
fix formatting
stephprince Dec 22, 2024
4edc013
update hdmf-zarr url
stephprince Dec 22, 2024
419d685
Apply suggestions from code review
stephprince Dec 23, 2024
5dee6e0
Update src/pynwb/core.py
stephprince Dec 23, 2024
1cf28a1
add code review suggestions
stephprince Dec 23, 2024
ac6a98a
add catch for extra warning
stephprince Dec 23, 2024
1c4bca2
remove unused variable
stephprince Dec 23, 2024
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## PyNWB 3.0.0 (Upcoming)

### Deprecations
- The following deprecated classes will now raise errors when creating new instances of these classes: ClusteringWaveforms, Clustering, SweepTable. Reading files using these data types will continue to be supported.
- The following methods and arguments have been deprecated: ProcessingModule.add_container, ProcessingModule.get_container, ProcessingModule.add_data_interface, ProcessingModule.get_data_interface, ScratchData.notes, NWBFile.ic_electrodes, NWBFile.ec_electrodes, NWBFile.icephys_filtering, NWBFile.modules, ImageSeries.bits_per_pixel, ImageSeries.format, ImagingPlane.manifold, ImagingPlane.conversion, IndexSeries.unit, IndexSeries.indexed_timeseries
stephprince marked this conversation as resolved.
Show resolved Hide resolved
- The following deprecated methods have been removed: NWBFile.add_ic_electrode, NWBFile.create_ic_electrode, NWBFile.get_ic_electrode, pynwb._get_resources

### Enhancements and minor changes
- Added support for NWB schema 2.8.0. @rly [#2001](https://github.com/NeurodataWithoutBorders/pynwb/pull/2001)
- Removed `SpatialSeries.bounds` field that was not functional. This will be fixed in a future release. @rly [#1907](https://github.com/NeurodataWithoutBorders/pynwb/pull/1907), [#1996](https://github.com/NeurodataWithoutBorders/pynwb/pull/1996)
Expand Down
2 changes: 1 addition & 1 deletion docs/gallery/general/scratch.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
# Now lets do an analysis for which we do not have a specification, but we would like to store
# the results for.

filt_ts = nwb_scratch.modules["filtering_module"]["filtered_timeseries"]
filt_ts = nwb_scratch.processing["filtering_module"]["filtered_timeseries"]

fft = np.fft.fft(filt_ts.data)

Expand Down
6 changes: 0 additions & 6 deletions src/pynwb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ def __get_resources() -> dict:
return ret


def _get_resources():
# LEGACY: Needed to support legacy implementation.
# TODO: Remove this in PyNWB 3.0.
warn("The function '_get_resources' is deprecated and will be removed in a future release.", DeprecationWarning)
return __get_resources()


# a global type map
global __TYPE_MAP
Expand Down
9 changes: 4 additions & 5 deletions src/pynwb/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,25 @@ def add_container(self, **kwargs):
'''
Add an NWBContainer to this ProcessingModule
'''
warn(PendingDeprecationWarning('add_container will be replaced by add'))
warn("add_container is deprecated. Use add instead.", DeprecationWarning)
rly marked this conversation as resolved.
Show resolved Hide resolved
stephprince marked this conversation as resolved.
Show resolved Hide resolved
self.add(kwargs['container'])

@docval({'name': 'container_name', 'type': str, 'doc': 'the name of the NWBContainer to retrieve'})
def get_container(self, **kwargs):
'''
Retrieve an NWBContainer from this ProcessingModule
'''
warn(PendingDeprecationWarning('get_container will be replaced by get'))
warn('get_container is deprecated. Use get instead.', DeprecationWarning)
return self.get(kwargs['container_name'])

@docval({'name': 'NWBDataInterface', 'type': (NWBDataInterface, DynamicTable),
'doc': 'the NWBDataInterface to add to this Module'})
def add_data_interface(self, **kwargs):
warn(PendingDeprecationWarning('add_data_interface will be replaced by add'))
self.add(kwargs['NWBDataInterface'])
warn('add_data_interface is deprecated. Use add instead.', DeprecationWarning)

@docval({'name': 'data_interface_name', 'type': str, 'doc': 'the name of the NWBContainer to retrieve'})
def get_data_interface(self, **kwargs):
warn(PendingDeprecationWarning('get_data_interface will be replaced by get'))
warn('get_data_interface is deprecated. Use get instead.', DeprecationWarning)
return self.get(kwargs['data_interface_name'])


Expand Down
20 changes: 10 additions & 10 deletions src/pynwb/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,27 +128,27 @@ def __init__(self, **kwargs):
notes, description = popargs('notes', 'description', kwargs)
super().__init__(**kwargs)
if notes != '':
warn('The `notes` argument of ScratchData.__init__ will be deprecated. Use description instead.',
PendingDeprecationWarning)
if notes != '' and description != '':
self._error_on_new_warn_on_construct(
error_msg=("The `notes` argument of ScratchData.__init__ has been deprecated. "
"Use description instead.")
)
if notes != '' and description is not None:
stephprince marked this conversation as resolved.
Show resolved Hide resolved
raise ValueError('Cannot provide both notes and description to ScratchData.__init__. The description '
'argument is recommended.')
description = notes
if not description:
warn('ScratchData.description will be required in a future major release of PyNWB.',
PendingDeprecationWarning)
self._error_on_new_warn_on_construct(error_msg='ScratchData.description is required.')
self.description = description

@property
def notes(self):
warn('Use of ScratchData.notes will be deprecated. Use ScratchData.description instead.',
PendingDeprecationWarning)
warn('Use of ScratchData.notes has been deprecated. Use ScratchData.description instead.', DeprecationWarning)
stephprince marked this conversation as resolved.
Show resolved Hide resolved
return self.description

@notes.setter
def notes(self, value):
warn('Use of ScratchData.notes will be deprecated. Use ScratchData.description instead.',
PendingDeprecationWarning)
self._error_on_new_warn_on_construct(
error_msg='Use of ScratchData.notes has been deprecated. Use ScratchData.description instead.')
self.description = value


Expand Down
8 changes: 6 additions & 2 deletions src/pynwb/ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ class Clustering(NWBDataInterface):
'shape': (None,)},
{'name': 'name', 'type': str, 'doc': 'the name of this container', 'default': 'Clustering'})
def __init__(self, **kwargs):
warnings.warn("use pynwb.misc.Units or NWBFile.units instead", DeprecationWarning)
self._error_on_new_warn_on_construct(
error_msg='The Clustering neurodata type is deprecated. Use pynwb.misc.Units or NWBFile.units instead'
)
args_to_set = popargs_to_dict(('description', 'num', 'peak_over_rms', 'times'), kwargs)
super().__init__(**kwargs)
args_to_set['peak_over_rms'] = list(args_to_set['peak_over_rms'])
Expand Down Expand Up @@ -261,7 +263,9 @@ class ClusterWaveforms(NWBDataInterface):
'doc': 'the standard deviations of waveforms for each cluster'},
{'name': 'name', 'type': str, 'doc': 'the name of this container', 'default': 'ClusterWaveforms'})
def __init__(self, **kwargs):
warnings.warn("use pynwb.misc.Units or NWBFile.units instead", DeprecationWarning)
self._error_on_new_warn_on_construct(
error_msg='The ClusterWaveforms neurodata type is deprecated. Use pynwb.misc.Units or NWBFile.units instead'
)
args_to_set = popargs_to_dict(('clustering_interface', 'waveform_filtering',
'waveform_mean', 'waveform_sd'), kwargs)
super().__init__(**kwargs)
Expand Down
97 changes: 35 additions & 62 deletions src/pynwb/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ class NWBFile(MultiContainerInterface, HERDManager):
'doc': 'DEPRECATED use icephys_electrodes parameter instead. '
'IntracellularElectrodes that belong to this NWBFile', 'default': None},
stephprince marked this conversation as resolved.
Show resolved Hide resolved
{'name': 'sweep_table', 'type': SweepTable,
'doc': 'the SweepTable that belong to this NWBFile', 'default': None},
'doc': '[DEPRECATED] Use IntracellularRecordingsTable instead. '
'The SweepTable that belong to this NWBFile', 'default': None},
{'name': 'imaging_planes', 'type': (list, tuple),
'doc': 'ImagingPlanes that belong to this NWBFile', 'default': None},
{'name': 'ogen_sites', 'type': (list, tuple),
Expand Down Expand Up @@ -491,11 +492,17 @@ def __init__(self, **kwargs):
icephys_electrodes = args_to_set['icephys_electrodes']
ic_electrodes = args_to_set['ic_electrodes']
if icephys_electrodes is None and ic_electrodes is not None:
stephprince marked this conversation as resolved.
Show resolved Hide resolved
warn("Use of the ic_electrodes parameter is deprecated. "
"Use the icephys_electrodes parameter instead", DeprecationWarning)
self._error_on_new_warn_on_construct(error_msg=("Use of the ic_electrodes parameter is deprecated. "
"Use the icephys_electrodes parameter instead"))
args_to_set['icephys_electrodes'] = ic_electrodes
args_to_set.pop('ic_electrodes') # do not set this arg

# backwards-compatibility for sweep table
if args_to_set['sweep_table'] is not None:
self._error_on_new_warn_on_construct(error_msg=("SweepTable is deprecated. Use the "
"IntracellularRecordingsTable instead. See also the "
"NWBFile.add_intracellular_recordings function."))

# convert single experimenter to tuple
experimenter = args_to_set['experimenter']
if isinstance(experimenter, str):
Expand Down Expand Up @@ -552,7 +559,7 @@ def objects(self):

@property
def modules(self):
warn("NWBFile.modules has been replaced by NWBFile.processing.", DeprecationWarning)
self._error_on_new_warn_on_construct(error_msg="NWBFile.modules is deprecated. Use NWBFile.processing instead.")
rly marked this conversation as resolved.
Show resolved Hide resolved
return self.processing

@property
Expand All @@ -561,17 +568,20 @@ def epoch_tags(self):

@property
def ec_electrode_groups(self):
warn("NWBFile.ec_electrode_groups has been replaced by NWBFile.electrode_groups.", DeprecationWarning)
self._error_on_new_warn_on_construct(error_msg=("NWBFile.ec_electrode_groups is deprecated. "
"Use NWBFile.electrode_groups instead."))
return self.electrode_groups

@property
def ec_electrodes(self):
warn("NWBFile.ec_electrodes has been replaced by NWBFile.electrodes.", DeprecationWarning)
self._error_on_new_warn_on_construct(error_msg=("NWBFile.ec_electrodes is deprecated. "
"Use NWBFile.electrodes instead."))
return self.electrodes

@property
def ic_electrodes(self):
warn("NWBFile.ic_electrodes has been replaced by NWBFile.icephys_electrodes.", DeprecationWarning)
self._error_on_new_warn_on_construct(error_msg=("NWBFile.ic_electrodes is deprecated. "
"Use NWBFile.icephys_electrodes instead."))
return self.icephys_electrodes

@property
Expand All @@ -581,34 +591,10 @@ def icephys_filtering(self):
@icephys_filtering.setter
def icephys_filtering(self, val):
if val is not None:
warn("Use of icephys_filtering is deprecated. Use the IntracellularElectrode.filtering field instead",
DeprecationWarning)
self._error_on_new_warn_on_construct("Use of icephys_filtering is deprecated. "
stephprince marked this conversation as resolved.
Show resolved Hide resolved
"Use the IntracellularElectrode.filtering field instead")
self.fields['icephys_filtering'] = val

def add_ic_electrode(self, *args, **kwargs):
"""
This method is deprecated and will be removed in future versions. Please
use :py:meth:`~pynwb.file.NWBFile.add_icephys_electrode` instead
"""
warn("NWBFile.add_ic_electrode has been replaced by NWBFile.add_icephys_electrode.", DeprecationWarning)
return self.add_icephys_electrode(*args, **kwargs)

def create_ic_electrode(self, *args, **kwargs):
"""
This method is deprecated and will be removed in future versions. Please
use :py:meth:`~pynwb.file.NWBFile.create_icephys_electrode` instead
"""
warn("NWBFile.create_ic_electrode has been replaced by NWBFile.create_icephys_electrode.", DeprecationWarning)
return self.create_icephys_electrode(*args, **kwargs)

def get_ic_electrode(self, *args, **kwargs):
"""
This method is deprecated and will be removed in future versions. Please
use :py:meth:`~pynwb.file.NWBFile.get_icephys_electrode` instead
"""
warn("NWBFile.get_ic_electrode has been replaced by NWBFile.get_icephys_electrode.", DeprecationWarning)
return self.get_icephys_electrode(*args, **kwargs)

def __check_epochs(self):
if self.epochs is None:
self.epochs = TimeIntervals(name='epochs', description='experimental epochs')
Expand All @@ -622,13 +608,6 @@ def add_epoch_column(self, **kwargs):
self.__check_epochs()
self.epochs.add_column(**kwargs)

def add_epoch_metadata_column(self, *args, **kwargs):
"""
This method is deprecated and will be removed in future versions. Please
use :py:meth:`~pynwb.file.NWBFile.add_epoch_column` instead
"""
raise DeprecationWarning("Please use NWBFile.add_epoch_column")

@docval(*get_docval(TimeIntervals.add_interval),
allow_extra=True)
def add_epoch(self, **kwargs):
Expand Down Expand Up @@ -837,7 +816,12 @@ def _check_sweep_table(self):
Create a SweepTable if not yet done.
"""
if self.sweep_table is None:
self.sweep_table = SweepTable(name='sweep_table')
if self._in_construct_mode:
sweep_table = SweepTable.__new__(SweepTable, parent=self, in_construct_mode=True)
sweep_table.__init__(name='sweep_table')
stephprince marked this conversation as resolved.
Show resolved Hide resolved
else:
sweep_table = SweepTable(name='sweep_table')
self.sweep_table = sweep_table

def _update_sweep_table(self, nwbdata):
"""
Expand All @@ -860,23 +844,11 @@ def add_acquisition(self, **kwargs):

@docval({'name': 'stimulus', 'type': (TimeSeries, DynamicTable, NWBDataInterface), 'default': None,
'doc': 'The stimulus presentation data to add to this NWBFile.'},
{'name': 'use_sweep_table', 'type': bool, 'default': False, 'doc': 'Use the deprecated SweepTable'},
{'name': 'timeseries', 'type': TimeSeries, 'default': None,
'doc': 'The "timeseries" keyword argument is deprecated. Use the "nwbdata" argument instead.'},)
{'name': 'use_sweep_table', 'type': bool, 'default': False, 'doc': 'Use the deprecated SweepTable'},)
stephprince marked this conversation as resolved.
Show resolved Hide resolved
def add_stimulus(self, **kwargs):
stimulus, timeseries = popargs('stimulus', 'timeseries', kwargs)
if stimulus is None and timeseries is None:
raise ValueError(
"The 'stimulus' keyword argument is required. The 'timeseries' keyword argument can be "
"provided for backwards compatibility but is deprecated in favor of 'stimulus' and will be "
"removed in PyNWB 3.0."
)
# TODO remove this support in PyNWB 3.0
if timeseries is not None:
warn("The 'timeseries' keyword argument is deprecated and will be removed in PyNWB 3.0. "
"Use the 'stimulus' argument instead.", DeprecationWarning)
if stimulus is None:
stimulus = timeseries
stimulus = popargs('stimulus', kwargs)
if stimulus is None:
raise ValueError("The 'stimulus' keyword argument is required.")
stephprince marked this conversation as resolved.
Show resolved Hide resolved
self._add_stimulus_internal(stimulus)
use_sweep_table = popargs('use_sweep_table', kwargs)
if use_sweep_table:
Expand Down Expand Up @@ -1061,11 +1033,12 @@ def get_icephys_meta_parent_table(self):
'doc': 'The name of the data. Required only when passing in a scalar, numpy.ndarray, list, or tuple',
'default': None},
{'name': 'notes', 'type': str,
'doc': ('Notes to add to the data. Only used when passing in numpy.ndarray, list, or tuple. This '
'argument is not recommended. Use the `description` argument instead.'),
'doc': ('[DEPRECATED] Notes to add to the data. '
'Only used when passing in numpy.ndarray, list, or tuple. This argument is not recommended. '
'Use the `description` argument instead.'),
stephprince marked this conversation as resolved.
Show resolved Hide resolved
'default': None},
{'name': 'table_description', 'type': str,
'doc': ('Description for the internal DynamicTable used to store a pandas.DataFrame. This '
'doc': ('[DEPRECATED] Description for the internal DynamicTable used to store a pandas.DataFrame. This '
'argument is not recommended. Use the `description` argument instead.'),
stephprince marked this conversation as resolved.
Show resolved Hide resolved
'default': ''},
{'name': 'description', 'type': str,
Expand All @@ -1078,8 +1051,8 @@ def add_scratch(self, **kwargs):
data, name, notes, table_description, description = getargs('data', 'name', 'notes', 'table_description',
'description', kwargs)
if notes is not None or table_description != '':
warn('Use of the `notes` or `table_description` argument will be removed in a future version of PyNWB. '
'Use the `description` argument instead.', PendingDeprecationWarning)
warn(('Use of the `notes` or `table_description` argument is deprecated. '
'Use the `description` argument instead.'), DeprecationWarning)
if description is not None:
raise ValueError('Cannot call add_scratch with (notes or table_description) and description')

Expand Down
9 changes: 6 additions & 3 deletions src/pynwb/icephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,12 @@ class SweepTable(DynamicTable):
'default': "A sweep table groups different PatchClampSeries together."},
*get_docval(DynamicTable.__init__, 'id', 'columns', 'colnames'))
def __init__(self, **kwargs):
warnings.warn("Use of SweepTable is deprecated. Use the IntracellularRecordingsTable "
"instead. See also the NWBFile.add_intracellular_recordings function.",
DeprecationWarning)
error_msg=('SweepTable is deprecated. Use the IntracellularRecordingsTable instead. '
'See also the NWBFile.add_intracellular_recordings function.')
if not self._in_construct_mode:
raise ValueError(error_msg)
warnings.warn(error_msg)

super().__init__(**kwargs)

@docval({'name': 'pcs', 'type': PatchClampSeries,
Expand Down
Loading
Loading