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

[ENH] Save data with compression #3047

Merged
merged 5 commits into from
Jun 13, 2018
Merged
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
17 changes: 10 additions & 7 deletions Orange/data/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,15 @@ def __new__(cls, name, bases, attrs):
for compression in Compression.all:
for ext in newcls.EXTENSIONS:
new_extensions.append(ext + compression)
if sys.platform in ('darwin', 'win32'):
# OSX file dialog doesn't support filtering on double
# extensions (e.g. .csv.gz)
# https://bugreports.qt.io/browse/QTBUG-38303
# This is just here for OWFile that gets QFileDialog
# filters from FileFormat.readers.keys()
if sys.platform == 'darwin':
new_extensions.append(compression)
# EDIT: Windows exhibit similar problems:
# while .tab.gz works, .tab.xz and .tab.bz2 do not!
new_extensions.append(compression)
newcls.EXTENSIONS = tuple(new_extensions)

return newcls
Expand Down Expand Up @@ -911,21 +913,22 @@ class TabReader(CSVReader):

class PickleReader(FileFormat):
"""Reader for pickled Table objects"""
EXTENSIONS = ('.pickle', '.pkl')
EXTENSIONS = ('.pkl', '.pickle')
DESCRIPTION = 'Pickled Python object file'
SUPPORT_COMPRESSED = True
SUPPORT_SPARSE_DATA = True

def read(self):
with open(self.filename, 'rb') as f:
with self.open(self.filename, 'rb') as f:
table = pickle.load(f)
if not isinstance(table, Table):
raise TypeError("file does not contain a data table")
else:
return table

@staticmethod
def write_file(filename, data):
with open(filename, 'wb') as f:
@classmethod
def write_file(cls, filename, data):
with cls.open(filename, 'wb') as f:
pickle.dump(data, f, pickle.HIGHEST_PROTOCOL)


Expand Down
5 changes: 4 additions & 1 deletion Orange/widgets/utils/filedialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from AnyQt.QtWidgets import \
QMessageBox, QFileDialog, QFileIconProvider, QComboBox

from Orange.data.io import FileFormat
from Orange.data.io import FileFormat, Compression
from Orange.widgets.settings import Setting
from Orange.util import deprecated

Expand Down Expand Up @@ -82,6 +82,9 @@ def open_filename_dialog_save(start_dir, start_filter, file_formats):
return None, None, None

base, ext = os.path.splitext(filename)
if ext in Compression.all:
base, base_ext = os.path.splitext(base)
ext = base_ext + ext
if not ext:
filename += format.EXTENSIONS[0]
elif ext not in format.EXTENSIONS:
Expand Down