Skip to content

Commit

Permalink
DiscreteVariable: Remove 'ordered' argument
Browse files Browse the repository at this point in the history
  • Loading branch information
VesnaT committed Mar 8, 2021
1 parent 7ad8924 commit 4e7a965
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 43 deletions.
16 changes: 2 additions & 14 deletions Orange/data/tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,16 +498,6 @@ def test_copy_checks_len_values(self):
var2 = var.copy(values=("W", "M"))
self.assertEqual(var2.values, ("W", "M"))

def test_remove_ordered(self):
"""
ordered is deprecated when this test starts to fail remove ordered
parameter. Remove also this test.
Ordered parameter should still be allowed in __init__ for backward
compatibilities in data-sets pickled with older versions, I suggest
adding **kwargs which is ignored
"""
self.assertLess(Orange.__version__, "3.29.0")

def test_pickle_backward_compatibility(self):
"""
Test that pickle made with an older version of Orange are correctly
Expand All @@ -522,11 +512,9 @@ def test_pickle_backward_compatibility(self):
this_dir, "..", "..", "tests", "datasets"
)
# pickle with values as list
with self.assertWarns(OrangeDeprecationWarning):
Table(os.path.join(datasets_dir, "sailing-orange-3-20.pkl"))
Table(os.path.join(datasets_dir, "sailing-orange-3-20.pkl"))
# pickle with values as tuple list
with self.assertWarns(OrangeDeprecationWarning):
Table(os.path.join(datasets_dir, "iris-orange-3-25.pkl"))
Table(os.path.join(datasets_dir, "iris-orange-3-25.pkl"))


@variabletest(ContinuousVariable)
Expand Down
22 changes: 2 additions & 20 deletions Orange/data/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def make_variable(cls, compute_value, *args):
return cls(*args, compute_value=compute_value)
else:
# For compatibility with old pickles
return cls(*args)
return cls(*tuple(x for i, x in enumerate(args) if i != 2))


def is_discrete_values(values):
Expand Down Expand Up @@ -626,8 +626,7 @@ class DiscreteVariable(Variable):
presorted_values = []

def __init__(
self, name="", values=(), ordered=None, compute_value=None,
*, sparse=False
self, name="", values=(), compute_value=None, *, sparse=False
):
""" Construct a discrete variable descriptor with the given values. """
values = tuple(values) # some people (including me) pass a generator
Expand All @@ -638,23 +637,6 @@ def __init__(
self._values = values
self._value_index = {value: i for i, value in enumerate(values)}

if ordered is not None:
warnings.warn(
"ordered is deprecated and does not have effect. It will be "
"removed in future versions.",
OrangeDeprecationWarning
)

@property
def ordered(self):
warnings.warn(
"ordered is deprecated. It will be removed in future versions.",
# DeprecationWarning warning is used instead of OrangeDeprecation
# warning otherwise tests fail (__repr__ still asks for ordered)
DeprecationWarning
)
return None

@property
def values(self):
return self._values
Expand Down
14 changes: 5 additions & 9 deletions Orange/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from Orange.data.io import FileFormat, TabReader, CSVReader, PickleReader
from Orange.data.io_base import PICKLE_PROTOCOL
from Orange.data.table import get_sample_datasets_dir
from Orange.data import Table, Variable
from Orange.data import Table
from Orange.tests import test_dirname
from Orange.util import OrangeDeprecationWarning

Expand Down Expand Up @@ -173,16 +173,12 @@ def test_load_pickle(self):
# load pickles created with Orange 3.20
# in next version there is a change in variables.py - line 738
# which broke back compatibility - tests introduced after the fix
with self.assertWarns(OrangeDeprecationWarning):
data1 = Table("datasets/sailing-orange-3-20.pkl")
with self.assertWarns(OrangeDeprecationWarning):
data2 = Table("datasets/sailing-orange-3-20.pkl.gz")
data1 = Table("datasets/sailing-orange-3-20.pkl")
data2 = Table("datasets/sailing-orange-3-20.pkl.gz")

# load pickles created with Orange 3.21
with self.assertWarns(OrangeDeprecationWarning):
data3 = Table("datasets/sailing-orange-3-21.pkl")
with self.assertWarns(OrangeDeprecationWarning):
data4 = Table("datasets/sailing-orange-3-21.pkl.gz")
data3 = Table("datasets/sailing-orange-3-21.pkl")
data4 = Table("datasets/sailing-orange-3-21.pkl.gz")

examples_count = 20
self.assertEqual(examples_count, len(data1))
Expand Down

0 comments on commit 4e7a965

Please sign in to comment.