Skip to content

Commit

Permalink
always reads raw_timestamps on defragment, add test for data round trip
Browse files Browse the repository at this point in the history
  • Loading branch information
jimkring committed Jan 24, 2024
1 parent 00b3be3 commit 63cfe5f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion nptdms/test/test_example_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,17 @@ def test_defragment_raw_timestamps():
"""Test defragmenting a file with raw timestamps"""
test_file_path = DATA_DIR + '/raw_timestamps.tdms'
output_file = BytesIO()
TdmsWriter.defragment(test_file_path, output_file, raw_timestamps=True)

# verify we can defragment a file with raw timestamps
TdmsWriter.defragment(test_file_path, output_file)

# verify that both files' channel data are the same
input_tdms = tdms.TdmsFile(test_file_path)
output_file.seek(0)
output_tdms = tdms.TdmsFile(output_file)
for group in input_tdms.groups():
for channel in group.channels():
np.testing.assert_equal(channel.data, output_tdms[group.name][channel.name].data)


def test_big_endian_format():
Expand Down
4 changes: 2 additions & 2 deletions nptdms/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TdmsWriter(object):
"""

@classmethod
def defragment(cls, source, destination, version=4712, index_file=False, raw_timestamps=False):
def defragment(cls, source, destination, version=4712, index_file=False):
""" Defragemnts an existing TdmsFile by loading and moving each Object to a separate channel
to stream read one consecutive part of the file for faster access.
Expand All @@ -39,7 +39,7 @@ def defragment(cls, source, destination, version=4712, index_file=False, raw_tim
If ``destination`` is a readable object ``index_file`` can either be a redable object or ``False``
to store a ``.tdms_index`` file inside of the submitted object or not.
"""
file = TdmsFile(source, raw_timestamps)
file = TdmsFile(source, raw_timestamps=True)
with cls(destination, version=version, index_file=index_file) as new_file:
new_file.write_segment([RootObject(file.properties)])
for group in file.groups():
Expand Down

0 comments on commit 63cfe5f

Please sign in to comment.