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

Export dialog type fix #1076

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion nion/swift/model/ImportExportManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,9 @@ def can_write(self, data_metadata: DataAndMetadata.DataMetadata, extension: str)
def write_display_item(self, display_item: DisplayItem.DisplayItem, path: pathlib.Path, extension: str) -> None:
data_item = display_item.data_item
assert data_item
assert data_item.data_metadata
data = data_item.data
if data is not None:
if data is not None and self.can_write(data_item.data_metadata, 'csv'):
numpy.savetxt(path, data, delimiter=', ')


Expand Down
12 changes: 12 additions & 0 deletions nion/swift/test/ImportExportManager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,18 @@ def test_data_item_with_numpy_bool_to_data_element_produces_json_compatible_dict
data_element = ImportExportManager.create_data_element_from_data_item(data_item, include_data=False)
json.dumps(data_element)

def test_csv_exporter_handles_3d_data(self):
with TestContext.create_memory_context() as test_context:
document_model = test_context.create_document_model()
data_item = DataItem.DataItem(numpy.zeros((10, 10, 10)))
document_model.append_data_item(data_item)
display_item = document_model.get_display_item_for_data_item(data_item)
current_working_directory = os.getcwd()
file_path = os.path.join(current_working_directory, "__file.csv")
handler = ImportExportManager.CSVImportExportHandler("csv-io-handler", "CSV Raw", ["csv"])
handler.write_display_item(display_item, pathlib.Path(file_path), "csv")
self.assertFalse(os.path.exists(file_path))


if __name__ == '__main__':
logging.getLogger().setLevel(logging.DEBUG)
Expand Down
Loading