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

[FIX] Table: from_file/from_url remove type conversion #5812

Merged
merged 2 commits into from
Feb 7, 2022
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
7 changes: 0 additions & 7 deletions Orange/data/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,11 +1077,6 @@ def from_file(cls, filename, sheet=None):
reader.select_sheet(sheet)
data = reader.read()

# Readers return plain table. Make sure to cast it to appropriate
# (subclass) type
if cls != data.__class__:
data = cls(data)

# no need to call _init_ids as fuctions from .io already
# construct a table with .ids

Expand All @@ -1093,8 +1088,6 @@ def from_url(cls, url):
from Orange.data.io import UrlReader
reader = UrlReader(url)
data = reader.read()
if cls != data.__class__:
data = cls(data)
return data

# Helper function for __setitem__:
Expand Down
10 changes: 10 additions & 0 deletions Orange/data/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,16 @@ def test_unpickled_owns_data(self):
with unpickled.unlocked():
unpickled.X[0, 0] = 42

@staticmethod
def test_unlock_table_derived():
# pylint: disable=abstract-method
class ExtendedTable(Table):
pass

t = ExtendedTable.from_file("iris")
with t.unlocked():
pass


class TestTableFilters(unittest.TestCase):
def setUp(self):
Expand Down
5 changes: 4 additions & 1 deletion Orange/tests/test_naive_bayes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@


class NotATable(Table): # pylint: disable=too-many-ancestors,abstract-method
pass
@classmethod
def from_file(cls, *args, **kwargs):
table = super().from_file(*args, **kwargs)
return cls(table)


class TestNaiveBayesLearner(unittest.TestCase):
Expand Down
13 changes: 0 additions & 13 deletions Orange/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2163,19 +2163,6 @@ def test_value_assignment(self):
self.table[i, j] = new_value
self.assertEqual(self.table[i, j], new_value)

def test_subclasses(self):
from pathlib import Path

class _ExtendedTable(data.Table):
pass

data_file = _ExtendedTable('iris')
data_url = _ExtendedTable.from_url(
Path(os.path.dirname(__file__), 'datasets/test1.tab').as_uri())

self.assertIsInstance(data_file, _ExtendedTable)
self.assertIsInstance(data_url, _ExtendedTable)


class TestTableStats(TableTests):
def test_get_nan_frequency(self):
Expand Down