Skip to content

Commit

Permalink
keep function behavior for deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
stephprince committed Dec 18, 2024
1 parent 01be0fb commit 7b4e197
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 30 deletions.
1 change: 1 addition & 0 deletions src/pynwb/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def add_container(self, **kwargs):
Add an NWBContainer to this ProcessingModule
'''
warn("add_container is deprecated. Use add instead.", DeprecationWarning)
self.add(kwargs['container'])

@docval({'name': 'container_name', 'type': str, 'doc': 'the name of the NWBContainer to retrieve'})
def get_container(self, **kwargs):
Expand Down
9 changes: 4 additions & 5 deletions src/pynwb/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,17 @@ def __init__(self, **kwargs):
"Use description instead.")
)
if notes != '' and description is not None:
self._error_on_new_warn_on_construct(
error_msg='Cannot provide both notes and description to ScratchData.__init__. The description '
'argument is recommended.'
)
raise ValueError('Cannot provide both notes and description to ScratchData.__init__. The description '
'argument is recommended.')
description = notes
if not description:
self._error_on_new_warn_on_construct(error_msg='ScratchData.description is required by PyNWB > 3.0.')
self._error_on_new_warn_on_construct(error_msg='ScratchData.description is required.')

Check warning on line 140 in src/pynwb/core.py

View check run for this annotation

Codecov / codecov/patch

src/pynwb/core.py#L140

Added line #L140 was not covered by tests
self.description = description

@property
def notes(self):
warn('Use of ScratchData.notes has been deprecated. Use ScratchData.description instead.', DeprecationWarning)

Check warning on line 145 in src/pynwb/core.py

View check run for this annotation

Codecov / codecov/patch

src/pynwb/core.py#L145

Added line #L145 was not covered by tests
return self.description

@notes.setter
def notes(self, value):
Expand Down
2 changes: 2 additions & 0 deletions src/pynwb/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,8 @@ def add_scratch(self, **kwargs):
if notes is not None or table_description != '':
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')

if isinstance(data, (str, int, float, bytes, np.ndarray, list, tuple, pd.DataFrame)):
if name is None:
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/hdf5/test_ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def setUpContainer(self):
with self.assertRaisesWith(ValueError, error_msg):
Clustering(**kwargs)

# create object in construct mode, modelling the behavior of the ObjectMapper on read
# create object in construct mode, modeling the behavior of the ObjectMapper on read
obj = Clustering.__new__(Clustering, in_construct_mode=True)
with self.assertWarnsWith(warn_type=UserWarning, exc_msg=error_msg):
obj.__init__(**kwargs)
Expand Down Expand Up @@ -249,7 +249,7 @@ def setUpContainer(self):
with self.assertRaisesWith(ValueError, msg):
cw = ClusterWaveforms(self.clustering, 'filtering', means, stdevs)

# create object in construct mode, modelling the behavior of the ObjectMapper on read
# create object in construct mode, modeling the behavior of the ObjectMapper on read
cw = ClusterWaveforms.__new__(ClusterWaveforms,
container_source=None,
parent=None,
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/hdf5/test_icephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def setUpContainer(self):
starting_time=123.6, rate=10e3, electrode=self.elec, gain=0.126,
stimulus_description="gotcha ya!", sweep_number=np.uint(4711))

# create the sweeptable in construct mode, modelling the behavior of the ObjectMapper on read
# create the sweeptable in construct mode, modeling the behavior of the ObjectMapper on read
sweeptable = SweepTable.__new__(SweepTable)
sweeptable._in_construct_mode = True
msg = ("SweepTable is deprecated. Use the IntracellularRecordingsTable instead. "
Expand Down Expand Up @@ -228,7 +228,7 @@ def setUpContainer(self):
starting_time=123.6, rate=10e3, electrode=self.elec, gain=0.126,
stimulus_description="gotcha ya!", sweep_number=np.uint(4712))

# create the sweeptable in construct mode, modelling the behavior of the ObjectMapper on read
# create the sweeptable in construct mode, modeling the behavior of the ObjectMapper on read
sweeptable = SweepTable.__new__(SweepTable)
sweeptable._in_construct_mode = True
msg = ("SweepTable is deprecated. Use the IntracellularRecordingsTable instead. "
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def test_init(self):
with self.assertRaisesWith(ValueError, error_msg):
cc = Clustering(**kwargs)

# create object in construct mode, modelling the behavior of the ObjectMapper on read
# create object in construct mode, modeling the behavior of the ObjectMapper on read
cc = Clustering.__new__(Clustering, in_construct_mode=True)
with self.assertWarnsWith(warn_type=UserWarning, exc_msg=error_msg):
cc.__init__(**kwargs)
Expand All @@ -305,7 +305,7 @@ def test_init(self):
num = [3, 4]
peak_over_rms = [5.3, 6.3]

# create object in construct mode, modelling the behavior of the ObjectMapper on read
# create object in construct mode, modeling the behavior of the ObjectMapper on read
error_msg = "The Clustering neurodata type is deprecated. Use pynwb.misc.Units or NWBFile.units instead"
cc = Clustering.__new__(Clustering,
container_source=None,
Expand All @@ -320,7 +320,7 @@ def test_init(self):
with self.assertRaisesWith(ValueError, error_msg):
cw = ClusterWaveforms(cc, 'filtering', means, stdevs)

# create object in construct mode, modelling the behavior of the ObjectMapper on read
# create object in construct mode, modeling the behavior of the ObjectMapper on read
cw = ClusterWaveforms.__new__(ClusterWaveforms,
container_source=None,
parent=None,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_access_processing(self):
with self.assertRaisesWith(ValueError, msg):
self.nwbfile.modules['test_mod']

# create object in construct mode, modelling the behavior of the ObjectMapper on read
# create object in construct mode, modeling the behavior of the ObjectMapper on read
self.nwbfile._in_construct_mode = True
with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg):
modules = self.nwbfile.modules['test_mod']
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_icephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ class NWBFileICEphys(TestCase):
def setUp(self):
self.icephys_electrode = GetElectrode()

def test_sweep_table_deprectation_warn(self):
def test_sweep_table_deprecation_warn(self):
msg = ("SweepTable is deprecated. Use the IntracellularRecordingsTable instead. "
"See also the NWBFile.add_intracellular_recordings function.")

with self.assertRaisesWith(ValueError, msg):
SweepTable()

# create object in construct mode, modelling the behavior of the ObjectMapper on read
# create object in construct mode, modeling the behavior of the ObjectMapper on read
sweepT = SweepTable.__new__(SweepTable, in_construct_mode=True)
with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg):
sweepT.__init__()
Expand All @@ -60,7 +60,7 @@ def test_sweep_table_deprectation_warn(self):
with self.assertRaisesWith(ValueError, msg):
NWBFile(**kwargs)

# create object in construct mode, modelling the behavior of the ObjectMapper on read
# create object in construct mode, modeling the behavior of the ObjectMapper on read
nwbfile = NWBFile.__new__(NWBFile, in_construct_mode=True)

with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg):
Expand All @@ -76,7 +76,7 @@ def test_ic_electrodes_parameter_deprecation(self):
with self.assertRaisesWith(ValueError, msg):
NWBFile(**kwargs)

# create object in construct mode, modelling the behavior of the ObjectMapper on read
# create object in construct mode, modeling the behavior of the ObjectMapper on read
nwbfile = NWBFile.__new__(NWBFile, in_construct_mode=True)
with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg):
nwbfile.__init__(**kwargs)
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/test_icephys_metadata_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ def test_deprecate_sweeptable_on_add_stimulus_template(self):
nwbfile.add_stimulus_template(local_stimulus, use_sweep_table=True)
# NOTE - the sweep table creation will error but the stimulus template will still be added

# create object in construct mode, modelling the behavior of the ObjectMapper on read
# create object in construct mode, modeling the behavior of the ObjectMapper on read
nwbfile._in_construct_mode = True
with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg):
nwbfile.add_stimulus_template(local_stimulus2, use_sweep_table=True)
Expand Down Expand Up @@ -1239,7 +1239,7 @@ def test_deprecate_sweepstable_on_init(self):
with self.assertRaisesWith(ValueError, msg):
nwbfile = NWBFile(**kwargs)

# create object in construct mode, modelling the behavior of the ObjectMapper on read
# create object in construct mode, modeling the behavior of the ObjectMapper on read
nwbfile = NWBFile.__new__(NWBFile, in_construct_mode=True)
with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg):
nwbfile.__init__(**kwargs)
Expand All @@ -1250,7 +1250,7 @@ def test_deprecate_sweepstable_on_init(self):
stimulus = self.__get_stimulus(electrode=electrode)
nwbfile.add_stimulus(stimulus, use_sweep_table=True)

def test_deprectation_icephys_filtering_on_init(self):
def test_deprecation_icephys_filtering_on_init(self):
kwargs = dict(session_description='my first synthetic recording',
identifier='EXAMPLE_ID',
session_start_time=datetime.now(tzlocal()),
Expand All @@ -1261,7 +1261,7 @@ def test_deprectation_icephys_filtering_on_init(self):
with self.assertRaisesWith(ValueError, msg):
nwbfile = NWBFile(**kwargs)

# create object in construct mode, modelling the behavior of the ObjectMapper on read
# create object in construct mode, modeling the behavior of the ObjectMapper on read
nwbfile = NWBFile.__new__(NWBFile, in_construct_mode=True)
with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg):
nwbfile.__init__(**kwargs)
Expand All @@ -1281,7 +1281,7 @@ def test_icephys_filtering_roundtrip(self):
with self.assertRaisesWith(ValueError, msg):
nwbfile.icephys_filtering = 'test filtering'

# create object in construct mode, modelling the behavior of the ObjectMapper on read
# create object in construct mode, modeling the behavior of the ObjectMapper on read
nwbfile._in_construct_mode = True
with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg):
nwbfile.icephys_filtering = 'test filtering'
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def test_external_file_with_incorrect_starting_frame_construct_mode(self):
"ImageSeries 'test_iS': The number of frame indices in "
"'starting_frame' should have the same length as 'external_file'."
)
# Create the image series in construct mode, modelling the behavior
# Create the image series in construct mode, modeling the behavior
# of the ObjectMapper on read while avoiding having to create, write,
# and read and entire NWB file
obj = ImageSeries.__new__(ImageSeries,
Expand Down Expand Up @@ -255,7 +255,7 @@ def test_external_file_default_format(self):
with self.assertRaisesWith(ValueError, msg):
ImageSeries(**kwargs)

# create object in construct mode, modelling the behavior of the ObjectMapper on read
# create object in construct mode, modeling the behavior of the ObjectMapper on read
iS = ImageSeries.__new__(ImageSeries, in_construct_mode=True)
with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg):
iS.__init__(**kwargs)
Expand Down Expand Up @@ -352,7 +352,7 @@ def test_init_bad_unit(self):
with self.assertRaisesWith(ValueError, msg):
IndexSeries(**kwargs)

# create object in construct mode, modelling the behavior of the ObjectMapper on read
# create object in construct mode, modeling the behavior of the ObjectMapper on read
iS = IndexSeries.__new__(IndexSeries, in_construct_mode=True)
with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg):
iS.__init__(**kwargs)
Expand All @@ -377,7 +377,7 @@ def test_init_indexed_ts(self):
with self.assertRaisesWith(ValueError, msg):
IndexSeries(**kwargs)

# create object in construct mode, modelling the behavior of the ObjectMapper on read
# create object in construct mode, modeling the behavior of the ObjectMapper on read
iS = IndexSeries.__new__(IndexSeries, in_construct_mode=True)
with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg):
iS.__init__(**kwargs)
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_ophys.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def test_manifold_deprecated(self):
with self.assertRaisesWith(ValueError, msg):
ImagingPlane(**kwargs)

# create object in construct mode, modelling the behavior of the ObjectMapper on read
# create object in construct mode, modeling the behavior of the ObjectMapper on read
obj = ImagingPlane.__new__(ImagingPlane, in_construct_mode=True)
with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg):
obj.__init__(**kwargs)
Expand All @@ -168,7 +168,7 @@ def test_conversion_deprecated(self):
with self.assertRaisesWith(ValueError, msg):
ImagingPlane(**kwargs)

# create object in construct mode, modelling the behavior of the ObjectMapper on read
# create object in construct mode, modeling the behavior of the ObjectMapper on read
obj = ImagingPlane.__new__(ImagingPlane, in_construct_mode=True)
with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg):
obj.__init__(**kwargs)
Expand All @@ -191,7 +191,7 @@ def test_unit_deprecated(self):
with self.assertRaisesWith(ValueError, msg):
ImagingPlane(**kwargs)

# create object in construct mode, modelling the behavior of the ObjectMapper on read
# create object in construct mode, modeling the behavior of the ObjectMapper on read
obj = ImagingPlane.__new__(ImagingPlane, in_construct_mode=True)
with self.assertWarnsWith(warn_type=UserWarning, exc_msg=msg):
obj.__init__(**kwargs)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_scratch.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_scratch_notes_deprecation(self):
with self.assertRaisesWith(ValueError, msg):
ScratchData(name='test', data=[1, 2, 3, 4, 5], notes='test notes')

# create object in construct mode, modelling the behavior of the ObjectMapper on read
# create object in construct mode, modeling the behavior of the ObjectMapper on read
data = ScratchData.__new__(ScratchData, in_construct_mode=True)
with self.assertWarnsWith(UserWarning, msg):
data.__init__(name='test', data=[1, 2, 3, 4, 5], notes='test notes')
Expand Down

0 comments on commit 7b4e197

Please sign in to comment.