Skip to content

Commit b3d35f3

Browse files
bastibemgeier
authored andcommitted
removed indexing
1 parent febda2e commit b3d35f3

File tree

2 files changed

+1
-58
lines changed

2 files changed

+1
-58
lines changed

soundfile.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -728,46 +728,6 @@ def __getattr__(self, name):
728728
def __len__(self):
729729
return self._info.frames
730730

731-
def __getitem__(self, frame):
732-
# access the file as if it where a Numpy array. The data is
733-
# returned as numpy array.
734-
from warnings import warn
735-
warn('indexing has been deprecated and will be removed in the future',
736-
Warning)
737-
second_frame = None
738-
if isinstance(frame, tuple):
739-
if len(frame) > 2:
740-
raise AttributeError(
741-
"SoundFile can only be accessed in one or two dimensions")
742-
frame, second_frame = frame
743-
start, stop = self._get_slice_bounds(frame)
744-
curr = self.seek(0, SEEK_CUR)
745-
self.seek(start, SEEK_SET)
746-
data = self.read(stop - start)
747-
self.seek(curr, SEEK_SET)
748-
if second_frame:
749-
return data[(slice(None), second_frame)]
750-
else:
751-
return data
752-
753-
def __setitem__(self, frame, data):
754-
# access the file as if it where a one-dimensional Numpy
755-
# array. Data must be in the form (frames x channels).
756-
# Both open slice bounds and negative values are allowed.
757-
from warnings import warn
758-
warn('indexing has been deprecated and will be removed in the future',
759-
Warning)
760-
start, stop = self._get_slice_bounds(frame)
761-
if stop - start != len(data):
762-
raise IndexError(
763-
"Could not fit data of length %i into slice of length %i" %
764-
(len(data), stop - start))
765-
curr = self.seek(0, SEEK_CUR)
766-
self.seek(start, SEEK_SET)
767-
self.write(data)
768-
self.seek(curr, SEEK_SET)
769-
return data
770-
771731
def seekable(self):
772732
"""Return True if the file supports seeking."""
773733
return self._info.seekable == _snd.SF_TRUE

tests/test_pysoundfile.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ def test_non_clipping_float_to_float(file_inmemory):
470470

471471

472472
def test_file_content(sf_stereo_r):
473-
assert np.all(data_stereo == sf_stereo_r[:])
473+
assert np.all(data_stereo == sf_stereo_r.read())
474474

475475

476476
def test_file_attributes_in_read_mode(sf_stereo_r):
@@ -577,11 +577,6 @@ def test_read_should_read_data_and_advance_read_pointer(sf_stereo_r):
577577
assert sf_stereo_r.seek(0, sf.SEEK_CUR) == 2
578578

579579

580-
def test_read_by_indexing_should_read_but_not_advance_read_pointer(
581-
sf_stereo_r):
582-
assert np.all(sf_stereo_r[:2] == data_stereo[:2])
583-
assert sf_stereo_r.seek(0, sf.SEEK_CUR) == 0
584-
585580

586581
def test_read_n_frames_should_return_n_frames(sf_stereo_r):
587582
assert len(sf_stereo_r.read(2)) == 2
@@ -661,18 +656,6 @@ def test_wplus_read_written_data(sf_stereo_wplus):
661656
assert np.all(data == data_stereo)
662657

663658

664-
def test_wplus_writing_using_indexing_should_write_but_not_advance_write_pointer(
665-
sf_stereo_wplus):
666-
data = np.ones((5, 2))
667-
# grow file to make room for indexing
668-
sf_stereo_wplus.write(np.zeros((5, 2)))
669-
position = sf_stereo_wplus.seek(0, sf.SEEK_CUR)
670-
sf_stereo_wplus[:len(data)] = data
671-
written_data = sf_stereo_wplus[:len(data)]
672-
assert np.all(data == written_data)
673-
assert position == sf_stereo_wplus.seek(0, sf.SEEK_CUR)
674-
675-
676659
def test_rplus_append_data(sf_stereo_rplus):
677660
sf_stereo_rplus.seek(0, sf.SEEK_END)
678661
sf_stereo_rplus.write(data_stereo / 2)

0 commit comments

Comments
 (0)