本文整理汇总了Python中Orange.data.io.FileFormat类的典型用法代码示例。如果您正苦于以下问题:Python FileFormat类的具体用法?Python FileFormat怎么用?Python FileFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileFormat类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_wildcard_extension
def test_wildcard_extension(self):
self.assertIsInstance(FileFormat.get_reader("t.wild"),
WildcardReader)
self.assertIsInstance(FileFormat.get_reader("t.wild2"),
WildcardReader)
with self.assertRaises(OSError):
FileFormat.get_reader("t.wild2a")
示例2: dragEnterEvent
def dragEnterEvent(self, event):
"""Accept drops of valid file urls"""
urls = event.mimeData().urls()
if urls:
try:
FileFormat.get_reader(urls[0].toLocalFile())
event.acceptProposedAction()
except IOError:
pass
示例3: test_locate_sample_datasets
def test_locate_sample_datasets(self):
with self.assertRaises(OSError):
FileFormat.locate("iris.tab",
search_dirs=[os.path.dirname(__file__)])
iris = FileFormat.locate("iris.tab",
search_dirs=[get_sample_datasets_dir()])
self.assertEqual(os.path.basename(iris), "iris.tab")
# test extension adding
iris = FileFormat.locate("iris",
search_dirs=[get_sample_datasets_dir()])
self.assertEqual(os.path.basename(iris), "iris.tab")
示例4: test_locate_wildcard_extension
def test_locate_wildcard_extension(self):
tempdir = tempfile.mkdtemp()
with self.assertRaises(OSError):
FileFormat.locate("t.wild9", search_dirs=[tempdir])
fn = os.path.join(tempdir, "t.wild8")
with open(fn, "wt") as f:
f.write("\n")
l = FileFormat.locate("t.wild8", search_dirs=[tempdir])
self.assertEqual(l, fn)
# test extension adding
l = FileFormat.locate("t", search_dirs=[tempdir])
self.assertEqual(l, fn)
shutil.rmtree(tempdir)
示例5: _get_reader
def _get_reader(self):
"""
Returns
-------
FileFormat
"""
if self.source == self.LOCAL_FILE:
path = self.last_path()
if path is None:
return self.NoFileSelected
if self.recent_paths and self.recent_paths[0].file_format:
qname = self.recent_paths[0].file_format
reader_class = class_from_qualified_name(qname)
reader = reader_class(path)
else:
reader = FileFormat.get_reader(path)
if self.recent_paths and self.recent_paths[0].sheet:
reader.select_sheet(self.recent_paths[0].sheet)
return reader
else:
url = self.url_combo.currentText().strip()
if url:
return UrlReader(url)
else:
return self.NoFileSelected
示例6: get_writer_selected
def get_writer_selected(self):
writer = FileFormat.get_reader(self.type_ext)
ext = self.type_ext + self.compress_ext
if ext not in writer.EXTENSIONS:
self.Error.unsupported_extension()
return None
writer.EXTENSIONS = [ext]
return writer
示例7: load_from_file
def load_from_file():
filename = self.last_path()
if not filename:
return None, ""
if not os.path.exists(filename):
filename = os.path.basename(filename)
filename = FileFormat.locate(filename, "")
self.information("Loading '{}' from the current directory."
.format(filename))
reader = FileFormat.get_reader(filename)
if isinstance(reader, ExcelReader):
reader.select_sheet(self.xls_sheet)
try:
return load(lambda x: reader.read(), filename)
except Exception as exc:
self.warnings.setText(str(exc))
# Let us not remove from recent files: user may fix them
raise
示例8: _get_reader
def _get_reader(self):
"""
Returns
-------
FileFormat
"""
if self.source == self.LOCAL_FILE:
reader = FileFormat.get_reader(self.last_path())
if self.recent_paths and self.recent_paths[0].sheet:
reader.select_sheet(self.recent_paths[0].sheet)
return reader
elif self.source == self.URL:
return UrlReader(self.url_combo.currentText())
示例9: test_mosaic_ifg_read
def test_mosaic_ifg_read(self):
# This reader will only be selected manually due to shared .dmt extension
absolute_filename = FileFormat.locate("agilent/5_mosaic_agg1024.dmt",
Orange.data.table.dataset_dirs)
d = agilentMosaicIFGReader(absolute_filename).read()
self.assertEqual(len(d), 32)
self.assertEqual(len(d.domain.attributes), 311)
# Pixel sizes are 5.5 * 32 = 176.0 (binning to reduce test data)
self.assertAlmostEqual(
d[1]["map_x"] - d[0]["map_x"], 176.0)
self.assertAlmostEqual(
d[4]["map_y"] - d[3]["map_y"], 176.0)
# Last pixel should start at (4 - 1) * 176.0 = 528.0
self.assertAlmostEqual(d[-1]["map_x"], 528.0)
# 1 x 2 mosiac, (8 - 1) * 176.0 = 1232.0
self.assertAlmostEqual(d[-1]["map_y"], 1232.0)
self.assertAlmostEqual(d[21][0], 0.7116039)
self.assertAlmostEqual(d[26][0], 0.48532167)
# Metadata
self.assertEqual(d.metas[0, 2], 1.57980039e+04)
self.assertEqual(d.metas[0, 3], 4)
示例10: test_find_reader
def test_find_reader(self):
reader = FileFormat.get_reader("some.same_extension")
self.assertIsInstance(reader, SameExtensionPreferred)
示例11: test_usual_extensions
def test_usual_extensions(self):
self.assertIsInstance(FileFormat.get_reader("t.tab"), TabReader)
self.assertIsInstance(FileFormat.get_reader("t.csv"), CSVReader)
self.assertIsInstance(FileFormat.get_reader("t.pkl"), PickleReader)
with self.assertRaises(OSError):
FileFormat.get_reader("test.undefined_extension")
示例12: is_multisheet_excel
def is_multisheet_excel(fn):
return len(FileFormat.get_reader(fn).sheets) > 0
示例13: _get_reader
def _get_reader(rp):
if rp.file_format:
reader_class = class_from_qualified_name(rp.file_format)
return reader_class(rp.abspath)
else:
return FileFormat.get_reader(rp.abspath)