Skip to content

Commit

Permalink
Merge pull request #4879 from PrimozGodec/readd-tuple-list
Browse files Browse the repository at this point in the history
[FIX] Re-add TupleList to DiscreteVariable
  • Loading branch information
lanzagar authored Jul 3, 2020
2 parents 62e5c69 + 6722145 commit 2655592
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
24 changes: 22 additions & 2 deletions Orange/data/tests/test_variable.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Test methods with long descriptive names can omit docstrings
# pylint: disable=missing-docstring
# pylint: disable=protected-access

import os
import sys
import math
import unittest
import pickle
import pkgutil
import warnings
from datetime import datetime, timezone

from io import StringIO
Expand All @@ -16,7 +17,7 @@

import Orange
from Orange.data import Variable, ContinuousVariable, DiscreteVariable, \
StringVariable, TimeVariable, Unknown, Value
StringVariable, TimeVariable, Unknown, Value, Table
from Orange.data.io import CSVReader
from Orange.preprocess.transformation import Identity
from Orange.tests.base import create_pickling_tests
Expand Down Expand Up @@ -500,6 +501,25 @@ def test_remove_ordered(self):
"""
self.assertLess(Orange.__version__, "3.29.0")

@staticmethod
def test_pickle_backward_compatibility():
"""
Test that pickle made with an older version of Orange are correctly
loaded after changes in DiscreteVariable
"""
with warnings.catch_warnings():
# travis/gh-action tests change OrangeDeprecationWarning to error
# temporary disable it
warnings.simplefilter('default', OrangeDeprecationWarning)
this_dir = os.path.dirname(os.path.realpath(__file__))
datasets_dir = os.path.join(
this_dir, "..", "..", "tests", "datasets"
)
# pickle with values as list
Table(os.path.join(datasets_dir, "sailing-orange-3-20.pkl"))
# pickle with values as tuple list
Table(os.path.join(datasets_dir, "iris-orange-3-25.pkl"))


@variabletest(ContinuousVariable)
class TestContinuousVariable(VariableTest):
Expand Down
3 changes: 3 additions & 0 deletions Orange/data/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,9 @@ def copy(self, compute_value=Variable._CopyComputeValue,
return var


TupleList = tuple # backward compatibility (for pickled table)


class DiscreteVariable(Variable):
"""
Descriptor for symbolic, discrete variables. Values of discrete variables
Expand Down
Binary file added Orange/tests/datasets/iris-orange-3-25.pkl
Binary file not shown.

0 comments on commit 2655592

Please sign in to comment.