Skip to content

Commit

Permalink
Merge pull request #3047 from lanzagar/save-compression
Browse files Browse the repository at this point in the history
[ENH] Save data with compression
  • Loading branch information
BlazZupan authored Jun 13, 2018
2 parents 459044b + b8ef72f commit 0eb8389
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
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

0 comments on commit 0eb8389

Please sign in to comment.