{
    "file_diffs": [
        {
            "old_file_content": "import operator\nimport os\nimport sys\nimport threading\nimport warnings\nimport weakref\nimport zlib\nfrom collections.abc import Iterable, Sequence, Sized\nfrom contextlib import contextmanager\nfrom functools import reduce\nfrom itertools import chain\nfrom numbers import Real, Integral\nfrom threading import Lock\n\nimport bottleneck as bn\nimport numpy as np\n\nfrom scipy import sparse as sp\nfrom scipy.sparse import issparse, csc_matrix\n\nimport Orange.data  # import for io.py\nfrom Orange.data import (\n    _contingency, _valuecount,\n    Domain, Variable, Storage, StringVariable, Unknown, Value, Instance,\n    ContinuousVariable, DiscreteVariable, MISSING_VALUES,\n    DomainConversion)\nfrom Orange.data.util import SharedComputeValue, \\\n    assure_array_dense, assure_array_sparse, \\\n    assure_column_dense, assure_column_sparse, get_unique_names_duplicates\nfrom Orange.misc.collections import frozendict\nfrom Orange.statistics.util import bincount, countnans, contingency, \\\n    stats as fast_stats, sparse_has_implicit_zeros, sparse_count_implicit_zeros, \\\n    sparse_implicit_zero_weights\nfrom Orange.util import OrangeDeprecationWarning, dummy_callback\n\n__all__ = [\"dataset_dirs\", \"get_sample_datasets_dir\", \"RowInstance\", \"Table\"]\n\n\ndef get_sample_datasets_dir():\n    orange_data_table = os.path.dirname(__file__)\n    dataset_dir = os.path.join(orange_data_table, '..', 'datasets')\n    return os.path.realpath(dataset_dir)\n\n\ndataset_dirs = ['', get_sample_datasets_dir()]\n\n\nclass _ThreadLocal(threading.local):\n    def __init__(self):\n        super().__init__()\n        # Domain conversion cache used in Table.from_table. It is defined\n        # here instead of as a class variable of a Table so that caching also works\n        # with descendants of Table.\n        self.conversion_cache = None\n        self.domain_cache = None\n\n\n_thread_local = _ThreadLocal()\n\n\ndef _idcache_save(cachedict, keys, value):\n    cachedict[tuple(map(id, keys))] = \\\n        value, [weakref.ref(k) for k in keys]\n\n\ndef _idcache_restore(cachedict, keys):\n    shared, weakrefs = cachedict.get(tuple(map(id, keys)), (None, []))\n    for r in weakrefs:\n        if r() is None:\n            return None\n    return shared\n\n\nclass DomainTransformationError(Exception):\n    pass\n\n\nclass RowInstance(Instance):\n    sparse_x = None\n    sparse_y = None\n    sparse_metas = None\n    _weight = None\n\n    def __init__(self, table, row_index):\n        \"\"\"\n        Construct a data instance representing the given row of the table.\n        \"\"\"\n        self.table = table\n        self._domain = table.domain\n        self.row_index = row_index\n        self.id = table.ids[row_index]\n        self._x = table.X[row_index]\n        if sp.issparse(self._x):\n            self.sparse_x = sp.csr_matrix(self._x)\n            self._x = np.asarray(self._x.todense())[0]\n        self._y = table._Y[row_index]\n        if sp.issparse(self._y):\n            self.sparse_y = sp.csr_matrix(self._y)\n            self._y = np.asarray(self._y.todense())[0]\n        self._y = np.atleast_1d(self._y)\n        self._metas = table.metas[row_index]\n        if sp.issparse(self._metas):\n            self.sparse_metas = sp.csr_matrix(self._metas)\n            self._metas = np.asarray(self._metas.todense())[0]\n\n    @property\n    def weight(self):\n        if not self.table.has_weights():\n            return 1\n        return self.table.W[self.row_index]\n\n    @weight.setter\n    def weight(self, weight):\n        if not self.table.has_weights():\n            self.table.set_weights()\n        self.table.W[self.row_index] = weight\n\n    def set_class(self, value):\n        # pylint: disable=protected-access\n        self._check_single_class()\n        if not isinstance(value, Real):\n            value = self.table.domain.class_var.to_val(value)\n        if self.sparse_y:\n            self.table._Y[self.row_index, 0] = value\n        else:\n            self.table._Y[self.row_index] = value\n            if self.table._Y.ndim == 1:  # if _y is not a view\n                self._y[0] = value\n\n    def __setitem__(self, key, value):\n        if not isinstance(key, Integral):\n            key = self._domain.index(key)\n        if isinstance(value, str):\n            var = self._domain[key]\n            value = var.to_val(value)\n        if key >= 0:\n            if not isinstance(value, Real):\n                raise TypeError(\"Expected primitive value, got '%s'\" %\n                                type(value).__name__)\n            if key < len(self._x):\n                # write to self.table.X to support table unlocking for live instances\n                self.table.X[self.row_index, key] = value\n                if self.sparse_x is not None:\n                    self._x[key] = value\n            else:\n                if self.sparse_y is not None:\n                    self.table._Y[self.row_index, key - len(self._x)] = value\n                else:\n                    self.table._Y[self.row_index] = value\n                    if self.table._Y.ndim == 1:  # if _y is not a view\n                        self._y[0] = value\n        else:\n            self.table.metas[self.row_index, -1 - key] = value\n            if self.sparse_metas is not None:\n                self._metas[-1 - key] = value\n\n    def _str(self, limit):\n        def sp_values(matrix, variables):\n            if not sp.issparse(matrix):\n                if matrix.ndim == 1:\n                    matrix = matrix[:, np.newaxis]\n                return Instance.str_values(matrix[row], variables, limit)\n\n            row_entries, idx = [], 0\n            while idx < len(variables):\n                # Make sure to stop printing variables if we limit the output\n                if limit and len(row_entries) >= 5:\n                    break\n\n                var = variables[idx]\n                if var.is_discrete or matrix[row, idx]:\n                    row_entries.append(\"%s=%s\" % (var.name, var.str_val(matrix[row, idx])))\n\n                idx += 1\n\n            s = \", \".join(row_entries)\n\n            if limit and idx < len(variables):\n                s += \", ...\"\n\n            return s\n\n        table = self.table\n        domain = table.domain\n        row = self.row_index\n        s = \"[\" + sp_values(table.X, domain.attributes)\n        if domain.class_vars:\n            s += \" | \" + sp_values(table.Y, domain.class_vars)\n        s += \"]\"\n        if self._domain.metas:\n            s += \" {\" + sp_values(table.metas, domain.metas) + \"}\"\n        return s\n\n    def __str__(self):\n        return self._str(False)\n\n    def __repr__(self):\n        return self._str(True)\n\n\nclass Columns:\n    def __init__(self, domain):\n        for v in chain(domain.variables, domain.metas):\n            setattr(self, v.name.replace(\" \", \"_\"), v)\n\n\nclass _ArrayConversion:\n\n    def __init__(self, target, src_cols, variables, is_sparse, source_domain):\n        self.target = target\n        self.src_cols = src_cols\n        self.is_sparse = is_sparse\n        self.subarray_from = self._can_copy_all(src_cols, source_domain)\n        self.variables = variables\n        dtype = np.float64\n        if any(isinstance(var, StringVariable) for var in self.variables):\n            dtype = object\n        self.dtype = dtype\n        self.row_selection_needed = any(not isinstance(x, Integral)\n                                        for x in src_cols)\n\n    def _can_copy_all(self, src_cols, source_domain):\n        n_src_attrs = len(source_domain.attributes)\n        if all(isinstance(x, Integral) and 0 <= x < n_src_attrs\n               for x in src_cols):\n            return \"X\"\n        if all(isinstance(x, Integral) and x < 0 for x in src_cols):\n            return \"metas\"\n        if all(isinstance(x, Integral) and x >= n_src_attrs\n               for x in src_cols):\n            return \"Y\"\n\n    def get_subarray(self, source, row_indices, n_rows):\n        if not len(self.src_cols):\n            if self.is_sparse:\n                return sp.csr_matrix((n_rows, 0), dtype=source.X.dtype)\n            else:\n                return np.zeros((n_rows, 0), dtype=source.X.dtype)\n\n        match_density = assure_array_sparse if self.is_sparse else assure_array_dense\n        n_src_attrs = len(source.domain.attributes)\n        if self.subarray_from == \"X\":\n            arr = match_density(_subarray(source.X, row_indices, self.src_cols))\n        elif self.subarray_from == \"metas\":\n            arr = match_density(_subarray(source.metas, row_indices,\n                                          [-1 - x for x in self.src_cols]))\n        elif self.subarray_from == \"Y\":\n            Y = source.Y if source.Y.ndim == 2 else source.Y[:, None]\n            arr = match_density(_subarray(\n                Y, row_indices,\n                [x - n_src_attrs for x in self.src_cols]))\n        else:\n            assert False\n        if arr.dtype != self.dtype:\n            arr = arr.astype(self.dtype)\n        assert arr.ndim == 2 or self.subarray_from == \"Y\" and arr.ndim == 1\n        return arr\n\n    def get_columns(self, source, row_indices, n_rows, out=None, target_indices=None):\n        n_src_attrs = len(source.domain.attributes)\n\n        data = []\n        sp_col = []\n        sp_row = []\n        match_density = (\n            assure_column_sparse if self.is_sparse else assure_column_dense\n        )\n\n        # converting to csc before instead of each column is faster\n        # do not convert if not required\n        if any(isinstance(x, int) for x in self.src_cols):\n            X = source.X\n            Y = source.Y\n            if Y.ndim == 1:\n                Y = Y[:, None]\n            if self.is_sparse:\n                X = csc_matrix(X)\n                Y = csc_matrix(Y)\n\n        if self.row_selection_needed:\n            if row_indices is ...:\n                sourceri = source\n            else:\n                sourceri = source[row_indices]\n\n        shared_cache = _thread_local.conversion_cache\n        for i, col in enumerate(self.src_cols):\n            if col is None:\n                col_array = match_density(\n                    np.full((n_rows, 1), self.variables[i].Unknown)\n                )\n            elif not isinstance(col, Integral):\n                if isinstance(col, SharedComputeValue):\n                    shared = _idcache_restore(shared_cache, (col.compute_shared, source))\n                    if shared is None:\n                        shared = col.compute_shared(sourceri)\n                        _idcache_save(shared_cache, (col.compute_shared, source), shared)\n                    col_array = match_density(\n                        col(sourceri, shared_data=shared))\n                else:\n                    col_array = match_density(col(sourceri))\n            elif col < 0:\n                col_array = match_density(\n                    source.metas[row_indices, -1 - col]\n                )\n            elif col < n_src_attrs:\n                col_array = match_density(X[row_indices, col])\n            else:\n                col_array = match_density(\n                    Y[row_indices, col - n_src_attrs]\n                )\n\n            if self.is_sparse:\n                # col_array should be coo matrix\n                data.append(col_array.data)\n                sp_col.append(np.full(len(col_array.data), i))\n                sp_row.append(col_array.indices)  # row indices should be same\n            else:\n                out[target_indices, i] = col_array\n\n        if self.is_sparse:\n            # creating csr directly would need plenty of manual work which\n            # would probably slow down the process - conversion coo to csr\n            # is fast\n            out = sp.coo_matrix(\n                (np.hstack(data), (np.hstack(sp_row), np.hstack(sp_col))),\n                shape=(n_rows, len(self.src_cols)),\n                dtype=self.dtype\n            )\n            out = out.tocsr()\n\n        return out\n\n\nclass _FromTableConversion:\n\n    def __init__(self, source, destination):\n        conversion = DomainConversion(source, destination)\n\n        self.X = _ArrayConversion(\"X\", conversion.attributes,\n                                  destination.attributes, conversion.sparse_X,\n                                  source)\n        self.Y = _ArrayConversion(\"Y\", conversion.class_vars,\n                                  destination.class_vars, conversion.sparse_Y,\n                                  source)\n        self.metas = _ArrayConversion(\"metas\", conversion.metas,\n                                      destination.metas, conversion.sparse_metas,\n                                      source)\n\n        self.subarray = []\n        self.columnwise = []\n\n        for part in [self.X, self.Y, self.metas]:\n            if part.subarray_from is None:\n                self.columnwise.append(part)\n            else:\n                self.subarray.append(part)\n\n\n# noinspection PyPep8Naming\nclass Table(Sequence, Storage):\n\n    LOCKING = None\n    \"\"\" If the class attribute LOCKING is True, tables will throw exceptions\n    on in-place modifications unless unlocked explicitly. LOCKING is supposed\n    to be set to True for testing to help us find bugs. If set to False\n    or None, no safeguards are in place. Two different values are used for\n    the same behaviour to distinguish the unchanged default (None) form\n    explicit deactivation (False) that some add-ons might need. \"\"\"\n\n    __file__ = None\n    name = \"untitled\"\n\n    domain = Domain([])\n    _X = _Y = _metas = _W = np.zeros((0, 0))  # pylint: disable=invalid-name\n    ids = np.zeros(0)\n    ids.setflags(write=False)\n    attributes = frozendict()\n\n    _Unlocked_X, _Unlocked_Y, _Unlocked_metas, _Unlocked_W = 1, 2, 4, 8\n    _unlocked = _Unlocked_X + _Unlocked_Y + \\\n                _Unlocked_metas + _Unlocked_W  # pylint: disable=invalid-name\n\n    @property\n    def columns(self):\n        \"\"\"\n        A class whose attributes contain attribute descriptors for columns.\n        For a table `table`, setting `c = table.columns` will allow accessing\n        the table's variables with, for instance `c.gender`, `c.age` ets.\n        Spaces are replaced with underscores.\n        \"\"\"\n        return Columns(self.domain)\n\n    _next_instance_id = 0\n    _next_instance_lock = Lock()\n\n    def _check_unlocked(self, partflag):\n        if not self._unlocked & partflag:\n            raise ValueError(\"Table is read-only unless unlocked\")\n\n    @property\n    def X(self):  # pylint: disable=invalid-name\n        return self._X\n\n    @X.setter\n    def X(self, value):\n        self._check_unlocked(self._Unlocked_X)\n        self._X = _dereferenced(value)\n\n    @property\n    def Y(self):  # pylint: disable=invalid-name\n        return self._Y\n\n    @Y.setter\n    def Y(self, value):\n        self._check_unlocked(self._Unlocked_Y)\n        if sp.issparse(value) and len(self) != value.shape[0]:\n            value = value.T\n        if sp.issparse(value):\n            value = _dereferenced(value.toarray())\n        if value.ndim == 2 and value.shape[1] == 1:\n            value = value[:, 0].copy()  # no views!\n        self._Y = value\n\n    @property\n    def metas(self):\n        return self._metas\n\n    @metas.setter\n    def metas(self, value):\n        self._check_unlocked(self._Unlocked_metas)\n        self._metas = _dereferenced(value)\n\n    @property\n    def W(self):  # pylint: disable=invalid-name\n        return self._W\n\n    @W.setter\n    def W(self, value):\n        self._check_unlocked(self._Unlocked_W)\n        self._W = value\n\n    def __setstate__(self, state):\n        # Backward compatibility with pickles before table locking\n        self._initialize_unlocked()  # __dict__ seems to be cleared before calling __setstate__\n        with self.unlocked():\n            for k in (\"X\", \"W\", \"metas\"):\n                if k in state:\n                    setattr(self, k, state.pop(k))\n            self.__dict__.update(state)\n\n    def _lock_parts(self):\n        return ((self._X, self._Unlocked_X, \"X\"),\n                (self._Y, self._Unlocked_Y, \"Y\"),\n                (self._metas, self._Unlocked_metas, \"metas\"),\n                (self._W, self._Unlocked_W, \"weights\"))\n\n    def _initialize_unlocked(self):\n        if Table.LOCKING:\n            self._unlocked = 0\n        else:\n            self._unlocked = sum(f for _, f, _ in self._lock_parts())\n\n    def _update_locks(self, force=False, unlock_bases=()):\n        if not Table.LOCKING:\n            return\n\n        def sync(*xs):\n            for x in xs:\n                try:\n                    undo_on_fail.append((x, x.flags.writeable))\n                    x.flags.writeable = writeable\n                except ValueError:\n                    if force \\\n                            and writeable \\\n                            and x.base is not None \\\n                            and not x.base.flags.writeable:\n                        x.base.flags.writeable = writeable\n                        x.flags.writeable = writeable\n                        forced_bases.append(x.base)\n                    else:\n                        raise\n\n        forced_bases = []\n        undo_on_fail = []\n        for base in unlock_bases:\n            base.flags.writeable = False\n        try:\n            for part, flag, _ in self._lock_parts():\n                if part is None:\n                    continue\n                writeable = bool(self._unlocked & flag)\n                if sp.isspmatrix_csr(part) or sp.isspmatrix_csc(part):\n                    sync(part.data, part.indices, part.indptr)\n                elif sp.isspmatrix_coo(part):\n                    sync(part.data, part.row, part.col)\n                elif sp.issparse(part):\n                    raise ValueError(\"Unsupported sparse data type\")\n                else:\n                    sync(part)\n        except:\n            for part, flag in undo_on_fail:\n                part.flags.writeable = flag\n            raise\n        return tuple(forced_bases)\n\n    def __unlocked(self, *parts, force=False):\n        prev_state = self._unlocked\n        for part, flag, _ in self._lock_parts():\n            if not parts or any(ppart is part for ppart in parts):\n                self._unlocked |= flag\n        try:\n            forced_bases = self._update_locks(force)\n            yield\n        finally:\n            self._unlocked = prev_state\n            self._update_locks(unlock_bases=forced_bases)\n\n    def force_unlocked(self, *parts):\n        \"\"\"\n        Unlocking without any checks.\n\n        Use with extreme caution. This is meant primarily for 3rd party\n        functions in Cython that expect read-write buffer, but do not\n        actually modify it. the given parts (default: all parts) of the table.\n\n        The function will still fail to unlock and raise an exception if the\n        table contains view to another table.\n        \"\"\"\n        return contextmanager(self.__unlocked)(*parts, force=True)\n\n    def unlocked(self, *parts):\n        \"\"\"\n        Unlock the given parts (default: all parts) of the table.\n\n        The caller must ensure that the table is safe to modify. The function\n        will raise an exception if the table contains view to other table.\n        \"\"\"\n        def can_unlock(x):\n            if sp.issparse(x):\n                return can_unlock(x.data)\n            return x.flags.writeable or x.flags.owndata\n\n        for part, flag, name in self._lock_parts():\n            if not flag & self._unlocked \\\n                    and (not parts or any(ppart is part for ppart in parts)) \\\n                    and part is not None and not can_unlock(part):\n                raise ValueError(f\"'{name}' is a view into another table \"\n                                 \"and cannot be unlocked\")\n        return contextmanager(self.__unlocked)(*parts)\n\n    def __new__(cls, *args, **kwargs):\n        def warn_deprecated(method):\n            warnings.warn(\"Direct calls to Table's constructor are deprecated \"\n                          \"and will be removed. Replace this call with \"\n                          f\"Table.{method}\", OrangeDeprecationWarning,\n                          stacklevel=3)\n\n        if not args:\n            if not kwargs:\n                return super().__new__(cls)\n            else:\n                raise TypeError(\"Table() must not be called directly\")\n\n        if isinstance(args[0], str):\n            if len(args) > 1:\n                raise TypeError(\"Table(name: str) expects just one argument\")\n            if args[0].startswith('https://') or args[0].startswith('http://'):\n                return cls.from_url(args[0], **kwargs)\n            else:\n                return cls.from_file(args[0], **kwargs)\n\n        elif isinstance(args[0], Table):\n            if len(args) > 1:\n                raise TypeError(\"Table(table: Table) expects just one argument\")\n            return cls.from_table(args[0].domain, args[0], **kwargs)\n        elif isinstance(args[0], Domain):\n            domain, args = args[0], args[1:]\n            if not args:\n                warn_deprecated(\"from_domain\")\n                return cls.from_domain(domain, **kwargs)\n            if isinstance(args[0], Table):\n                warn_deprecated(\"from_table\")\n                return cls.from_table(domain, *args, **kwargs)\n            elif isinstance(args[0], list):\n                warn_deprecated(\"from_list\")\n                return cls.from_list(domain, *args, **kwargs)\n        else:\n            warnings.warn(\"Omitting domain in a call to Table(X, Y, metas), is \"\n                          \"deprecated and will be removed. \"\n                          \"Call Table.from_numpy(None, X, Y, metas) instead.\",\n                          OrangeDeprecationWarning, stacklevel=2)\n            domain = None\n\n        return cls.from_numpy(domain, *args, **kwargs)\n\n    def __init__(self, *args, **kwargs):  # pylint: disable=unused-argument\n        self._initialize_unlocked()\n        self._update_locks()\n\n    @classmethod\n    def from_domain(cls, domain, n_rows=0, weights=False):\n        \"\"\"\n        Construct a new `Table` with the given number of rows for the given\n        domain. The optional vector of weights is initialized to 1's.\n\n        :param domain: domain for the `Table`\n        :type domain: Orange.data.Domain\n        :param n_rows: number of rows in the new table\n        :type n_rows: int\n        :param weights: indicates whether to construct a vector of weights\n        :type weights: bool\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n        self = cls()\n        self.domain = domain\n        self.n_rows = n_rows\n        with self.unlocked():\n            self.X = np.zeros((n_rows, len(domain.attributes)))\n            if len(domain.class_vars) != 1:\n                self.Y = np.zeros((n_rows, len(domain.class_vars)))\n            else:\n                self.Y = np.zeros(n_rows)\n            if weights:\n                self.W = np.ones(n_rows)\n            else:\n                self.W = np.empty((n_rows, 0))\n            self.metas = np.empty((n_rows, len(self.domain.metas)), object)\n            cls._init_ids(self)\n            self.attributes = {}\n        return self\n\n    @classmethod\n    def from_table(cls, domain, source, row_indices=...):\n        \"\"\"\n        Create a new table from selected columns and/or rows of an existing\n        one. The columns are chosen using a domain. The domain may also include\n        variables that do not appear in the source table; they are computed\n        from source variables if possible.\n\n        The resulting data may be a view or a copy of the existing data.\n\n        :param domain: the domain for the new table\n        :type domain: Orange.data.Domain\n        :param source: the source table\n        :type source: Orange.data.Table\n        :param row_indices: indices of the rows to include\n        :type row_indices: a slice or a sequence\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n\n        PART = 5000\n\n        new_cache = _thread_local.conversion_cache is None\n        try:\n            if new_cache:\n                _thread_local.conversion_cache = {}\n                _thread_local.domain_cache = {}\n            else:\n                cached = _idcache_restore(_thread_local.conversion_cache, (domain, source))\n                if cached is not None:\n                    return cached\n            if domain is source.domain:\n                table = cls.from_table_rows(source, row_indices)\n                # assure resulting domain is the instance passed on input\n                table.domain = domain\n                # since sparse flags are not considered when checking for\n                # domain equality, fix manually.\n                with table.unlocked():\n                    table = assure_domain_conversion_sparsity(table, source)\n                return table\n\n            if row_indices is ...:\n                n_rows = len(source)\n            elif isinstance(row_indices, slice):\n                row_indices_range = range(*row_indices.indices(source.X.shape[0]))\n                n_rows = len(row_indices_range)\n            else:\n                n_rows = len(row_indices)\n\n            self = cls()\n            self.domain = domain\n\n            table_conversion = \\\n                _idcache_restore(_thread_local.domain_cache, (domain, source.domain))\n            if table_conversion is None:\n                table_conversion = _FromTableConversion(source.domain, domain)\n                _idcache_save(_thread_local.domain_cache, (domain, source.domain),\n                              table_conversion)\n\n            # if an array can be a subarray of the input table, this needs to be done\n            # on the whole table, because this avoids needless copies of contents\n\n            with self.unlocked():\n                for array_conv in table_conversion.subarray:\n                    out = array_conv.get_subarray(source, row_indices, n_rows)\n                    setattr(self, array_conv.target, out)\n\n                parts = {}\n\n                for array_conv in table_conversion.columnwise:\n                    if array_conv.is_sparse:\n                        parts[array_conv.target] = []\n                    else:\n                        # F-order enables faster writing to the array while accessing and\n                        # matrix operations work with same speed (e.g. dot)\n                        parts[array_conv.target] = \\\n                            np.zeros((n_rows, len(array_conv.src_cols)),\n                                     order=\"F\", dtype=array_conv.dtype)\n\n                if n_rows <= PART:\n                    for array_conv in table_conversion.columnwise:\n                        out = array_conv.get_columns(source, row_indices, n_rows,\n                                                     parts[array_conv.target],\n                                                     ...)\n                        setattr(self, array_conv.target, out)\n                else:\n                    i_done = 0\n\n                    while i_done < n_rows:\n                        target_indices = slice(i_done, min(n_rows, i_done + PART))\n                        if row_indices is ...:\n                            source_indices = target_indices\n                        elif isinstance(row_indices, slice):\n                            r = row_indices_range[target_indices]\n                            source_indices = slice(r.start, r.stop, r.step)\n                        else:\n                            source_indices = row_indices[target_indices]\n                        part_rows = min(n_rows, i_done+PART) - i_done\n\n                        for array_conv in table_conversion.columnwise:\n                            out = array_conv.get_columns(source, source_indices, part_rows,\n                                                         parts[array_conv.target],\n                                                         target_indices)\n                            if array_conv.is_sparse:  # dense arrays are populated in-place\n                                parts[array_conv.target].append(out)\n\n                        i_done += PART\n\n                        # clear cache after a part is done\n                        if new_cache:\n                            _thread_local.conversion_cache = {}\n\n                    for array_conv in table_conversion.columnwise:\n                        cparts = parts[array_conv.target]\n                        out = cparts if not array_conv.is_sparse else sp.vstack(cparts)\n                        setattr(self, array_conv.target, out)\n\n                if source.has_weights():\n                    self.W = source.W[row_indices]\n                else:\n                    self.W = np.empty((n_rows, 0))\n                self.name = getattr(source, 'name', '')\n                if hasattr(source, 'ids'):\n                    self.ids = source.ids[row_indices]\n                else:\n                    cls._init_ids(self)\n                self.attributes = getattr(source, 'attributes', {})\n                _idcache_save(_thread_local.conversion_cache, (domain, source), self)\n            return self\n        finally:\n            if new_cache:\n                _thread_local.conversion_cache = None\n                _thread_local.domain_cache = None\n\n    def transform(self, domain):\n        \"\"\"\n        Construct a table with a different domain.\n\n        The new table keeps the row ids and other information. If the table\n        is a subclass of :obj:`Table`, the resulting table will be of the same\n        type.\n\n        In a typical scenario, an existing table is augmented with a new\n        column by ::\n\n            domain = Domain(old_domain.attributes + [new_attribute],\n                            old_domain.class_vars,\n                            old_domain.metas)\n            table = data.transform(domain)\n            table[:, new_attribute] = new_column\n\n        Args:\n            domain (Domain): new domain\n\n        Returns:\n            A new table\n        \"\"\"\n        return type(self).from_table(domain, self)\n\n    @classmethod\n    def from_table_rows(cls, source, row_indices):\n        \"\"\"\n        Construct a new table by selecting rows from the source table.\n\n        :param source: an existing table\n        :type source: Orange.data.Table\n        :param row_indices: indices of the rows to include\n        :type row_indices: a slice or a sequence\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n        def get_rows(a):\n            a = a[row_indices]\n            if isinstance(row_indices, slice) or row_indices is ...:\n                a = a.copy()\n            return a\n\n        self = cls()\n        self.domain = source.domain\n        with self.unlocked():\n            self.X = get_rows(source.X)\n            if self.X.ndim == 1:\n                self.X = self.X.reshape(-1, len(self.domain.attributes))\n            self.Y = get_rows(source.Y)\n            self.metas = get_rows(source.metas)\n            if self.metas.ndim == 1:\n                self.metas = self.metas.reshape(-1, len(self.domain.metas))\n            self.W = get_rows(source.W)\n            self.name = getattr(source, 'name', '')\n            self.ids = np.array(source.ids[row_indices])\n            self.attributes = getattr(source, 'attributes', {})\n        return self\n\n    @classmethod\n    def from_numpy(cls, domain, X, Y=None, metas=None, W=None,\n                   attributes=None, ids=None):\n        \"\"\"\n        Construct a table from numpy arrays with the given domain. The number\n        of variables in the domain must match the number of columns in the\n        corresponding arrays. All arrays must have the same number of rows.\n        Arrays may be of different numpy types, and may be dense or sparse.\n\n        :param domain: the domain for the new table\n        :type domain: Orange.data.Domain\n        :param X: array with attribute values\n        :type X: np.array\n        :param Y: array with class values\n        :type Y: np.array\n        :param metas: array with meta attributes\n        :type metas: np.array\n        :param W: array with weights\n        :type W: np.array\n        :return:\n        \"\"\"\n        X, Y, W = _check_arrays(X, Y, W, dtype='float64')\n        metas, = _check_arrays(metas, dtype=object, shape_1=X.shape[0])\n        ids, = _check_arrays(ids, dtype=int, shape_1=X.shape[0])\n\n        if domain is None:\n            domain = Domain.from_numpy(X, Y, metas)\n\n        if Y is None:\n            if not domain.class_vars or sp.issparse(X):\n                Y = np.empty((X.shape[0], 0), dtype=np.float64)\n            else:\n                own_data = X.flags.owndata and X.base is None\n                Y = X[:, len(domain.attributes):]\n                X = X[:, :len(domain.attributes)]\n                if own_data:\n                    Y = Y.copy()\n                    X = X.copy()\n        if metas is None:\n            metas = np.empty((X.shape[0], 0), object)\n        if W is None or W.size == 0:\n            W = np.empty((X.shape[0], 0))\n        elif W.shape != (W.size, ):\n            W = W.reshape(W.size).copy()\n\n        if X.shape[1] != len(domain.attributes):\n            raise ValueError(\n                \"Invalid number of variable columns ({} != {})\".format(\n                    X.shape[1], len(domain.attributes))\n            )\n        if Y.ndim == 1:\n            if not domain.class_var:\n                raise ValueError(\n                    \"Invalid number of class columns \"\n                    f\"(1 != {len(domain.class_vars)})\")\n        elif Y.shape[1] != len(domain.class_vars):\n            raise ValueError(\n                \"Invalid number of class columns ({} != {})\".format(\n                    Y.shape[1], len(domain.class_vars))\n            )\n        if metas.shape[1] != len(domain.metas):\n            raise ValueError(\n                \"Invalid number of meta attribute columns ({} != {})\".format(\n                    metas.shape[1], len(domain.metas))\n            )\n        if not X.shape[0] == Y.shape[0] == metas.shape[0] == W.shape[0]:\n            raise ValueError(\n                \"Parts of data contain different numbers of rows.\")\n\n        self = cls()\n        with self.unlocked():\n            self.domain = domain\n            self.X = X\n            self.Y = Y\n            self.metas = metas\n            self.W = W\n            self.n_rows = self.X.shape[0]\n            if ids is None:\n                cls._init_ids(self)\n            else:\n                self.ids = ids\n            self.attributes = {} if attributes is None else attributes\n        return self\n\n    @classmethod\n    def from_list(cls, domain, rows, weights=None):\n        if weights is not None and len(rows) != len(weights):\n            raise ValueError(\"mismatching number of instances and weights\")\n        self = cls.from_domain(domain, len(rows), weights is not None)\n        all_vars = domain.variables + domain.metas\n        nattrs = len(domain.attributes)\n        nattrscls = len(domain.variables)\n        with self.unlocked():\n            for i, row in enumerate(rows):\n                if isinstance(row, Instance):\n                    row = row.list\n                vals = [var.to_val(val) for var, val in zip(all_vars, row)]\n                self.X[i] = vals[:nattrs]\n                if self._Y.ndim == 1:\n                    self._Y[i] = vals[nattrs] if nattrs < len(vals) else np.nan\n                else:\n                    self._Y[i] = vals[nattrs:nattrscls]\n                # for backward compatibility: allow omittine some (or all) metas\n                self.metas[i, :len(vals) - nattrscls] = vals[nattrscls:]\n            if weights is not None:\n                self.W = np.array(weights)\n            self.attributes = {}\n        return self\n\n    @classmethod\n    def _init_ids(cls, obj):\n        with cls._next_instance_lock:\n            obj.ids = np.array(range(cls._next_instance_id, cls._next_instance_id + obj.X.shape[0]))\n            cls._next_instance_id += obj.X.shape[0]\n\n    @classmethod\n    def new_id(cls):\n        with cls._next_instance_lock:\n            id = cls._next_instance_id\n            cls._next_instance_id += 1\n            return id\n\n    def to_pandas_dfs(self):\n        return Orange.data.pandas_compat.table_to_frames(self)\n\n    @staticmethod\n    def from_pandas_dfs(xdf, ydf, mdf):\n        return Orange.data.pandas_compat.table_from_frames(xdf, ydf, mdf)\n\n    @property\n    def X_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.Attribute\n        )\n\n    @X_df.setter\n    def X_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.Attribute\n        )\n\n    @property\n    def Y_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.ClassAttribute\n        )\n\n    @Y_df.setter\n    def Y_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.ClassAttribute\n        )\n\n    @property\n    def metas_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.Meta\n        )\n\n    @metas_df.setter\n    def metas_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.Meta\n        )\n\n    def save(self, filename):\n        \"\"\"\n        Save a data table to a file. The path can be absolute or relative.\n\n        :param filename: File name\n        :type filename: str\n        \"\"\"\n        ext = os.path.splitext(filename)[1]\n        from Orange.data.io import FileFormat\n        writer = FileFormat.writers.get(ext)\n        if not writer:\n            desc = FileFormat.names.get(ext)\n            if desc:\n                raise IOError(\n                    \"Writing of {}s is not supported\".format(desc.lower()))\n            else:\n                raise IOError(\"Unknown file name extension.\")\n        writer.write_file(filename, self)\n\n    @classmethod\n    def from_file(cls, filename, sheet=None):\n        \"\"\"\n        Read a data table from a file. The path can be absolute or relative.\n\n        :param filename: File name\n        :type filename: str\n        :param sheet: Sheet in a file (optional)\n        :type sheet: str\n        :return: a new data table\n        :rtype: Orange.data.Table\n        \"\"\"\n        from Orange.data.io import FileFormat\n\n        absolute_filename = FileFormat.locate(filename, dataset_dirs)\n        reader = FileFormat.get_reader(absolute_filename)\n        reader.select_sheet(sheet)\n        data = reader.read()\n\n        # Readers return plain table. Make sure to cast it to appropriate\n        # (subclass) type\n        if cls != data.__class__:\n            data = cls(data)\n\n        # no need to call _init_ids as fuctions from .io already\n        # construct a table with .ids\n\n        data.__file__ = absolute_filename\n        return data\n\n    @classmethod\n    def from_url(cls, url):\n        from Orange.data.io import UrlReader\n        reader = UrlReader(url)\n        data = reader.read()\n        if cls != data.__class__:\n            data = cls(data)\n        return data\n\n    # Helper function for __setitem__:\n    # Set the row of table data matrices\n    # noinspection PyProtectedMember\n    def _set_row(self, example, row):\n        # pylint: disable=protected-access\n        domain = self.domain\n        if isinstance(example, Instance):\n            if example.domain == domain:\n                self.X[row] = example._x\n                if self._Y.ndim == 1:\n                    self._Y[row] = float(example._y)\n                else:\n                    self._Y[row] = np.atleast_1d(example._y)\n                self.metas[row] = example._metas\n                return\n\n            self.X[row], self._Y[row], self.metas[row] = \\\n                self.domain.convert(example)\n            try:\n                self.ids[row] = example.id\n            except:\n                with type(self)._next_instance_lock:\n                    self.ids[row] = type(self)._next_instance_id\n                    type(self)._next_instance_id += 1\n\n        else:\n            attrs = domain.attributes\n            if len(example) != len(domain.variables):\n                raise ValueError(\"invalid length\")\n            self._X[row] = [var.to_val(val) for var, val in zip(attrs, example)]\n            if self._Y.ndim == 1:\n                self._Y[row] = domain.class_var.to_val(example[len(attrs)])\n            else:\n                self._Y[row] = [var.to_val(val)\n                                for var, val in zip(domain.class_vars,\n                                                    example[len(attrs):])]\n            self.metas[row] = np.array([var.Unknown for var in domain.metas],\n                                       dtype=object)\n\n    def _check_all_dense(self):\n        return all(x in (Storage.DENSE, Storage.MISSING)\n                   for x in (self.X_density(), self.Y_density(),\n                             self.metas_density()))\n\n    def __getitem__(self, key):\n        if isinstance(key, Integral):\n            return RowInstance(self, key)\n        if not isinstance(key, tuple):\n            return self.from_table_rows(self, key)\n\n        if len(key) != 2:\n            raise IndexError(\"Table indices must be one- or two-dimensional\")\n\n        row_idx, col_idx = key\n        if isinstance(row_idx, Integral):\n            if isinstance(col_idx, (str, Integral, Variable)):\n                col_idx = self.domain.index(col_idx)\n                var = self.domain[col_idx]\n                if 0 <= col_idx < len(self.domain.attributes):\n                    val = self.X[row_idx, col_idx]\n                elif col_idx == len(self.domain.attributes) and self._Y.ndim == 1:\n                    val = self._Y[row_idx]\n                elif col_idx >= len(self.domain.attributes):\n                    val = self._Y[row_idx,\n                                  col_idx - len(self.domain.attributes)]\n                else:\n                    val = self.metas[row_idx, -1 - col_idx]\n                if isinstance(col_idx, DiscreteVariable) and var is not col_idx:\n                    val = col_idx.get_mapper_from(var)(val)\n                return Value(var, val)\n            else:\n                row_idx = [row_idx]\n\n        # multiple rows OR single row but multiple columns:\n        # construct a new table\n        attributes, col_indices = self.domain._compute_col_indices(col_idx)\n        if attributes is not None:\n            n_attrs = len(self.domain.attributes)\n            r_attrs = [attributes[i]\n                       for i, col in enumerate(col_indices)\n                       if 0 <= col < n_attrs]\n            r_classes = [attributes[i]\n                         for i, col in enumerate(col_indices)\n                         if col >= n_attrs]\n            r_metas = [attributes[i]\n                       for i, col in enumerate(col_indices) if col < 0]\n            domain = Domain(r_attrs, r_classes, r_metas)\n        else:\n            domain = self.domain\n        return self.from_table(domain, self, row_idx)\n\n    def __setitem__(self, key, value):\n        if not isinstance(key, tuple):\n            if isinstance(value, Real):\n                self.X[key, :] = value\n                return\n            self._set_row(value, key)\n            return\n\n        if len(key) != 2:\n            raise IndexError(\"Table indices must be one- or two-dimensional\")\n        row_idx, col_idx = key\n\n        # single row\n        if isinstance(row_idx, Integral):\n            if isinstance(col_idx, slice):\n                col_idx = range(*slice.indices(col_idx, self.X.shape[1]))\n            if not isinstance(col_idx, str) and isinstance(col_idx, Iterable):\n                col_idx = list(col_idx)\n            if not isinstance(col_idx, str) and isinstance(col_idx, Sized):\n                if isinstance(value, (Sequence, np.ndarray)):\n                    values = value\n                elif isinstance(value, Iterable):\n                    values = list(value)\n                else:\n                    raise TypeError(\"Setting multiple values requires a \"\n                                    \"sequence or numpy array\")\n                if len(values) != len(col_idx):\n                    raise ValueError(\"Invalid number of values\")\n            else:\n                col_idx, values = [col_idx], [value]\n            if isinstance(col_idx, DiscreteVariable) \\\n                    and self.domain[col_idx] != col_idx:\n                values = self.domain[col_idx].get_mapper_from(col_idx)(values)\n            for val, col_idx in zip(values, col_idx):\n                if not isinstance(val, Integral):\n                    val = self.domain[col_idx].to_val(val)\n                if not isinstance(col_idx, Integral):\n                    col_idx = self.domain.index(col_idx)\n                if col_idx >= 0:\n                    if col_idx < self.X.shape[1]:\n                        self.X[row_idx, col_idx] = val\n                    elif self._Y.ndim == 1 and col_idx == self.X.shape[1]:\n                        self._Y[row_idx] = val\n                    else:\n                        self._Y[row_idx, col_idx - self.X.shape[1]] = val\n                else:\n                    self.metas[row_idx, -1 - col_idx] = val\n\n        # multiple rows, multiple columns\n        attributes, col_indices = self.domain._compute_col_indices(col_idx)\n        if col_indices is ...:\n            col_indices = range(len(self.domain.variables))\n        n_attrs = self.X.shape[1]\n        if isinstance(value, str):\n            if not attributes:\n                attributes = self.domain.attributes\n            for var, col in zip(attributes, col_indices):\n                val = var.to_val(value)\n                if 0 <= col < n_attrs:\n                    self.X[row_idx, col] = val\n                elif col >= n_attrs:\n                    if self._Y.ndim == 1 and col == n_attrs:\n                        self._Y[row_idx] = val\n                    else:\n                        self._Y[row_idx, col - n_attrs] = val\n                else:\n                    self.metas[row_idx, -1 - col] = val\n        else:\n            attr_cols = np.fromiter(\n                (col for col in col_indices if 0 <= col < n_attrs), int)\n            class_cols = np.fromiter(\n                (col - n_attrs for col in col_indices if col >= n_attrs), int)\n            meta_cols = np.fromiter(\n                (-1 - col for col in col_indices if col < 0), int)\n            if value is None:\n                value = Unknown\n\n            if not isinstance(value, (Real, np.ndarray)) and \\\n                    (len(attr_cols) or len(class_cols)):\n                raise TypeError(\n                    \"Ordinary attributes can only have primitive values\")\n            if len(attr_cols):\n                self.X[row_idx, attr_cols] = value\n            if len(class_cols):\n                if self._Y.ndim == 1 and np.all(class_cols == 0):\n                    if isinstance(value, np.ndarray):\n                        yshape = self._Y[row_idx].shape\n                        if value.shape != yshape:\n                            value = value.reshape(yshape)\n                    self._Y[row_idx] = value\n                else:\n                    self._Y[row_idx, class_cols] = value\n            if len(meta_cols):\n                self.metas[row_idx, meta_cols] = value\n\n    def __len__(self):\n        return self.X.shape[0]\n\n    def __str__(self):\n        return \"[\" + \",\\n \".join(str(ex) for ex in self) + \"]\"\n\n    def __repr__(self):\n        head = 5\n        if self.is_sparse():\n            head = min(self.X.shape[0], head)\n        s = \"[\" + \",\\n \".join(repr(ex) for ex in self[:head])\n        if len(self) > head:\n            s += \",\\n ...\"\n        s += \"\\n]\"\n        return s\n\n    @classmethod\n    def concatenate(cls, tables, axis=0):\n        \"\"\"\n        Concatenate tables into a new table, either vertically or horizontally.\n\n        If axis=0 (vertical concatenate), all tables must have the same domain.\n\n        If axis=1 (horizontal),\n        - all variable names must be unique.\n        - ids are copied from the first table.\n        - weights are copied from the first table in which they are defined.\n        - the dictionary of table's attributes are merged. If the same attribute\n          appears in multiple dictionaries, the earlier are used.\n\n        Args:\n            tables (Table): tables to be joined\n\n        Returns:\n            table (Table)\n        \"\"\"\n        if axis not in (0, 1):\n            raise ValueError(\"invalid axis\")\n        if not tables:\n            raise ValueError('need at least one table to concatenate')\n\n        if len(tables) == 1:\n            return tables[0].copy()\n\n        if axis == 0:\n            conc = cls._concatenate_vertical(tables)\n        else:\n            conc = cls._concatenate_horizontal(tables)\n\n        # TODO: Add attributes = {} to __init__\n        conc.attributes = getattr(conc, \"attributes\", {})\n        for table in reversed(tables):\n            conc.attributes.update(table.attributes)\n\n        names = [table.name for table in tables if table.name != \"untitled\"]\n        if names:\n            conc.name = names[0]\n        return conc\n\n    @classmethod\n    def _concatenate_vertical(cls, tables):\n        def vstack(arrs):\n            return [np, sp][any(sp.issparse(arr) for arr in arrs)].vstack(arrs)\n\n        def merge1d(arrs):\n            arrs = list(arrs)\n            ydims = {arr.ndim for arr in arrs}\n            if ydims == {1}:\n                return np.hstack(arrs)\n            else:\n                return vstack([\n                    arr if arr.ndim == 2 else np.atleast_2d(arr).T\n                    for arr in arrs\n                ])\n\n        def collect(attr):\n            return [getattr(arr, attr) for arr in tables]\n\n        domain = tables[0].domain\n        if any(table.domain != domain for table in tables):\n            raise ValueError('concatenated tables must have the same domain')\n\n        conc = cls.from_numpy(\n            domain,\n            vstack(collect(\"X\")),\n            merge1d(collect(\"Y\")),\n            vstack(collect(\"metas\")),\n            merge1d(collect(\"W\"))\n        )\n        conc.ids = np.hstack([t.ids for t in tables])\n        return conc\n\n    @classmethod\n    def _concatenate_horizontal(cls, tables):\n        \"\"\"\n        \"\"\"\n        def all_of(objs, names):\n            return (tuple(getattr(obj, name) for obj in objs)\n                    for name in names)\n\n        def stack(arrs):\n            non_empty = tuple(arr if arr.ndim == 2 else arr[:, np.newaxis]\n                              for arr in arrs\n                              if arr is not None and arr.size > 0)\n            return np.hstack(non_empty) if non_empty else None\n\n        doms, Ws = all_of(tables, (\"domain\", \"W\"))\n        Xs, Ys, Ms = map(stack, all_of(tables, (\"X\", \"Y\", \"metas\")))\n        # pylint: disable=undefined-loop-variable\n        for W in Ws:\n            if W.size:\n                break\n\n        parts = all_of(doms, (\"attributes\", \"class_vars\", \"metas\"))\n        domain = Domain(*(tuple(chain(*lst)) for lst in parts))\n        return cls.from_numpy(domain, Xs, Ys, Ms, W, ids=tables[0].ids)\n\n    def add_column(self, variable, data, to_metas=None):\n        \"\"\"\n        Create a new table with an additional column\n\n        Column's name must be unique\n\n        Args:\n            variable (Variable): variable for the new column\n            data (np.ndarray): data for the new column\n            to_metas (bool, optional): if `True` the column is added as meta\n                column. Otherwise, primitive variables are added to attributes\n                and non-primitive to metas.\n\n        Returns:\n            table (Table): a new table with the additional column\n        \"\"\"\n        dom = self.domain\n        attrs, classes, metavars = dom.attributes, dom.class_vars, dom.metas\n        to_metas = to_metas or not variable.is_primitive()\n        if to_metas:\n            metavars += (variable, )\n        else:\n            attrs += (variable, )\n        domain = Domain(attrs, classes, metavars)\n        new_table = self.transform(domain)\n        with new_table.unlocked(new_table.metas if to_metas else new_table.X):\n            new_table.get_column_view(variable)[0][:] = data\n        return new_table\n\n    def is_view(self):\n        \"\"\"\n        Return `True` if all arrays represent a view referring to another table\n        \"\"\"\n        return ((not self._X.shape[-1] or self._X.base is not None) and\n                (not self._Y.shape[-1] or self._Y.base is not None) and\n                (not self._metas.shape[-1] or self._metas.base is not None) and\n                (not self._weights.shape[-1] or self._W.base is not None))\n\n    def is_copy(self):\n        \"\"\"\n        Return `True` if the table owns its data\n        \"\"\"\n        return ((not self._X.shape[-1] or self._X.base is None) and\n                (self._Y.base is None) and\n                (self._metas.base is None) and\n                (self._W.base is None))\n\n    def is_sparse(self):\n        \"\"\"\n        Return `True` if the table stores data in sparse format\n        \"\"\"\n        return any(sp.issparse(i) for i in [self._X, self._Y, self._metas])\n\n    def ensure_copy(self):\n        \"\"\"\n        Ensure that the table owns its data; copy arrays when necessary.\n        \"\"\"\n\n        def is_view(x):\n            # Sparse matrices don't have views like numpy arrays. Since indexing on\n            # them creates copies in constructor we can skip this check here.\n            return not sp.issparse(x) and x.base is not None\n\n        if is_view(self._X):\n            self._X = self._X.copy()\n        if is_view(self._Y):\n            self._Y = self._Y.copy()\n        if is_view(self._metas):\n            self._metas = self._metas.copy()\n        if is_view(self._W):\n            self._W = self._W.copy()\n\n    def copy(self):\n        \"\"\"\n        Return a copy of the table\n        \"\"\"\n        t = self.__class__(self)\n        t.ensure_copy()\n        return t\n\n    @staticmethod\n    def __determine_density(data):\n        if data is None:\n            return Storage.Missing\n        if data is not None and sp.issparse(data):\n            return Storage.SPARSE_BOOL if (data.data == 1).all() else Storage.SPARSE\n        else:\n            return Storage.DENSE\n\n    def X_density(self):\n        if not hasattr(self, \"_X_density\"):\n            self._X_density = self.__determine_density(self.X)\n        return self._X_density\n\n    def Y_density(self):\n        if not hasattr(self, \"_Y_density\"):\n            self._Y_density = self.__determine_density(self._Y)\n        return self._Y_density\n\n    def metas_density(self):\n        if not hasattr(self, \"_metas_density\"):\n            self._metas_density = self.__determine_density(self.metas)\n        return self._metas_density\n\n    def set_weights(self, weight=1):\n        \"\"\"\n        Set weights of data instances; create a vector of weights if necessary.\n        \"\"\"\n        if not self.W.shape[-1]:\n            self.W = np.empty(len(self))\n        self.W[:] = weight\n\n    def has_weights(self):\n        \"\"\"Return `True` if the data instances are weighed. \"\"\"\n        return self.W.shape[-1] != 0\n\n    def total_weight(self):\n        \"\"\"\n        Return the total weight of instances in the table, or their number if\n        they are unweighted.\n        \"\"\"\n        if self.W.shape[-1]:\n            return sum(self.W)\n        return len(self)\n\n    def has_missing(self):\n        \"\"\"Return `True` if there are any missing attribute or class values.\"\"\"\n        missing_x = not sp.issparse(self.X) and bn.anynan(self.X)  # do not check for sparse X\n        return missing_x or bn.anynan(self._Y)\n\n    def has_missing_attribute(self):\n        \"\"\"Return `True` if there are any missing attribute values.\"\"\"\n        return not sp.issparse(self.X) and bn.anynan(self.X)  # do not check for sparse X\n\n    def has_missing_class(self):\n        \"\"\"Return `True` if there are any missing class values.\"\"\"\n        return bn.anynan(self._Y)\n\n    def get_nan_frequency_attribute(self):\n        if self.X.size == 0:\n            return 0\n        return np.isnan(self.X).sum() / self.X.size\n\n    def get_nan_frequency_class(self):\n        if self.Y.size == 0:\n            return 0\n        return np.isnan(self._Y).sum() / self._Y.size\n\n    def checksum(self, include_metas=True):\n        # TODO: zlib.adler32 does not work for numpy arrays with dtype object\n        # (after pickling and unpickling such arrays, checksum changes)\n        # Why, and should we fix it or remove it?\n        \"\"\"Return a checksum over X, Y, metas and W.\"\"\"\n        cs = zlib.adler32(np.ascontiguousarray(self._X))\n        cs = zlib.adler32(np.ascontiguousarray(self._Y), cs)\n        if include_metas:\n            cs = zlib.adler32(np.ascontiguousarray(self._metas), cs)\n        cs = zlib.adler32(np.ascontiguousarray(self._W), cs)\n        return cs\n\n    def shuffle(self):\n        \"\"\"Randomly shuffle the rows of the table.\"\"\"\n        if not self._check_all_dense():\n            raise ValueError(\"Rows of sparse data cannot be shuffled\")\n        ind = np.arange(self.X.shape[0])\n        np.random.shuffle(ind)\n        self.X = self.X[ind]\n        self._Y = self._Y[ind]\n        self.metas = self.metas[ind]\n        self.W = self.W[ind]\n\n    def get_column_view(self, index):\n        \"\"\"\n        Return a vector - as a view, not a copy - with a column of the table,\n        and a bool flag telling whether this column is sparse. Note that\n        vertical slicing of sparse matrices is inefficient.\n\n        :param index: the index of the column\n        :type index: int, str or Orange.data.Variable\n        :return: (one-dimensional numpy array, sparse)\n        \"\"\"\n\n        def rx(M):\n            if sp.issparse(M):\n                return np.asarray(M.todense())[:, 0], True\n            else:\n                return M, False\n\n        if isinstance(index, Integral):\n            col_index = index\n        else:\n            col_index = self.domain.index(index)\n        if col_index >= 0:\n            if col_index < self.X.shape[1]:\n                col = rx(self.X[:, col_index])\n            elif self._Y.ndim == 1 and col_index == self._X.shape[1]:\n                col = rx(self._Y)\n            else:\n                col = rx(self._Y[:, col_index - self.X.shape[1]])\n        else:\n            col = rx(self.metas[:, -1 - col_index])\n\n        if isinstance(index, DiscreteVariable) \\\n                and index.values != self.domain[col_index].values:\n            col = index.get_mapper_from(self.domain[col_index])(col[0]), col[1]\n            col[0].flags.writeable = False\n        return col\n\n    def _filter_is_defined(self, columns=None, negate=False):\n        # structure of function is obvious; pylint: disable=too-many-branches\n        def _sp_anynan(a):\n            return a.indptr[1:] != a[-1:] + a.shape[1]\n\n        if columns is None:\n            if sp.issparse(self.X):\n                remove = _sp_anynan(self.X)\n            else:\n                remove = bn.anynan(self.X, axis=1)\n            if sp.issparse(self._Y):\n                remove += _sp_anynan(self._Y)\n            else:\n                if self._Y.ndim == 1:\n                    remove += np.isnan(self._Y)\n                else:\n                    remove += bn.anynan(self._Y, axis=1)\n            if sp.issparse(self.metas):\n                remove += _sp_anynan(self._metas)\n            else:\n                for i, var in enumerate(self.domain.metas):\n                    col = self.metas[:, i].flatten()\n                    if var.is_primitive():\n                        remove += np.isnan(col.astype(float))\n                    else:\n                        remove += ~col.astype(bool)\n        else:\n            remove = np.zeros(len(self), dtype=bool)\n            for column in columns:\n                col, sparse = self.get_column_view(column)\n                if sparse:\n                    remove += col == 0\n                elif self.domain[column].is_primitive():\n                    remove += bn.anynan([col.astype(float)], axis=0)\n                else:\n                    remove += col.astype(bool)\n        retain = remove if negate else np.logical_not(remove)\n        return self.from_table_rows(self, retain)\n\n    def _filter_has_class(self, negate=False):\n        if sp.issparse(self._Y):\n            if negate:\n                retain = (self._Y.indptr[1:] !=\n                          self._Y.indptr[-1:] + self._Y.shape[1])\n            else:\n                retain = (self._Y.indptr[1:] ==\n                          self._Y.indptr[-1:] + self._Y.shape[1])\n        else:\n            if self._Y.ndim == 1:\n                retain = np.isnan(self._Y)\n            else:\n                retain = bn.anynan(self._Y, axis=1)\n            if not negate:\n                retain = np.logical_not(retain)\n        return self.from_table_rows(self, retain)\n\n    def _filter_same_value(self, column, value, negate=False):\n        if not isinstance(value, Real):\n            value = self.domain[column].to_val(value)\n        sel = self.get_column_view(column)[0] == value\n        if negate:\n            sel = np.logical_not(sel)\n        return self.from_table_rows(self, sel)\n\n    def _filter_values(self, filter):\n        selection = self._values_filter_to_indicator(filter)\n        return self.from_table(self.domain, self, selection)\n\n    def _values_filter_to_indicator(self, filter):\n        \"\"\"Return selection of rows matching the filter conditions\n\n        Handles conjunction/disjunction and negate modifiers\n\n        Parameters\n        ----------\n        filter: Values object containing the conditions\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        from Orange.data.filter import Values\n\n        if isinstance(filter, Values):\n            conditions = filter.conditions\n            conjunction = filter.conjunction\n        else:\n            conditions = [filter]\n            conjunction = True\n        if conjunction:\n            sel = np.ones(len(self), dtype=bool)\n        else:\n            sel = np.zeros(len(self), dtype=bool)\n\n        for f in conditions:\n            selection = self._filter_to_indicator(f)\n\n            if conjunction:\n                sel *= selection\n            else:\n                sel += selection\n\n        if filter.negate:\n            sel = ~sel\n        return sel\n\n    def _filter_to_indicator(self, filter):\n        \"\"\"Return selection of rows that match the condition.\n\n        Parameters\n        ----------\n        filter: ValueFilter describing the condition\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        from Orange.data.filter import (\n            FilterContinuous, FilterDiscrete, FilterRegex, FilterString,\n            FilterStringList, IsDefined, Values\n        )\n        if isinstance(filter, Values):\n            return self._values_filter_to_indicator(filter)\n\n        def get_col_indices():\n            cols = chain(self.domain.variables, self.domain.metas)\n            if isinstance(filter, IsDefined):\n                if filter.columns is not None:\n                    return list(filter.columns)\n                else:\n                    return list(cols)\n\n            if filter.column is not None:\n                return [filter.column]\n\n            if isinstance(filter, FilterDiscrete):\n                raise ValueError(\"Discrete filter can't be applied across rows\")\n            if isinstance(filter, FilterContinuous):\n                return [col for col in cols if col.is_continuous]\n            if isinstance(filter,\n                          (FilterString, FilterStringList, FilterRegex)):\n                return [col for col in cols if col.is_string]\n            raise TypeError(\"Invalid filter\")\n\n        def col_filter(col_idx):\n            col = self.get_column_view(col_idx)[0]\n            if isinstance(filter, IsDefined):\n                if self.domain[col_idx].is_primitive():\n                    return ~np.isnan(col.astype(float))\n                else:\n                    return col.astype(bool)\n            if isinstance(filter, FilterDiscrete):\n                return self._discrete_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterContinuous):\n                return self._continuous_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterString):\n                return self._string_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterStringList):\n                if not filter.case_sensitive:\n                    col = np.char.lower(np.array(col, dtype=str))\n                    vals = [val.lower() for val in filter.values]\n                else:\n                    vals = filter.values\n                return reduce(operator.add, (col == val for val in vals))\n            if isinstance(filter, FilterRegex):\n                return np.vectorize(filter)(col)\n            raise TypeError(\"Invalid filter\")\n\n        col_indices = get_col_indices()\n        if len(col_indices) == 1:\n            sel = col_filter(col_indices[0])\n        else:\n            sel = np.ones(len(self), dtype=bool)\n            for col_idx in col_indices:\n                sel *= col_filter(col_idx)\n\n        if isinstance(filter, IsDefined) and filter.negate:\n            sel = ~sel\n        return sel\n\n    def _discrete_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given discrete filter.\n\n        Parameters\n        ----------\n        filter: FilterDiscrete\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.values is None:  # <- is defined filter\n            col = col.astype(float)\n            return ~np.isnan(col)\n\n        sel = np.zeros(len(self), dtype=bool)\n        for val in filter.values:\n            if not isinstance(val, Real):\n                val = self.domain[filter.column].to_val(val)\n            sel += (col == val)\n        return sel\n\n    def _continuous_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given continuous filter.\n\n        Parameters\n        ----------\n        filter: FilterContinuous\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.oper == filter.IsDefined:\n            col = col.astype(float)\n            return ~np.isnan(col)\n\n        return self._range_filter_to_indicator(filter, col, filter.min, filter.max)\n\n    def _string_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given string filter.\n\n        Parameters\n        ----------\n        filter: FilterString\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.oper == filter.IsDefined:\n            return col.astype(bool)\n\n        col = col.astype(str)\n        fmin = filter.min or \"\"\n        fmax = filter.max or \"\"\n\n        if not filter.case_sensitive:\n            # convert all to lower case\n            col = np.char.lower(col)\n            fmin = fmin.lower()\n            fmax = fmax.lower()\n\n        if filter.oper == filter.Contains:\n            return np.fromiter((fmin in e for e in col),\n                               dtype=bool)\n        if filter.oper == filter.StartsWith:\n            return np.fromiter((e.startswith(fmin) for e in col),\n                               dtype=bool)\n        if filter.oper == filter.EndsWith:\n            return np.fromiter((e.endswith(fmin) for e in col),\n                               dtype=bool)\n\n        return self._range_filter_to_indicator(filter, col, fmin, fmax)\n\n    @staticmethod\n    def _range_filter_to_indicator(filter, col, fmin, fmax):\n        with np.errstate(invalid=\"ignore\"):  # nan's are properly discarded\n            if filter.oper == filter.Equal:\n                return col == fmin\n            if filter.oper == filter.NotEqual:\n                return col != fmin\n            if filter.oper == filter.Less:\n                return col < fmin\n            if filter.oper == filter.LessEqual:\n                return col <= fmin\n            if filter.oper == filter.Greater:\n                return col > fmin\n            if filter.oper == filter.GreaterEqual:\n                return col >= fmin\n            if filter.oper == filter.Between:\n                return (col >= fmin) * (col <= fmax)\n            if filter.oper == filter.Outside:\n                return (col < fmin) + (col > fmax)\n\n            raise TypeError(\"Invalid operator\")\n\n    def _compute_basic_stats(self, columns=None,\n                             include_metas=False, compute_variance=False):\n        if compute_variance:\n            raise NotImplementedError(\"computation of variance is \"\n                                      \"not implemented yet\")\n        W = self._W if self.has_weights() else None\n        rr = []\n        stats = []\n        if not columns:\n            if self.domain.attributes:\n                rr.append(fast_stats(self._X, W))\n            if self.domain.class_vars:\n                rr.append(fast_stats(self._Y, W))\n            if include_metas and self.domain.metas:\n                rr.append(fast_stats(self.metas, W))\n            if len(rr):\n                stats = np.vstack(tuple(rr))\n        else:\n            nattrs = len(self.domain.attributes)\n            for column in columns:\n                c = self.domain.index(column)\n                if 0 <= c < nattrs:\n                    S = fast_stats(self._X[:, [c]], W and W[:, [c]])\n                elif c >= nattrs:\n                    if self._Y.ndim == 1 and c == nattrs:\n                        S = fast_stats(self._Y[:, None], W and W[:, None])\n                    else:\n                        S = fast_stats(self._Y[:, [c - nattrs]], W and W[:, [c - nattrs]])\n                else:\n                    S = fast_stats(self._metas[:, [-1 - c]], W and W[:, [-1 - c]])\n                stats.append(S[0])\n        return stats\n\n    def _compute_distributions(self, columns=None):\n        if columns is None:\n            columns = range(len(self.domain.variables))\n        else:\n            columns = [self.domain.index(var) for var in columns]\n\n        distributions = []\n        X = self.X\n        if sp.issparse(X):\n            X = X.tocsc()\n\n\n        W = self.W.ravel() if self.has_weights() else None\n\n        for col in columns:\n            variable = self.domain[col]\n\n            # Select the correct data column from X, Y or metas\n            if 0 <= col < X.shape[1]:\n                x = X[:, col]\n            elif col < 0:\n                x = self.metas[:, col * (-1) - 1]\n                if np.issubdtype(x.dtype, np.dtype(object)):\n                    x = x.astype(float)\n            elif self._Y.ndim == 1 and col == X.shape[1]:\n                x = self._Y\n            else:\n                x = self._Y[:, col - X.shape[1]]\n\n            if variable.is_discrete:\n                dist, unknowns = bincount(x, weights=W, max_val=len(variable.values) - 1)\n            elif not x.shape[0]:\n                dist, unknowns = np.zeros((2, 0)), 0\n            else:\n                if W is not None:\n                    if sp.issparse(x):\n                        arg_sort = np.argsort(x.data)\n                        ranks = x.indices[arg_sort]\n                        vals = np.vstack((x.data[arg_sort], W[ranks]))\n                    else:\n                        ranks = np.argsort(x)\n                        vals = np.vstack((x[ranks], W[ranks]))\n                else:\n                    x_values = x.data if sp.issparse(x) else x\n                    vals = np.ones((2, x_values.shape[0]))\n                    vals[0, :] = x_values\n                    vals[0, :].sort()\n\n                dist = np.array(_valuecount.valuecount(vals))\n                # If sparse, then 0s will not be counted with `valuecount`, so\n                # we have to add them to the result manually.\n                if sp.issparse(x) and sparse_has_implicit_zeros(x):\n                    if W is not None:\n                        zero_weights = sparse_implicit_zero_weights(x, W).sum()\n                    else:\n                        zero_weights = sparse_count_implicit_zeros(x)\n                    zero_vec = [0, zero_weights]\n                    dist = np.insert(dist, np.searchsorted(dist[0], 0), zero_vec, axis=1)\n                # Since `countnans` assumes vector shape to be (1, n) and `x`\n                # shape is (n, 1), we pass the transpose\n                unknowns = countnans(x.T, W)\n            distributions.append((dist, unknowns))\n\n        return distributions\n\n    def _compute_contingency(self, col_vars=None, row_var=None):\n        n_atts = self.X.shape[1]\n\n        if col_vars is None:\n            col_vars = range(len(self.domain.variables))\n        else:\n            col_vars = [self.domain.index(var) for var in col_vars]\n        if row_var is None:\n            row_var = self.domain.class_var\n            if row_var is None:\n                raise ValueError(\"No row variable\")\n\n        row_desc = self.domain[row_var]\n        if not row_desc.is_discrete:\n            raise TypeError(\"Row variable must be discrete\")\n        row_indi = self.domain.index(row_var)\n        n_rows = len(row_desc.values)\n        if 0 <= row_indi < n_atts:\n            row_data = self.X[:, row_indi]\n        elif row_indi < 0:\n            row_data = self.metas[:, -1 - row_indi]\n        elif self._Y.ndim == 1 and row_indi == n_atts:\n            row_data = self._Y\n        else:\n            row_data = self._Y[:, row_indi - n_atts]\n\n        W = self.W if self.has_weights() else None\n\n        col_desc = [self.domain[var] for var in col_vars]\n        col_indi = [self.domain.index(var) for var in col_vars]\n\n        if any(not (var.is_discrete or var.is_continuous)\n               for var in col_desc):\n            raise ValueError(\"Contingency can be computed only for categorical \"\n                             \"and numeric values.\")\n\n        # when we select a column in sparse matrix it is still two dimensional\n        # and sparse - since it is just a column we can afford to transform\n        # it to dense and make it 1D\n        if issparse(row_data):\n            row_data = row_data.toarray().ravel()\n        if row_data.dtype.kind != \"f\":  # meta attributes can be stored as type object\n            row_data = row_data.astype(float)\n\n        contingencies = [None] * len(col_desc)\n        for arr, f_cond, f_ind in (\n                (self.X, lambda i: 0 <= i < n_atts, lambda i: i),\n                (self._Y, lambda i: i >= n_atts, lambda i: i - n_atts),\n                (self.metas, lambda i: i < 0, lambda i: -1 - i)):\n\n            arr_indi = [e for e, ind in enumerate(col_indi) if f_cond(ind)]\n\n            vars = [(e, f_ind(col_indi[e]), col_desc[e]) for e in arr_indi]\n            disc_vars = [v for v in vars if v[2].is_discrete]\n            if disc_vars:\n                if sp.issparse(arr):\n                    max_vals = max(len(v[2].values) for v in disc_vars)\n                    disc_indi = {i for _, i, _ in disc_vars}\n                    mask = [i in disc_indi for i in range(arr.shape[1])]\n                    conts, nans_cols, nans_rows, nans = contingency(\n                        arr, row_data, max_vals - 1, n_rows - 1, W, mask)\n                    for col_i, arr_i, var in disc_vars:\n                        n_vals = len(var.values)\n                        contingencies[col_i] = (\n                            conts[arr_i][:, :n_vals], nans_cols[arr_i],\n                            nans_rows[arr_i], nans[arr_i])\n                else:\n                    for col_i, arr_i, var in disc_vars:\n                        col = arr if arr.ndim == 1 else arr[:, arr_i]\n                        contingencies[col_i] = contingency(\n                            col.astype(float),\n                            row_data, len(var.values) - 1, n_rows - 1, W)\n\n            cont_vars = [v for v in vars if v[2].is_continuous]\n            if cont_vars:\n                W_ = None\n                if W is not None:\n                    W_ = W.astype(dtype=np.float64)\n                if sp.issparse(arr):\n                    arr = sp.csc_matrix(arr)\n\n                for col_i, arr_i, _ in cont_vars:\n                    if sp.issparse(arr):\n                        col_data = arr.data[arr.indptr[arr_i]:arr.indptr[arr_i + 1]]\n                        rows = arr.indices[arr.indptr[arr_i]:arr.indptr[arr_i + 1]]\n                        W_ = None if W_ is None else W_[rows]\n                        classes_ = row_data[rows]\n                    else:\n                        col_data, W_, classes_ = arr[:, arr_i], W_, row_data\n\n                    col_data = col_data.astype(dtype=np.float64)\n                    contingencies[col_i] = _contingency.contingency_floatarray(\n                        col_data, classes_, n_rows, W_)\n\n        return contingencies\n\n    @classmethod\n    def transpose(cls, table, feature_names_column=\"\",\n                  meta_attr_name=\"Feature name\", feature_name=\"Feature\",\n                  remove_redundant_inst=False, progress_callback=None):\n        \"\"\"\n        Transpose the table.\n\n        :param table: Table - table to transpose\n        :param feature_names_column: str - name of (String) meta attribute to\n            use for feature names\n        :param meta_attr_name: str - name of new meta attribute into which\n            feature names are mapped\n        :param feature_name: str - default feature name prefix\n        :param remove_redundant_inst: bool - remove instance that\n            represents feature_names_column\n        :param progress_callback: callable - to report the progress\n        :return: Table - transposed table\n        \"\"\"\n        if progress_callback is None:\n            progress_callback = dummy_callback\n        progress_callback(0, \"Transposing...\")\n\n        if isinstance(feature_names_column, Variable):\n            feature_names_column = feature_names_column.name\n\n        self = cls()\n        n_cols, self.n_rows = table.X.shape\n        old_domain = table.attributes.get(\"old_domain\")\n        table_domain_attributes = list(table.domain.attributes)\n        attr_index = None\n        if remove_redundant_inst:\n            attr_names = [a.name for a in table_domain_attributes]\n            if feature_names_column and feature_names_column in attr_names:\n                attr_index = attr_names.index(feature_names_column)\n                self.n_rows = self.n_rows - 1\n                table_domain_attributes.remove(\n                    table_domain_attributes[attr_index])\n\n        # attributes\n        # - classes and metas to attributes of attributes\n        # - arbitrary meta column to feature names\n        with self.unlocked():\n            self.X = table.X.T\n            if attr_index is not None:\n                self.X = np.delete(self.X, attr_index, 0)\n            if feature_names_column:\n                names = [str(row[feature_names_column]) for row in table]\n                progress_callback(0.1)\n                names = get_unique_names_duplicates(names)\n                progress_callback(0.3)\n                attributes = [ContinuousVariable(name) for name in names]\n            else:\n                places = int(np.ceil(np.log10(n_cols))) if n_cols else 1\n                attributes = [ContinuousVariable(f\"{feature_name} {i:0{places}}\")\n                              for i in range(1, n_cols + 1)]\n            progress_callback(0.4)\n\n            if old_domain is not None and feature_names_column:\n                for i, _ in enumerate(attributes):\n                    if attributes[i].name in old_domain:\n                        var = old_domain[attributes[i].name]\n                        attr = ContinuousVariable(var.name) if var.is_continuous \\\n                            else DiscreteVariable(var.name, var.values)\n                        attr.attributes = var.attributes.copy()\n                        attributes[i] = attr\n\n            def set_attributes_of_attributes(_vars, _table):\n                for i, variable in enumerate(_vars):\n                    if variable.name == feature_names_column:\n                        continue\n                    for j, row in enumerate(_table):\n                        value = variable.repr_val(row) if np.isscalar(row) \\\n                            else row[i] if isinstance(row[i], str) \\\n                            else variable.repr_val(row[i])\n\n                        if value not in MISSING_VALUES:\n                            attributes[j].attributes[variable.name] = value\n\n            set_attributes_of_attributes(table.domain.class_vars, table.Y)\n            progress_callback(0.5)\n            set_attributes_of_attributes(table.domain.metas, table.metas)\n\n            # weights\n            self.W = np.empty((self.n_rows, 0))\n\n            def get_table_from_attributes_of_attributes(_vars, _dtype=float):\n                T = np.empty((self.n_rows, len(_vars)), dtype=_dtype)\n                for i, _attr in enumerate(table_domain_attributes):\n                    for j, _var in enumerate(_vars):\n                        val = str(_attr.attributes.get(_var.name, \"\"))\n                        if not _var.is_string:\n                            val = np.nan if val in MISSING_VALUES else \\\n                                _var.values.index(val) if \\\n                                    _var.is_discrete else float(val)\n                        T[i, j] = val\n                return T\n\n            # class_vars - attributes of attributes to class - from old domain\n            class_vars = []\n            if old_domain is not None:\n                class_vars = old_domain.class_vars\n            self.Y = get_table_from_attributes_of_attributes(class_vars)\n\n            # metas\n            # - feature names and attributes of attributes to metas\n            self.metas, metas = np.empty((self.n_rows, 0), dtype=object), []\n            if meta_attr_name not in [m.name for m in table.domain.metas] and \\\n                    table_domain_attributes:\n                self.metas = np.array([[a.name] for a in table_domain_attributes],\n                                      dtype=object)\n                metas.append(StringVariable(meta_attr_name))\n\n            names = chain.from_iterable(list(attr.attributes)\n                                        for attr in table_domain_attributes)\n            names = sorted(set(names) - {var.name for var in class_vars})\n            progress_callback(0.6)\n\n            def guessed_var(i, var_name):\n                orig_vals = M[:, i]\n                val_map, vals, var_type = Orange.data.io.guess_data_type(orig_vals)\n                values, variable = Orange.data.io.sanitize_variable(\n                    val_map, vals, orig_vals, var_type, {}, name=var_name)\n                M[:, i] = values\n                return variable\n\n            _metas = [StringVariable(n) for n in names]\n            if old_domain is not None:\n                _metas = [m for m in old_domain.metas if m.name != meta_attr_name]\n            M = get_table_from_attributes_of_attributes(_metas, _dtype=object)\n            progress_callback(0.7)\n            if old_domain is None:\n                _metas = [guessed_var(i, m.name) for i, m in enumerate(_metas)]\n            if _metas:\n                self.metas = np.hstack((self.metas, M))\n                metas.extend(_metas)\n\n            self.domain = Domain(attributes, class_vars, metas)\n            progress_callback(0.9)\n            cls._init_ids(self)\n            self.attributes = table.attributes.copy()\n            self.attributes[\"old_domain\"] = table.domain\n            progress_callback(1)\n            return self\n\n    def to_sparse(self, sparse_attributes=True, sparse_class=False,\n                  sparse_metas=False):\n        def sparsify(features):\n            for f in features:\n                f.sparse = True\n\n        new_domain = self.domain.copy()\n\n        if sparse_attributes:\n            sparsify(new_domain.attributes)\n        if sparse_class:\n            sparsify(new_domain.class_vars)\n        if sparse_metas:\n            sparsify(new_domain.metas)\n        return self.transform(new_domain)\n\n    def to_dense(self, dense_attributes=True, dense_class=True,\n                 dense_metas=True):\n        def densify(features):\n            for f in features:\n                f.sparse = False\n\n        new_domain = self.domain.copy()\n\n        if dense_attributes:\n            densify(new_domain.attributes)\n        if dense_class:\n            densify(new_domain.class_vars)\n        if dense_metas:\n            densify(new_domain.metas)\n        t = self.transform(new_domain)\n        t.ids = self.ids  # preserve indices\n        return t\n\n\ndef _dereferenced(array):\n    # CSR and CSC matrices are constructed so that array.data is a\n    # view to a base, which prevents unlocking them. Therefore, if\n    # sparse matrix doesn't own its data, but its base array is\n    # referenced only by this matrix, we copy it. This doesn't\n    # increase memory use, but allows unlocking.\n    if sp.issparse(array) \\\n            and array.data.base is not None \\\n            and sys.getrefcount(array.data.base) == 2:  # 2 = 1 real + 1 for arg\n        array.data = array.data.copy()\n    return array\n\n\ndef _check_arrays(*arrays, dtype=None, shape_1=None):\n    checked = []\n    if not len(arrays):\n        return checked\n\n    def ninstances(array):\n        if hasattr(array, \"shape\"):\n            return array.shape[0]\n        else:\n            return len(array) if array is not None else 0\n\n    if shape_1 is None:\n        shape_1 = ninstances(arrays[0])\n\n    for array in arrays:\n        if array is None:\n            checked.append(array)\n            continue\n\n        if ninstances(array) != shape_1:\n            raise ValueError(\"Leading dimension mismatch (%d != %d)\"\n                             % (ninstances(array), shape_1))\n\n        if sp.issparse(array):\n            if not (sp.isspmatrix_csr(array) or sp.isspmatrix_csc(array)):\n                array = array.tocsr()\n            array.data = np.asarray(array.data)\n            array = _dereferenced(array)\n            has_inf = _check_inf(array.data)\n        else:\n            if dtype is not None:\n                array = np.asarray(array, dtype=dtype)\n            else:\n                array = np.asarray(array)\n            has_inf = _check_inf(array)\n\n        if has_inf:\n            array[np.isinf(array)] = np.nan\n            warnings.warn(\"Array contains infinity.\", RuntimeWarning)\n        checked.append(array)\n\n    return checked\n\n\ndef _check_inf(array):\n    return array.dtype.char in np.typecodes['AllFloat'] and \\\n           np.isinf(array.data).any()\n\n\ndef _subarray(arr, rows, cols):\n    rows = _optimize_indices(rows, arr.shape[0])\n    if arr.ndim == 1:\n        return arr[rows]\n    cols = _optimize_indices(cols, arr.shape[1])\n    return arr[_rxc_ix(rows, cols)]\n\n\ndef _optimize_indices(indices, maxlen):\n    \"\"\"\n    Convert integer indices to slice if possible. It only converts increasing\n    integer ranges with positive steps and valid starts and ends.\n    Only convert valid ends so that invalid ranges will still raise\n    an exception.\n\n    Allows numpy to reuse the data array, because it defaults to copying\n    if given indices.\n\n    Parameters\n    ----------\n    indices : 1D sequence, slice or Ellipsis\n    \"\"\"\n    if isinstance(indices, slice):\n        return indices\n\n    if indices is ...:\n        return slice(None, None, 1)\n\n    # a very common case for column selection\n    if len(indices) == 1 and not isinstance(indices[0], bool):\n        if indices[0] >= 0:\n            return slice(indices[0], indices[0] + 1, 1)\n        else:\n            return slice(indices[0], indices[0] - 1, -1)\n\n    if len(indices) >= 1:\n        indices = np.asarray(indices)\n        if indices.dtype != bool:\n            begin = indices[0]\n            end = indices[-1]\n            steps = np.diff(indices) if len(indices) > 1 else np.array([1])\n            step = steps[0]\n\n            # continuous ranges with constant step and valid start and stop index can be slices\n            if np.all(steps == step) and step > 0 and begin >= 0 and end < maxlen:\n                return slice(begin, end + step, step)\n\n    return indices\n\n\ndef _rxc_ix(rows, cols):\n    \"\"\"\n    Construct an index object to index the `rows` x `cols` cross product.\n\n    Rows and columns can be a 1d bool or int sequence, or a slice.\n    The later is a convenience and is interpreted the same\n    as `slice(None, None, -1)`\n\n    Parameters\n    ----------\n    rows : 1D sequence, slice\n        Row indices.\n    cols : 1D sequence, slice\n        Column indices.\n\n    See Also\n    --------\n    numpy.ix_\n\n    Examples\n    --------\n    >>> import numpy as np\n    >>> a = np.arange(10).reshape(2, 5)\n    >>> a[_rxc_ix([0, 1], [3, 4])]\n    array([[3, 4],\n           [8, 9]])\n    >>> a[_rxc_ix([False, True], slice(None, None, 1))]\n    array([[5, 6, 7, 8, 9]])\n\n    \"\"\"\n    isslice = (isinstance(rows, slice), isinstance(cols, slice))\n    if isslice == (True, True):\n        return rows, cols\n    elif isslice == (True, False):\n        return rows, np.asarray(np.ix_(cols), int).ravel()\n    elif isslice == (False, True):\n        return np.asarray(np.ix_(rows), int).ravel(), cols\n    else:\n        r, c = np.ix_(rows, cols)\n        return np.asarray(r, int), np.asarray(c, int)\n\n\ndef assure_domain_conversion_sparsity(target, source):\n    \"\"\"\n    Assure that the table obeys the domain conversion's suggestions about sparsity.\n\n    Args:\n        target (Table): the target table.\n        source (Table): the source table.\n\n    Returns:\n        Table: with fixed sparsity. The sparsity is set as it is recommended by domain conversion\n            for transformation from source to the target domain.\n    \"\"\"\n    conversion = DomainConversion(source.domain, target.domain)\n    match_density = [assure_array_dense, assure_array_sparse]\n    target.X = match_density[conversion.sparse_X](target.X)\n    target.Y = match_density[conversion.sparse_Y](target.Y)\n    target.metas = match_density[conversion.sparse_metas](target.metas)\n    return target\n\n\nclass Role:\n    Attribute = 0\n    ClassAttribute = 1\n    Meta = 2\n\n    @staticmethod\n    def get_arr(role, table):\n        return table.X if role == Role.Attribute else \\\n               table.Y if role == Role.ClassAttribute else \\\n               table.metas\n",
            "new_file_content": "import operator\nimport os\nimport sys\nimport threading\nimport warnings\nimport weakref\nimport zlib\nfrom collections.abc import Iterable, Sequence, Sized\nfrom contextlib import contextmanager\nfrom functools import reduce\nfrom itertools import chain\nfrom numbers import Real, Integral\nfrom threading import Lock\n\nimport bottleneck as bn\nimport numpy as np\n\nfrom scipy import sparse as sp\nfrom scipy.sparse import issparse, csc_matrix\n\nimport Orange.data  # import for io.py\nfrom Orange.data import (\n    _contingency, _valuecount,\n    Domain, Variable, Storage, StringVariable, Unknown, Value, Instance,\n    ContinuousVariable, DiscreteVariable, MISSING_VALUES,\n    DomainConversion)\nfrom Orange.data.util import SharedComputeValue, \\\n    assure_array_dense, assure_array_sparse, \\\n    assure_column_dense, assure_column_sparse, get_unique_names_duplicates\nfrom Orange.misc.collections import frozendict\nfrom Orange.statistics.util import bincount, countnans, contingency, \\\n    stats as fast_stats, sparse_has_implicit_zeros, sparse_count_implicit_zeros, \\\n    sparse_implicit_zero_weights\nfrom Orange.util import OrangeDeprecationWarning, dummy_callback\n\n__all__ = [\"dataset_dirs\", \"get_sample_datasets_dir\", \"RowInstance\", \"Table\"]\n\n\ndef get_sample_datasets_dir():\n    orange_data_table = os.path.dirname(__file__)\n    dataset_dir = os.path.join(orange_data_table, '..', 'datasets')\n    return os.path.realpath(dataset_dir)\n\n\ndataset_dirs = ['', get_sample_datasets_dir()]\n\n\nclass _ThreadLocal(threading.local):\n    def __init__(self):\n        super().__init__()\n        # Domain conversion cache used in Table.from_table. It is defined\n        # here instead of as a class variable of a Table so that caching also works\n        # with descendants of Table.\n        self.conversion_cache = None\n        self.domain_cache = None\n\n\n_thread_local = _ThreadLocal()\n\n\ndef _idcache_save(cachedict, keys, value):\n    cachedict[tuple(map(id, keys))] = \\\n        value, [weakref.ref(k) for k in keys]\n\n\ndef _idcache_restore(cachedict, keys):\n    shared, weakrefs = cachedict.get(tuple(map(id, keys)), (None, []))\n    for r in weakrefs:\n        if r() is None:\n            return None\n    return shared\n\n\nclass DomainTransformationError(Exception):\n    pass\n\n\nclass RowInstance(Instance):\n    sparse_x = None\n    sparse_y = None\n    sparse_metas = None\n    _weight = None\n\n    def __init__(self, table, row_index):\n        \"\"\"\n        Construct a data instance representing the given row of the table.\n        \"\"\"\n        self.table = table\n        self._domain = table.domain\n        self.row_index = row_index\n        self.id = table.ids[row_index]\n        self._x = table.X[row_index]\n        if sp.issparse(self._x):\n            self.sparse_x = sp.csr_matrix(self._x)\n            self._x = np.asarray(self._x.todense())[0]\n        self._y = table._Y[row_index]\n        if sp.issparse(self._y):\n            self.sparse_y = sp.csr_matrix(self._y)\n            self._y = np.asarray(self._y.todense())[0]\n        self._y = np.atleast_1d(self._y)\n        self._metas = table.metas[row_index]\n        if sp.issparse(self._metas):\n            self.sparse_metas = sp.csr_matrix(self._metas)\n            self._metas = np.asarray(self._metas.todense())[0]\n\n    @property\n    def weight(self):\n        if not self.table.has_weights():\n            return 1\n        return self.table.W[self.row_index]\n\n    @weight.setter\n    def weight(self, weight):\n        if not self.table.has_weights():\n            self.table.set_weights()\n        self.table.W[self.row_index] = weight\n\n    def set_class(self, value):\n        # pylint: disable=protected-access\n        self._check_single_class()\n        if not isinstance(value, Real):\n            value = self.table.domain.class_var.to_val(value)\n        if self.sparse_y:\n            self.table._Y[self.row_index, 0] = value\n        else:\n            self.table._Y[self.row_index] = value\n            if self.table._Y.ndim == 1:  # if _y is not a view\n                self._y[0] = value\n\n    def __setitem__(self, key, value):\n        if not isinstance(key, Integral):\n            key = self._domain.index(key)\n        if isinstance(value, str):\n            var = self._domain[key]\n            value = var.to_val(value)\n        if key >= 0:\n            if not isinstance(value, Real):\n                raise TypeError(\"Expected primitive value, got '%s'\" %\n                                type(value).__name__)\n            if key < len(self._x):\n                # write to self.table.X to support table unlocking for live instances\n                self.table.X[self.row_index, key] = value\n                if self.sparse_x is not None:\n                    self._x[key] = value\n            else:\n                if self.sparse_y is not None:\n                    self.table._Y[self.row_index, key - len(self._x)] = value\n                else:\n                    self.table._Y[self.row_index] = value\n                    if self.table._Y.ndim == 1:  # if _y is not a view\n                        self._y[0] = value\n        else:\n            self.table.metas[self.row_index, -1 - key] = value\n            if self.sparse_metas is not None:\n                self._metas[-1 - key] = value\n\n    def _str(self, limit):\n        def sp_values(matrix, variables):\n            if not sp.issparse(matrix):\n                if matrix.ndim == 1:\n                    matrix = matrix[:, np.newaxis]\n                return Instance.str_values(matrix[row], variables, limit)\n\n            row_entries, idx = [], 0\n            while idx < len(variables):\n                # Make sure to stop printing variables if we limit the output\n                if limit and len(row_entries) >= 5:\n                    break\n\n                var = variables[idx]\n                if var.is_discrete or matrix[row, idx]:\n                    row_entries.append(\"%s=%s\" % (var.name, var.str_val(matrix[row, idx])))\n\n                idx += 1\n\n            s = \", \".join(row_entries)\n\n            if limit and idx < len(variables):\n                s += \", ...\"\n\n            return s\n\n        table = self.table\n        domain = table.domain\n        row = self.row_index\n        s = \"[\" + sp_values(table.X, domain.attributes)\n        if domain.class_vars:\n            s += \" | \" + sp_values(table.Y, domain.class_vars)\n        s += \"]\"\n        if self._domain.metas:\n            s += \" {\" + sp_values(table.metas, domain.metas) + \"}\"\n        return s\n\n    def __str__(self):\n        return self._str(False)\n\n    def __repr__(self):\n        return self._str(True)\n\n\nclass Columns:\n    def __init__(self, domain):\n        for v in chain(domain.variables, domain.metas):\n            setattr(self, v.name.replace(\" \", \"_\"), v)\n\n\nclass _ArrayConversion:\n\n    def __init__(self, target, src_cols, variables, is_sparse, source_domain):\n        self.target = target\n        self.src_cols = src_cols\n        self.is_sparse = is_sparse\n        self.subarray_from = self._can_copy_all(src_cols, source_domain)\n        self.variables = variables\n        dtype = np.float64\n        if any(isinstance(var, StringVariable) for var in self.variables):\n            dtype = object\n        self.dtype = dtype\n        self.row_selection_needed = any(not isinstance(x, Integral)\n                                        for x in src_cols)\n\n    def _can_copy_all(self, src_cols, source_domain):\n        n_src_attrs = len(source_domain.attributes)\n        if all(isinstance(x, Integral) and 0 <= x < n_src_attrs\n               for x in src_cols):\n            return \"X\"\n        if all(isinstance(x, Integral) and x < 0 for x in src_cols):\n            return \"metas\"\n        if all(isinstance(x, Integral) and x >= n_src_attrs\n               for x in src_cols):\n            return \"Y\"\n\n    def get_subarray(self, source, row_indices, n_rows):\n        if not len(self.src_cols):\n            if self.is_sparse:\n                return sp.csr_matrix((n_rows, 0), dtype=source.X.dtype)\n            else:\n                return np.zeros((n_rows, 0), dtype=source.X.dtype)\n\n        match_density = assure_array_sparse if self.is_sparse else assure_array_dense\n        n_src_attrs = len(source.domain.attributes)\n        if self.subarray_from == \"X\":\n            arr = match_density(_subarray(source.X, row_indices, self.src_cols))\n        elif self.subarray_from == \"metas\":\n            arr = match_density(_subarray(source.metas, row_indices,\n                                          [-1 - x for x in self.src_cols]))\n        elif self.subarray_from == \"Y\":\n            Y = source.Y if source.Y.ndim == 2 else source.Y[:, None]\n            arr = match_density(_subarray(\n                Y, row_indices,\n                [x - n_src_attrs for x in self.src_cols]))\n        else:\n            assert False\n        if arr.dtype != self.dtype:\n            arr = arr.astype(self.dtype)\n        assert arr.ndim == 2 or self.subarray_from == \"Y\" and arr.ndim == 1\n        return arr\n\n    def get_columns(self, source, row_indices, n_rows, out=None, target_indices=None):\n        n_src_attrs = len(source.domain.attributes)\n\n        data = []\n        sp_col = []\n        sp_row = []\n        match_density = (\n            assure_column_sparse if self.is_sparse else assure_column_dense\n        )\n\n        # converting to csc before instead of each column is faster\n        # do not convert if not required\n        if any(isinstance(x, int) for x in self.src_cols):\n            X = source.X\n            Y = source.Y\n            if Y.ndim == 1:\n                Y = Y[:, None]\n            if self.is_sparse:\n                X = csc_matrix(X)\n                Y = csc_matrix(Y)\n\n        if self.row_selection_needed:\n            if row_indices is ...:\n                sourceri = source\n            else:\n                sourceri = source[row_indices]\n\n        shared_cache = _thread_local.conversion_cache\n        for i, col in enumerate(self.src_cols):\n            if col is None:\n                col_array = match_density(\n                    np.full((n_rows, 1), self.variables[i].Unknown)\n                )\n            elif not isinstance(col, Integral):\n                if isinstance(col, SharedComputeValue):\n                    shared = _idcache_restore(shared_cache, (col.compute_shared, source))\n                    if shared is None:\n                        shared = col.compute_shared(sourceri)\n                        _idcache_save(shared_cache, (col.compute_shared, source), shared)\n                    col_array = match_density(\n                        col(sourceri, shared_data=shared))\n                else:\n                    col_array = match_density(col(sourceri))\n            elif col < 0:\n                col_array = match_density(\n                    source.metas[row_indices, -1 - col]\n                )\n            elif col < n_src_attrs:\n                col_array = match_density(X[row_indices, col])\n            else:\n                col_array = match_density(\n                    Y[row_indices, col - n_src_attrs]\n                )\n\n            if self.is_sparse:\n                # col_array should be coo matrix\n                data.append(col_array.data)\n                sp_col.append(np.full(len(col_array.data), i))\n                sp_row.append(col_array.indices)  # row indices should be same\n            else:\n                out[target_indices, i] = col_array\n\n        if self.is_sparse:\n            # creating csr directly would need plenty of manual work which\n            # would probably slow down the process - conversion coo to csr\n            # is fast\n            out = sp.coo_matrix(\n                (np.hstack(data), (np.hstack(sp_row), np.hstack(sp_col))),\n                shape=(n_rows, len(self.src_cols)),\n                dtype=self.dtype\n            )\n            out = out.tocsr()\n\n        return out\n\n\nclass _FromTableConversion:\n\n    def __init__(self, source, destination):\n        conversion = DomainConversion(source, destination)\n\n        self.X = _ArrayConversion(\"X\", conversion.attributes,\n                                  destination.attributes, conversion.sparse_X,\n                                  source)\n        self.Y = _ArrayConversion(\"Y\", conversion.class_vars,\n                                  destination.class_vars, conversion.sparse_Y,\n                                  source)\n        self.metas = _ArrayConversion(\"metas\", conversion.metas,\n                                      destination.metas, conversion.sparse_metas,\n                                      source)\n\n        self.subarray = []\n        self.columnwise = []\n\n        for part in [self.X, self.Y, self.metas]:\n            if part.subarray_from is None:\n                self.columnwise.append(part)\n            else:\n                self.subarray.append(part)\n\n\n# noinspection PyPep8Naming\nclass Table(Sequence, Storage):\n\n    LOCKING = None\n    \"\"\" If the class attribute LOCKING is True, tables will throw exceptions\n    on in-place modifications unless unlocked explicitly. LOCKING is supposed\n    to be set to True for testing to help us find bugs. If set to False\n    or None, no safeguards are in place. Two different values are used for\n    the same behaviour to distinguish the unchanged default (None) form\n    explicit deactivation (False) that some add-ons might need. \"\"\"\n\n    __file__ = None\n    name = \"untitled\"\n\n    domain = Domain([])\n    _X = _Y = _metas = _W = np.zeros((0, 0))  # pylint: disable=invalid-name\n    ids = np.zeros(0)\n    ids.setflags(write=False)\n    attributes = frozendict()\n\n    _Unlocked_X, _Unlocked_Y, _Unlocked_metas, _Unlocked_W = 1, 2, 4, 8\n    _unlocked = _Unlocked_X + _Unlocked_Y + \\\n                _Unlocked_metas + _Unlocked_W  # pylint: disable=invalid-name\n\n    @property\n    def columns(self):\n        \"\"\"\n        A class whose attributes contain attribute descriptors for columns.\n        For a table `table`, setting `c = table.columns` will allow accessing\n        the table's variables with, for instance `c.gender`, `c.age` ets.\n        Spaces are replaced with underscores.\n        \"\"\"\n        return Columns(self.domain)\n\n    _next_instance_id = 0\n    _next_instance_lock = Lock()\n\n    def _check_unlocked(self, partflag):\n        if not self._unlocked & partflag:\n            raise ValueError(\"Table is read-only unless unlocked\")\n\n    @property\n    def X(self):  # pylint: disable=invalid-name\n        return self._X\n\n    @X.setter\n    def X(self, value):\n        self._check_unlocked(self._Unlocked_X)\n        self._X = _dereferenced(value)\n\n    @property\n    def Y(self):  # pylint: disable=invalid-name\n        return self._Y\n\n    @Y.setter\n    def Y(self, value):\n        self._check_unlocked(self._Unlocked_Y)\n        if sp.issparse(value) and len(self) != value.shape[0]:\n            value = value.T\n        if sp.issparse(value):\n            value = _dereferenced(value.toarray())\n        if value.ndim == 2 and value.shape[1] == 1:\n            value = value[:, 0].copy()  # no views!\n        self._Y = value\n\n    @property\n    def metas(self):\n        return self._metas\n\n    @metas.setter\n    def metas(self, value):\n        self._check_unlocked(self._Unlocked_metas)\n        self._metas = _dereferenced(value)\n\n    @property\n    def W(self):  # pylint: disable=invalid-name\n        return self._W\n\n    @W.setter\n    def W(self, value):\n        self._check_unlocked(self._Unlocked_W)\n        self._W = value\n\n    def __setstate__(self, state):\n        # Backward compatibility with pickles before table locking\n        self._initialize_unlocked()  # __dict__ seems to be cleared before calling __setstate__\n        with self.unlocked():\n            for k in (\"X\", \"W\", \"metas\"):\n                if k in state:\n                    setattr(self, k, state.pop(k))\n            if \"_Y\" in state:\n                setattr(self, \"Y\", state.pop(\"_Y\"))  # state[\"_Y\"] is a 2d array\n            self.__dict__.update(state)\n\n    def __getstate__(self):\n        # Compatibility with pickles before table locking:\n        # return the same state as before table lock\n        state = self.__dict__.copy()\n        for k in [\"X\", \"metas\", \"W\"]:\n            if \"_\" + k in state:  # Check existence; SQL tables do not contain them\n                state[k] = state.pop(\"_\" + k)\n        # before locking, _Y was always a 2d array: save it as such\n        if \"_Y\" in state:\n            y = state.pop(\"_Y\")\n            y2d = y.reshape(-1, 1) if y.ndim == 1 else y\n            state[\"_Y\"] = y2d\n        return state\n\n    def _lock_parts(self):\n        return ((self._X, self._Unlocked_X, \"X\"),\n                (self._Y, self._Unlocked_Y, \"Y\"),\n                (self._metas, self._Unlocked_metas, \"metas\"),\n                (self._W, self._Unlocked_W, \"weights\"))\n\n    def _initialize_unlocked(self):\n        if Table.LOCKING:\n            self._unlocked = 0\n        else:\n            self._unlocked = sum(f for _, f, _ in self._lock_parts())\n\n    def _update_locks(self, force=False, unlock_bases=()):\n        if not Table.LOCKING:\n            return\n\n        def sync(*xs):\n            for x in xs:\n                try:\n                    undo_on_fail.append((x, x.flags.writeable))\n                    x.flags.writeable = writeable\n                except ValueError:\n                    if force \\\n                            and writeable \\\n                            and x.base is not None \\\n                            and not x.base.flags.writeable:\n                        x.base.flags.writeable = writeable\n                        x.flags.writeable = writeable\n                        forced_bases.append(x.base)\n                    else:\n                        raise\n\n        forced_bases = []\n        undo_on_fail = []\n        for base in unlock_bases:\n            base.flags.writeable = False\n        try:\n            for part, flag, _ in self._lock_parts():\n                if part is None:\n                    continue\n                writeable = bool(self._unlocked & flag)\n                if sp.isspmatrix_csr(part) or sp.isspmatrix_csc(part):\n                    sync(part.data, part.indices, part.indptr)\n                elif sp.isspmatrix_coo(part):\n                    sync(part.data, part.row, part.col)\n                elif sp.issparse(part):\n                    raise ValueError(\"Unsupported sparse data type\")\n                else:\n                    sync(part)\n        except:\n            for part, flag in undo_on_fail:\n                part.flags.writeable = flag\n            raise\n        return tuple(forced_bases)\n\n    def __unlocked(self, *parts, force=False):\n        prev_state = self._unlocked\n        for part, flag, _ in self._lock_parts():\n            if not parts or any(ppart is part for ppart in parts):\n                self._unlocked |= flag\n        try:\n            forced_bases = self._update_locks(force)\n            yield\n        finally:\n            self._unlocked = prev_state\n            self._update_locks(unlock_bases=forced_bases)\n\n    def force_unlocked(self, *parts):\n        \"\"\"\n        Unlocking without any checks.\n\n        Use with extreme caution. This is meant primarily for 3rd party\n        functions in Cython that expect read-write buffer, but do not\n        actually modify it. the given parts (default: all parts) of the table.\n\n        The function will still fail to unlock and raise an exception if the\n        table contains view to another table.\n        \"\"\"\n        return contextmanager(self.__unlocked)(*parts, force=True)\n\n    def unlocked(self, *parts):\n        \"\"\"\n        Unlock the given parts (default: all parts) of the table.\n\n        The caller must ensure that the table is safe to modify. The function\n        will raise an exception if the table contains view to other table.\n        \"\"\"\n        def can_unlock(x):\n            if sp.issparse(x):\n                return can_unlock(x.data)\n            return x.flags.writeable or x.flags.owndata\n\n        for part, flag, name in self._lock_parts():\n            if not flag & self._unlocked \\\n                    and (not parts or any(ppart is part for ppart in parts)) \\\n                    and part is not None and not can_unlock(part):\n                raise ValueError(f\"'{name}' is a view into another table \"\n                                 \"and cannot be unlocked\")\n        return contextmanager(self.__unlocked)(*parts)\n\n    def __new__(cls, *args, **kwargs):\n        def warn_deprecated(method):\n            warnings.warn(\"Direct calls to Table's constructor are deprecated \"\n                          \"and will be removed. Replace this call with \"\n                          f\"Table.{method}\", OrangeDeprecationWarning,\n                          stacklevel=3)\n\n        if not args:\n            if not kwargs:\n                return super().__new__(cls)\n            else:\n                raise TypeError(\"Table() must not be called directly\")\n\n        if isinstance(args[0], str):\n            if len(args) > 1:\n                raise TypeError(\"Table(name: str) expects just one argument\")\n            if args[0].startswith('https://') or args[0].startswith('http://'):\n                return cls.from_url(args[0], **kwargs)\n            else:\n                return cls.from_file(args[0], **kwargs)\n\n        elif isinstance(args[0], Table):\n            if len(args) > 1:\n                raise TypeError(\"Table(table: Table) expects just one argument\")\n            return cls.from_table(args[0].domain, args[0], **kwargs)\n        elif isinstance(args[0], Domain):\n            domain, args = args[0], args[1:]\n            if not args:\n                warn_deprecated(\"from_domain\")\n                return cls.from_domain(domain, **kwargs)\n            if isinstance(args[0], Table):\n                warn_deprecated(\"from_table\")\n                return cls.from_table(domain, *args, **kwargs)\n            elif isinstance(args[0], list):\n                warn_deprecated(\"from_list\")\n                return cls.from_list(domain, *args, **kwargs)\n        else:\n            warnings.warn(\"Omitting domain in a call to Table(X, Y, metas), is \"\n                          \"deprecated and will be removed. \"\n                          \"Call Table.from_numpy(None, X, Y, metas) instead.\",\n                          OrangeDeprecationWarning, stacklevel=2)\n            domain = None\n\n        return cls.from_numpy(domain, *args, **kwargs)\n\n    def __init__(self, *args, **kwargs):  # pylint: disable=unused-argument\n        self._initialize_unlocked()\n        self._update_locks()\n\n    @classmethod\n    def from_domain(cls, domain, n_rows=0, weights=False):\n        \"\"\"\n        Construct a new `Table` with the given number of rows for the given\n        domain. The optional vector of weights is initialized to 1's.\n\n        :param domain: domain for the `Table`\n        :type domain: Orange.data.Domain\n        :param n_rows: number of rows in the new table\n        :type n_rows: int\n        :param weights: indicates whether to construct a vector of weights\n        :type weights: bool\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n        self = cls()\n        self.domain = domain\n        self.n_rows = n_rows\n        with self.unlocked():\n            self.X = np.zeros((n_rows, len(domain.attributes)))\n            if len(domain.class_vars) != 1:\n                self.Y = np.zeros((n_rows, len(domain.class_vars)))\n            else:\n                self.Y = np.zeros(n_rows)\n            if weights:\n                self.W = np.ones(n_rows)\n            else:\n                self.W = np.empty((n_rows, 0))\n            self.metas = np.empty((n_rows, len(self.domain.metas)), object)\n            cls._init_ids(self)\n            self.attributes = {}\n        return self\n\n    @classmethod\n    def from_table(cls, domain, source, row_indices=...):\n        \"\"\"\n        Create a new table from selected columns and/or rows of an existing\n        one. The columns are chosen using a domain. The domain may also include\n        variables that do not appear in the source table; they are computed\n        from source variables if possible.\n\n        The resulting data may be a view or a copy of the existing data.\n\n        :param domain: the domain for the new table\n        :type domain: Orange.data.Domain\n        :param source: the source table\n        :type source: Orange.data.Table\n        :param row_indices: indices of the rows to include\n        :type row_indices: a slice or a sequence\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n\n        PART = 5000\n\n        new_cache = _thread_local.conversion_cache is None\n        try:\n            if new_cache:\n                _thread_local.conversion_cache = {}\n                _thread_local.domain_cache = {}\n            else:\n                cached = _idcache_restore(_thread_local.conversion_cache, (domain, source))\n                if cached is not None:\n                    return cached\n            if domain is source.domain:\n                table = cls.from_table_rows(source, row_indices)\n                # assure resulting domain is the instance passed on input\n                table.domain = domain\n                # since sparse flags are not considered when checking for\n                # domain equality, fix manually.\n                with table.unlocked():\n                    table = assure_domain_conversion_sparsity(table, source)\n                return table\n\n            if row_indices is ...:\n                n_rows = len(source)\n            elif isinstance(row_indices, slice):\n                row_indices_range = range(*row_indices.indices(source.X.shape[0]))\n                n_rows = len(row_indices_range)\n            else:\n                n_rows = len(row_indices)\n\n            self = cls()\n            self.domain = domain\n\n            table_conversion = \\\n                _idcache_restore(_thread_local.domain_cache, (domain, source.domain))\n            if table_conversion is None:\n                table_conversion = _FromTableConversion(source.domain, domain)\n                _idcache_save(_thread_local.domain_cache, (domain, source.domain),\n                              table_conversion)\n\n            # if an array can be a subarray of the input table, this needs to be done\n            # on the whole table, because this avoids needless copies of contents\n\n            with self.unlocked():\n                for array_conv in table_conversion.subarray:\n                    out = array_conv.get_subarray(source, row_indices, n_rows)\n                    setattr(self, array_conv.target, out)\n\n                parts = {}\n\n                for array_conv in table_conversion.columnwise:\n                    if array_conv.is_sparse:\n                        parts[array_conv.target] = []\n                    else:\n                        # F-order enables faster writing to the array while accessing and\n                        # matrix operations work with same speed (e.g. dot)\n                        parts[array_conv.target] = \\\n                            np.zeros((n_rows, len(array_conv.src_cols)),\n                                     order=\"F\", dtype=array_conv.dtype)\n\n                if n_rows <= PART:\n                    for array_conv in table_conversion.columnwise:\n                        out = array_conv.get_columns(source, row_indices, n_rows,\n                                                     parts[array_conv.target],\n                                                     ...)\n                        setattr(self, array_conv.target, out)\n                else:\n                    i_done = 0\n\n                    while i_done < n_rows:\n                        target_indices = slice(i_done, min(n_rows, i_done + PART))\n                        if row_indices is ...:\n                            source_indices = target_indices\n                        elif isinstance(row_indices, slice):\n                            r = row_indices_range[target_indices]\n                            source_indices = slice(r.start, r.stop, r.step)\n                        else:\n                            source_indices = row_indices[target_indices]\n                        part_rows = min(n_rows, i_done+PART) - i_done\n\n                        for array_conv in table_conversion.columnwise:\n                            out = array_conv.get_columns(source, source_indices, part_rows,\n                                                         parts[array_conv.target],\n                                                         target_indices)\n                            if array_conv.is_sparse:  # dense arrays are populated in-place\n                                parts[array_conv.target].append(out)\n\n                        i_done += PART\n\n                        # clear cache after a part is done\n                        if new_cache:\n                            _thread_local.conversion_cache = {}\n\n                    for array_conv in table_conversion.columnwise:\n                        cparts = parts[array_conv.target]\n                        out = cparts if not array_conv.is_sparse else sp.vstack(cparts)\n                        setattr(self, array_conv.target, out)\n\n                if source.has_weights():\n                    self.W = source.W[row_indices]\n                else:\n                    self.W = np.empty((n_rows, 0))\n                self.name = getattr(source, 'name', '')\n                if hasattr(source, 'ids'):\n                    self.ids = source.ids[row_indices]\n                else:\n                    cls._init_ids(self)\n                self.attributes = getattr(source, 'attributes', {})\n                _idcache_save(_thread_local.conversion_cache, (domain, source), self)\n            return self\n        finally:\n            if new_cache:\n                _thread_local.conversion_cache = None\n                _thread_local.domain_cache = None\n\n    def transform(self, domain):\n        \"\"\"\n        Construct a table with a different domain.\n\n        The new table keeps the row ids and other information. If the table\n        is a subclass of :obj:`Table`, the resulting table will be of the same\n        type.\n\n        In a typical scenario, an existing table is augmented with a new\n        column by ::\n\n            domain = Domain(old_domain.attributes + [new_attribute],\n                            old_domain.class_vars,\n                            old_domain.metas)\n            table = data.transform(domain)\n            table[:, new_attribute] = new_column\n\n        Args:\n            domain (Domain): new domain\n\n        Returns:\n            A new table\n        \"\"\"\n        return type(self).from_table(domain, self)\n\n    @classmethod\n    def from_table_rows(cls, source, row_indices):\n        \"\"\"\n        Construct a new table by selecting rows from the source table.\n\n        :param source: an existing table\n        :type source: Orange.data.Table\n        :param row_indices: indices of the rows to include\n        :type row_indices: a slice or a sequence\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n        def get_rows(a):\n            a = a[row_indices]\n            if isinstance(row_indices, slice) or row_indices is ...:\n                a = a.copy()\n            return a\n\n        self = cls()\n        self.domain = source.domain\n        with self.unlocked():\n            self.X = get_rows(source.X)\n            if self.X.ndim == 1:\n                self.X = self.X.reshape(-1, len(self.domain.attributes))\n            self.Y = get_rows(source.Y)\n            self.metas = get_rows(source.metas)\n            if self.metas.ndim == 1:\n                self.metas = self.metas.reshape(-1, len(self.domain.metas))\n            self.W = get_rows(source.W)\n            self.name = getattr(source, 'name', '')\n            self.ids = np.array(source.ids[row_indices])\n            self.attributes = getattr(source, 'attributes', {})\n        return self\n\n    @classmethod\n    def from_numpy(cls, domain, X, Y=None, metas=None, W=None,\n                   attributes=None, ids=None):\n        \"\"\"\n        Construct a table from numpy arrays with the given domain. The number\n        of variables in the domain must match the number of columns in the\n        corresponding arrays. All arrays must have the same number of rows.\n        Arrays may be of different numpy types, and may be dense or sparse.\n\n        :param domain: the domain for the new table\n        :type domain: Orange.data.Domain\n        :param X: array with attribute values\n        :type X: np.array\n        :param Y: array with class values\n        :type Y: np.array\n        :param metas: array with meta attributes\n        :type metas: np.array\n        :param W: array with weights\n        :type W: np.array\n        :return:\n        \"\"\"\n        X, Y, W = _check_arrays(X, Y, W, dtype='float64')\n        metas, = _check_arrays(metas, dtype=object, shape_1=X.shape[0])\n        ids, = _check_arrays(ids, dtype=int, shape_1=X.shape[0])\n\n        if domain is None:\n            domain = Domain.from_numpy(X, Y, metas)\n\n        if Y is None:\n            if not domain.class_vars or sp.issparse(X):\n                Y = np.empty((X.shape[0], 0), dtype=np.float64)\n            else:\n                own_data = X.flags.owndata and X.base is None\n                Y = X[:, len(domain.attributes):]\n                X = X[:, :len(domain.attributes)]\n                if own_data:\n                    Y = Y.copy()\n                    X = X.copy()\n        if metas is None:\n            metas = np.empty((X.shape[0], 0), object)\n        if W is None or W.size == 0:\n            W = np.empty((X.shape[0], 0))\n        elif W.shape != (W.size, ):\n            W = W.reshape(W.size).copy()\n\n        if X.shape[1] != len(domain.attributes):\n            raise ValueError(\n                \"Invalid number of variable columns ({} != {})\".format(\n                    X.shape[1], len(domain.attributes))\n            )\n        if Y.ndim == 1:\n            if not domain.class_var:\n                raise ValueError(\n                    \"Invalid number of class columns \"\n                    f\"(1 != {len(domain.class_vars)})\")\n        elif Y.shape[1] != len(domain.class_vars):\n            raise ValueError(\n                \"Invalid number of class columns ({} != {})\".format(\n                    Y.shape[1], len(domain.class_vars))\n            )\n        if metas.shape[1] != len(domain.metas):\n            raise ValueError(\n                \"Invalid number of meta attribute columns ({} != {})\".format(\n                    metas.shape[1], len(domain.metas))\n            )\n        if not X.shape[0] == Y.shape[0] == metas.shape[0] == W.shape[0]:\n            raise ValueError(\n                \"Parts of data contain different numbers of rows.\")\n\n        self = cls()\n        with self.unlocked():\n            self.domain = domain\n            self.X = X\n            self.Y = Y\n            self.metas = metas\n            self.W = W\n            self.n_rows = self.X.shape[0]\n            if ids is None:\n                cls._init_ids(self)\n            else:\n                self.ids = ids\n            self.attributes = {} if attributes is None else attributes\n        return self\n\n    @classmethod\n    def from_list(cls, domain, rows, weights=None):\n        if weights is not None and len(rows) != len(weights):\n            raise ValueError(\"mismatching number of instances and weights\")\n        self = cls.from_domain(domain, len(rows), weights is not None)\n        all_vars = domain.variables + domain.metas\n        nattrs = len(domain.attributes)\n        nattrscls = len(domain.variables)\n        with self.unlocked():\n            for i, row in enumerate(rows):\n                if isinstance(row, Instance):\n                    row = row.list\n                vals = [var.to_val(val) for var, val in zip(all_vars, row)]\n                self.X[i] = vals[:nattrs]\n                if self._Y.ndim == 1:\n                    self._Y[i] = vals[nattrs] if nattrs < len(vals) else np.nan\n                else:\n                    self._Y[i] = vals[nattrs:nattrscls]\n                # for backward compatibility: allow omittine some (or all) metas\n                self.metas[i, :len(vals) - nattrscls] = vals[nattrscls:]\n            if weights is not None:\n                self.W = np.array(weights)\n            self.attributes = {}\n        return self\n\n    @classmethod\n    def _init_ids(cls, obj):\n        with cls._next_instance_lock:\n            obj.ids = np.array(range(cls._next_instance_id, cls._next_instance_id + obj.X.shape[0]))\n            cls._next_instance_id += obj.X.shape[0]\n\n    @classmethod\n    def new_id(cls):\n        with cls._next_instance_lock:\n            id = cls._next_instance_id\n            cls._next_instance_id += 1\n            return id\n\n    def to_pandas_dfs(self):\n        return Orange.data.pandas_compat.table_to_frames(self)\n\n    @staticmethod\n    def from_pandas_dfs(xdf, ydf, mdf):\n        return Orange.data.pandas_compat.table_from_frames(xdf, ydf, mdf)\n\n    @property\n    def X_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.Attribute\n        )\n\n    @X_df.setter\n    def X_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.Attribute\n        )\n\n    @property\n    def Y_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.ClassAttribute\n        )\n\n    @Y_df.setter\n    def Y_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.ClassAttribute\n        )\n\n    @property\n    def metas_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.Meta\n        )\n\n    @metas_df.setter\n    def metas_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.Meta\n        )\n\n    def save(self, filename):\n        \"\"\"\n        Save a data table to a file. The path can be absolute or relative.\n\n        :param filename: File name\n        :type filename: str\n        \"\"\"\n        ext = os.path.splitext(filename)[1]\n        from Orange.data.io import FileFormat\n        writer = FileFormat.writers.get(ext)\n        if not writer:\n            desc = FileFormat.names.get(ext)\n            if desc:\n                raise IOError(\n                    \"Writing of {}s is not supported\".format(desc.lower()))\n            else:\n                raise IOError(\"Unknown file name extension.\")\n        writer.write_file(filename, self)\n\n    @classmethod\n    def from_file(cls, filename, sheet=None):\n        \"\"\"\n        Read a data table from a file. The path can be absolute or relative.\n\n        :param filename: File name\n        :type filename: str\n        :param sheet: Sheet in a file (optional)\n        :type sheet: str\n        :return: a new data table\n        :rtype: Orange.data.Table\n        \"\"\"\n        from Orange.data.io import FileFormat\n\n        absolute_filename = FileFormat.locate(filename, dataset_dirs)\n        reader = FileFormat.get_reader(absolute_filename)\n        reader.select_sheet(sheet)\n        data = reader.read()\n\n        # Readers return plain table. Make sure to cast it to appropriate\n        # (subclass) type\n        if cls != data.__class__:\n            data = cls(data)\n\n        # no need to call _init_ids as fuctions from .io already\n        # construct a table with .ids\n\n        data.__file__ = absolute_filename\n        return data\n\n    @classmethod\n    def from_url(cls, url):\n        from Orange.data.io import UrlReader\n        reader = UrlReader(url)\n        data = reader.read()\n        if cls != data.__class__:\n            data = cls(data)\n        return data\n\n    # Helper function for __setitem__:\n    # Set the row of table data matrices\n    # noinspection PyProtectedMember\n    def _set_row(self, example, row):\n        # pylint: disable=protected-access\n        domain = self.domain\n        if isinstance(example, Instance):\n            if example.domain == domain:\n                self.X[row] = example._x\n                if self._Y.ndim == 1:\n                    self._Y[row] = float(example._y)\n                else:\n                    self._Y[row] = np.atleast_1d(example._y)\n                self.metas[row] = example._metas\n                return\n\n            self.X[row], self._Y[row], self.metas[row] = \\\n                self.domain.convert(example)\n            try:\n                self.ids[row] = example.id\n            except:\n                with type(self)._next_instance_lock:\n                    self.ids[row] = type(self)._next_instance_id\n                    type(self)._next_instance_id += 1\n\n        else:\n            attrs = domain.attributes\n            if len(example) != len(domain.variables):\n                raise ValueError(\"invalid length\")\n            self._X[row] = [var.to_val(val) for var, val in zip(attrs, example)]\n            if self._Y.ndim == 1:\n                self._Y[row] = domain.class_var.to_val(example[len(attrs)])\n            else:\n                self._Y[row] = [var.to_val(val)\n                                for var, val in zip(domain.class_vars,\n                                                    example[len(attrs):])]\n            self.metas[row] = np.array([var.Unknown for var in domain.metas],\n                                       dtype=object)\n\n    def _check_all_dense(self):\n        return all(x in (Storage.DENSE, Storage.MISSING)\n                   for x in (self.X_density(), self.Y_density(),\n                             self.metas_density()))\n\n    def __getitem__(self, key):\n        if isinstance(key, Integral):\n            return RowInstance(self, key)\n        if not isinstance(key, tuple):\n            return self.from_table_rows(self, key)\n\n        if len(key) != 2:\n            raise IndexError(\"Table indices must be one- or two-dimensional\")\n\n        row_idx, col_idx = key\n        if isinstance(row_idx, Integral):\n            if isinstance(col_idx, (str, Integral, Variable)):\n                col_idx = self.domain.index(col_idx)\n                var = self.domain[col_idx]\n                if 0 <= col_idx < len(self.domain.attributes):\n                    val = self.X[row_idx, col_idx]\n                elif col_idx == len(self.domain.attributes) and self._Y.ndim == 1:\n                    val = self._Y[row_idx]\n                elif col_idx >= len(self.domain.attributes):\n                    val = self._Y[row_idx,\n                                  col_idx - len(self.domain.attributes)]\n                else:\n                    val = self.metas[row_idx, -1 - col_idx]\n                if isinstance(col_idx, DiscreteVariable) and var is not col_idx:\n                    val = col_idx.get_mapper_from(var)(val)\n                return Value(var, val)\n            else:\n                row_idx = [row_idx]\n\n        # multiple rows OR single row but multiple columns:\n        # construct a new table\n        attributes, col_indices = self.domain._compute_col_indices(col_idx)\n        if attributes is not None:\n            n_attrs = len(self.domain.attributes)\n            r_attrs = [attributes[i]\n                       for i, col in enumerate(col_indices)\n                       if 0 <= col < n_attrs]\n            r_classes = [attributes[i]\n                         for i, col in enumerate(col_indices)\n                         if col >= n_attrs]\n            r_metas = [attributes[i]\n                       for i, col in enumerate(col_indices) if col < 0]\n            domain = Domain(r_attrs, r_classes, r_metas)\n        else:\n            domain = self.domain\n        return self.from_table(domain, self, row_idx)\n\n    def __setitem__(self, key, value):\n        if not isinstance(key, tuple):\n            if isinstance(value, Real):\n                self.X[key, :] = value\n                return\n            self._set_row(value, key)\n            return\n\n        if len(key) != 2:\n            raise IndexError(\"Table indices must be one- or two-dimensional\")\n        row_idx, col_idx = key\n\n        # single row\n        if isinstance(row_idx, Integral):\n            if isinstance(col_idx, slice):\n                col_idx = range(*slice.indices(col_idx, self.X.shape[1]))\n            if not isinstance(col_idx, str) and isinstance(col_idx, Iterable):\n                col_idx = list(col_idx)\n            if not isinstance(col_idx, str) and isinstance(col_idx, Sized):\n                if isinstance(value, (Sequence, np.ndarray)):\n                    values = value\n                elif isinstance(value, Iterable):\n                    values = list(value)\n                else:\n                    raise TypeError(\"Setting multiple values requires a \"\n                                    \"sequence or numpy array\")\n                if len(values) != len(col_idx):\n                    raise ValueError(\"Invalid number of values\")\n            else:\n                col_idx, values = [col_idx], [value]\n            if isinstance(col_idx, DiscreteVariable) \\\n                    and self.domain[col_idx] != col_idx:\n                values = self.domain[col_idx].get_mapper_from(col_idx)(values)\n            for val, col_idx in zip(values, col_idx):\n                if not isinstance(val, Integral):\n                    val = self.domain[col_idx].to_val(val)\n                if not isinstance(col_idx, Integral):\n                    col_idx = self.domain.index(col_idx)\n                if col_idx >= 0:\n                    if col_idx < self.X.shape[1]:\n                        self.X[row_idx, col_idx] = val\n                    elif self._Y.ndim == 1 and col_idx == self.X.shape[1]:\n                        self._Y[row_idx] = val\n                    else:\n                        self._Y[row_idx, col_idx - self.X.shape[1]] = val\n                else:\n                    self.metas[row_idx, -1 - col_idx] = val\n\n        # multiple rows, multiple columns\n        attributes, col_indices = self.domain._compute_col_indices(col_idx)\n        if col_indices is ...:\n            col_indices = range(len(self.domain.variables))\n        n_attrs = self.X.shape[1]\n        if isinstance(value, str):\n            if not attributes:\n                attributes = self.domain.attributes\n            for var, col in zip(attributes, col_indices):\n                val = var.to_val(value)\n                if 0 <= col < n_attrs:\n                    self.X[row_idx, col] = val\n                elif col >= n_attrs:\n                    if self._Y.ndim == 1 and col == n_attrs:\n                        self._Y[row_idx] = val\n                    else:\n                        self._Y[row_idx, col - n_attrs] = val\n                else:\n                    self.metas[row_idx, -1 - col] = val\n        else:\n            attr_cols = np.fromiter(\n                (col for col in col_indices if 0 <= col < n_attrs), int)\n            class_cols = np.fromiter(\n                (col - n_attrs for col in col_indices if col >= n_attrs), int)\n            meta_cols = np.fromiter(\n                (-1 - col for col in col_indices if col < 0), int)\n            if value is None:\n                value = Unknown\n\n            if not isinstance(value, (Real, np.ndarray)) and \\\n                    (len(attr_cols) or len(class_cols)):\n                raise TypeError(\n                    \"Ordinary attributes can only have primitive values\")\n            if len(attr_cols):\n                self.X[row_idx, attr_cols] = value\n            if len(class_cols):\n                if self._Y.ndim == 1 and np.all(class_cols == 0):\n                    if isinstance(value, np.ndarray):\n                        yshape = self._Y[row_idx].shape\n                        if value.shape != yshape:\n                            value = value.reshape(yshape)\n                    self._Y[row_idx] = value\n                else:\n                    self._Y[row_idx, class_cols] = value\n            if len(meta_cols):\n                self.metas[row_idx, meta_cols] = value\n\n    def __len__(self):\n        return self.X.shape[0]\n\n    def __str__(self):\n        return \"[\" + \",\\n \".join(str(ex) for ex in self) + \"]\"\n\n    def __repr__(self):\n        head = 5\n        if self.is_sparse():\n            head = min(self.X.shape[0], head)\n        s = \"[\" + \",\\n \".join(repr(ex) for ex in self[:head])\n        if len(self) > head:\n            s += \",\\n ...\"\n        s += \"\\n]\"\n        return s\n\n    @classmethod\n    def concatenate(cls, tables, axis=0):\n        \"\"\"\n        Concatenate tables into a new table, either vertically or horizontally.\n\n        If axis=0 (vertical concatenate), all tables must have the same domain.\n\n        If axis=1 (horizontal),\n        - all variable names must be unique.\n        - ids are copied from the first table.\n        - weights are copied from the first table in which they are defined.\n        - the dictionary of table's attributes are merged. If the same attribute\n          appears in multiple dictionaries, the earlier are used.\n\n        Args:\n            tables (Table): tables to be joined\n\n        Returns:\n            table (Table)\n        \"\"\"\n        if axis not in (0, 1):\n            raise ValueError(\"invalid axis\")\n        if not tables:\n            raise ValueError('need at least one table to concatenate')\n\n        if len(tables) == 1:\n            return tables[0].copy()\n\n        if axis == 0:\n            conc = cls._concatenate_vertical(tables)\n        else:\n            conc = cls._concatenate_horizontal(tables)\n\n        # TODO: Add attributes = {} to __init__\n        conc.attributes = getattr(conc, \"attributes\", {})\n        for table in reversed(tables):\n            conc.attributes.update(table.attributes)\n\n        names = [table.name for table in tables if table.name != \"untitled\"]\n        if names:\n            conc.name = names[0]\n        return conc\n\n    @classmethod\n    def _concatenate_vertical(cls, tables):\n        def vstack(arrs):\n            return [np, sp][any(sp.issparse(arr) for arr in arrs)].vstack(arrs)\n\n        def merge1d(arrs):\n            arrs = list(arrs)\n            ydims = {arr.ndim for arr in arrs}\n            if ydims == {1}:\n                return np.hstack(arrs)\n            else:\n                return vstack([\n                    arr if arr.ndim == 2 else np.atleast_2d(arr).T\n                    for arr in arrs\n                ])\n\n        def collect(attr):\n            return [getattr(arr, attr) for arr in tables]\n\n        domain = tables[0].domain\n        if any(table.domain != domain for table in tables):\n            raise ValueError('concatenated tables must have the same domain')\n\n        conc = cls.from_numpy(\n            domain,\n            vstack(collect(\"X\")),\n            merge1d(collect(\"Y\")),\n            vstack(collect(\"metas\")),\n            merge1d(collect(\"W\"))\n        )\n        conc.ids = np.hstack([t.ids for t in tables])\n        return conc\n\n    @classmethod\n    def _concatenate_horizontal(cls, tables):\n        \"\"\"\n        \"\"\"\n        def all_of(objs, names):\n            return (tuple(getattr(obj, name) for obj in objs)\n                    for name in names)\n\n        def stack(arrs):\n            non_empty = tuple(arr if arr.ndim == 2 else arr[:, np.newaxis]\n                              for arr in arrs\n                              if arr is not None and arr.size > 0)\n            return np.hstack(non_empty) if non_empty else None\n\n        doms, Ws = all_of(tables, (\"domain\", \"W\"))\n        Xs, Ys, Ms = map(stack, all_of(tables, (\"X\", \"Y\", \"metas\")))\n        # pylint: disable=undefined-loop-variable\n        for W in Ws:\n            if W.size:\n                break\n\n        parts = all_of(doms, (\"attributes\", \"class_vars\", \"metas\"))\n        domain = Domain(*(tuple(chain(*lst)) for lst in parts))\n        return cls.from_numpy(domain, Xs, Ys, Ms, W, ids=tables[0].ids)\n\n    def add_column(self, variable, data, to_metas=None):\n        \"\"\"\n        Create a new table with an additional column\n\n        Column's name must be unique\n\n        Args:\n            variable (Variable): variable for the new column\n            data (np.ndarray): data for the new column\n            to_metas (bool, optional): if `True` the column is added as meta\n                column. Otherwise, primitive variables are added to attributes\n                and non-primitive to metas.\n\n        Returns:\n            table (Table): a new table with the additional column\n        \"\"\"\n        dom = self.domain\n        attrs, classes, metavars = dom.attributes, dom.class_vars, dom.metas\n        to_metas = to_metas or not variable.is_primitive()\n        if to_metas:\n            metavars += (variable, )\n        else:\n            attrs += (variable, )\n        domain = Domain(attrs, classes, metavars)\n        new_table = self.transform(domain)\n        with new_table.unlocked(new_table.metas if to_metas else new_table.X):\n            new_table.get_column_view(variable)[0][:] = data\n        return new_table\n\n    def is_view(self):\n        \"\"\"\n        Return `True` if all arrays represent a view referring to another table\n        \"\"\"\n        return ((not self._X.shape[-1] or self._X.base is not None) and\n                (not self._Y.shape[-1] or self._Y.base is not None) and\n                (not self._metas.shape[-1] or self._metas.base is not None) and\n                (not self._weights.shape[-1] or self._W.base is not None))\n\n    def is_copy(self):\n        \"\"\"\n        Return `True` if the table owns its data\n        \"\"\"\n        return ((not self._X.shape[-1] or self._X.base is None) and\n                (self._Y.base is None) and\n                (self._metas.base is None) and\n                (self._W.base is None))\n\n    def is_sparse(self):\n        \"\"\"\n        Return `True` if the table stores data in sparse format\n        \"\"\"\n        return any(sp.issparse(i) for i in [self._X, self._Y, self._metas])\n\n    def ensure_copy(self):\n        \"\"\"\n        Ensure that the table owns its data; copy arrays when necessary.\n        \"\"\"\n\n        def is_view(x):\n            # Sparse matrices don't have views like numpy arrays. Since indexing on\n            # them creates copies in constructor we can skip this check here.\n            return not sp.issparse(x) and x.base is not None\n\n        if is_view(self._X):\n            self._X = self._X.copy()\n        if is_view(self._Y):\n            self._Y = self._Y.copy()\n        if is_view(self._metas):\n            self._metas = self._metas.copy()\n        if is_view(self._W):\n            self._W = self._W.copy()\n\n    def copy(self):\n        \"\"\"\n        Return a copy of the table\n        \"\"\"\n        t = self.__class__(self)\n        t.ensure_copy()\n        return t\n\n    @staticmethod\n    def __determine_density(data):\n        if data is None:\n            return Storage.Missing\n        if data is not None and sp.issparse(data):\n            return Storage.SPARSE_BOOL if (data.data == 1).all() else Storage.SPARSE\n        else:\n            return Storage.DENSE\n\n    def X_density(self):\n        if not hasattr(self, \"_X_density\"):\n            self._X_density = self.__determine_density(self.X)\n        return self._X_density\n\n    def Y_density(self):\n        if not hasattr(self, \"_Y_density\"):\n            self._Y_density = self.__determine_density(self._Y)\n        return self._Y_density\n\n    def metas_density(self):\n        if not hasattr(self, \"_metas_density\"):\n            self._metas_density = self.__determine_density(self.metas)\n        return self._metas_density\n\n    def set_weights(self, weight=1):\n        \"\"\"\n        Set weights of data instances; create a vector of weights if necessary.\n        \"\"\"\n        if not self.W.shape[-1]:\n            self.W = np.empty(len(self))\n        self.W[:] = weight\n\n    def has_weights(self):\n        \"\"\"Return `True` if the data instances are weighed. \"\"\"\n        return self.W.shape[-1] != 0\n\n    def total_weight(self):\n        \"\"\"\n        Return the total weight of instances in the table, or their number if\n        they are unweighted.\n        \"\"\"\n        if self.W.shape[-1]:\n            return sum(self.W)\n        return len(self)\n\n    def has_missing(self):\n        \"\"\"Return `True` if there are any missing attribute or class values.\"\"\"\n        missing_x = not sp.issparse(self.X) and bn.anynan(self.X)  # do not check for sparse X\n        return missing_x or bn.anynan(self._Y)\n\n    def has_missing_attribute(self):\n        \"\"\"Return `True` if there are any missing attribute values.\"\"\"\n        return not sp.issparse(self.X) and bn.anynan(self.X)  # do not check for sparse X\n\n    def has_missing_class(self):\n        \"\"\"Return `True` if there are any missing class values.\"\"\"\n        return bn.anynan(self._Y)\n\n    def get_nan_frequency_attribute(self):\n        if self.X.size == 0:\n            return 0\n        return np.isnan(self.X).sum() / self.X.size\n\n    def get_nan_frequency_class(self):\n        if self.Y.size == 0:\n            return 0\n        return np.isnan(self._Y).sum() / self._Y.size\n\n    def checksum(self, include_metas=True):\n        # TODO: zlib.adler32 does not work for numpy arrays with dtype object\n        # (after pickling and unpickling such arrays, checksum changes)\n        # Why, and should we fix it or remove it?\n        \"\"\"Return a checksum over X, Y, metas and W.\"\"\"\n        cs = zlib.adler32(np.ascontiguousarray(self._X))\n        cs = zlib.adler32(np.ascontiguousarray(self._Y), cs)\n        if include_metas:\n            cs = zlib.adler32(np.ascontiguousarray(self._metas), cs)\n        cs = zlib.adler32(np.ascontiguousarray(self._W), cs)\n        return cs\n\n    def shuffle(self):\n        \"\"\"Randomly shuffle the rows of the table.\"\"\"\n        if not self._check_all_dense():\n            raise ValueError(\"Rows of sparse data cannot be shuffled\")\n        ind = np.arange(self.X.shape[0])\n        np.random.shuffle(ind)\n        self.X = self.X[ind]\n        self._Y = self._Y[ind]\n        self.metas = self.metas[ind]\n        self.W = self.W[ind]\n\n    def get_column_view(self, index):\n        \"\"\"\n        Return a vector - as a view, not a copy - with a column of the table,\n        and a bool flag telling whether this column is sparse. Note that\n        vertical slicing of sparse matrices is inefficient.\n\n        :param index: the index of the column\n        :type index: int, str or Orange.data.Variable\n        :return: (one-dimensional numpy array, sparse)\n        \"\"\"\n\n        def rx(M):\n            if sp.issparse(M):\n                return np.asarray(M.todense())[:, 0], True\n            else:\n                return M, False\n\n        if isinstance(index, Integral):\n            col_index = index\n        else:\n            col_index = self.domain.index(index)\n        if col_index >= 0:\n            if col_index < self.X.shape[1]:\n                col = rx(self.X[:, col_index])\n            elif self._Y.ndim == 1 and col_index == self._X.shape[1]:\n                col = rx(self._Y)\n            else:\n                col = rx(self._Y[:, col_index - self.X.shape[1]])\n        else:\n            col = rx(self.metas[:, -1 - col_index])\n\n        if isinstance(index, DiscreteVariable) \\\n                and index.values != self.domain[col_index].values:\n            col = index.get_mapper_from(self.domain[col_index])(col[0]), col[1]\n            col[0].flags.writeable = False\n        return col\n\n    def _filter_is_defined(self, columns=None, negate=False):\n        # structure of function is obvious; pylint: disable=too-many-branches\n        def _sp_anynan(a):\n            return a.indptr[1:] != a[-1:] + a.shape[1]\n\n        if columns is None:\n            if sp.issparse(self.X):\n                remove = _sp_anynan(self.X)\n            else:\n                remove = bn.anynan(self.X, axis=1)\n            if sp.issparse(self._Y):\n                remove += _sp_anynan(self._Y)\n            else:\n                if self._Y.ndim == 1:\n                    remove += np.isnan(self._Y)\n                else:\n                    remove += bn.anynan(self._Y, axis=1)\n            if sp.issparse(self.metas):\n                remove += _sp_anynan(self._metas)\n            else:\n                for i, var in enumerate(self.domain.metas):\n                    col = self.metas[:, i].flatten()\n                    if var.is_primitive():\n                        remove += np.isnan(col.astype(float))\n                    else:\n                        remove += ~col.astype(bool)\n        else:\n            remove = np.zeros(len(self), dtype=bool)\n            for column in columns:\n                col, sparse = self.get_column_view(column)\n                if sparse:\n                    remove += col == 0\n                elif self.domain[column].is_primitive():\n                    remove += bn.anynan([col.astype(float)], axis=0)\n                else:\n                    remove += col.astype(bool)\n        retain = remove if negate else np.logical_not(remove)\n        return self.from_table_rows(self, retain)\n\n    def _filter_has_class(self, negate=False):\n        if sp.issparse(self._Y):\n            if negate:\n                retain = (self._Y.indptr[1:] !=\n                          self._Y.indptr[-1:] + self._Y.shape[1])\n            else:\n                retain = (self._Y.indptr[1:] ==\n                          self._Y.indptr[-1:] + self._Y.shape[1])\n        else:\n            if self._Y.ndim == 1:\n                retain = np.isnan(self._Y)\n            else:\n                retain = bn.anynan(self._Y, axis=1)\n            if not negate:\n                retain = np.logical_not(retain)\n        return self.from_table_rows(self, retain)\n\n    def _filter_same_value(self, column, value, negate=False):\n        if not isinstance(value, Real):\n            value = self.domain[column].to_val(value)\n        sel = self.get_column_view(column)[0] == value\n        if negate:\n            sel = np.logical_not(sel)\n        return self.from_table_rows(self, sel)\n\n    def _filter_values(self, filter):\n        selection = self._values_filter_to_indicator(filter)\n        return self.from_table(self.domain, self, selection)\n\n    def _values_filter_to_indicator(self, filter):\n        \"\"\"Return selection of rows matching the filter conditions\n\n        Handles conjunction/disjunction and negate modifiers\n\n        Parameters\n        ----------\n        filter: Values object containing the conditions\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        from Orange.data.filter import Values\n\n        if isinstance(filter, Values):\n            conditions = filter.conditions\n            conjunction = filter.conjunction\n        else:\n            conditions = [filter]\n            conjunction = True\n        if conjunction:\n            sel = np.ones(len(self), dtype=bool)\n        else:\n            sel = np.zeros(len(self), dtype=bool)\n\n        for f in conditions:\n            selection = self._filter_to_indicator(f)\n\n            if conjunction:\n                sel *= selection\n            else:\n                sel += selection\n\n        if filter.negate:\n            sel = ~sel\n        return sel\n\n    def _filter_to_indicator(self, filter):\n        \"\"\"Return selection of rows that match the condition.\n\n        Parameters\n        ----------\n        filter: ValueFilter describing the condition\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        from Orange.data.filter import (\n            FilterContinuous, FilterDiscrete, FilterRegex, FilterString,\n            FilterStringList, IsDefined, Values\n        )\n        if isinstance(filter, Values):\n            return self._values_filter_to_indicator(filter)\n\n        def get_col_indices():\n            cols = chain(self.domain.variables, self.domain.metas)\n            if isinstance(filter, IsDefined):\n                if filter.columns is not None:\n                    return list(filter.columns)\n                else:\n                    return list(cols)\n\n            if filter.column is not None:\n                return [filter.column]\n\n            if isinstance(filter, FilterDiscrete):\n                raise ValueError(\"Discrete filter can't be applied across rows\")\n            if isinstance(filter, FilterContinuous):\n                return [col for col in cols if col.is_continuous]\n            if isinstance(filter,\n                          (FilterString, FilterStringList, FilterRegex)):\n                return [col for col in cols if col.is_string]\n            raise TypeError(\"Invalid filter\")\n\n        def col_filter(col_idx):\n            col = self.get_column_view(col_idx)[0]\n            if isinstance(filter, IsDefined):\n                if self.domain[col_idx].is_primitive():\n                    return ~np.isnan(col.astype(float))\n                else:\n                    return col.astype(bool)\n            if isinstance(filter, FilterDiscrete):\n                return self._discrete_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterContinuous):\n                return self._continuous_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterString):\n                return self._string_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterStringList):\n                if not filter.case_sensitive:\n                    col = np.char.lower(np.array(col, dtype=str))\n                    vals = [val.lower() for val in filter.values]\n                else:\n                    vals = filter.values\n                return reduce(operator.add, (col == val for val in vals))\n            if isinstance(filter, FilterRegex):\n                return np.vectorize(filter)(col)\n            raise TypeError(\"Invalid filter\")\n\n        col_indices = get_col_indices()\n        if len(col_indices) == 1:\n            sel = col_filter(col_indices[0])\n        else:\n            sel = np.ones(len(self), dtype=bool)\n            for col_idx in col_indices:\n                sel *= col_filter(col_idx)\n\n        if isinstance(filter, IsDefined) and filter.negate:\n            sel = ~sel\n        return sel\n\n    def _discrete_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given discrete filter.\n\n        Parameters\n        ----------\n        filter: FilterDiscrete\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.values is None:  # <- is defined filter\n            col = col.astype(float)\n            return ~np.isnan(col)\n\n        sel = np.zeros(len(self), dtype=bool)\n        for val in filter.values:\n            if not isinstance(val, Real):\n                val = self.domain[filter.column].to_val(val)\n            sel += (col == val)\n        return sel\n\n    def _continuous_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given continuous filter.\n\n        Parameters\n        ----------\n        filter: FilterContinuous\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.oper == filter.IsDefined:\n            col = col.astype(float)\n            return ~np.isnan(col)\n\n        return self._range_filter_to_indicator(filter, col, filter.min, filter.max)\n\n    def _string_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given string filter.\n\n        Parameters\n        ----------\n        filter: FilterString\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.oper == filter.IsDefined:\n            return col.astype(bool)\n\n        col = col.astype(str)\n        fmin = filter.min or \"\"\n        fmax = filter.max or \"\"\n\n        if not filter.case_sensitive:\n            # convert all to lower case\n            col = np.char.lower(col)\n            fmin = fmin.lower()\n            fmax = fmax.lower()\n\n        if filter.oper == filter.Contains:\n            return np.fromiter((fmin in e for e in col),\n                               dtype=bool)\n        if filter.oper == filter.StartsWith:\n            return np.fromiter((e.startswith(fmin) for e in col),\n                               dtype=bool)\n        if filter.oper == filter.EndsWith:\n            return np.fromiter((e.endswith(fmin) for e in col),\n                               dtype=bool)\n\n        return self._range_filter_to_indicator(filter, col, fmin, fmax)\n\n    @staticmethod\n    def _range_filter_to_indicator(filter, col, fmin, fmax):\n        with np.errstate(invalid=\"ignore\"):  # nan's are properly discarded\n            if filter.oper == filter.Equal:\n                return col == fmin\n            if filter.oper == filter.NotEqual:\n                return col != fmin\n            if filter.oper == filter.Less:\n                return col < fmin\n            if filter.oper == filter.LessEqual:\n                return col <= fmin\n            if filter.oper == filter.Greater:\n                return col > fmin\n            if filter.oper == filter.GreaterEqual:\n                return col >= fmin\n            if filter.oper == filter.Between:\n                return (col >= fmin) * (col <= fmax)\n            if filter.oper == filter.Outside:\n                return (col < fmin) + (col > fmax)\n\n            raise TypeError(\"Invalid operator\")\n\n    def _compute_basic_stats(self, columns=None,\n                             include_metas=False, compute_variance=False):\n        if compute_variance:\n            raise NotImplementedError(\"computation of variance is \"\n                                      \"not implemented yet\")\n        W = self._W if self.has_weights() else None\n        rr = []\n        stats = []\n        if not columns:\n            if self.domain.attributes:\n                rr.append(fast_stats(self._X, W))\n            if self.domain.class_vars:\n                rr.append(fast_stats(self._Y, W))\n            if include_metas and self.domain.metas:\n                rr.append(fast_stats(self.metas, W))\n            if len(rr):\n                stats = np.vstack(tuple(rr))\n        else:\n            nattrs = len(self.domain.attributes)\n            for column in columns:\n                c = self.domain.index(column)\n                if 0 <= c < nattrs:\n                    S = fast_stats(self._X[:, [c]], W and W[:, [c]])\n                elif c >= nattrs:\n                    if self._Y.ndim == 1 and c == nattrs:\n                        S = fast_stats(self._Y[:, None], W and W[:, None])\n                    else:\n                        S = fast_stats(self._Y[:, [c - nattrs]], W and W[:, [c - nattrs]])\n                else:\n                    S = fast_stats(self._metas[:, [-1 - c]], W and W[:, [-1 - c]])\n                stats.append(S[0])\n        return stats\n\n    def _compute_distributions(self, columns=None):\n        if columns is None:\n            columns = range(len(self.domain.variables))\n        else:\n            columns = [self.domain.index(var) for var in columns]\n\n        distributions = []\n        X = self.X\n        if sp.issparse(X):\n            X = X.tocsc()\n\n\n        W = self.W.ravel() if self.has_weights() else None\n\n        for col in columns:\n            variable = self.domain[col]\n\n            # Select the correct data column from X, Y or metas\n            if 0 <= col < X.shape[1]:\n                x = X[:, col]\n            elif col < 0:\n                x = self.metas[:, col * (-1) - 1]\n                if np.issubdtype(x.dtype, np.dtype(object)):\n                    x = x.astype(float)\n            elif self._Y.ndim == 1 and col == X.shape[1]:\n                x = self._Y\n            else:\n                x = self._Y[:, col - X.shape[1]]\n\n            if variable.is_discrete:\n                dist, unknowns = bincount(x, weights=W, max_val=len(variable.values) - 1)\n            elif not x.shape[0]:\n                dist, unknowns = np.zeros((2, 0)), 0\n            else:\n                if W is not None:\n                    if sp.issparse(x):\n                        arg_sort = np.argsort(x.data)\n                        ranks = x.indices[arg_sort]\n                        vals = np.vstack((x.data[arg_sort], W[ranks]))\n                    else:\n                        ranks = np.argsort(x)\n                        vals = np.vstack((x[ranks], W[ranks]))\n                else:\n                    x_values = x.data if sp.issparse(x) else x\n                    vals = np.ones((2, x_values.shape[0]))\n                    vals[0, :] = x_values\n                    vals[0, :].sort()\n\n                dist = np.array(_valuecount.valuecount(vals))\n                # If sparse, then 0s will not be counted with `valuecount`, so\n                # we have to add them to the result manually.\n                if sp.issparse(x) and sparse_has_implicit_zeros(x):\n                    if W is not None:\n                        zero_weights = sparse_implicit_zero_weights(x, W).sum()\n                    else:\n                        zero_weights = sparse_count_implicit_zeros(x)\n                    zero_vec = [0, zero_weights]\n                    dist = np.insert(dist, np.searchsorted(dist[0], 0), zero_vec, axis=1)\n                # Since `countnans` assumes vector shape to be (1, n) and `x`\n                # shape is (n, 1), we pass the transpose\n                unknowns = countnans(x.T, W)\n            distributions.append((dist, unknowns))\n\n        return distributions\n\n    def _compute_contingency(self, col_vars=None, row_var=None):\n        n_atts = self.X.shape[1]\n\n        if col_vars is None:\n            col_vars = range(len(self.domain.variables))\n        else:\n            col_vars = [self.domain.index(var) for var in col_vars]\n        if row_var is None:\n            row_var = self.domain.class_var\n            if row_var is None:\n                raise ValueError(\"No row variable\")\n\n        row_desc = self.domain[row_var]\n        if not row_desc.is_discrete:\n            raise TypeError(\"Row variable must be discrete\")\n        row_indi = self.domain.index(row_var)\n        n_rows = len(row_desc.values)\n        if 0 <= row_indi < n_atts:\n            row_data = self.X[:, row_indi]\n        elif row_indi < 0:\n            row_data = self.metas[:, -1 - row_indi]\n        elif self._Y.ndim == 1 and row_indi == n_atts:\n            row_data = self._Y\n        else:\n            row_data = self._Y[:, row_indi - n_atts]\n\n        W = self.W if self.has_weights() else None\n\n        col_desc = [self.domain[var] for var in col_vars]\n        col_indi = [self.domain.index(var) for var in col_vars]\n\n        if any(not (var.is_discrete or var.is_continuous)\n               for var in col_desc):\n            raise ValueError(\"Contingency can be computed only for categorical \"\n                             \"and numeric values.\")\n\n        # when we select a column in sparse matrix it is still two dimensional\n        # and sparse - since it is just a column we can afford to transform\n        # it to dense and make it 1D\n        if issparse(row_data):\n            row_data = row_data.toarray().ravel()\n        if row_data.dtype.kind != \"f\":  # meta attributes can be stored as type object\n            row_data = row_data.astype(float)\n\n        contingencies = [None] * len(col_desc)\n        for arr, f_cond, f_ind in (\n                (self.X, lambda i: 0 <= i < n_atts, lambda i: i),\n                (self._Y, lambda i: i >= n_atts, lambda i: i - n_atts),\n                (self.metas, lambda i: i < 0, lambda i: -1 - i)):\n\n            arr_indi = [e for e, ind in enumerate(col_indi) if f_cond(ind)]\n\n            vars = [(e, f_ind(col_indi[e]), col_desc[e]) for e in arr_indi]\n            disc_vars = [v for v in vars if v[2].is_discrete]\n            if disc_vars:\n                if sp.issparse(arr):\n                    max_vals = max(len(v[2].values) for v in disc_vars)\n                    disc_indi = {i for _, i, _ in disc_vars}\n                    mask = [i in disc_indi for i in range(arr.shape[1])]\n                    conts, nans_cols, nans_rows, nans = contingency(\n                        arr, row_data, max_vals - 1, n_rows - 1, W, mask)\n                    for col_i, arr_i, var in disc_vars:\n                        n_vals = len(var.values)\n                        contingencies[col_i] = (\n                            conts[arr_i][:, :n_vals], nans_cols[arr_i],\n                            nans_rows[arr_i], nans[arr_i])\n                else:\n                    for col_i, arr_i, var in disc_vars:\n                        col = arr if arr.ndim == 1 else arr[:, arr_i]\n                        contingencies[col_i] = contingency(\n                            col.astype(float),\n                            row_data, len(var.values) - 1, n_rows - 1, W)\n\n            cont_vars = [v for v in vars if v[2].is_continuous]\n            if cont_vars:\n                W_ = None\n                if W is not None:\n                    W_ = W.astype(dtype=np.float64)\n                if sp.issparse(arr):\n                    arr = sp.csc_matrix(arr)\n\n                for col_i, arr_i, _ in cont_vars:\n                    if sp.issparse(arr):\n                        col_data = arr.data[arr.indptr[arr_i]:arr.indptr[arr_i + 1]]\n                        rows = arr.indices[arr.indptr[arr_i]:arr.indptr[arr_i + 1]]\n                        W_ = None if W_ is None else W_[rows]\n                        classes_ = row_data[rows]\n                    else:\n                        col_data, W_, classes_ = arr[:, arr_i], W_, row_data\n\n                    col_data = col_data.astype(dtype=np.float64)\n                    contingencies[col_i] = _contingency.contingency_floatarray(\n                        col_data, classes_, n_rows, W_)\n\n        return contingencies\n\n    @classmethod\n    def transpose(cls, table, feature_names_column=\"\",\n                  meta_attr_name=\"Feature name\", feature_name=\"Feature\",\n                  remove_redundant_inst=False, progress_callback=None):\n        \"\"\"\n        Transpose the table.\n\n        :param table: Table - table to transpose\n        :param feature_names_column: str - name of (String) meta attribute to\n            use for feature names\n        :param meta_attr_name: str - name of new meta attribute into which\n            feature names are mapped\n        :param feature_name: str - default feature name prefix\n        :param remove_redundant_inst: bool - remove instance that\n            represents feature_names_column\n        :param progress_callback: callable - to report the progress\n        :return: Table - transposed table\n        \"\"\"\n        if progress_callback is None:\n            progress_callback = dummy_callback\n        progress_callback(0, \"Transposing...\")\n\n        if isinstance(feature_names_column, Variable):\n            feature_names_column = feature_names_column.name\n\n        self = cls()\n        n_cols, self.n_rows = table.X.shape\n        old_domain = table.attributes.get(\"old_domain\")\n        table_domain_attributes = list(table.domain.attributes)\n        attr_index = None\n        if remove_redundant_inst:\n            attr_names = [a.name for a in table_domain_attributes]\n            if feature_names_column and feature_names_column in attr_names:\n                attr_index = attr_names.index(feature_names_column)\n                self.n_rows = self.n_rows - 1\n                table_domain_attributes.remove(\n                    table_domain_attributes[attr_index])\n\n        # attributes\n        # - classes and metas to attributes of attributes\n        # - arbitrary meta column to feature names\n        with self.unlocked():\n            self.X = table.X.T\n            if attr_index is not None:\n                self.X = np.delete(self.X, attr_index, 0)\n            if feature_names_column:\n                names = [str(row[feature_names_column]) for row in table]\n                progress_callback(0.1)\n                names = get_unique_names_duplicates(names)\n                progress_callback(0.3)\n                attributes = [ContinuousVariable(name) for name in names]\n            else:\n                places = int(np.ceil(np.log10(n_cols))) if n_cols else 1\n                attributes = [ContinuousVariable(f\"{feature_name} {i:0{places}}\")\n                              for i in range(1, n_cols + 1)]\n            progress_callback(0.4)\n\n            if old_domain is not None and feature_names_column:\n                for i, _ in enumerate(attributes):\n                    if attributes[i].name in old_domain:\n                        var = old_domain[attributes[i].name]\n                        attr = ContinuousVariable(var.name) if var.is_continuous \\\n                            else DiscreteVariable(var.name, var.values)\n                        attr.attributes = var.attributes.copy()\n                        attributes[i] = attr\n\n            def set_attributes_of_attributes(_vars, _table):\n                for i, variable in enumerate(_vars):\n                    if variable.name == feature_names_column:\n                        continue\n                    for j, row in enumerate(_table):\n                        value = variable.repr_val(row) if np.isscalar(row) \\\n                            else row[i] if isinstance(row[i], str) \\\n                            else variable.repr_val(row[i])\n\n                        if value not in MISSING_VALUES:\n                            attributes[j].attributes[variable.name] = value\n\n            set_attributes_of_attributes(table.domain.class_vars, table.Y)\n            progress_callback(0.5)\n            set_attributes_of_attributes(table.domain.metas, table.metas)\n\n            # weights\n            self.W = np.empty((self.n_rows, 0))\n\n            def get_table_from_attributes_of_attributes(_vars, _dtype=float):\n                T = np.empty((self.n_rows, len(_vars)), dtype=_dtype)\n                for i, _attr in enumerate(table_domain_attributes):\n                    for j, _var in enumerate(_vars):\n                        val = str(_attr.attributes.get(_var.name, \"\"))\n                        if not _var.is_string:\n                            val = np.nan if val in MISSING_VALUES else \\\n                                _var.values.index(val) if \\\n                                    _var.is_discrete else float(val)\n                        T[i, j] = val\n                return T\n\n            # class_vars - attributes of attributes to class - from old domain\n            class_vars = []\n            if old_domain is not None:\n                class_vars = old_domain.class_vars\n            self.Y = get_table_from_attributes_of_attributes(class_vars)\n\n            # metas\n            # - feature names and attributes of attributes to metas\n            self.metas, metas = np.empty((self.n_rows, 0), dtype=object), []\n            if meta_attr_name not in [m.name for m in table.domain.metas] and \\\n                    table_domain_attributes:\n                self.metas = np.array([[a.name] for a in table_domain_attributes],\n                                      dtype=object)\n                metas.append(StringVariable(meta_attr_name))\n\n            names = chain.from_iterable(list(attr.attributes)\n                                        for attr in table_domain_attributes)\n            names = sorted(set(names) - {var.name for var in class_vars})\n            progress_callback(0.6)\n\n            def guessed_var(i, var_name):\n                orig_vals = M[:, i]\n                val_map, vals, var_type = Orange.data.io.guess_data_type(orig_vals)\n                values, variable = Orange.data.io.sanitize_variable(\n                    val_map, vals, orig_vals, var_type, {}, name=var_name)\n                M[:, i] = values\n                return variable\n\n            _metas = [StringVariable(n) for n in names]\n            if old_domain is not None:\n                _metas = [m for m in old_domain.metas if m.name != meta_attr_name]\n            M = get_table_from_attributes_of_attributes(_metas, _dtype=object)\n            progress_callback(0.7)\n            if old_domain is None:\n                _metas = [guessed_var(i, m.name) for i, m in enumerate(_metas)]\n            if _metas:\n                self.metas = np.hstack((self.metas, M))\n                metas.extend(_metas)\n\n            self.domain = Domain(attributes, class_vars, metas)\n            progress_callback(0.9)\n            cls._init_ids(self)\n            self.attributes = table.attributes.copy()\n            self.attributes[\"old_domain\"] = table.domain\n            progress_callback(1)\n            return self\n\n    def to_sparse(self, sparse_attributes=True, sparse_class=False,\n                  sparse_metas=False):\n        def sparsify(features):\n            for f in features:\n                f.sparse = True\n\n        new_domain = self.domain.copy()\n\n        if sparse_attributes:\n            sparsify(new_domain.attributes)\n        if sparse_class:\n            sparsify(new_domain.class_vars)\n        if sparse_metas:\n            sparsify(new_domain.metas)\n        return self.transform(new_domain)\n\n    def to_dense(self, dense_attributes=True, dense_class=True,\n                 dense_metas=True):\n        def densify(features):\n            for f in features:\n                f.sparse = False\n\n        new_domain = self.domain.copy()\n\n        if dense_attributes:\n            densify(new_domain.attributes)\n        if dense_class:\n            densify(new_domain.class_vars)\n        if dense_metas:\n            densify(new_domain.metas)\n        t = self.transform(new_domain)\n        t.ids = self.ids  # preserve indices\n        return t\n\n\ndef _dereferenced(array):\n    # CSR and CSC matrices are constructed so that array.data is a\n    # view to a base, which prevents unlocking them. Therefore, if\n    # sparse matrix doesn't own its data, but its base array is\n    # referenced only by this matrix, we copy it. This doesn't\n    # increase memory use, but allows unlocking.\n    if sp.issparse(array) \\\n            and array.data.base is not None \\\n            and sys.getrefcount(array.data.base) == 2:  # 2 = 1 real + 1 for arg\n        array.data = array.data.copy()\n    return array\n\n\ndef _check_arrays(*arrays, dtype=None, shape_1=None):\n    checked = []\n    if not len(arrays):\n        return checked\n\n    def ninstances(array):\n        if hasattr(array, \"shape\"):\n            return array.shape[0]\n        else:\n            return len(array) if array is not None else 0\n\n    if shape_1 is None:\n        shape_1 = ninstances(arrays[0])\n\n    for array in arrays:\n        if array is None:\n            checked.append(array)\n            continue\n\n        if ninstances(array) != shape_1:\n            raise ValueError(\"Leading dimension mismatch (%d != %d)\"\n                             % (ninstances(array), shape_1))\n\n        if sp.issparse(array):\n            if not (sp.isspmatrix_csr(array) or sp.isspmatrix_csc(array)):\n                array = array.tocsr()\n            array.data = np.asarray(array.data)\n            array = _dereferenced(array)\n            has_inf = _check_inf(array.data)\n        else:\n            if dtype is not None:\n                array = np.asarray(array, dtype=dtype)\n            else:\n                array = np.asarray(array)\n            has_inf = _check_inf(array)\n\n        if has_inf:\n            array[np.isinf(array)] = np.nan\n            warnings.warn(\"Array contains infinity.\", RuntimeWarning)\n        checked.append(array)\n\n    return checked\n\n\ndef _check_inf(array):\n    return array.dtype.char in np.typecodes['AllFloat'] and \\\n           np.isinf(array.data).any()\n\n\ndef _subarray(arr, rows, cols):\n    rows = _optimize_indices(rows, arr.shape[0])\n    if arr.ndim == 1:\n        return arr[rows]\n    cols = _optimize_indices(cols, arr.shape[1])\n    return arr[_rxc_ix(rows, cols)]\n\n\ndef _optimize_indices(indices, maxlen):\n    \"\"\"\n    Convert integer indices to slice if possible. It only converts increasing\n    integer ranges with positive steps and valid starts and ends.\n    Only convert valid ends so that invalid ranges will still raise\n    an exception.\n\n    Allows numpy to reuse the data array, because it defaults to copying\n    if given indices.\n\n    Parameters\n    ----------\n    indices : 1D sequence, slice or Ellipsis\n    \"\"\"\n    if isinstance(indices, slice):\n        return indices\n\n    if indices is ...:\n        return slice(None, None, 1)\n\n    # a very common case for column selection\n    if len(indices) == 1 and not isinstance(indices[0], bool):\n        if indices[0] >= 0:\n            return slice(indices[0], indices[0] + 1, 1)\n        else:\n            return slice(indices[0], indices[0] - 1, -1)\n\n    if len(indices) >= 1:\n        indices = np.asarray(indices)\n        if indices.dtype != bool:\n            begin = indices[0]\n            end = indices[-1]\n            steps = np.diff(indices) if len(indices) > 1 else np.array([1])\n            step = steps[0]\n\n            # continuous ranges with constant step and valid start and stop index can be slices\n            if np.all(steps == step) and step > 0 and begin >= 0 and end < maxlen:\n                return slice(begin, end + step, step)\n\n    return indices\n\n\ndef _rxc_ix(rows, cols):\n    \"\"\"\n    Construct an index object to index the `rows` x `cols` cross product.\n\n    Rows and columns can be a 1d bool or int sequence, or a slice.\n    The later is a convenience and is interpreted the same\n    as `slice(None, None, -1)`\n\n    Parameters\n    ----------\n    rows : 1D sequence, slice\n        Row indices.\n    cols : 1D sequence, slice\n        Column indices.\n\n    See Also\n    --------\n    numpy.ix_\n\n    Examples\n    --------\n    >>> import numpy as np\n    >>> a = np.arange(10).reshape(2, 5)\n    >>> a[_rxc_ix([0, 1], [3, 4])]\n    array([[3, 4],\n           [8, 9]])\n    >>> a[_rxc_ix([False, True], slice(None, None, 1))]\n    array([[5, 6, 7, 8, 9]])\n\n    \"\"\"\n    isslice = (isinstance(rows, slice), isinstance(cols, slice))\n    if isslice == (True, True):\n        return rows, cols\n    elif isslice == (True, False):\n        return rows, np.asarray(np.ix_(cols), int).ravel()\n    elif isslice == (False, True):\n        return np.asarray(np.ix_(rows), int).ravel(), cols\n    else:\n        r, c = np.ix_(rows, cols)\n        return np.asarray(r, int), np.asarray(c, int)\n\n\ndef assure_domain_conversion_sparsity(target, source):\n    \"\"\"\n    Assure that the table obeys the domain conversion's suggestions about sparsity.\n\n    Args:\n        target (Table): the target table.\n        source (Table): the source table.\n\n    Returns:\n        Table: with fixed sparsity. The sparsity is set as it is recommended by domain conversion\n            for transformation from source to the target domain.\n    \"\"\"\n    conversion = DomainConversion(source.domain, target.domain)\n    match_density = [assure_array_dense, assure_array_sparse]\n    target.X = match_density[conversion.sparse_X](target.X)\n    target.Y = match_density[conversion.sparse_Y](target.Y)\n    target.metas = match_density[conversion.sparse_metas](target.metas)\n    return target\n\n\nclass Role:\n    Attribute = 0\n    ClassAttribute = 1\n    Meta = 2\n\n    @staticmethod\n    def get_arr(role, table):\n        return table.X if role == Role.Attribute else \\\n               table.Y if role == Role.ClassAttribute else \\\n               table.metas\n",
            "header": {
                "file": {
                    "path": "Orange/data/table.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "b785109c3",
                "new_commit_hash": "a3800c046",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/Orange/data/table.py"
            },
            "plus_file": {
                "path": "b/Orange/data/table.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 447,
                            "length": 8
                        },
                        "new_range": {
                            "start": 447,
                            "length": 24
                        },
                        "section": "class Table(Sequence, Storage):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "            for k in (\"X\", \"W\", \"metas\"):",
                                "type": "context"
                            },
                            {
                                "content": "                if k in state:",
                                "type": "context"
                            },
                            {
                                "content": "                    setattr(self, k, state.pop(k))",
                                "type": "context"
                            },
                            {
                                "content": "            if \"_Y\" in state:",
                                "type": "added"
                            },
                            {
                                "content": "                setattr(self, \"Y\", state.pop(\"_Y\"))  # state[\"_Y\"] is a 2d array",
                                "type": "added"
                            },
                            {
                                "content": "            self.__dict__.update(state)",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "    def __getstate__(self):",
                                "type": "added"
                            },
                            {
                                "content": "        # Compatibility with pickles before table locking:",
                                "type": "added"
                            },
                            {
                                "content": "        # return the same state as before table lock",
                                "type": "added"
                            },
                            {
                                "content": "        state = self.__dict__.copy()",
                                "type": "added"
                            },
                            {
                                "content": "        for k in [\"X\", \"metas\", \"W\"]:",
                                "type": "added"
                            },
                            {
                                "content": "            if \"_\" + k in state:  # Check existence; SQL tables do not contain them",
                                "type": "added"
                            },
                            {
                                "content": "                state[k] = state.pop(\"_\" + k)",
                                "type": "added"
                            },
                            {
                                "content": "        # before locking, _Y was always a 2d array: save it as such",
                                "type": "added"
                            },
                            {
                                "content": "        if \"_Y\" in state:",
                                "type": "added"
                            },
                            {
                                "content": "            y = state.pop(\"_Y\")",
                                "type": "added"
                            },
                            {
                                "content": "            y2d = y.reshape(-1, 1) if y.ndim == 1 else y",
                                "type": "added"
                            },
                            {
                                "content": "            state[\"_Y\"] = y2d",
                                "type": "added"
                            },
                            {
                                "content": "        return state",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "    def _lock_parts(self):",
                                "type": "context"
                            },
                            {
                                "content": "        return ((self._X, self._Unlocked_X, \"X\"),",
                                "type": "context"
                            },
                            {
                                "content": "                (self._Y, self._Unlocked_Y, \"Y\"),",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "Orange/data/table.py",
                            "type": "class",
                            "name": "Table",
                            "content": "class Table(Sequence, Storage):\n\n    LOCKING = None\n    \"\"\" If the class attribute LOCKING is True, tables will throw exceptions\n    on in-place modifications unless unlocked explicitly. LOCKING is supposed\n    to be set to True for testing to help us find bugs. If set to False\n    or None, no safeguards are in place. Two different values are used for\n    the same behaviour to distinguish the unchanged default (None) form\n    explicit deactivation (False) that some add-ons might need. \"\"\"\n\n    __file__ = None\n    name = \"untitled\"\n\n    domain = Domain([])\n    _X = _Y = _metas = _W = np.zeros((0, 0))  # pylint: disable=invalid-name\n    ids = np.zeros(0)\n    ids.setflags(write=False)\n    attributes = frozendict()\n\n    _Unlocked_X, _Unlocked_Y, _Unlocked_metas, _Unlocked_W = 1, 2, 4, 8\n    _unlocked = _Unlocked_X + _Unlocked_Y + \\\n                _Unlocked_metas + _Unlocked_W  # pylint: disable=invalid-name\n\n    @property\n    def columns(self):\n        \"\"\"\n        A class whose attributes contain attribute descriptors for columns.\n        For a table `table`, setting `c = table.columns` will allow accessing\n        the table's variables with, for instance `c.gender`, `c.age` ets.\n        Spaces are replaced with underscores.\n        \"\"\"\n        return Columns(self.domain)\n\n    _next_instance_id = 0\n    _next_instance_lock = Lock()\n\n    def _check_unlocked(self, partflag):\n        if not self._unlocked & partflag:\n            raise ValueError(\"Table is read-only unless unlocked\")\n\n    @property\n    def X(self):  # pylint: disable=invalid-name\n        return self._X\n\n    @X.setter\n    def X(self, value):\n        self._check_unlocked(self._Unlocked_X)\n        self._X = _dereferenced(value)\n\n    @property\n    def Y(self):  # pylint: disable=invalid-name\n        return self._Y\n\n    @Y.setter\n    def Y(self, value):\n        self._check_unlocked(self._Unlocked_Y)\n        if sp.issparse(value) and len(self) != value.shape[0]:\n            value = value.T\n        if sp.issparse(value):\n            value = _dereferenced(value.toarray())\n        if value.ndim == 2 and value.shape[1] == 1:\n            value = value[:, 0].copy()  # no views!\n        self._Y = value\n\n    @property\n    def metas(self):\n        return self._metas\n\n    @metas.setter\n    def metas(self, value):\n        self._check_unlocked(self._Unlocked_metas)\n        self._metas = _dereferenced(value)\n\n    @property\n    def W(self):  # pylint: disable=invalid-name\n        return self._W\n\n    @W.setter\n    def W(self, value):\n        self._check_unlocked(self._Unlocked_W)\n        self._W = value\n\n    def __setstate__(self, state):\n        # Backward compatibility with pickles before table locking\n        self._initialize_unlocked()  # __dict__ seems to be cleared before calling __setstate__\n        with self.unlocked():\n            for k in (\"X\", \"W\", \"metas\"):\n                if k in state:\n                    setattr(self, k, state.pop(k))\n            if \"_Y\" in state:\n                setattr(self, \"Y\", state.pop(\"_Y\"))  # state[\"_Y\"] is a 2d array\n            self.__dict__.update(state)\n\n    def __getstate__(self):\n        # Compatibility with pickles before table locking:\n        # return the same state as before table lock\n        state = self.__dict__.copy()\n        for k in [\"X\", \"metas\", \"W\"]:\n            if \"_\" + k in state:  # Check existence; SQL tables do not contain them\n                state[k] = state.pop(\"_\" + k)\n        # before locking, _Y was always a 2d array: save it as such\n        if \"_Y\" in state:\n            y = state.pop(\"_Y\")\n            y2d = y.reshape(-1, 1) if y.ndim == 1 else y\n            state[\"_Y\"] = y2d\n        return state\n\n    def _lock_parts(self):\n        return ((self._X, self._Unlocked_X, \"X\"),\n                (self._Y, self._Unlocked_Y, \"Y\"),\n                (self._metas, self._Unlocked_metas, \"metas\"),\n                (self._W, self._Unlocked_W, \"weights\"))\n\n    def _initialize_unlocked(self):\n        if Table.LOCKING:\n            self._unlocked = 0\n        else:\n            self._unlocked = sum(f for _, f, _ in self._lock_parts())\n\n    def _update_locks(self, force=False, unlock_bases=()):\n        if not Table.LOCKING:\n            return\n\n        def sync(*xs):\n            for x in xs:\n                try:\n                    undo_on_fail.append((x, x.flags.writeable))\n                    x.flags.writeable = writeable\n                except ValueError:\n                    if force \\\n                            and writeable \\\n                            and x.base is not None \\\n                            and not x.base.flags.writeable:\n                        x.base.flags.writeable = writeable\n                        x.flags.writeable = writeable\n                        forced_bases.append(x.base)\n                    else:\n                        raise\n\n        forced_bases = []\n        undo_on_fail = []\n        for base in unlock_bases:\n            base.flags.writeable = False\n        try:\n            for part, flag, _ in self._lock_parts():\n                if part is None:\n                    continue\n                writeable = bool(self._unlocked & flag)\n                if sp.isspmatrix_csr(part) or sp.isspmatrix_csc(part):\n                    sync(part.data, part.indices, part.indptr)\n                elif sp.isspmatrix_coo(part):\n                    sync(part.data, part.row, part.col)\n                elif sp.issparse(part):\n                    raise ValueError(\"Unsupported sparse data type\")\n                else:\n                    sync(part)\n        except:\n            for part, flag in undo_on_fail:\n                part.flags.writeable = flag\n            raise\n        return tuple(forced_bases)\n\n    def __unlocked(self, *parts, force=False):\n        prev_state = self._unlocked\n        for part, flag, _ in self._lock_parts():\n            if not parts or any(ppart is part for ppart in parts):\n                self._unlocked |= flag\n        try:\n            forced_bases = self._update_locks(force)\n            yield\n        finally:\n            self._unlocked = prev_state\n            self._update_locks(unlock_bases=forced_bases)\n\n    def force_unlocked(self, *parts):\n        \"\"\"\n        Unlocking without any checks.\n\n        Use with extreme caution. This is meant primarily for 3rd party\n        functions in Cython that expect read-write buffer, but do not\n        actually modify it. the given parts (default: all parts) of the table.\n\n        The function will still fail to unlock and raise an exception if the\n        table contains view to another table.\n        \"\"\"\n        return contextmanager(self.__unlocked)(*parts, force=True)\n\n    def unlocked(self, *parts):\n        \"\"\"\n        Unlock the given parts (default: all parts) of the table.\n\n        The caller must ensure that the table is safe to modify. The function\n        will raise an exception if the table contains view to other table.\n        \"\"\"\n        def can_unlock(x):\n            if sp.issparse(x):\n                return can_unlock(x.data)\n            return x.flags.writeable or x.flags.owndata\n\n        for part, flag, name in self._lock_parts():\n            if not flag & self._unlocked \\\n                    and (not parts or any(ppart is part for ppart in parts)) \\\n                    and part is not None and not can_unlock(part):\n                raise ValueError(f\"'{name}' is a view into another table \"\n                                 \"and cannot be unlocked\")\n        return contextmanager(self.__unlocked)(*parts)\n\n    def __new__(cls, *args, **kwargs):\n        def warn_deprecated(method):\n            warnings.warn(\"Direct calls to Table's constructor are deprecated \"\n                          \"and will be removed. Replace this call with \"\n                          f\"Table.{method}\", OrangeDeprecationWarning,\n                          stacklevel=3)\n\n        if not args:\n            if not kwargs:\n                return super().__new__(cls)\n            else:\n                raise TypeError(\"Table() must not be called directly\")\n\n        if isinstance(args[0], str):\n            if len(args) > 1:\n                raise TypeError(\"Table(name: str) expects just one argument\")\n            if args[0].startswith('https://') or args[0].startswith('http://'):\n                return cls.from_url(args[0], **kwargs)\n            else:\n                return cls.from_file(args[0], **kwargs)\n\n        elif isinstance(args[0], Table):\n            if len(args) > 1:\n                raise TypeError(\"Table(table: Table) expects just one argument\")\n            return cls.from_table(args[0].domain, args[0], **kwargs)\n        elif isinstance(args[0], Domain):\n            domain, args = args[0], args[1:]\n            if not args:\n                warn_deprecated(\"from_domain\")\n                return cls.from_domain(domain, **kwargs)\n            if isinstance(args[0], Table):\n                warn_deprecated(\"from_table\")\n                return cls.from_table(domain, *args, **kwargs)\n            elif isinstance(args[0], list):\n                warn_deprecated(\"from_list\")\n                return cls.from_list(domain, *args, **kwargs)\n        else:\n            warnings.warn(\"Omitting domain in a call to Table(X, Y, metas), is \"\n                          \"deprecated and will be removed. \"\n                          \"Call Table.from_numpy(None, X, Y, metas) instead.\",\n                          OrangeDeprecationWarning, stacklevel=2)\n            domain = None\n\n        return cls.from_numpy(domain, *args, **kwargs)\n\n    def __init__(self, *args, **kwargs):  # pylint: disable=unused-argument\n        self._initialize_unlocked()\n        self._update_locks()\n\n    @classmethod\n    def from_domain(cls, domain, n_rows=0, weights=False):\n        \"\"\"\n        Construct a new `Table` with the given number of rows for the given\n        domain. The optional vector of weights is initialized to 1's.\n\n        :param domain: domain for the `Table`\n        :type domain: Orange.data.Domain\n        :param n_rows: number of rows in the new table\n        :type n_rows: int\n        :param weights: indicates whether to construct a vector of weights\n        :type weights: bool\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n        self = cls()\n        self.domain = domain\n        self.n_rows = n_rows\n        with self.unlocked():\n            self.X = np.zeros((n_rows, len(domain.attributes)))\n            if len(domain.class_vars) != 1:\n                self.Y = np.zeros((n_rows, len(domain.class_vars)))\n            else:\n                self.Y = np.zeros(n_rows)\n            if weights:\n                self.W = np.ones(n_rows)\n            else:\n                self.W = np.empty((n_rows, 0))\n            self.metas = np.empty((n_rows, len(self.domain.metas)), object)\n            cls._init_ids(self)\n            self.attributes = {}\n        return self\n\n    @classmethod\n    def from_table(cls, domain, source, row_indices=...):\n        \"\"\"\n        Create a new table from selected columns and/or rows of an existing\n        one. The columns are chosen using a domain. The domain may also include\n        variables that do not appear in the source table; they are computed\n        from source variables if possible.\n\n        The resulting data may be a view or a copy of the existing data.\n\n        :param domain: the domain for the new table\n        :type domain: Orange.data.Domain\n        :param source: the source table\n        :type source: Orange.data.Table\n        :param row_indices: indices of the rows to include\n        :type row_indices: a slice or a sequence\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n\n        PART = 5000\n\n        new_cache = _thread_local.conversion_cache is None\n        try:\n            if new_cache:\n                _thread_local.conversion_cache = {}\n                _thread_local.domain_cache = {}\n            else:\n                cached = _idcache_restore(_thread_local.conversion_cache, (domain, source))\n                if cached is not None:\n                    return cached\n            if domain is source.domain:\n                table = cls.from_table_rows(source, row_indices)\n                # assure resulting domain is the instance passed on input\n                table.domain = domain\n                # since sparse flags are not considered when checking for\n                # domain equality, fix manually.\n                with table.unlocked():\n                    table = assure_domain_conversion_sparsity(table, source)\n                return table\n\n            if row_indices is ...:\n                n_rows = len(source)\n            elif isinstance(row_indices, slice):\n                row_indices_range = range(*row_indices.indices(source.X.shape[0]))\n                n_rows = len(row_indices_range)\n            else:\n                n_rows = len(row_indices)\n\n            self = cls()\n            self.domain = domain\n\n            table_conversion = \\\n                _idcache_restore(_thread_local.domain_cache, (domain, source.domain))\n            if table_conversion is None:\n                table_conversion = _FromTableConversion(source.domain, domain)\n                _idcache_save(_thread_local.domain_cache, (domain, source.domain),\n                              table_conversion)\n\n            # if an array can be a subarray of the input table, this needs to be done\n            # on the whole table, because this avoids needless copies of contents\n\n            with self.unlocked():\n                for array_conv in table_conversion.subarray:\n                    out = array_conv.get_subarray(source, row_indices, n_rows)\n                    setattr(self, array_conv.target, out)\n\n                parts = {}\n\n                for array_conv in table_conversion.columnwise:\n                    if array_conv.is_sparse:\n                        parts[array_conv.target] = []\n                    else:\n                        # F-order enables faster writing to the array while accessing and\n                        # matrix operations work with same speed (e.g. dot)\n                        parts[array_conv.target] = \\\n                            np.zeros((n_rows, len(array_conv.src_cols)),\n                                     order=\"F\", dtype=array_conv.dtype)\n\n                if n_rows <= PART:\n                    for array_conv in table_conversion.columnwise:\n                        out = array_conv.get_columns(source, row_indices, n_rows,\n                                                     parts[array_conv.target],\n                                                     ...)\n                        setattr(self, array_conv.target, out)\n                else:\n                    i_done = 0\n\n                    while i_done < n_rows:\n                        target_indices = slice(i_done, min(n_rows, i_done + PART))\n                        if row_indices is ...:\n                            source_indices = target_indices\n                        elif isinstance(row_indices, slice):\n                            r = row_indices_range[target_indices]\n                            source_indices = slice(r.start, r.stop, r.step)\n                        else:\n                            source_indices = row_indices[target_indices]\n                        part_rows = min(n_rows, i_done+PART) - i_done\n\n                        for array_conv in table_conversion.columnwise:\n                            out = array_conv.get_columns(source, source_indices, part_rows,\n                                                         parts[array_conv.target],\n                                                         target_indices)\n                            if array_conv.is_sparse:  # dense arrays are populated in-place\n                                parts[array_conv.target].append(out)\n\n                        i_done += PART\n\n                        # clear cache after a part is done\n                        if new_cache:\n                            _thread_local.conversion_cache = {}\n\n                    for array_conv in table_conversion.columnwise:\n                        cparts = parts[array_conv.target]\n                        out = cparts if not array_conv.is_sparse else sp.vstack(cparts)\n                        setattr(self, array_conv.target, out)\n\n                if source.has_weights():\n                    self.W = source.W[row_indices]\n                else:\n                    self.W = np.empty((n_rows, 0))\n                self.name = getattr(source, 'name', '')\n                if hasattr(source, 'ids'):\n                    self.ids = source.ids[row_indices]\n                else:\n                    cls._init_ids(self)\n                self.attributes = getattr(source, 'attributes', {})\n                _idcache_save(_thread_local.conversion_cache, (domain, source), self)\n            return self\n        finally:\n            if new_cache:\n                _thread_local.conversion_cache = None\n                _thread_local.domain_cache = None\n\n    def transform(self, domain):\n        \"\"\"\n        Construct a table with a different domain.\n\n        The new table keeps the row ids and other information. If the table\n        is a subclass of :obj:`Table`, the resulting table will be of the same\n        type.\n\n        In a typical scenario, an existing table is augmented with a new\n        column by ::\n\n            domain = Domain(old_domain.attributes + [new_attribute],\n                            old_domain.class_vars,\n                            old_domain.metas)\n            table = data.transform(domain)\n            table[:, new_attribute] = new_column\n\n        Args:\n            domain (Domain): new domain\n\n        Returns:\n            A new table\n        \"\"\"\n        return type(self).from_table(domain, self)\n\n    @classmethod\n    def from_table_rows(cls, source, row_indices):\n        \"\"\"\n        Construct a new table by selecting rows from the source table.\n\n        :param source: an existing table\n        :type source: Orange.data.Table\n        :param row_indices: indices of the rows to include\n        :type row_indices: a slice or a sequence\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n        def get_rows(a):\n            a = a[row_indices]\n            if isinstance(row_indices, slice) or row_indices is ...:\n                a = a.copy()\n            return a\n\n        self = cls()\n        self.domain = source.domain\n        with self.unlocked():\n            self.X = get_rows(source.X)\n            if self.X.ndim == 1:\n                self.X = self.X.reshape(-1, len(self.domain.attributes))\n            self.Y = get_rows(source.Y)\n            self.metas = get_rows(source.metas)\n            if self.metas.ndim == 1:\n                self.metas = self.metas.reshape(-1, len(self.domain.metas))\n            self.W = get_rows(source.W)\n            self.name = getattr(source, 'name', '')\n            self.ids = np.array(source.ids[row_indices])\n            self.attributes = getattr(source, 'attributes', {})\n        return self\n\n    @classmethod\n    def from_numpy(cls, domain, X, Y=None, metas=None, W=None,\n                   attributes=None, ids=None):\n        \"\"\"\n        Construct a table from numpy arrays with the given domain. The number\n        of variables in the domain must match the number of columns in the\n        corresponding arrays. All arrays must have the same number of rows.\n        Arrays may be of different numpy types, and may be dense or sparse.\n\n        :param domain: the domain for the new table\n        :type domain: Orange.data.Domain\n        :param X: array with attribute values\n        :type X: np.array\n        :param Y: array with class values\n        :type Y: np.array\n        :param metas: array with meta attributes\n        :type metas: np.array\n        :param W: array with weights\n        :type W: np.array\n        :return:\n        \"\"\"\n        X, Y, W = _check_arrays(X, Y, W, dtype='float64')\n        metas, = _check_arrays(metas, dtype=object, shape_1=X.shape[0])\n        ids, = _check_arrays(ids, dtype=int, shape_1=X.shape[0])\n\n        if domain is None:\n            domain = Domain.from_numpy(X, Y, metas)\n\n        if Y is None:\n            if not domain.class_vars or sp.issparse(X):\n                Y = np.empty((X.shape[0], 0), dtype=np.float64)\n            else:\n                own_data = X.flags.owndata and X.base is None\n                Y = X[:, len(domain.attributes):]\n                X = X[:, :len(domain.attributes)]\n                if own_data:\n                    Y = Y.copy()\n                    X = X.copy()\n        if metas is None:\n            metas = np.empty((X.shape[0], 0), object)\n        if W is None or W.size == 0:\n            W = np.empty((X.shape[0], 0))\n        elif W.shape != (W.size, ):\n            W = W.reshape(W.size).copy()\n\n        if X.shape[1] != len(domain.attributes):\n            raise ValueError(\n                \"Invalid number of variable columns ({} != {})\".format(\n                    X.shape[1], len(domain.attributes))\n            )\n        if Y.ndim == 1:\n            if not domain.class_var:\n                raise ValueError(\n                    \"Invalid number of class columns \"\n                    f\"(1 != {len(domain.class_vars)})\")\n        elif Y.shape[1] != len(domain.class_vars):\n            raise ValueError(\n                \"Invalid number of class columns ({} != {})\".format(\n                    Y.shape[1], len(domain.class_vars))\n            )\n        if metas.shape[1] != len(domain.metas):\n            raise ValueError(\n                \"Invalid number of meta attribute columns ({} != {})\".format(\n                    metas.shape[1], len(domain.metas))\n            )\n        if not X.shape[0] == Y.shape[0] == metas.shape[0] == W.shape[0]:\n            raise ValueError(\n                \"Parts of data contain different numbers of rows.\")\n\n        self = cls()\n        with self.unlocked():\n            self.domain = domain\n            self.X = X\n            self.Y = Y\n            self.metas = metas\n            self.W = W\n            self.n_rows = self.X.shape[0]\n            if ids is None:\n                cls._init_ids(self)\n            else:\n                self.ids = ids\n            self.attributes = {} if attributes is None else attributes\n        return self\n\n    @classmethod\n    def from_list(cls, domain, rows, weights=None):\n        if weights is not None and len(rows) != len(weights):\n            raise ValueError(\"mismatching number of instances and weights\")\n        self = cls.from_domain(domain, len(rows), weights is not None)\n        all_vars = domain.variables + domain.metas\n        nattrs = len(domain.attributes)\n        nattrscls = len(domain.variables)\n        with self.unlocked():\n            for i, row in enumerate(rows):\n                if isinstance(row, Instance):\n                    row = row.list\n                vals = [var.to_val(val) for var, val in zip(all_vars, row)]\n                self.X[i] = vals[:nattrs]\n                if self._Y.ndim == 1:\n                    self._Y[i] = vals[nattrs] if nattrs < len(vals) else np.nan\n                else:\n                    self._Y[i] = vals[nattrs:nattrscls]\n                # for backward compatibility: allow omittine some (or all) metas\n                self.metas[i, :len(vals) - nattrscls] = vals[nattrscls:]\n            if weights is not None:\n                self.W = np.array(weights)\n            self.attributes = {}\n        return self\n\n    @classmethod\n    def _init_ids(cls, obj):\n        with cls._next_instance_lock:\n            obj.ids = np.array(range(cls._next_instance_id, cls._next_instance_id + obj.X.shape[0]))\n            cls._next_instance_id += obj.X.shape[0]\n\n    @classmethod\n    def new_id(cls):\n        with cls._next_instance_lock:\n            id = cls._next_instance_id\n            cls._next_instance_id += 1\n            return id\n\n    def to_pandas_dfs(self):\n        return Orange.data.pandas_compat.table_to_frames(self)\n\n    @staticmethod\n    def from_pandas_dfs(xdf, ydf, mdf):\n        return Orange.data.pandas_compat.table_from_frames(xdf, ydf, mdf)\n\n    @property\n    def X_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.Attribute\n        )\n\n    @X_df.setter\n    def X_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.Attribute\n        )\n\n    @property\n    def Y_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.ClassAttribute\n        )\n\n    @Y_df.setter\n    def Y_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.ClassAttribute\n        )\n\n    @property\n    def metas_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.Meta\n        )\n\n    @metas_df.setter\n    def metas_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.Meta\n        )\n\n    def save(self, filename):\n        \"\"\"\n        Save a data table to a file. The path can be absolute or relative.\n\n        :param filename: File name\n        :type filename: str\n        \"\"\"\n        ext = os.path.splitext(filename)[1]\n        from Orange.data.io import FileFormat\n        writer = FileFormat.writers.get(ext)\n        if not writer:\n            desc = FileFormat.names.get(ext)\n            if desc:\n                raise IOError(\n                    \"Writing of {}s is not supported\".format(desc.lower()))\n            else:\n                raise IOError(\"Unknown file name extension.\")\n        writer.write_file(filename, self)\n\n    @classmethod\n    def from_file(cls, filename, sheet=None):\n        \"\"\"\n        Read a data table from a file. The path can be absolute or relative.\n\n        :param filename: File name\n        :type filename: str\n        :param sheet: Sheet in a file (optional)\n        :type sheet: str\n        :return: a new data table\n        :rtype: Orange.data.Table\n        \"\"\"\n        from Orange.data.io import FileFormat\n\n        absolute_filename = FileFormat.locate(filename, dataset_dirs)\n        reader = FileFormat.get_reader(absolute_filename)\n        reader.select_sheet(sheet)\n        data = reader.read()\n\n        # Readers return plain table. Make sure to cast it to appropriate\n        # (subclass) type\n        if cls != data.__class__:\n            data = cls(data)\n\n        # no need to call _init_ids as fuctions from .io already\n        # construct a table with .ids\n\n        data.__file__ = absolute_filename\n        return data\n\n    @classmethod\n    def from_url(cls, url):\n        from Orange.data.io import UrlReader\n        reader = UrlReader(url)\n        data = reader.read()\n        if cls != data.__class__:\n            data = cls(data)\n        return data\n\n    # Helper function for __setitem__:\n    # Set the row of table data matrices\n    # noinspection PyProtectedMember\n    def _set_row(self, example, row):\n        # pylint: disable=protected-access\n        domain = self.domain\n        if isinstance(example, Instance):\n            if example.domain == domain:\n                self.X[row] = example._x\n                if self._Y.ndim == 1:\n                    self._Y[row] = float(example._y)\n                else:\n                    self._Y[row] = np.atleast_1d(example._y)\n                self.metas[row] = example._metas\n                return\n\n            self.X[row], self._Y[row], self.metas[row] = \\\n                self.domain.convert(example)\n            try:\n                self.ids[row] = example.id\n            except:\n                with type(self)._next_instance_lock:\n                    self.ids[row] = type(self)._next_instance_id\n                    type(self)._next_instance_id += 1\n\n        else:\n            attrs = domain.attributes\n            if len(example) != len(domain.variables):\n                raise ValueError(\"invalid length\")\n            self._X[row] = [var.to_val(val) for var, val in zip(attrs, example)]\n            if self._Y.ndim == 1:\n                self._Y[row] = domain.class_var.to_val(example[len(attrs)])\n            else:\n                self._Y[row] = [var.to_val(val)\n                                for var, val in zip(domain.class_vars,\n                                                    example[len(attrs):])]\n            self.metas[row] = np.array([var.Unknown for var in domain.metas],\n                                       dtype=object)\n\n    def _check_all_dense(self):\n        return all(x in (Storage.DENSE, Storage.MISSING)\n                   for x in (self.X_density(), self.Y_density(),\n                             self.metas_density()))\n\n    def __getitem__(self, key):\n        if isinstance(key, Integral):\n            return RowInstance(self, key)\n        if not isinstance(key, tuple):\n            return self.from_table_rows(self, key)\n\n        if len(key) != 2:\n            raise IndexError(\"Table indices must be one- or two-dimensional\")\n\n        row_idx, col_idx = key\n        if isinstance(row_idx, Integral):\n            if isinstance(col_idx, (str, Integral, Variable)):\n                col_idx = self.domain.index(col_idx)\n                var = self.domain[col_idx]\n                if 0 <= col_idx < len(self.domain.attributes):\n                    val = self.X[row_idx, col_idx]\n                elif col_idx == len(self.domain.attributes) and self._Y.ndim == 1:\n                    val = self._Y[row_idx]\n                elif col_idx >= len(self.domain.attributes):\n                    val = self._Y[row_idx,\n                                  col_idx - len(self.domain.attributes)]\n                else:\n                    val = self.metas[row_idx, -1 - col_idx]\n                if isinstance(col_idx, DiscreteVariable) and var is not col_idx:\n                    val = col_idx.get_mapper_from(var)(val)\n                return Value(var, val)\n            else:\n                row_idx = [row_idx]\n\n        # multiple rows OR single row but multiple columns:\n        # construct a new table\n        attributes, col_indices = self.domain._compute_col_indices(col_idx)\n        if attributes is not None:\n            n_attrs = len(self.domain.attributes)\n            r_attrs = [attributes[i]\n                       for i, col in enumerate(col_indices)\n                       if 0 <= col < n_attrs]\n            r_classes = [attributes[i]\n                         for i, col in enumerate(col_indices)\n                         if col >= n_attrs]\n            r_metas = [attributes[i]\n                       for i, col in enumerate(col_indices) if col < 0]\n            domain = Domain(r_attrs, r_classes, r_metas)\n        else:\n            domain = self.domain\n        return self.from_table(domain, self, row_idx)\n\n    def __setitem__(self, key, value):\n        if not isinstance(key, tuple):\n            if isinstance(value, Real):\n                self.X[key, :] = value\n                return\n            self._set_row(value, key)\n            return\n\n        if len(key) != 2:\n            raise IndexError(\"Table indices must be one- or two-dimensional\")\n        row_idx, col_idx = key\n\n        # single row\n        if isinstance(row_idx, Integral):\n            if isinstance(col_idx, slice):\n                col_idx = range(*slice.indices(col_idx, self.X.shape[1]))\n            if not isinstance(col_idx, str) and isinstance(col_idx, Iterable):\n                col_idx = list(col_idx)\n            if not isinstance(col_idx, str) and isinstance(col_idx, Sized):\n                if isinstance(value, (Sequence, np.ndarray)):\n                    values = value\n                elif isinstance(value, Iterable):\n                    values = list(value)\n                else:\n                    raise TypeError(\"Setting multiple values requires a \"\n                                    \"sequence or numpy array\")\n                if len(values) != len(col_idx):\n                    raise ValueError(\"Invalid number of values\")\n            else:\n                col_idx, values = [col_idx], [value]\n            if isinstance(col_idx, DiscreteVariable) \\\n                    and self.domain[col_idx] != col_idx:\n                values = self.domain[col_idx].get_mapper_from(col_idx)(values)\n            for val, col_idx in zip(values, col_idx):\n                if not isinstance(val, Integral):\n                    val = self.domain[col_idx].to_val(val)\n                if not isinstance(col_idx, Integral):\n                    col_idx = self.domain.index(col_idx)\n                if col_idx >= 0:\n                    if col_idx < self.X.shape[1]:\n                        self.X[row_idx, col_idx] = val\n                    elif self._Y.ndim == 1 and col_idx == self.X.shape[1]:\n                        self._Y[row_idx] = val\n                    else:\n                        self._Y[row_idx, col_idx - self.X.shape[1]] = val\n                else:\n                    self.metas[row_idx, -1 - col_idx] = val\n\n        # multiple rows, multiple columns\n        attributes, col_indices = self.domain._compute_col_indices(col_idx)\n        if col_indices is ...:\n            col_indices = range(len(self.domain.variables))\n        n_attrs = self.X.shape[1]\n        if isinstance(value, str):\n            if not attributes:\n                attributes = self.domain.attributes\n            for var, col in zip(attributes, col_indices):\n                val = var.to_val(value)\n                if 0 <= col < n_attrs:\n                    self.X[row_idx, col] = val\n                elif col >= n_attrs:\n                    if self._Y.ndim == 1 and col == n_attrs:\n                        self._Y[row_idx] = val\n                    else:\n                        self._Y[row_idx, col - n_attrs] = val\n                else:\n                    self.metas[row_idx, -1 - col] = val\n        else:\n            attr_cols = np.fromiter(\n                (col for col in col_indices if 0 <= col < n_attrs), int)\n            class_cols = np.fromiter(\n                (col - n_attrs for col in col_indices if col >= n_attrs), int)\n            meta_cols = np.fromiter(\n                (-1 - col for col in col_indices if col < 0), int)\n            if value is None:\n                value = Unknown\n\n            if not isinstance(value, (Real, np.ndarray)) and \\\n                    (len(attr_cols) or len(class_cols)):\n                raise TypeError(\n                    \"Ordinary attributes can only have primitive values\")\n            if len(attr_cols):\n                self.X[row_idx, attr_cols] = value\n            if len(class_cols):\n                if self._Y.ndim == 1 and np.all(class_cols == 0):\n                    if isinstance(value, np.ndarray):\n                        yshape = self._Y[row_idx].shape\n                        if value.shape != yshape:\n                            value = value.reshape(yshape)\n                    self._Y[row_idx] = value\n                else:\n                    self._Y[row_idx, class_cols] = value\n            if len(meta_cols):\n                self.metas[row_idx, meta_cols] = value\n\n    def __len__(self):\n        return self.X.shape[0]\n\n    def __str__(self):\n        return \"[\" + \",\\n \".join(str(ex) for ex in self) + \"]\"\n\n    def __repr__(self):\n        head = 5\n        if self.is_sparse():\n            head = min(self.X.shape[0], head)\n        s = \"[\" + \",\\n \".join(repr(ex) for ex in self[:head])\n        if len(self) > head:\n            s += \",\\n ...\"\n        s += \"\\n]\"\n        return s\n\n    @classmethod\n    def concatenate(cls, tables, axis=0):\n        \"\"\"\n        Concatenate tables into a new table, either vertically or horizontally.\n\n        If axis=0 (vertical concatenate), all tables must have the same domain.\n\n        If axis=1 (horizontal),\n        - all variable names must be unique.\n        - ids are copied from the first table.\n        - weights are copied from the first table in which they are defined.\n        - the dictionary of table's attributes are merged. If the same attribute\n          appears in multiple dictionaries, the earlier are used.\n\n        Args:\n            tables (Table): tables to be joined\n\n        Returns:\n            table (Table)\n        \"\"\"\n        if axis not in (0, 1):\n            raise ValueError(\"invalid axis\")\n        if not tables:\n            raise ValueError('need at least one table to concatenate')\n\n        if len(tables) == 1:\n            return tables[0].copy()\n\n        if axis == 0:\n            conc = cls._concatenate_vertical(tables)\n        else:\n            conc = cls._concatenate_horizontal(tables)\n\n        # TODO: Add attributes = {} to __init__\n        conc.attributes = getattr(conc, \"attributes\", {})\n        for table in reversed(tables):\n            conc.attributes.update(table.attributes)\n\n        names = [table.name for table in tables if table.name != \"untitled\"]\n        if names:\n            conc.name = names[0]\n        return conc\n\n    @classmethod\n    def _concatenate_vertical(cls, tables):\n        def vstack(arrs):\n            return [np, sp][any(sp.issparse(arr) for arr in arrs)].vstack(arrs)\n\n        def merge1d(arrs):\n            arrs = list(arrs)\n            ydims = {arr.ndim for arr in arrs}\n            if ydims == {1}:\n                return np.hstack(arrs)\n            else:\n                return vstack([\n                    arr if arr.ndim == 2 else np.atleast_2d(arr).T\n                    for arr in arrs\n                ])\n\n        def collect(attr):\n            return [getattr(arr, attr) for arr in tables]\n\n        domain = tables[0].domain\n        if any(table.domain != domain for table in tables):\n            raise ValueError('concatenated tables must have the same domain')\n\n        conc = cls.from_numpy(\n            domain,\n            vstack(collect(\"X\")),\n            merge1d(collect(\"Y\")),\n            vstack(collect(\"metas\")),\n            merge1d(collect(\"W\"))\n        )\n        conc.ids = np.hstack([t.ids for t in tables])\n        return conc\n\n    @classmethod\n    def _concatenate_horizontal(cls, tables):\n        \"\"\"\n        \"\"\"\n        def all_of(objs, names):\n            return (tuple(getattr(obj, name) for obj in objs)\n                    for name in names)\n\n        def stack(arrs):\n            non_empty = tuple(arr if arr.ndim == 2 else arr[:, np.newaxis]\n                              for arr in arrs\n                              if arr is not None and arr.size > 0)\n            return np.hstack(non_empty) if non_empty else None\n\n        doms, Ws = all_of(tables, (\"domain\", \"W\"))\n        Xs, Ys, Ms = map(stack, all_of(tables, (\"X\", \"Y\", \"metas\")))\n        # pylint: disable=undefined-loop-variable\n        for W in Ws:\n            if W.size:\n                break\n\n        parts = all_of(doms, (\"attributes\", \"class_vars\", \"metas\"))\n        domain = Domain(*(tuple(chain(*lst)) for lst in parts))\n        return cls.from_numpy(domain, Xs, Ys, Ms, W, ids=tables[0].ids)\n\n    def add_column(self, variable, data, to_metas=None):\n        \"\"\"\n        Create a new table with an additional column\n\n        Column's name must be unique\n\n        Args:\n            variable (Variable): variable for the new column\n            data (np.ndarray): data for the new column\n            to_metas (bool, optional): if `True` the column is added as meta\n                column. Otherwise, primitive variables are added to attributes\n                and non-primitive to metas.\n\n        Returns:\n            table (Table): a new table with the additional column\n        \"\"\"\n        dom = self.domain\n        attrs, classes, metavars = dom.attributes, dom.class_vars, dom.metas\n        to_metas = to_metas or not variable.is_primitive()\n        if to_metas:\n            metavars += (variable, )\n        else:\n            attrs += (variable, )\n        domain = Domain(attrs, classes, metavars)\n        new_table = self.transform(domain)\n        with new_table.unlocked(new_table.metas if to_metas else new_table.X):\n            new_table.get_column_view(variable)[0][:] = data\n        return new_table\n\n    def is_view(self):\n        \"\"\"\n        Return `True` if all arrays represent a view referring to another table\n        \"\"\"\n        return ((not self._X.shape[-1] or self._X.base is not None) and\n                (not self._Y.shape[-1] or self._Y.base is not None) and\n                (not self._metas.shape[-1] or self._metas.base is not None) and\n                (not self._weights.shape[-1] or self._W.base is not None))\n\n    def is_copy(self):\n        \"\"\"\n        Return `True` if the table owns its data\n        \"\"\"\n        return ((not self._X.shape[-1] or self._X.base is None) and\n                (self._Y.base is None) and\n                (self._metas.base is None) and\n                (self._W.base is None))\n\n    def is_sparse(self):\n        \"\"\"\n        Return `True` if the table stores data in sparse format\n        \"\"\"\n        return any(sp.issparse(i) for i in [self._X, self._Y, self._metas])\n\n    def ensure_copy(self):\n        \"\"\"\n        Ensure that the table owns its data; copy arrays when necessary.\n        \"\"\"\n\n        def is_view(x):\n            # Sparse matrices don't have views like numpy arrays. Since indexing on\n            # them creates copies in constructor we can skip this check here.\n            return not sp.issparse(x) and x.base is not None\n\n        if is_view(self._X):\n            self._X = self._X.copy()\n        if is_view(self._Y):\n            self._Y = self._Y.copy()\n        if is_view(self._metas):\n            self._metas = self._metas.copy()\n        if is_view(self._W):\n            self._W = self._W.copy()\n\n    def copy(self):\n        \"\"\"\n        Return a copy of the table\n        \"\"\"\n        t = self.__class__(self)\n        t.ensure_copy()\n        return t\n\n    @staticmethod\n    def __determine_density(data):\n        if data is None:\n            return Storage.Missing\n        if data is not None and sp.issparse(data):\n            return Storage.SPARSE_BOOL if (data.data == 1).all() else Storage.SPARSE\n        else:\n            return Storage.DENSE\n\n    def X_density(self):\n        if not hasattr(self, \"_X_density\"):\n            self._X_density = self.__determine_density(self.X)\n        return self._X_density\n\n    def Y_density(self):\n        if not hasattr(self, \"_Y_density\"):\n            self._Y_density = self.__determine_density(self._Y)\n        return self._Y_density\n\n    def metas_density(self):\n        if not hasattr(self, \"_metas_density\"):\n            self._metas_density = self.__determine_density(self.metas)\n        return self._metas_density\n\n    def set_weights(self, weight=1):\n        \"\"\"\n        Set weights of data instances; create a vector of weights if necessary.\n        \"\"\"\n        if not self.W.shape[-1]:\n            self.W = np.empty(len(self))\n        self.W[:] = weight\n\n    def has_weights(self):\n        \"\"\"Return `True` if the data instances are weighed. \"\"\"\n        return self.W.shape[-1] != 0\n\n    def total_weight(self):\n        \"\"\"\n        Return the total weight of instances in the table, or their number if\n        they are unweighted.\n        \"\"\"\n        if self.W.shape[-1]:\n            return sum(self.W)\n        return len(self)\n\n    def has_missing(self):\n        \"\"\"Return `True` if there are any missing attribute or class values.\"\"\"\n        missing_x = not sp.issparse(self.X) and bn.anynan(self.X)  # do not check for sparse X\n        return missing_x or bn.anynan(self._Y)\n\n    def has_missing_attribute(self):\n        \"\"\"Return `True` if there are any missing attribute values.\"\"\"\n        return not sp.issparse(self.X) and bn.anynan(self.X)  # do not check for sparse X\n\n    def has_missing_class(self):\n        \"\"\"Return `True` if there are any missing class values.\"\"\"\n        return bn.anynan(self._Y)\n\n    def get_nan_frequency_attribute(self):\n        if self.X.size == 0:\n            return 0\n        return np.isnan(self.X).sum() / self.X.size\n\n    def get_nan_frequency_class(self):\n        if self.Y.size == 0:\n            return 0\n        return np.isnan(self._Y).sum() / self._Y.size\n\n    def checksum(self, include_metas=True):\n        # TODO: zlib.adler32 does not work for numpy arrays with dtype object\n        # (after pickling and unpickling such arrays, checksum changes)\n        # Why, and should we fix it or remove it?\n        \"\"\"Return a checksum over X, Y, metas and W.\"\"\"\n        cs = zlib.adler32(np.ascontiguousarray(self._X))\n        cs = zlib.adler32(np.ascontiguousarray(self._Y), cs)\n        if include_metas:\n            cs = zlib.adler32(np.ascontiguousarray(self._metas), cs)\n        cs = zlib.adler32(np.ascontiguousarray(self._W), cs)\n        return cs\n\n    def shuffle(self):\n        \"\"\"Randomly shuffle the rows of the table.\"\"\"\n        if not self._check_all_dense():\n            raise ValueError(\"Rows of sparse data cannot be shuffled\")\n        ind = np.arange(self.X.shape[0])\n        np.random.shuffle(ind)\n        self.X = self.X[ind]\n        self._Y = self._Y[ind]\n        self.metas = self.metas[ind]\n        self.W = self.W[ind]\n\n    def get_column_view(self, index):\n        \"\"\"\n        Return a vector - as a view, not a copy - with a column of the table,\n        and a bool flag telling whether this column is sparse. Note that\n        vertical slicing of sparse matrices is inefficient.\n\n        :param index: the index of the column\n        :type index: int, str or Orange.data.Variable\n        :return: (one-dimensional numpy array, sparse)\n        \"\"\"\n\n        def rx(M):\n            if sp.issparse(M):\n                return np.asarray(M.todense())[:, 0], True\n            else:\n                return M, False\n\n        if isinstance(index, Integral):\n            col_index = index\n        else:\n            col_index = self.domain.index(index)\n        if col_index >= 0:\n            if col_index < self.X.shape[1]:\n                col = rx(self.X[:, col_index])\n            elif self._Y.ndim == 1 and col_index == self._X.shape[1]:\n                col = rx(self._Y)\n            else:\n                col = rx(self._Y[:, col_index - self.X.shape[1]])\n        else:\n            col = rx(self.metas[:, -1 - col_index])\n\n        if isinstance(index, DiscreteVariable) \\\n                and index.values != self.domain[col_index].values:\n            col = index.get_mapper_from(self.domain[col_index])(col[0]), col[1]\n            col[0].flags.writeable = False\n        return col\n\n    def _filter_is_defined(self, columns=None, negate=False):\n        # structure of function is obvious; pylint: disable=too-many-branches\n        def _sp_anynan(a):\n            return a.indptr[1:] != a[-1:] + a.shape[1]\n\n        if columns is None:\n            if sp.issparse(self.X):\n                remove = _sp_anynan(self.X)\n            else:\n                remove = bn.anynan(self.X, axis=1)\n            if sp.issparse(self._Y):\n                remove += _sp_anynan(self._Y)\n            else:\n                if self._Y.ndim == 1:\n                    remove += np.isnan(self._Y)\n                else:\n                    remove += bn.anynan(self._Y, axis=1)\n            if sp.issparse(self.metas):\n                remove += _sp_anynan(self._metas)\n            else:\n                for i, var in enumerate(self.domain.metas):\n                    col = self.metas[:, i].flatten()\n                    if var.is_primitive():\n                        remove += np.isnan(col.astype(float))\n                    else:\n                        remove += ~col.astype(bool)\n        else:\n            remove = np.zeros(len(self), dtype=bool)\n            for column in columns:\n                col, sparse = self.get_column_view(column)\n                if sparse:\n                    remove += col == 0\n                elif self.domain[column].is_primitive():\n                    remove += bn.anynan([col.astype(float)], axis=0)\n                else:\n                    remove += col.astype(bool)\n        retain = remove if negate else np.logical_not(remove)\n        return self.from_table_rows(self, retain)\n\n    def _filter_has_class(self, negate=False):\n        if sp.issparse(self._Y):\n            if negate:\n                retain = (self._Y.indptr[1:] !=\n                          self._Y.indptr[-1:] + self._Y.shape[1])\n            else:\n                retain = (self._Y.indptr[1:] ==\n                          self._Y.indptr[-1:] + self._Y.shape[1])\n        else:\n            if self._Y.ndim == 1:\n                retain = np.isnan(self._Y)\n            else:\n                retain = bn.anynan(self._Y, axis=1)\n            if not negate:\n                retain = np.logical_not(retain)\n        return self.from_table_rows(self, retain)\n\n    def _filter_same_value(self, column, value, negate=False):\n        if not isinstance(value, Real):\n            value = self.domain[column].to_val(value)\n        sel = self.get_column_view(column)[0] == value\n        if negate:\n            sel = np.logical_not(sel)\n        return self.from_table_rows(self, sel)\n\n    def _filter_values(self, filter):\n        selection = self._values_filter_to_indicator(filter)\n        return self.from_table(self.domain, self, selection)\n\n    def _values_filter_to_indicator(self, filter):\n        \"\"\"Return selection of rows matching the filter conditions\n\n        Handles conjunction/disjunction and negate modifiers\n\n        Parameters\n        ----------\n        filter: Values object containing the conditions\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        from Orange.data.filter import Values\n\n        if isinstance(filter, Values):\n            conditions = filter.conditions\n            conjunction = filter.conjunction\n        else:\n            conditions = [filter]\n            conjunction = True\n        if conjunction:\n            sel = np.ones(len(self), dtype=bool)\n        else:\n            sel = np.zeros(len(self), dtype=bool)\n\n        for f in conditions:\n            selection = self._filter_to_indicator(f)\n\n            if conjunction:\n                sel *= selection\n            else:\n                sel += selection\n\n        if filter.negate:\n            sel = ~sel\n        return sel\n\n    def _filter_to_indicator(self, filter):\n        \"\"\"Return selection of rows that match the condition.\n\n        Parameters\n        ----------\n        filter: ValueFilter describing the condition\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        from Orange.data.filter import (\n            FilterContinuous, FilterDiscrete, FilterRegex, FilterString,\n            FilterStringList, IsDefined, Values\n        )\n        if isinstance(filter, Values):\n            return self._values_filter_to_indicator(filter)\n\n        def get_col_indices():\n            cols = chain(self.domain.variables, self.domain.metas)\n            if isinstance(filter, IsDefined):\n                if filter.columns is not None:\n                    return list(filter.columns)\n                else:\n                    return list(cols)\n\n            if filter.column is not None:\n                return [filter.column]\n\n            if isinstance(filter, FilterDiscrete):\n                raise ValueError(\"Discrete filter can't be applied across rows\")\n            if isinstance(filter, FilterContinuous):\n                return [col for col in cols if col.is_continuous]\n            if isinstance(filter,\n                          (FilterString, FilterStringList, FilterRegex)):\n                return [col for col in cols if col.is_string]\n            raise TypeError(\"Invalid filter\")\n\n        def col_filter(col_idx):\n            col = self.get_column_view(col_idx)[0]\n            if isinstance(filter, IsDefined):\n                if self.domain[col_idx].is_primitive():\n                    return ~np.isnan(col.astype(float))\n                else:\n                    return col.astype(bool)\n            if isinstance(filter, FilterDiscrete):\n                return self._discrete_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterContinuous):\n                return self._continuous_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterString):\n                return self._string_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterStringList):\n                if not filter.case_sensitive:\n                    col = np.char.lower(np.array(col, dtype=str))\n                    vals = [val.lower() for val in filter.values]\n                else:\n                    vals = filter.values\n                return reduce(operator.add, (col == val for val in vals))\n            if isinstance(filter, FilterRegex):\n                return np.vectorize(filter)(col)\n            raise TypeError(\"Invalid filter\")\n\n        col_indices = get_col_indices()\n        if len(col_indices) == 1:\n            sel = col_filter(col_indices[0])\n        else:\n            sel = np.ones(len(self), dtype=bool)\n            for col_idx in col_indices:\n                sel *= col_filter(col_idx)\n\n        if isinstance(filter, IsDefined) and filter.negate:\n            sel = ~sel\n        return sel\n\n    def _discrete_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given discrete filter.\n\n        Parameters\n        ----------\n        filter: FilterDiscrete\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.values is None:  # <- is defined filter\n            col = col.astype(float)\n            return ~np.isnan(col)\n\n        sel = np.zeros(len(self), dtype=bool)\n        for val in filter.values:\n            if not isinstance(val, Real):\n                val = self.domain[filter.column].to_val(val)\n            sel += (col == val)\n        return sel\n\n    def _continuous_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given continuous filter.\n\n        Parameters\n        ----------\n        filter: FilterContinuous\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.oper == filter.IsDefined:\n            col = col.astype(float)\n            return ~np.isnan(col)\n\n        return self._range_filter_to_indicator(filter, col, filter.min, filter.max)\n\n    def _string_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given string filter.\n\n        Parameters\n        ----------\n        filter: FilterString\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.oper == filter.IsDefined:\n            return col.astype(bool)\n\n        col = col.astype(str)\n        fmin = filter.min or \"\"\n        fmax = filter.max or \"\"\n\n        if not filter.case_sensitive:\n            # convert all to lower case\n            col = np.char.lower(col)\n            fmin = fmin.lower()\n            fmax = fmax.lower()\n\n        if filter.oper == filter.Contains:\n            return np.fromiter((fmin in e for e in col),\n                               dtype=bool)\n        if filter.oper == filter.StartsWith:\n            return np.fromiter((e.startswith(fmin) for e in col),\n                               dtype=bool)\n        if filter.oper == filter.EndsWith:\n            return np.fromiter((e.endswith(fmin) for e in col),\n                               dtype=bool)\n\n        return self._range_filter_to_indicator(filter, col, fmin, fmax)\n\n    @staticmethod\n    def _range_filter_to_indicator(filter, col, fmin, fmax):\n        with np.errstate(invalid=\"ignore\"):  # nan's are properly discarded\n            if filter.oper == filter.Equal:\n                return col == fmin\n            if filter.oper == filter.NotEqual:\n                return col != fmin\n            if filter.oper == filter.Less:\n                return col < fmin\n            if filter.oper == filter.LessEqual:\n                return col <= fmin\n            if filter.oper == filter.Greater:\n                return col > fmin\n            if filter.oper == filter.GreaterEqual:\n                return col >= fmin\n            if filter.oper == filter.Between:\n                return (col >= fmin) * (col <= fmax)\n            if filter.oper == filter.Outside:\n                return (col < fmin) + (col > fmax)\n\n            raise TypeError(\"Invalid operator\")\n\n    def _compute_basic_stats(self, columns=None,\n                             include_metas=False, compute_variance=False):\n        if compute_variance:\n            raise NotImplementedError(\"computation of variance is \"\n                                      \"not implemented yet\")\n        W = self._W if self.has_weights() else None\n        rr = []\n        stats = []\n        if not columns:\n            if self.domain.attributes:\n                rr.append(fast_stats(self._X, W))\n            if self.domain.class_vars:\n                rr.append(fast_stats(self._Y, W))\n            if include_metas and self.domain.metas:\n                rr.append(fast_stats(self.metas, W))\n            if len(rr):\n                stats = np.vstack(tuple(rr))\n        else:\n            nattrs = len(self.domain.attributes)\n            for column in columns:\n                c = self.domain.index(column)\n                if 0 <= c < nattrs:\n                    S = fast_stats(self._X[:, [c]], W and W[:, [c]])\n                elif c >= nattrs:\n                    if self._Y.ndim == 1 and c == nattrs:\n                        S = fast_stats(self._Y[:, None], W and W[:, None])\n                    else:\n                        S = fast_stats(self._Y[:, [c - nattrs]], W and W[:, [c - nattrs]])\n                else:\n                    S = fast_stats(self._metas[:, [-1 - c]], W and W[:, [-1 - c]])\n                stats.append(S[0])\n        return stats\n\n    def _compute_distributions(self, columns=None):\n        if columns is None:\n            columns = range(len(self.domain.variables))\n        else:\n            columns = [self.domain.index(var) for var in columns]\n\n        distributions = []\n        X = self.X\n        if sp.issparse(X):\n            X = X.tocsc()\n\n\n        W = self.W.ravel() if self.has_weights() else None\n\n        for col in columns:\n            variable = self.domain[col]\n\n            # Select the correct data column from X, Y or metas\n            if 0 <= col < X.shape[1]:\n                x = X[:, col]\n            elif col < 0:\n                x = self.metas[:, col * (-1) - 1]\n                if np.issubdtype(x.dtype, np.dtype(object)):\n                    x = x.astype(float)\n            elif self._Y.ndim == 1 and col == X.shape[1]:\n                x = self._Y\n            else:\n                x = self._Y[:, col - X.shape[1]]\n\n            if variable.is_discrete:\n                dist, unknowns = bincount(x, weights=W, max_val=len(variable.values) - 1)\n            elif not x.shape[0]:\n                dist, unknowns = np.zeros((2, 0)), 0\n            else:\n                if W is not None:\n                    if sp.issparse(x):\n                        arg_sort = np.argsort(x.data)\n                        ranks = x.indices[arg_sort]\n                        vals = np.vstack((x.data[arg_sort], W[ranks]))\n                    else:\n                        ranks = np.argsort(x)\n                        vals = np.vstack((x[ranks], W[ranks]))\n                else:\n                    x_values = x.data if sp.issparse(x) else x\n                    vals = np.ones((2, x_values.shape[0]))\n                    vals[0, :] = x_values\n                    vals[0, :].sort()\n\n                dist = np.array(_valuecount.valuecount(vals))\n                # If sparse, then 0s will not be counted with `valuecount`, so\n                # we have to add them to the result manually.\n                if sp.issparse(x) and sparse_has_implicit_zeros(x):\n                    if W is not None:\n                        zero_weights = sparse_implicit_zero_weights(x, W).sum()\n                    else:\n                        zero_weights = sparse_count_implicit_zeros(x)\n                    zero_vec = [0, zero_weights]\n                    dist = np.insert(dist, np.searchsorted(dist[0], 0), zero_vec, axis=1)\n                # Since `countnans` assumes vector shape to be (1, n) and `x`\n                # shape is (n, 1), we pass the transpose\n                unknowns = countnans(x.T, W)\n            distributions.append((dist, unknowns))\n\n        return distributions\n\n    def _compute_contingency(self, col_vars=None, row_var=None):\n        n_atts = self.X.shape[1]\n\n        if col_vars is None:\n            col_vars = range(len(self.domain.variables))\n        else:\n            col_vars = [self.domain.index(var) for var in col_vars]\n        if row_var is None:\n            row_var = self.domain.class_var\n            if row_var is None:\n                raise ValueError(\"No row variable\")\n\n        row_desc = self.domain[row_var]\n        if not row_desc.is_discrete:\n            raise TypeError(\"Row variable must be discrete\")\n        row_indi = self.domain.index(row_var)\n        n_rows = len(row_desc.values)\n        if 0 <= row_indi < n_atts:\n            row_data = self.X[:, row_indi]\n        elif row_indi < 0:\n            row_data = self.metas[:, -1 - row_indi]\n        elif self._Y.ndim == 1 and row_indi == n_atts:\n            row_data = self._Y\n        else:\n            row_data = self._Y[:, row_indi - n_atts]\n\n        W = self.W if self.has_weights() else None\n\n        col_desc = [self.domain[var] for var in col_vars]\n        col_indi = [self.domain.index(var) for var in col_vars]\n\n        if any(not (var.is_discrete or var.is_continuous)\n               for var in col_desc):\n            raise ValueError(\"Contingency can be computed only for categorical \"\n                             \"and numeric values.\")\n\n        # when we select a column in sparse matrix it is still two dimensional\n        # and sparse - since it is just a column we can afford to transform\n        # it to dense and make it 1D\n        if issparse(row_data):\n            row_data = row_data.toarray().ravel()\n        if row_data.dtype.kind != \"f\":  # meta attributes can be stored as type object\n            row_data = row_data.astype(float)\n\n        contingencies = [None] * len(col_desc)\n        for arr, f_cond, f_ind in (\n                (self.X, lambda i: 0 <= i < n_atts, lambda i: i),\n                (self._Y, lambda i: i >= n_atts, lambda i: i - n_atts),\n                (self.metas, lambda i: i < 0, lambda i: -1 - i)):\n\n            arr_indi = [e for e, ind in enumerate(col_indi) if f_cond(ind)]\n\n            vars = [(e, f_ind(col_indi[e]), col_desc[e]) for e in arr_indi]\n            disc_vars = [v for v in vars if v[2].is_discrete]\n            if disc_vars:\n                if sp.issparse(arr):\n                    max_vals = max(len(v[2].values) for v in disc_vars)\n                    disc_indi = {i for _, i, _ in disc_vars}\n                    mask = [i in disc_indi for i in range(arr.shape[1])]\n                    conts, nans_cols, nans_rows, nans = contingency(\n                        arr, row_data, max_vals - 1, n_rows - 1, W, mask)\n                    for col_i, arr_i, var in disc_vars:\n                        n_vals = len(var.values)\n                        contingencies[col_i] = (\n                            conts[arr_i][:, :n_vals], nans_cols[arr_i],\n                            nans_rows[arr_i], nans[arr_i])\n                else:\n                    for col_i, arr_i, var in disc_vars:\n                        col = arr if arr.ndim == 1 else arr[:, arr_i]\n                        contingencies[col_i] = contingency(\n                            col.astype(float),\n                            row_data, len(var.values) - 1, n_rows - 1, W)\n\n            cont_vars = [v for v in vars if v[2].is_continuous]\n            if cont_vars:\n                W_ = None\n                if W is not None:\n                    W_ = W.astype(dtype=np.float64)\n                if sp.issparse(arr):\n                    arr = sp.csc_matrix(arr)\n\n                for col_i, arr_i, _ in cont_vars:\n                    if sp.issparse(arr):\n                        col_data = arr.data[arr.indptr[arr_i]:arr.indptr[arr_i + 1]]\n                        rows = arr.indices[arr.indptr[arr_i]:arr.indptr[arr_i + 1]]\n                        W_ = None if W_ is None else W_[rows]\n                        classes_ = row_data[rows]\n                    else:\n                        col_data, W_, classes_ = arr[:, arr_i], W_, row_data\n\n                    col_data = col_data.astype(dtype=np.float64)\n                    contingencies[col_i] = _contingency.contingency_floatarray(\n                        col_data, classes_, n_rows, W_)\n\n        return contingencies\n\n    @classmethod\n    def transpose(cls, table, feature_names_column=\"\",\n                  meta_attr_name=\"Feature name\", feature_name=\"Feature\",\n                  remove_redundant_inst=False, progress_callback=None):\n        \"\"\"\n        Transpose the table.\n\n        :param table: Table - table to transpose\n        :param feature_names_column: str - name of (String) meta attribute to\n            use for feature names\n        :param meta_attr_name: str - name of new meta attribute into which\n            feature names are mapped\n        :param feature_name: str - default feature name prefix\n        :param remove_redundant_inst: bool - remove instance that\n            represents feature_names_column\n        :param progress_callback: callable - to report the progress\n        :return: Table - transposed table\n        \"\"\"\n        if progress_callback is None:\n            progress_callback = dummy_callback\n        progress_callback(0, \"Transposing...\")\n\n        if isinstance(feature_names_column, Variable):\n            feature_names_column = feature_names_column.name\n\n        self = cls()\n        n_cols, self.n_rows = table.X.shape\n        old_domain = table.attributes.get(\"old_domain\")\n        table_domain_attributes = list(table.domain.attributes)\n        attr_index = None\n        if remove_redundant_inst:\n            attr_names = [a.name for a in table_domain_attributes]\n            if feature_names_column and feature_names_column in attr_names:\n                attr_index = attr_names.index(feature_names_column)\n                self.n_rows = self.n_rows - 1\n                table_domain_attributes.remove(\n                    table_domain_attributes[attr_index])\n\n        # attributes\n        # - classes and metas to attributes of attributes\n        # - arbitrary meta column to feature names\n        with self.unlocked():\n            self.X = table.X.T\n            if attr_index is not None:\n                self.X = np.delete(self.X, attr_index, 0)\n            if feature_names_column:\n                names = [str(row[feature_names_column]) for row in table]\n                progress_callback(0.1)\n                names = get_unique_names_duplicates(names)\n                progress_callback(0.3)\n                attributes = [ContinuousVariable(name) for name in names]\n            else:\n                places = int(np.ceil(np.log10(n_cols))) if n_cols else 1\n                attributes = [ContinuousVariable(f\"{feature_name} {i:0{places}}\")\n                              for i in range(1, n_cols + 1)]\n            progress_callback(0.4)\n\n            if old_domain is not None and feature_names_column:\n                for i, _ in enumerate(attributes):\n                    if attributes[i].name in old_domain:\n                        var = old_domain[attributes[i].name]\n                        attr = ContinuousVariable(var.name) if var.is_continuous \\\n                            else DiscreteVariable(var.name, var.values)\n                        attr.attributes = var.attributes.copy()\n                        attributes[i] = attr\n\n            def set_attributes_of_attributes(_vars, _table):\n                for i, variable in enumerate(_vars):\n                    if variable.name == feature_names_column:\n                        continue\n                    for j, row in enumerate(_table):\n                        value = variable.repr_val(row) if np.isscalar(row) \\\n                            else row[i] if isinstance(row[i], str) \\\n                            else variable.repr_val(row[i])\n\n                        if value not in MISSING_VALUES:\n                            attributes[j].attributes[variable.name] = value\n\n            set_attributes_of_attributes(table.domain.class_vars, table.Y)\n            progress_callback(0.5)\n            set_attributes_of_attributes(table.domain.metas, table.metas)\n\n            # weights\n            self.W = np.empty((self.n_rows, 0))\n\n            def get_table_from_attributes_of_attributes(_vars, _dtype=float):\n                T = np.empty((self.n_rows, len(_vars)), dtype=_dtype)\n                for i, _attr in enumerate(table_domain_attributes):\n                    for j, _var in enumerate(_vars):\n                        val = str(_attr.attributes.get(_var.name, \"\"))\n                        if not _var.is_string:\n                            val = np.nan if val in MISSING_VALUES else \\\n                                _var.values.index(val) if \\\n                                    _var.is_discrete else float(val)\n                        T[i, j] = val\n                return T\n\n            # class_vars - attributes of attributes to class - from old domain\n            class_vars = []\n            if old_domain is not None:\n                class_vars = old_domain.class_vars\n            self.Y = get_table_from_attributes_of_attributes(class_vars)\n\n            # metas\n            # - feature names and attributes of attributes to metas\n            self.metas, metas = np.empty((self.n_rows, 0), dtype=object), []\n            if meta_attr_name not in [m.name for m in table.domain.metas] and \\\n                    table_domain_attributes:\n                self.metas = np.array([[a.name] for a in table_domain_attributes],\n                                      dtype=object)\n                metas.append(StringVariable(meta_attr_name))\n\n            names = chain.from_iterable(list(attr.attributes)\n                                        for attr in table_domain_attributes)\n            names = sorted(set(names) - {var.name for var in class_vars})\n            progress_callback(0.6)\n\n            def guessed_var(i, var_name):\n                orig_vals = M[:, i]\n                val_map, vals, var_type = Orange.data.io.guess_data_type(orig_vals)\n                values, variable = Orange.data.io.sanitize_variable(\n                    val_map, vals, orig_vals, var_type, {}, name=var_name)\n                M[:, i] = values\n                return variable\n\n            _metas = [StringVariable(n) for n in names]\n            if old_domain is not None:\n                _metas = [m for m in old_domain.metas if m.name != meta_attr_name]\n            M = get_table_from_attributes_of_attributes(_metas, _dtype=object)\n            progress_callback(0.7)\n            if old_domain is None:\n                _metas = [guessed_var(i, m.name) for i, m in enumerate(_metas)]\n            if _metas:\n                self.metas = np.hstack((self.metas, M))\n                metas.extend(_metas)\n\n            self.domain = Domain(attributes, class_vars, metas)\n            progress_callback(0.9)\n            cls._init_ids(self)\n            self.attributes = table.attributes.copy()\n            self.attributes[\"old_domain\"] = table.domain\n            progress_callback(1)\n            return self\n\n    def to_sparse(self, sparse_attributes=True, sparse_class=False,\n                  sparse_metas=False):\n        def sparsify(features):\n            for f in features:\n                f.sparse = True\n\n        new_domain = self.domain.copy()\n\n        if sparse_attributes:\n            sparsify(new_domain.attributes)\n        if sparse_class:\n            sparsify(new_domain.class_vars)\n        if sparse_metas:\n            sparsify(new_domain.metas)\n        return self.transform(new_domain)\n\n    def to_dense(self, dense_attributes=True, dense_class=True,\n                 dense_metas=True):\n        def densify(features):\n            for f in features:\n                f.sparse = False\n\n        new_domain = self.domain.copy()\n\n        if dense_attributes:\n            densify(new_domain.attributes)\n        if dense_class:\n            densify(new_domain.class_vars)\n        if dense_metas:\n            densify(new_domain.metas)\n        t = self.transform(new_domain)\n        t.ids = self.ids  # preserve indices\n        return t",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 361,
                            "end_lineno": 2227,
                            "parent": null
                        },
                        {
                            "file_name": "Orange/data/table.py",
                            "type": "method",
                            "name": "Table.__setstate__",
                            "content": "class Table(Sequence, Storage):\n\n    LOCKING = None\n    \"\"\" If the class attribute LOCKING is True, tables will throw exceptions\n    on in-place modifications unless unlocked explicitly. LOCKING is supposed\n    to be set to True for testing to help us find bugs. If set to False\n    or None, no safeguards are in place. Two different values are used for\n    the same behaviour to distinguish the unchanged default (None) form\n    explicit deactivation (False) that some add-ons might need. \"\"\"\n\n    __file__ = None\n    name = \"untitled\"\n\n    domain = Domain([])\n    _X = _Y = _metas = _W = np.zeros((0, 0))  # pylint: disable=invalid-name\n    ids = np.zeros(0)\n    ids.setflags(write=False)\n    attributes = frozendict()\n\n    _Unlocked_X, _Unlocked_Y, _Unlocked_metas, _Unlocked_W = 1, 2, 4, 8\n    _unlocked = _Unlocked_X + _Unlocked_Y + \\\n                _Unlocked_metas + _Unlocked_W  # pylint: disable=invalid-name\n\n    @property\n    def columns(self):\n        \"\"\"\n        A class whose attributes contain attribute descriptors for columns.\n        For a table `table`, setting `c = table.columns` will allow accessing\n        the table's variables with, for instance `c.gender`, `c.age` ets.\n        Spaces are replaced with underscores.\n        \"\"\"\n        return Columns(self.domain)\n\n    _next_instance_id = 0\n    _next_instance_lock = Lock()\n\n    def _check_unlocked(self, partflag):\n        if not self._unlocked & partflag:\n            raise ValueError(\"Table is read-only unless unlocked\")\n\n    @property\n    def X(self):  # pylint: disable=invalid-name\n        return self._X\n\n    @X.setter\n    def X(self, value):\n        self._check_unlocked(self._Unlocked_X)\n        self._X = _dereferenced(value)\n\n    @property\n    def Y(self):  # pylint: disable=invalid-name\n        return self._Y\n\n    @Y.setter\n    def Y(self, value):\n        self._check_unlocked(self._Unlocked_Y)\n        if sp.issparse(value) and len(self) != value.shape[0]:\n            value = value.T\n        if sp.issparse(value):\n            value = _dereferenced(value.toarray())\n        if value.ndim == 2 and value.shape[1] == 1:\n            value = value[:, 0].copy()  # no views!\n        self._Y = value\n\n    @property\n    def metas(self):\n        return self._metas\n\n    @metas.setter\n    def metas(self, value):\n        self._check_unlocked(self._Unlocked_metas)\n        self._metas = _dereferenced(value)\n\n    @property\n    def W(self):  # pylint: disable=invalid-name\n        return self._W\n\n    @W.setter\n    def W(self, value):\n        self._check_unlocked(self._Unlocked_W)\n        self._W = value\n\n    def __setstate__(self, state):\n        # Backward compatibility with pickles before table locking\n        self._initialize_unlocked()  # __dict__ seems to be cleared before calling __setstate__\n        with self.unlocked():\n            for k in (\"X\", \"W\", \"metas\"):\n                if k in state:\n                    setattr(self, k, state.pop(k))\n            if \"_Y\" in state:\n                setattr(self, \"Y\", state.pop(\"_Y\"))  # state[\"_Y\"] is a 2d array\n            self.__dict__.update(state)\n\n    def __getstate__(self):\n        # Compatibility with pickles before table locking:\n        # return the same state as before table lock\n        state = self.__dict__.copy()\n        for k in [\"X\", \"metas\", \"W\"]:\n            if \"_\" + k in state:  # Check existence; SQL tables do not contain them\n                state[k] = state.pop(\"_\" + k)\n        # before locking, _Y was always a 2d array: save it as such\n        if \"_Y\" in state:\n            y = state.pop(\"_Y\")\n            y2d = y.reshape(-1, 1) if y.ndim == 1 else y\n            state[\"_Y\"] = y2d\n        return state\n\n    def _lock_parts(self):\n        return ((self._X, self._Unlocked_X, \"X\"),\n                (self._Y, self._Unlocked_Y, \"Y\"),\n                (self._metas, self._Unlocked_metas, \"metas\"),\n                (self._W, self._Unlocked_W, \"weights\"))\n\n    def _initialize_unlocked(self):\n        if Table.LOCKING:\n            self._unlocked = 0\n        else:\n            self._unlocked = sum(f for _, f, _ in self._lock_parts())\n\n    def _update_locks(self, force=False, unlock_bases=()):\n        if not Table.LOCKING:\n            return\n\n        def sync(*xs):\n            for x in xs:\n                try:\n                    undo_on_fail.append((x, x.flags.writeable))\n                    x.flags.writeable = writeable\n                except ValueError:\n                    if force \\\n                            and writeable \\\n                            and x.base is not None \\\n                            and not x.base.flags.writeable:\n                        x.base.flags.writeable = writeable\n                        x.flags.writeable = writeable\n                        forced_bases.append(x.base)\n                    else:\n                        raise\n\n        forced_bases = []\n        undo_on_fail = []\n        for base in unlock_bases:\n            base.flags.writeable = False\n        try:\n            for part, flag, _ in self._lock_parts():\n                if part is None:\n                    continue\n                writeable = bool(self._unlocked & flag)\n                if sp.isspmatrix_csr(part) or sp.isspmatrix_csc(part):\n                    sync(part.data, part.indices, part.indptr)\n                elif sp.isspmatrix_coo(part):\n                    sync(part.data, part.row, part.col)\n                elif sp.issparse(part):\n                    raise ValueError(\"Unsupported sparse data type\")\n                else:\n                    sync(part)\n        except:\n            for part, flag in undo_on_fail:\n                part.flags.writeable = flag\n            raise\n        return tuple(forced_bases)\n\n    def __unlocked(self, *parts, force=False):\n        prev_state = self._unlocked\n        for part, flag, _ in self._lock_parts():\n            if not parts or any(ppart is part for ppart in parts):\n                self._unlocked |= flag\n        try:\n            forced_bases = self._update_locks(force)\n            yield\n        finally:\n            self._unlocked = prev_state\n            self._update_locks(unlock_bases=forced_bases)\n\n    def force_unlocked(self, *parts):\n        \"\"\"\n        Unlocking without any checks.\n\n        Use with extreme caution. This is meant primarily for 3rd party\n        functions in Cython that expect read-write buffer, but do not\n        actually modify it. the given parts (default: all parts) of the table.\n\n        The function will still fail to unlock and raise an exception if the\n        table contains view to another table.\n        \"\"\"\n        return contextmanager(self.__unlocked)(*parts, force=True)\n\n    def unlocked(self, *parts):\n        \"\"\"\n        Unlock the given parts (default: all parts) of the table.\n\n        The caller must ensure that the table is safe to modify. The function\n        will raise an exception if the table contains view to other table.\n        \"\"\"\n        def can_unlock(x):\n            if sp.issparse(x):\n                return can_unlock(x.data)\n            return x.flags.writeable or x.flags.owndata\n\n        for part, flag, name in self._lock_parts():\n            if not flag & self._unlocked \\\n                    and (not parts or any(ppart is part for ppart in parts)) \\\n                    and part is not None and not can_unlock(part):\n                raise ValueError(f\"'{name}' is a view into another table \"\n                                 \"and cannot be unlocked\")\n        return contextmanager(self.__unlocked)(*parts)\n\n    def __new__(cls, *args, **kwargs):\n        def warn_deprecated(method):\n            warnings.warn(\"Direct calls to Table's constructor are deprecated \"\n                          \"and will be removed. Replace this call with \"\n                          f\"Table.{method}\", OrangeDeprecationWarning,\n                          stacklevel=3)\n\n        if not args:\n            if not kwargs:\n                return super().__new__(cls)\n            else:\n                raise TypeError(\"Table() must not be called directly\")\n\n        if isinstance(args[0], str):\n            if len(args) > 1:\n                raise TypeError(\"Table(name: str) expects just one argument\")\n            if args[0].startswith('https://') or args[0].startswith('http://'):\n                return cls.from_url(args[0], **kwargs)\n            else:\n                return cls.from_file(args[0], **kwargs)\n\n        elif isinstance(args[0], Table):\n            if len(args) > 1:\n                raise TypeError(\"Table(table: Table) expects just one argument\")\n            return cls.from_table(args[0].domain, args[0], **kwargs)\n        elif isinstance(args[0], Domain):\n            domain, args = args[0], args[1:]\n            if not args:\n                warn_deprecated(\"from_domain\")\n                return cls.from_domain(domain, **kwargs)\n            if isinstance(args[0], Table):\n                warn_deprecated(\"from_table\")\n                return cls.from_table(domain, *args, **kwargs)\n            elif isinstance(args[0], list):\n                warn_deprecated(\"from_list\")\n                return cls.from_list(domain, *args, **kwargs)\n        else:\n            warnings.warn(\"Omitting domain in a call to Table(X, Y, metas), is \"\n                          \"deprecated and will be removed. \"\n                          \"Call Table.from_numpy(None, X, Y, metas) instead.\",\n                          OrangeDeprecationWarning, stacklevel=2)\n            domain = None\n\n        return cls.from_numpy(domain, *args, **kwargs)\n\n    def __init__(self, *args, **kwargs):  # pylint: disable=unused-argument\n        self._initialize_unlocked()\n        self._update_locks()\n\n    @classmethod\n    def from_domain(cls, domain, n_rows=0, weights=False):\n        \"\"\"\n        Construct a new `Table` with the given number of rows for the given\n        domain. The optional vector of weights is initialized to 1's.\n\n        :param domain: domain for the `Table`\n        :type domain: Orange.data.Domain\n        :param n_rows: number of rows in the new table\n        :type n_rows: int\n        :param weights: indicates whether to construct a vector of weights\n        :type weights: bool\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n        self = cls()\n        self.domain = domain\n        self.n_rows = n_rows\n        with self.unlocked():\n            self.X = np.zeros((n_rows, len(domain.attributes)))\n            if len(domain.class_vars) != 1:\n                self.Y = np.zeros((n_rows, len(domain.class_vars)))\n            else:\n                self.Y = np.zeros(n_rows)\n            if weights:\n                self.W = np.ones(n_rows)\n            else:\n                self.W = np.empty((n_rows, 0))\n            self.metas = np.empty((n_rows, len(self.domain.metas)), object)\n            cls._init_ids(self)\n            self.attributes = {}\n        return self\n\n    @classmethod\n    def from_table(cls, domain, source, row_indices=...):\n        \"\"\"\n        Create a new table from selected columns and/or rows of an existing\n        one. The columns are chosen using a domain. The domain may also include\n        variables that do not appear in the source table; they are computed\n        from source variables if possible.\n\n        The resulting data may be a view or a copy of the existing data.\n\n        :param domain: the domain for the new table\n        :type domain: Orange.data.Domain\n        :param source: the source table\n        :type source: Orange.data.Table\n        :param row_indices: indices of the rows to include\n        :type row_indices: a slice or a sequence\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n\n        PART = 5000\n\n        new_cache = _thread_local.conversion_cache is None\n        try:\n            if new_cache:\n                _thread_local.conversion_cache = {}\n                _thread_local.domain_cache = {}\n            else:\n                cached = _idcache_restore(_thread_local.conversion_cache, (domain, source))\n                if cached is not None:\n                    return cached\n            if domain is source.domain:\n                table = cls.from_table_rows(source, row_indices)\n                # assure resulting domain is the instance passed on input\n                table.domain = domain\n                # since sparse flags are not considered when checking for\n                # domain equality, fix manually.\n                with table.unlocked():\n                    table = assure_domain_conversion_sparsity(table, source)\n                return table\n\n            if row_indices is ...:\n                n_rows = len(source)\n            elif isinstance(row_indices, slice):\n                row_indices_range = range(*row_indices.indices(source.X.shape[0]))\n                n_rows = len(row_indices_range)\n            else:\n                n_rows = len(row_indices)\n\n            self = cls()\n            self.domain = domain\n\n            table_conversion = \\\n                _idcache_restore(_thread_local.domain_cache, (domain, source.domain))\n            if table_conversion is None:\n                table_conversion = _FromTableConversion(source.domain, domain)\n                _idcache_save(_thread_local.domain_cache, (domain, source.domain),\n                              table_conversion)\n\n            # if an array can be a subarray of the input table, this needs to be done\n            # on the whole table, because this avoids needless copies of contents\n\n            with self.unlocked():\n                for array_conv in table_conversion.subarray:\n                    out = array_conv.get_subarray(source, row_indices, n_rows)\n                    setattr(self, array_conv.target, out)\n\n                parts = {}\n\n                for array_conv in table_conversion.columnwise:\n                    if array_conv.is_sparse:\n                        parts[array_conv.target] = []\n                    else:\n                        # F-order enables faster writing to the array while accessing and\n                        # matrix operations work with same speed (e.g. dot)\n                        parts[array_conv.target] = \\\n                            np.zeros((n_rows, len(array_conv.src_cols)),\n                                     order=\"F\", dtype=array_conv.dtype)\n\n                if n_rows <= PART:\n                    for array_conv in table_conversion.columnwise:\n                        out = array_conv.get_columns(source, row_indices, n_rows,\n                                                     parts[array_conv.target],\n                                                     ...)\n                        setattr(self, array_conv.target, out)\n                else:\n                    i_done = 0\n\n                    while i_done < n_rows:\n                        target_indices = slice(i_done, min(n_rows, i_done + PART))\n                        if row_indices is ...:\n                            source_indices = target_indices\n                        elif isinstance(row_indices, slice):\n                            r = row_indices_range[target_indices]\n                            source_indices = slice(r.start, r.stop, r.step)\n                        else:\n                            source_indices = row_indices[target_indices]\n                        part_rows = min(n_rows, i_done+PART) - i_done\n\n                        for array_conv in table_conversion.columnwise:\n                            out = array_conv.get_columns(source, source_indices, part_rows,\n                                                         parts[array_conv.target],\n                                                         target_indices)\n                            if array_conv.is_sparse:  # dense arrays are populated in-place\n                                parts[array_conv.target].append(out)\n\n                        i_done += PART\n\n                        # clear cache after a part is done\n                        if new_cache:\n                            _thread_local.conversion_cache = {}\n\n                    for array_conv in table_conversion.columnwise:\n                        cparts = parts[array_conv.target]\n                        out = cparts if not array_conv.is_sparse else sp.vstack(cparts)\n                        setattr(self, array_conv.target, out)\n\n                if source.has_weights():\n                    self.W = source.W[row_indices]\n                else:\n                    self.W = np.empty((n_rows, 0))\n                self.name = getattr(source, 'name', '')\n                if hasattr(source, 'ids'):\n                    self.ids = source.ids[row_indices]\n                else:\n                    cls._init_ids(self)\n                self.attributes = getattr(source, 'attributes', {})\n                _idcache_save(_thread_local.conversion_cache, (domain, source), self)\n            return self\n        finally:\n            if new_cache:\n                _thread_local.conversion_cache = None\n                _thread_local.domain_cache = None\n\n    def transform(self, domain):\n        \"\"\"\n        Construct a table with a different domain.\n\n        The new table keeps the row ids and other information. If the table\n        is a subclass of :obj:`Table`, the resulting table will be of the same\n        type.\n\n        In a typical scenario, an existing table is augmented with a new\n        column by ::\n\n            domain = Domain(old_domain.attributes + [new_attribute],\n                            old_domain.class_vars,\n                            old_domain.metas)\n            table = data.transform(domain)\n            table[:, new_attribute] = new_column\n\n        Args:\n            domain (Domain): new domain\n\n        Returns:\n            A new table\n        \"\"\"\n        return type(self).from_table(domain, self)\n\n    @classmethod\n    def from_table_rows(cls, source, row_indices):\n        \"\"\"\n        Construct a new table by selecting rows from the source table.\n\n        :param source: an existing table\n        :type source: Orange.data.Table\n        :param row_indices: indices of the rows to include\n        :type row_indices: a slice or a sequence\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n        def get_rows(a):\n            a = a[row_indices]\n            if isinstance(row_indices, slice) or row_indices is ...:\n                a = a.copy()\n            return a\n\n        self = cls()\n        self.domain = source.domain\n        with self.unlocked():\n            self.X = get_rows(source.X)\n            if self.X.ndim == 1:\n                self.X = self.X.reshape(-1, len(self.domain.attributes))\n            self.Y = get_rows(source.Y)\n            self.metas = get_rows(source.metas)\n            if self.metas.ndim == 1:\n                self.metas = self.metas.reshape(-1, len(self.domain.metas))\n            self.W = get_rows(source.W)\n            self.name = getattr(source, 'name', '')\n            self.ids = np.array(source.ids[row_indices])\n            self.attributes = getattr(source, 'attributes', {})\n        return self\n\n    @classmethod\n    def from_numpy(cls, domain, X, Y=None, metas=None, W=None,\n                   attributes=None, ids=None):\n        \"\"\"\n        Construct a table from numpy arrays with the given domain. The number\n        of variables in the domain must match the number of columns in the\n        corresponding arrays. All arrays must have the same number of rows.\n        Arrays may be of different numpy types, and may be dense or sparse.\n\n        :param domain: the domain for the new table\n        :type domain: Orange.data.Domain\n        :param X: array with attribute values\n        :type X: np.array\n        :param Y: array with class values\n        :type Y: np.array\n        :param metas: array with meta attributes\n        :type metas: np.array\n        :param W: array with weights\n        :type W: np.array\n        :return:\n        \"\"\"\n        X, Y, W = _check_arrays(X, Y, W, dtype='float64')\n        metas, = _check_arrays(metas, dtype=object, shape_1=X.shape[0])\n        ids, = _check_arrays(ids, dtype=int, shape_1=X.shape[0])\n\n        if domain is None:\n            domain = Domain.from_numpy(X, Y, metas)\n\n        if Y is None:\n            if not domain.class_vars or sp.issparse(X):\n                Y = np.empty((X.shape[0], 0), dtype=np.float64)\n            else:\n                own_data = X.flags.owndata and X.base is None\n                Y = X[:, len(domain.attributes):]\n                X = X[:, :len(domain.attributes)]\n                if own_data:\n                    Y = Y.copy()\n                    X = X.copy()\n        if metas is None:\n            metas = np.empty((X.shape[0], 0), object)\n        if W is None or W.size == 0:\n            W = np.empty((X.shape[0], 0))\n        elif W.shape != (W.size, ):\n            W = W.reshape(W.size).copy()\n\n        if X.shape[1] != len(domain.attributes):\n            raise ValueError(\n                \"Invalid number of variable columns ({} != {})\".format(\n                    X.shape[1], len(domain.attributes))\n            )\n        if Y.ndim == 1:\n            if not domain.class_var:\n                raise ValueError(\n                    \"Invalid number of class columns \"\n                    f\"(1 != {len(domain.class_vars)})\")\n        elif Y.shape[1] != len(domain.class_vars):\n            raise ValueError(\n                \"Invalid number of class columns ({} != {})\".format(\n                    Y.shape[1], len(domain.class_vars))\n            )\n        if metas.shape[1] != len(domain.metas):\n            raise ValueError(\n                \"Invalid number of meta attribute columns ({} != {})\".format(\n                    metas.shape[1], len(domain.metas))\n            )\n        if not X.shape[0] == Y.shape[0] == metas.shape[0] == W.shape[0]:\n            raise ValueError(\n                \"Parts of data contain different numbers of rows.\")\n\n        self = cls()\n        with self.unlocked():\n            self.domain = domain\n            self.X = X\n            self.Y = Y\n            self.metas = metas\n            self.W = W\n            self.n_rows = self.X.shape[0]\n            if ids is None:\n                cls._init_ids(self)\n            else:\n                self.ids = ids\n            self.attributes = {} if attributes is None else attributes\n        return self\n\n    @classmethod\n    def from_list(cls, domain, rows, weights=None):\n        if weights is not None and len(rows) != len(weights):\n            raise ValueError(\"mismatching number of instances and weights\")\n        self = cls.from_domain(domain, len(rows), weights is not None)\n        all_vars = domain.variables + domain.metas\n        nattrs = len(domain.attributes)\n        nattrscls = len(domain.variables)\n        with self.unlocked():\n            for i, row in enumerate(rows):\n                if isinstance(row, Instance):\n                    row = row.list\n                vals = [var.to_val(val) for var, val in zip(all_vars, row)]\n                self.X[i] = vals[:nattrs]\n                if self._Y.ndim == 1:\n                    self._Y[i] = vals[nattrs] if nattrs < len(vals) else np.nan\n                else:\n                    self._Y[i] = vals[nattrs:nattrscls]\n                # for backward compatibility: allow omittine some (or all) metas\n                self.metas[i, :len(vals) - nattrscls] = vals[nattrscls:]\n            if weights is not None:\n                self.W = np.array(weights)\n            self.attributes = {}\n        return self\n\n    @classmethod\n    def _init_ids(cls, obj):\n        with cls._next_instance_lock:\n            obj.ids = np.array(range(cls._next_instance_id, cls._next_instance_id + obj.X.shape[0]))\n            cls._next_instance_id += obj.X.shape[0]\n\n    @classmethod\n    def new_id(cls):\n        with cls._next_instance_lock:\n            id = cls._next_instance_id\n            cls._next_instance_id += 1\n            return id\n\n    def to_pandas_dfs(self):\n        return Orange.data.pandas_compat.table_to_frames(self)\n\n    @staticmethod\n    def from_pandas_dfs(xdf, ydf, mdf):\n        return Orange.data.pandas_compat.table_from_frames(xdf, ydf, mdf)\n\n    @property\n    def X_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.Attribute\n        )\n\n    @X_df.setter\n    def X_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.Attribute\n        )\n\n    @property\n    def Y_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.ClassAttribute\n        )\n\n    @Y_df.setter\n    def Y_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.ClassAttribute\n        )\n\n    @property\n    def metas_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.Meta\n        )\n\n    @metas_df.setter\n    def metas_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.Meta\n        )\n\n    def save(self, filename):\n        \"\"\"\n        Save a data table to a file. The path can be absolute or relative.\n\n        :param filename: File name\n        :type filename: str\n        \"\"\"\n        ext = os.path.splitext(filename)[1]\n        from Orange.data.io import FileFormat\n        writer = FileFormat.writers.get(ext)\n        if not writer:\n            desc = FileFormat.names.get(ext)\n            if desc:\n                raise IOError(\n                    \"Writing of {}s is not supported\".format(desc.lower()))\n            else:\n                raise IOError(\"Unknown file name extension.\")\n        writer.write_file(filename, self)\n\n    @classmethod\n    def from_file(cls, filename, sheet=None):\n        \"\"\"\n        Read a data table from a file. The path can be absolute or relative.\n\n        :param filename: File name\n        :type filename: str\n        :param sheet: Sheet in a file (optional)\n        :type sheet: str\n        :return: a new data table\n        :rtype: Orange.data.Table\n        \"\"\"\n        from Orange.data.io import FileFormat\n\n        absolute_filename = FileFormat.locate(filename, dataset_dirs)\n        reader = FileFormat.get_reader(absolute_filename)\n        reader.select_sheet(sheet)\n        data = reader.read()\n\n        # Readers return plain table. Make sure to cast it to appropriate\n        # (subclass) type\n        if cls != data.__class__:\n            data = cls(data)\n\n        # no need to call _init_ids as fuctions from .io already\n        # construct a table with .ids\n\n        data.__file__ = absolute_filename\n        return data\n\n    @classmethod\n    def from_url(cls, url):\n        from Orange.data.io import UrlReader\n        reader = UrlReader(url)\n        data = reader.read()\n        if cls != data.__class__:\n            data = cls(data)\n        return data\n\n    # Helper function for __setitem__:\n    # Set the row of table data matrices\n    # noinspection PyProtectedMember\n    def _set_row(self, example, row):\n        # pylint: disable=protected-access\n        domain = self.domain\n        if isinstance(example, Instance):\n            if example.domain == domain:\n                self.X[row] = example._x\n                if self._Y.ndim == 1:\n                    self._Y[row] = float(example._y)\n                else:\n                    self._Y[row] = np.atleast_1d(example._y)\n                self.metas[row] = example._metas\n                return\n\n            self.X[row], self._Y[row], self.metas[row] = \\\n                self.domain.convert(example)\n            try:\n                self.ids[row] = example.id\n            except:\n                with type(self)._next_instance_lock:\n                    self.ids[row] = type(self)._next_instance_id\n                    type(self)._next_instance_id += 1\n\n        else:\n            attrs = domain.attributes\n            if len(example) != len(domain.variables):\n                raise ValueError(\"invalid length\")\n            self._X[row] = [var.to_val(val) for var, val in zip(attrs, example)]\n            if self._Y.ndim == 1:\n                self._Y[row] = domain.class_var.to_val(example[len(attrs)])\n            else:\n                self._Y[row] = [var.to_val(val)\n                                for var, val in zip(domain.class_vars,\n                                                    example[len(attrs):])]\n            self.metas[row] = np.array([var.Unknown for var in domain.metas],\n                                       dtype=object)\n\n    def _check_all_dense(self):\n        return all(x in (Storage.DENSE, Storage.MISSING)\n                   for x in (self.X_density(), self.Y_density(),\n                             self.metas_density()))\n\n    def __getitem__(self, key):\n        if isinstance(key, Integral):\n            return RowInstance(self, key)\n        if not isinstance(key, tuple):\n            return self.from_table_rows(self, key)\n\n        if len(key) != 2:\n            raise IndexError(\"Table indices must be one- or two-dimensional\")\n\n        row_idx, col_idx = key\n        if isinstance(row_idx, Integral):\n            if isinstance(col_idx, (str, Integral, Variable)):\n                col_idx = self.domain.index(col_idx)\n                var = self.domain[col_idx]\n                if 0 <= col_idx < len(self.domain.attributes):\n                    val = self.X[row_idx, col_idx]\n                elif col_idx == len(self.domain.attributes) and self._Y.ndim == 1:\n                    val = self._Y[row_idx]\n                elif col_idx >= len(self.domain.attributes):\n                    val = self._Y[row_idx,\n                                  col_idx - len(self.domain.attributes)]\n                else:\n                    val = self.metas[row_idx, -1 - col_idx]\n                if isinstance(col_idx, DiscreteVariable) and var is not col_idx:\n                    val = col_idx.get_mapper_from(var)(val)\n                return Value(var, val)\n            else:\n                row_idx = [row_idx]\n\n        # multiple rows OR single row but multiple columns:\n        # construct a new table\n        attributes, col_indices = self.domain._compute_col_indices(col_idx)\n        if attributes is not None:\n            n_attrs = len(self.domain.attributes)\n            r_attrs = [attributes[i]\n                       for i, col in enumerate(col_indices)\n                       if 0 <= col < n_attrs]\n            r_classes = [attributes[i]\n                         for i, col in enumerate(col_indices)\n                         if col >= n_attrs]\n            r_metas = [attributes[i]\n                       for i, col in enumerate(col_indices) if col < 0]\n            domain = Domain(r_attrs, r_classes, r_metas)\n        else:\n            domain = self.domain\n        return self.from_table(domain, self, row_idx)\n\n    def __setitem__(self, key, value):\n        if not isinstance(key, tuple):\n            if isinstance(value, Real):\n                self.X[key, :] = value\n                return\n            self._set_row(value, key)\n            return\n\n        if len(key) != 2:\n            raise IndexError(\"Table indices must be one- or two-dimensional\")\n        row_idx, col_idx = key\n\n        # single row\n        if isinstance(row_idx, Integral):\n            if isinstance(col_idx, slice):\n                col_idx = range(*slice.indices(col_idx, self.X.shape[1]))\n            if not isinstance(col_idx, str) and isinstance(col_idx, Iterable):\n                col_idx = list(col_idx)\n            if not isinstance(col_idx, str) and isinstance(col_idx, Sized):\n                if isinstance(value, (Sequence, np.ndarray)):\n                    values = value\n                elif isinstance(value, Iterable):\n                    values = list(value)\n                else:\n                    raise TypeError(\"Setting multiple values requires a \"\n                                    \"sequence or numpy array\")\n                if len(values) != len(col_idx):\n                    raise ValueError(\"Invalid number of values\")\n            else:\n                col_idx, values = [col_idx], [value]\n            if isinstance(col_idx, DiscreteVariable) \\\n                    and self.domain[col_idx] != col_idx:\n                values = self.domain[col_idx].get_mapper_from(col_idx)(values)\n            for val, col_idx in zip(values, col_idx):\n                if not isinstance(val, Integral):\n                    val = self.domain[col_idx].to_val(val)\n                if not isinstance(col_idx, Integral):\n                    col_idx = self.domain.index(col_idx)\n                if col_idx >= 0:\n                    if col_idx < self.X.shape[1]:\n                        self.X[row_idx, col_idx] = val\n                    elif self._Y.ndim == 1 and col_idx == self.X.shape[1]:\n                        self._Y[row_idx] = val\n                    else:\n                        self._Y[row_idx, col_idx - self.X.shape[1]] = val\n                else:\n                    self.metas[row_idx, -1 - col_idx] = val\n\n        # multiple rows, multiple columns\n        attributes, col_indices = self.domain._compute_col_indices(col_idx)\n        if col_indices is ...:\n            col_indices = range(len(self.domain.variables))\n        n_attrs = self.X.shape[1]\n        if isinstance(value, str):\n            if not attributes:\n                attributes = self.domain.attributes\n            for var, col in zip(attributes, col_indices):\n                val = var.to_val(value)\n                if 0 <= col < n_attrs:\n                    self.X[row_idx, col] = val\n                elif col >= n_attrs:\n                    if self._Y.ndim == 1 and col == n_attrs:\n                        self._Y[row_idx] = val\n                    else:\n                        self._Y[row_idx, col - n_attrs] = val\n                else:\n                    self.metas[row_idx, -1 - col] = val\n        else:\n            attr_cols = np.fromiter(\n                (col for col in col_indices if 0 <= col < n_attrs), int)\n            class_cols = np.fromiter(\n                (col - n_attrs for col in col_indices if col >= n_attrs), int)\n            meta_cols = np.fromiter(\n                (-1 - col for col in col_indices if col < 0), int)\n            if value is None:\n                value = Unknown\n\n            if not isinstance(value, (Real, np.ndarray)) and \\\n                    (len(attr_cols) or len(class_cols)):\n                raise TypeError(\n                    \"Ordinary attributes can only have primitive values\")\n            if len(attr_cols):\n                self.X[row_idx, attr_cols] = value\n            if len(class_cols):\n                if self._Y.ndim == 1 and np.all(class_cols == 0):\n                    if isinstance(value, np.ndarray):\n                        yshape = self._Y[row_idx].shape\n                        if value.shape != yshape:\n                            value = value.reshape(yshape)\n                    self._Y[row_idx] = value\n                else:\n                    self._Y[row_idx, class_cols] = value\n            if len(meta_cols):\n                self.metas[row_idx, meta_cols] = value\n\n    def __len__(self):\n        return self.X.shape[0]\n\n    def __str__(self):\n        return \"[\" + \",\\n \".join(str(ex) for ex in self) + \"]\"\n\n    def __repr__(self):\n        head = 5\n        if self.is_sparse():\n            head = min(self.X.shape[0], head)\n        s = \"[\" + \",\\n \".join(repr(ex) for ex in self[:head])\n        if len(self) > head:\n            s += \",\\n ...\"\n        s += \"\\n]\"\n        return s\n\n    @classmethod\n    def concatenate(cls, tables, axis=0):\n        \"\"\"\n        Concatenate tables into a new table, either vertically or horizontally.\n\n        If axis=0 (vertical concatenate), all tables must have the same domain.\n\n        If axis=1 (horizontal),\n        - all variable names must be unique.\n        - ids are copied from the first table.\n        - weights are copied from the first table in which they are defined.\n        - the dictionary of table's attributes are merged. If the same attribute\n          appears in multiple dictionaries, the earlier are used.\n\n        Args:\n            tables (Table): tables to be joined\n\n        Returns:\n            table (Table)\n        \"\"\"\n        if axis not in (0, 1):\n            raise ValueError(\"invalid axis\")\n        if not tables:\n            raise ValueError('need at least one table to concatenate')\n\n        if len(tables) == 1:\n            return tables[0].copy()\n\n        if axis == 0:\n            conc = cls._concatenate_vertical(tables)\n        else:\n            conc = cls._concatenate_horizontal(tables)\n\n        # TODO: Add attributes = {} to __init__\n        conc.attributes = getattr(conc, \"attributes\", {})\n        for table in reversed(tables):\n            conc.attributes.update(table.attributes)\n\n        names = [table.name for table in tables if table.name != \"untitled\"]\n        if names:\n            conc.name = names[0]\n        return conc\n\n    @classmethod\n    def _concatenate_vertical(cls, tables):\n        def vstack(arrs):\n            return [np, sp][any(sp.issparse(arr) for arr in arrs)].vstack(arrs)\n\n        def merge1d(arrs):\n            arrs = list(arrs)\n            ydims = {arr.ndim for arr in arrs}\n            if ydims == {1}:\n                return np.hstack(arrs)\n            else:\n                return vstack([\n                    arr if arr.ndim == 2 else np.atleast_2d(arr).T\n                    for arr in arrs\n                ])\n\n        def collect(attr):\n            return [getattr(arr, attr) for arr in tables]\n\n        domain = tables[0].domain\n        if any(table.domain != domain for table in tables):\n            raise ValueError('concatenated tables must have the same domain')\n\n        conc = cls.from_numpy(\n            domain,\n            vstack(collect(\"X\")),\n            merge1d(collect(\"Y\")),\n            vstack(collect(\"metas\")),\n            merge1d(collect(\"W\"))\n        )\n        conc.ids = np.hstack([t.ids for t in tables])\n        return conc\n\n    @classmethod\n    def _concatenate_horizontal(cls, tables):\n        \"\"\"\n        \"\"\"\n        def all_of(objs, names):\n            return (tuple(getattr(obj, name) for obj in objs)\n                    for name in names)\n\n        def stack(arrs):\n            non_empty = tuple(arr if arr.ndim == 2 else arr[:, np.newaxis]\n                              for arr in arrs\n                              if arr is not None and arr.size > 0)\n            return np.hstack(non_empty) if non_empty else None\n\n        doms, Ws = all_of(tables, (\"domain\", \"W\"))\n        Xs, Ys, Ms = map(stack, all_of(tables, (\"X\", \"Y\", \"metas\")))\n        # pylint: disable=undefined-loop-variable\n        for W in Ws:\n            if W.size:\n                break\n\n        parts = all_of(doms, (\"attributes\", \"class_vars\", \"metas\"))\n        domain = Domain(*(tuple(chain(*lst)) for lst in parts))\n        return cls.from_numpy(domain, Xs, Ys, Ms, W, ids=tables[0].ids)\n\n    def add_column(self, variable, data, to_metas=None):\n        \"\"\"\n        Create a new table with an additional column\n\n        Column's name must be unique\n\n        Args:\n            variable (Variable): variable for the new column\n            data (np.ndarray): data for the new column\n            to_metas (bool, optional): if `True` the column is added as meta\n                column. Otherwise, primitive variables are added to attributes\n                and non-primitive to metas.\n\n        Returns:\n            table (Table): a new table with the additional column\n        \"\"\"\n        dom = self.domain\n        attrs, classes, metavars = dom.attributes, dom.class_vars, dom.metas\n        to_metas = to_metas or not variable.is_primitive()\n        if to_metas:\n            metavars += (variable, )\n        else:\n            attrs += (variable, )\n        domain = Domain(attrs, classes, metavars)\n        new_table = self.transform(domain)\n        with new_table.unlocked(new_table.metas if to_metas else new_table.X):\n            new_table.get_column_view(variable)[0][:] = data\n        return new_table\n\n    def is_view(self):\n        \"\"\"\n        Return `True` if all arrays represent a view referring to another table\n        \"\"\"\n        return ((not self._X.shape[-1] or self._X.base is not None) and\n                (not self._Y.shape[-1] or self._Y.base is not None) and\n                (not self._metas.shape[-1] or self._metas.base is not None) and\n                (not self._weights.shape[-1] or self._W.base is not None))\n\n    def is_copy(self):\n        \"\"\"\n        Return `True` if the table owns its data\n        \"\"\"\n        return ((not self._X.shape[-1] or self._X.base is None) and\n                (self._Y.base is None) and\n                (self._metas.base is None) and\n                (self._W.base is None))\n\n    def is_sparse(self):\n        \"\"\"\n        Return `True` if the table stores data in sparse format\n        \"\"\"\n        return any(sp.issparse(i) for i in [self._X, self._Y, self._metas])\n\n    def ensure_copy(self):\n        \"\"\"\n        Ensure that the table owns its data; copy arrays when necessary.\n        \"\"\"\n\n        def is_view(x):\n            # Sparse matrices don't have views like numpy arrays. Since indexing on\n            # them creates copies in constructor we can skip this check here.\n            return not sp.issparse(x) and x.base is not None\n\n        if is_view(self._X):\n            self._X = self._X.copy()\n        if is_view(self._Y):\n            self._Y = self._Y.copy()\n        if is_view(self._metas):\n            self._metas = self._metas.copy()\n        if is_view(self._W):\n            self._W = self._W.copy()\n\n    def copy(self):\n        \"\"\"\n        Return a copy of the table\n        \"\"\"\n        t = self.__class__(self)\n        t.ensure_copy()\n        return t\n\n    @staticmethod\n    def __determine_density(data):\n        if data is None:\n            return Storage.Missing\n        if data is not None and sp.issparse(data):\n            return Storage.SPARSE_BOOL if (data.data == 1).all() else Storage.SPARSE\n        else:\n            return Storage.DENSE\n\n    def X_density(self):\n        if not hasattr(self, \"_X_density\"):\n            self._X_density = self.__determine_density(self.X)\n        return self._X_density\n\n    def Y_density(self):\n        if not hasattr(self, \"_Y_density\"):\n            self._Y_density = self.__determine_density(self._Y)\n        return self._Y_density\n\n    def metas_density(self):\n        if not hasattr(self, \"_metas_density\"):\n            self._metas_density = self.__determine_density(self.metas)\n        return self._metas_density\n\n    def set_weights(self, weight=1):\n        \"\"\"\n        Set weights of data instances; create a vector of weights if necessary.\n        \"\"\"\n        if not self.W.shape[-1]:\n            self.W = np.empty(len(self))\n        self.W[:] = weight\n\n    def has_weights(self):\n        \"\"\"Return `True` if the data instances are weighed. \"\"\"\n        return self.W.shape[-1] != 0\n\n    def total_weight(self):\n        \"\"\"\n        Return the total weight of instances in the table, or their number if\n        they are unweighted.\n        \"\"\"\n        if self.W.shape[-1]:\n            return sum(self.W)\n        return len(self)\n\n    def has_missing(self):\n        \"\"\"Return `True` if there are any missing attribute or class values.\"\"\"\n        missing_x = not sp.issparse(self.X) and bn.anynan(self.X)  # do not check for sparse X\n        return missing_x or bn.anynan(self._Y)\n\n    def has_missing_attribute(self):\n        \"\"\"Return `True` if there are any missing attribute values.\"\"\"\n        return not sp.issparse(self.X) and bn.anynan(self.X)  # do not check for sparse X\n\n    def has_missing_class(self):\n        \"\"\"Return `True` if there are any missing class values.\"\"\"\n        return bn.anynan(self._Y)\n\n    def get_nan_frequency_attribute(self):\n        if self.X.size == 0:\n            return 0\n        return np.isnan(self.X).sum() / self.X.size\n\n    def get_nan_frequency_class(self):\n        if self.Y.size == 0:\n            return 0\n        return np.isnan(self._Y).sum() / self._Y.size\n\n    def checksum(self, include_metas=True):\n        # TODO: zlib.adler32 does not work for numpy arrays with dtype object\n        # (after pickling and unpickling such arrays, checksum changes)\n        # Why, and should we fix it or remove it?\n        \"\"\"Return a checksum over X, Y, metas and W.\"\"\"\n        cs = zlib.adler32(np.ascontiguousarray(self._X))\n        cs = zlib.adler32(np.ascontiguousarray(self._Y), cs)\n        if include_metas:\n            cs = zlib.adler32(np.ascontiguousarray(self._metas), cs)\n        cs = zlib.adler32(np.ascontiguousarray(self._W), cs)\n        return cs\n\n    def shuffle(self):\n        \"\"\"Randomly shuffle the rows of the table.\"\"\"\n        if not self._check_all_dense():\n            raise ValueError(\"Rows of sparse data cannot be shuffled\")\n        ind = np.arange(self.X.shape[0])\n        np.random.shuffle(ind)\n        self.X = self.X[ind]\n        self._Y = self._Y[ind]\n        self.metas = self.metas[ind]\n        self.W = self.W[ind]\n\n    def get_column_view(self, index):\n        \"\"\"\n        Return a vector - as a view, not a copy - with a column of the table,\n        and a bool flag telling whether this column is sparse. Note that\n        vertical slicing of sparse matrices is inefficient.\n\n        :param index: the index of the column\n        :type index: int, str or Orange.data.Variable\n        :return: (one-dimensional numpy array, sparse)\n        \"\"\"\n\n        def rx(M):\n            if sp.issparse(M):\n                return np.asarray(M.todense())[:, 0], True\n            else:\n                return M, False\n\n        if isinstance(index, Integral):\n            col_index = index\n        else:\n            col_index = self.domain.index(index)\n        if col_index >= 0:\n            if col_index < self.X.shape[1]:\n                col = rx(self.X[:, col_index])\n            elif self._Y.ndim == 1 and col_index == self._X.shape[1]:\n                col = rx(self._Y)\n            else:\n                col = rx(self._Y[:, col_index - self.X.shape[1]])\n        else:\n            col = rx(self.metas[:, -1 - col_index])\n\n        if isinstance(index, DiscreteVariable) \\\n                and index.values != self.domain[col_index].values:\n            col = index.get_mapper_from(self.domain[col_index])(col[0]), col[1]\n            col[0].flags.writeable = False\n        return col\n\n    def _filter_is_defined(self, columns=None, negate=False):\n        # structure of function is obvious; pylint: disable=too-many-branches\n        def _sp_anynan(a):\n            return a.indptr[1:] != a[-1:] + a.shape[1]\n\n        if columns is None:\n            if sp.issparse(self.X):\n                remove = _sp_anynan(self.X)\n            else:\n                remove = bn.anynan(self.X, axis=1)\n            if sp.issparse(self._Y):\n                remove += _sp_anynan(self._Y)\n            else:\n                if self._Y.ndim == 1:\n                    remove += np.isnan(self._Y)\n                else:\n                    remove += bn.anynan(self._Y, axis=1)\n            if sp.issparse(self.metas):\n                remove += _sp_anynan(self._metas)\n            else:\n                for i, var in enumerate(self.domain.metas):\n                    col = self.metas[:, i].flatten()\n                    if var.is_primitive():\n                        remove += np.isnan(col.astype(float))\n                    else:\n                        remove += ~col.astype(bool)\n        else:\n            remove = np.zeros(len(self), dtype=bool)\n            for column in columns:\n                col, sparse = self.get_column_view(column)\n                if sparse:\n                    remove += col == 0\n                elif self.domain[column].is_primitive():\n                    remove += bn.anynan([col.astype(float)], axis=0)\n                else:\n                    remove += col.astype(bool)\n        retain = remove if negate else np.logical_not(remove)\n        return self.from_table_rows(self, retain)\n\n    def _filter_has_class(self, negate=False):\n        if sp.issparse(self._Y):\n            if negate:\n                retain = (self._Y.indptr[1:] !=\n                          self._Y.indptr[-1:] + self._Y.shape[1])\n            else:\n                retain = (self._Y.indptr[1:] ==\n                          self._Y.indptr[-1:] + self._Y.shape[1])\n        else:\n            if self._Y.ndim == 1:\n                retain = np.isnan(self._Y)\n            else:\n                retain = bn.anynan(self._Y, axis=1)\n            if not negate:\n                retain = np.logical_not(retain)\n        return self.from_table_rows(self, retain)\n\n    def _filter_same_value(self, column, value, negate=False):\n        if not isinstance(value, Real):\n            value = self.domain[column].to_val(value)\n        sel = self.get_column_view(column)[0] == value\n        if negate:\n            sel = np.logical_not(sel)\n        return self.from_table_rows(self, sel)\n\n    def _filter_values(self, filter):\n        selection = self._values_filter_to_indicator(filter)\n        return self.from_table(self.domain, self, selection)\n\n    def _values_filter_to_indicator(self, filter):\n        \"\"\"Return selection of rows matching the filter conditions\n\n        Handles conjunction/disjunction and negate modifiers\n\n        Parameters\n        ----------\n        filter: Values object containing the conditions\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        from Orange.data.filter import Values\n\n        if isinstance(filter, Values):\n            conditions = filter.conditions\n            conjunction = filter.conjunction\n        else:\n            conditions = [filter]\n            conjunction = True\n        if conjunction:\n            sel = np.ones(len(self), dtype=bool)\n        else:\n            sel = np.zeros(len(self), dtype=bool)\n\n        for f in conditions:\n            selection = self._filter_to_indicator(f)\n\n            if conjunction:\n                sel *= selection\n            else:\n                sel += selection\n\n        if filter.negate:\n            sel = ~sel\n        return sel\n\n    def _filter_to_indicator(self, filter):\n        \"\"\"Return selection of rows that match the condition.\n\n        Parameters\n        ----------\n        filter: ValueFilter describing the condition\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        from Orange.data.filter import (\n            FilterContinuous, FilterDiscrete, FilterRegex, FilterString,\n            FilterStringList, IsDefined, Values\n        )\n        if isinstance(filter, Values):\n            return self._values_filter_to_indicator(filter)\n\n        def get_col_indices():\n            cols = chain(self.domain.variables, self.domain.metas)\n            if isinstance(filter, IsDefined):\n                if filter.columns is not None:\n                    return list(filter.columns)\n                else:\n                    return list(cols)\n\n            if filter.column is not None:\n                return [filter.column]\n\n            if isinstance(filter, FilterDiscrete):\n                raise ValueError(\"Discrete filter can't be applied across rows\")\n            if isinstance(filter, FilterContinuous):\n                return [col for col in cols if col.is_continuous]\n            if isinstance(filter,\n                          (FilterString, FilterStringList, FilterRegex)):\n                return [col for col in cols if col.is_string]\n            raise TypeError(\"Invalid filter\")\n\n        def col_filter(col_idx):\n            col = self.get_column_view(col_idx)[0]\n            if isinstance(filter, IsDefined):\n                if self.domain[col_idx].is_primitive():\n                    return ~np.isnan(col.astype(float))\n                else:\n                    return col.astype(bool)\n            if isinstance(filter, FilterDiscrete):\n                return self._discrete_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterContinuous):\n                return self._continuous_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterString):\n                return self._string_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterStringList):\n                if not filter.case_sensitive:\n                    col = np.char.lower(np.array(col, dtype=str))\n                    vals = [val.lower() for val in filter.values]\n                else:\n                    vals = filter.values\n                return reduce(operator.add, (col == val for val in vals))\n            if isinstance(filter, FilterRegex):\n                return np.vectorize(filter)(col)\n            raise TypeError(\"Invalid filter\")\n\n        col_indices = get_col_indices()\n        if len(col_indices) == 1:\n            sel = col_filter(col_indices[0])\n        else:\n            sel = np.ones(len(self), dtype=bool)\n            for col_idx in col_indices:\n                sel *= col_filter(col_idx)\n\n        if isinstance(filter, IsDefined) and filter.negate:\n            sel = ~sel\n        return sel\n\n    def _discrete_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given discrete filter.\n\n        Parameters\n        ----------\n        filter: FilterDiscrete\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.values is None:  # <- is defined filter\n            col = col.astype(float)\n            return ~np.isnan(col)\n\n        sel = np.zeros(len(self), dtype=bool)\n        for val in filter.values:\n            if not isinstance(val, Real):\n                val = self.domain[filter.column].to_val(val)\n            sel += (col == val)\n        return sel\n\n    def _continuous_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given continuous filter.\n\n        Parameters\n        ----------\n        filter: FilterContinuous\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.oper == filter.IsDefined:\n            col = col.astype(float)\n            return ~np.isnan(col)\n\n        return self._range_filter_to_indicator(filter, col, filter.min, filter.max)\n\n    def _string_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given string filter.\n\n        Parameters\n        ----------\n        filter: FilterString\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.oper == filter.IsDefined:\n            return col.astype(bool)\n\n        col = col.astype(str)\n        fmin = filter.min or \"\"\n        fmax = filter.max or \"\"\n\n        if not filter.case_sensitive:\n            # convert all to lower case\n            col = np.char.lower(col)\n            fmin = fmin.lower()\n            fmax = fmax.lower()\n\n        if filter.oper == filter.Contains:\n            return np.fromiter((fmin in e for e in col),\n                               dtype=bool)\n        if filter.oper == filter.StartsWith:\n            return np.fromiter((e.startswith(fmin) for e in col),\n                               dtype=bool)\n        if filter.oper == filter.EndsWith:\n            return np.fromiter((e.endswith(fmin) for e in col),\n                               dtype=bool)\n\n        return self._range_filter_to_indicator(filter, col, fmin, fmax)\n\n    @staticmethod\n    def _range_filter_to_indicator(filter, col, fmin, fmax):\n        with np.errstate(invalid=\"ignore\"):  # nan's are properly discarded\n            if filter.oper == filter.Equal:\n                return col == fmin\n            if filter.oper == filter.NotEqual:\n                return col != fmin\n            if filter.oper == filter.Less:\n                return col < fmin\n            if filter.oper == filter.LessEqual:\n                return col <= fmin\n            if filter.oper == filter.Greater:\n                return col > fmin\n            if filter.oper == filter.GreaterEqual:\n                return col >= fmin\n            if filter.oper == filter.Between:\n                return (col >= fmin) * (col <= fmax)\n            if filter.oper == filter.Outside:\n                return (col < fmin) + (col > fmax)\n\n            raise TypeError(\"Invalid operator\")\n\n    def _compute_basic_stats(self, columns=None,\n                             include_metas=False, compute_variance=False):\n        if compute_variance:\n            raise NotImplementedError(\"computation of variance is \"\n                                      \"not implemented yet\")\n        W = self._W if self.has_weights() else None\n        rr = []\n        stats = []\n        if not columns:\n            if self.domain.attributes:\n                rr.append(fast_stats(self._X, W))\n            if self.domain.class_vars:\n                rr.append(fast_stats(self._Y, W))\n            if include_metas and self.domain.metas:\n                rr.append(fast_stats(self.metas, W))\n            if len(rr):\n                stats = np.vstack(tuple(rr))\n        else:\n            nattrs = len(self.domain.attributes)\n            for column in columns:\n                c = self.domain.index(column)\n                if 0 <= c < nattrs:\n                    S = fast_stats(self._X[:, [c]], W and W[:, [c]])\n                elif c >= nattrs:\n                    if self._Y.ndim == 1 and c == nattrs:\n                        S = fast_stats(self._Y[:, None], W and W[:, None])\n                    else:\n                        S = fast_stats(self._Y[:, [c - nattrs]], W and W[:, [c - nattrs]])\n                else:\n                    S = fast_stats(self._metas[:, [-1 - c]], W and W[:, [-1 - c]])\n                stats.append(S[0])\n        return stats\n\n    def _compute_distributions(self, columns=None):\n        if columns is None:\n            columns = range(len(self.domain.variables))\n        else:\n            columns = [self.domain.index(var) for var in columns]\n\n        distributions = []\n        X = self.X\n        if sp.issparse(X):\n            X = X.tocsc()\n\n\n        W = self.W.ravel() if self.has_weights() else None\n\n        for col in columns:\n            variable = self.domain[col]\n\n            # Select the correct data column from X, Y or metas\n            if 0 <= col < X.shape[1]:\n                x = X[:, col]\n            elif col < 0:\n                x = self.metas[:, col * (-1) - 1]\n                if np.issubdtype(x.dtype, np.dtype(object)):\n                    x = x.astype(float)\n            elif self._Y.ndim == 1 and col == X.shape[1]:\n                x = self._Y\n            else:\n                x = self._Y[:, col - X.shape[1]]\n\n            if variable.is_discrete:\n                dist, unknowns = bincount(x, weights=W, max_val=len(variable.values) - 1)\n            elif not x.shape[0]:\n                dist, unknowns = np.zeros((2, 0)), 0\n            else:\n                if W is not None:\n                    if sp.issparse(x):\n                        arg_sort = np.argsort(x.data)\n                        ranks = x.indices[arg_sort]\n                        vals = np.vstack((x.data[arg_sort], W[ranks]))\n                    else:\n                        ranks = np.argsort(x)\n                        vals = np.vstack((x[ranks], W[ranks]))\n                else:\n                    x_values = x.data if sp.issparse(x) else x\n                    vals = np.ones((2, x_values.shape[0]))\n                    vals[0, :] = x_values\n                    vals[0, :].sort()\n\n                dist = np.array(_valuecount.valuecount(vals))\n                # If sparse, then 0s will not be counted with `valuecount`, so\n                # we have to add them to the result manually.\n                if sp.issparse(x) and sparse_has_implicit_zeros(x):\n                    if W is not None:\n                        zero_weights = sparse_implicit_zero_weights(x, W).sum()\n                    else:\n                        zero_weights = sparse_count_implicit_zeros(x)\n                    zero_vec = [0, zero_weights]\n                    dist = np.insert(dist, np.searchsorted(dist[0], 0), zero_vec, axis=1)\n                # Since `countnans` assumes vector shape to be (1, n) and `x`\n                # shape is (n, 1), we pass the transpose\n                unknowns = countnans(x.T, W)\n            distributions.append((dist, unknowns))\n\n        return distributions\n\n    def _compute_contingency(self, col_vars=None, row_var=None):\n        n_atts = self.X.shape[1]\n\n        if col_vars is None:\n            col_vars = range(len(self.domain.variables))\n        else:\n            col_vars = [self.domain.index(var) for var in col_vars]\n        if row_var is None:\n            row_var = self.domain.class_var\n            if row_var is None:\n                raise ValueError(\"No row variable\")\n\n        row_desc = self.domain[row_var]\n        if not row_desc.is_discrete:\n            raise TypeError(\"Row variable must be discrete\")\n        row_indi = self.domain.index(row_var)\n        n_rows = len(row_desc.values)\n        if 0 <= row_indi < n_atts:\n            row_data = self.X[:, row_indi]\n        elif row_indi < 0:\n            row_data = self.metas[:, -1 - row_indi]\n        elif self._Y.ndim == 1 and row_indi == n_atts:\n            row_data = self._Y\n        else:\n            row_data = self._Y[:, row_indi - n_atts]\n\n        W = self.W if self.has_weights() else None\n\n        col_desc = [self.domain[var] for var in col_vars]\n        col_indi = [self.domain.index(var) for var in col_vars]\n\n        if any(not (var.is_discrete or var.is_continuous)\n               for var in col_desc):\n            raise ValueError(\"Contingency can be computed only for categorical \"\n                             \"and numeric values.\")\n\n        # when we select a column in sparse matrix it is still two dimensional\n        # and sparse - since it is just a column we can afford to transform\n        # it to dense and make it 1D\n        if issparse(row_data):\n            row_data = row_data.toarray().ravel()\n        if row_data.dtype.kind != \"f\":  # meta attributes can be stored as type object\n            row_data = row_data.astype(float)\n\n        contingencies = [None] * len(col_desc)\n        for arr, f_cond, f_ind in (\n                (self.X, lambda i: 0 <= i < n_atts, lambda i: i),\n                (self._Y, lambda i: i >= n_atts, lambda i: i - n_atts),\n                (self.metas, lambda i: i < 0, lambda i: -1 - i)):\n\n            arr_indi = [e for e, ind in enumerate(col_indi) if f_cond(ind)]\n\n            vars = [(e, f_ind(col_indi[e]), col_desc[e]) for e in arr_indi]\n            disc_vars = [v for v in vars if v[2].is_discrete]\n            if disc_vars:\n                if sp.issparse(arr):\n                    max_vals = max(len(v[2].values) for v in disc_vars)\n                    disc_indi = {i for _, i, _ in disc_vars}\n                    mask = [i in disc_indi for i in range(arr.shape[1])]\n                    conts, nans_cols, nans_rows, nans = contingency(\n                        arr, row_data, max_vals - 1, n_rows - 1, W, mask)\n                    for col_i, arr_i, var in disc_vars:\n                        n_vals = len(var.values)\n                        contingencies[col_i] = (\n                            conts[arr_i][:, :n_vals], nans_cols[arr_i],\n                            nans_rows[arr_i], nans[arr_i])\n                else:\n                    for col_i, arr_i, var in disc_vars:\n                        col = arr if arr.ndim == 1 else arr[:, arr_i]\n                        contingencies[col_i] = contingency(\n                            col.astype(float),\n                            row_data, len(var.values) - 1, n_rows - 1, W)\n\n            cont_vars = [v for v in vars if v[2].is_continuous]\n            if cont_vars:\n                W_ = None\n                if W is not None:\n                    W_ = W.astype(dtype=np.float64)\n                if sp.issparse(arr):\n                    arr = sp.csc_matrix(arr)\n\n                for col_i, arr_i, _ in cont_vars:\n                    if sp.issparse(arr):\n                        col_data = arr.data[arr.indptr[arr_i]:arr.indptr[arr_i + 1]]\n                        rows = arr.indices[arr.indptr[arr_i]:arr.indptr[arr_i + 1]]\n                        W_ = None if W_ is None else W_[rows]\n                        classes_ = row_data[rows]\n                    else:\n                        col_data, W_, classes_ = arr[:, arr_i], W_, row_data\n\n                    col_data = col_data.astype(dtype=np.float64)\n                    contingencies[col_i] = _contingency.contingency_floatarray(\n                        col_data, classes_, n_rows, W_)\n\n        return contingencies\n\n    @classmethod\n    def transpose(cls, table, feature_names_column=\"\",\n                  meta_attr_name=\"Feature name\", feature_name=\"Feature\",\n                  remove_redundant_inst=False, progress_callback=None):\n        \"\"\"\n        Transpose the table.\n\n        :param table: Table - table to transpose\n        :param feature_names_column: str - name of (String) meta attribute to\n            use for feature names\n        :param meta_attr_name: str - name of new meta attribute into which\n            feature names are mapped\n        :param feature_name: str - default feature name prefix\n        :param remove_redundant_inst: bool - remove instance that\n            represents feature_names_column\n        :param progress_callback: callable - to report the progress\n        :return: Table - transposed table\n        \"\"\"\n        if progress_callback is None:\n            progress_callback = dummy_callback\n        progress_callback(0, \"Transposing...\")\n\n        if isinstance(feature_names_column, Variable):\n            feature_names_column = feature_names_column.name\n\n        self = cls()\n        n_cols, self.n_rows = table.X.shape\n        old_domain = table.attributes.get(\"old_domain\")\n        table_domain_attributes = list(table.domain.attributes)\n        attr_index = None\n        if remove_redundant_inst:\n            attr_names = [a.name for a in table_domain_attributes]\n            if feature_names_column and feature_names_column in attr_names:\n                attr_index = attr_names.index(feature_names_column)\n                self.n_rows = self.n_rows - 1\n                table_domain_attributes.remove(\n                    table_domain_attributes[attr_index])\n\n        # attributes\n        # - classes and metas to attributes of attributes\n        # - arbitrary meta column to feature names\n        with self.unlocked():\n            self.X = table.X.T\n            if attr_index is not None:\n                self.X = np.delete(self.X, attr_index, 0)\n            if feature_names_column:\n                names = [str(row[feature_names_column]) for row in table]\n                progress_callback(0.1)\n                names = get_unique_names_duplicates(names)\n                progress_callback(0.3)\n                attributes = [ContinuousVariable(name) for name in names]\n            else:\n                places = int(np.ceil(np.log10(n_cols))) if n_cols else 1\n                attributes = [ContinuousVariable(f\"{feature_name} {i:0{places}}\")\n                              for i in range(1, n_cols + 1)]\n            progress_callback(0.4)\n\n            if old_domain is not None and feature_names_column:\n                for i, _ in enumerate(attributes):\n                    if attributes[i].name in old_domain:\n                        var = old_domain[attributes[i].name]\n                        attr = ContinuousVariable(var.name) if var.is_continuous \\\n                            else DiscreteVariable(var.name, var.values)\n                        attr.attributes = var.attributes.copy()\n                        attributes[i] = attr\n\n            def set_attributes_of_attributes(_vars, _table):\n                for i, variable in enumerate(_vars):\n                    if variable.name == feature_names_column:\n                        continue\n                    for j, row in enumerate(_table):\n                        value = variable.repr_val(row) if np.isscalar(row) \\\n                            else row[i] if isinstance(row[i], str) \\\n                            else variable.repr_val(row[i])\n\n                        if value not in MISSING_VALUES:\n                            attributes[j].attributes[variable.name] = value\n\n            set_attributes_of_attributes(table.domain.class_vars, table.Y)\n            progress_callback(0.5)\n            set_attributes_of_attributes(table.domain.metas, table.metas)\n\n            # weights\n            self.W = np.empty((self.n_rows, 0))\n\n            def get_table_from_attributes_of_attributes(_vars, _dtype=float):\n                T = np.empty((self.n_rows, len(_vars)), dtype=_dtype)\n                for i, _attr in enumerate(table_domain_attributes):\n                    for j, _var in enumerate(_vars):\n                        val = str(_attr.attributes.get(_var.name, \"\"))\n                        if not _var.is_string:\n                            val = np.nan if val in MISSING_VALUES else \\\n                                _var.values.index(val) if \\\n                                    _var.is_discrete else float(val)\n                        T[i, j] = val\n                return T\n\n            # class_vars - attributes of attributes to class - from old domain\n            class_vars = []\n            if old_domain is not None:\n                class_vars = old_domain.class_vars\n            self.Y = get_table_from_attributes_of_attributes(class_vars)\n\n            # metas\n            # - feature names and attributes of attributes to metas\n            self.metas, metas = np.empty((self.n_rows, 0), dtype=object), []\n            if meta_attr_name not in [m.name for m in table.domain.metas] and \\\n                    table_domain_attributes:\n                self.metas = np.array([[a.name] for a in table_domain_attributes],\n                                      dtype=object)\n                metas.append(StringVariable(meta_attr_name))\n\n            names = chain.from_iterable(list(attr.attributes)\n                                        for attr in table_domain_attributes)\n            names = sorted(set(names) - {var.name for var in class_vars})\n            progress_callback(0.6)\n\n            def guessed_var(i, var_name):\n                orig_vals = M[:, i]\n                val_map, vals, var_type = Orange.data.io.guess_data_type(orig_vals)\n                values, variable = Orange.data.io.sanitize_variable(\n                    val_map, vals, orig_vals, var_type, {}, name=var_name)\n                M[:, i] = values\n                return variable\n\n            _metas = [StringVariable(n) for n in names]\n            if old_domain is not None:\n                _metas = [m for m in old_domain.metas if m.name != meta_attr_name]\n            M = get_table_from_attributes_of_attributes(_metas, _dtype=object)\n            progress_callback(0.7)\n            if old_domain is None:\n                _metas = [guessed_var(i, m.name) for i, m in enumerate(_metas)]\n            if _metas:\n                self.metas = np.hstack((self.metas, M))\n                metas.extend(_metas)\n\n            self.domain = Domain(attributes, class_vars, metas)\n            progress_callback(0.9)\n            cls._init_ids(self)\n            self.attributes = table.attributes.copy()\n            self.attributes[\"old_domain\"] = table.domain\n            progress_callback(1)\n            return self\n\n    def to_sparse(self, sparse_attributes=True, sparse_class=False,\n                  sparse_metas=False):\n        def sparsify(features):\n            for f in features:\n                f.sparse = True\n\n        new_domain = self.domain.copy()\n\n        if sparse_attributes:\n            sparsify(new_domain.attributes)\n        if sparse_class:\n            sparsify(new_domain.class_vars)\n        if sparse_metas:\n            sparsify(new_domain.metas)\n        return self.transform(new_domain)\n\n    def to_dense(self, dense_attributes=True, dense_class=True,\n                 dense_metas=True):\n        def densify(features):\n            for f in features:\n                f.sparse = False\n\n        new_domain = self.domain.copy()\n\n        if dense_attributes:\n            densify(new_domain.attributes)\n        if dense_class:\n            densify(new_domain.class_vars)\n        if dense_metas:\n            densify(new_domain.metas)\n        t = self.transform(new_domain)\n        t.ids = self.ids  # preserve indices\n        return t",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 443,
                            "end_lineno": 452,
                            "parent": {
                                "file_name": "Orange/data/table.py",
                                "type": "class",
                                "name": "Table",
                                "content": "class Table(Sequence, Storage):\n\n    LOCKING = None\n    \"\"\" If the class attribute LOCKING is True, tables will throw exceptions\n    on in-place modifications unless unlocked explicitly. LOCKING is supposed\n    to be set to True for testing to help us find bugs. If set to False\n    or None, no safeguards are in place. Two different values are used for\n    the same behaviour to distinguish the unchanged default (None) form\n    explicit deactivation (False) that some add-ons might need. \"\"\"\n\n    __file__ = None\n    name = \"untitled\"\n\n    domain = Domain([])\n    _X = _Y = _metas = _W = np.zeros((0, 0))  # pylint: disable=invalid-name\n    ids = np.zeros(0)\n    ids.setflags(write=False)\n    attributes = frozendict()\n\n    _Unlocked_X, _Unlocked_Y, _Unlocked_metas, _Unlocked_W = 1, 2, 4, 8\n    _unlocked = _Unlocked_X + _Unlocked_Y + \\\n                _Unlocked_metas + _Unlocked_W  # pylint: disable=invalid-name\n\n    @property\n    def columns(self):\n        \"\"\"\n        A class whose attributes contain attribute descriptors for columns.\n        For a table `table`, setting `c = table.columns` will allow accessing\n        the table's variables with, for instance `c.gender`, `c.age` ets.\n        Spaces are replaced with underscores.\n        \"\"\"\n        return Columns(self.domain)\n\n    _next_instance_id = 0\n    _next_instance_lock = Lock()\n\n    def _check_unlocked(self, partflag):\n        if not self._unlocked & partflag:\n            raise ValueError(\"Table is read-only unless unlocked\")\n\n    @property\n    def X(self):  # pylint: disable=invalid-name\n        return self._X\n\n    @X.setter\n    def X(self, value):\n        self._check_unlocked(self._Unlocked_X)\n        self._X = _dereferenced(value)\n\n    @property\n    def Y(self):  # pylint: disable=invalid-name\n        return self._Y\n\n    @Y.setter\n    def Y(self, value):\n        self._check_unlocked(self._Unlocked_Y)\n        if sp.issparse(value) and len(self) != value.shape[0]:\n            value = value.T\n        if sp.issparse(value):\n            value = _dereferenced(value.toarray())\n        if value.ndim == 2 and value.shape[1] == 1:\n            value = value[:, 0].copy()  # no views!\n        self._Y = value\n\n    @property\n    def metas(self):\n        return self._metas\n\n    @metas.setter\n    def metas(self, value):\n        self._check_unlocked(self._Unlocked_metas)\n        self._metas = _dereferenced(value)\n\n    @property\n    def W(self):  # pylint: disable=invalid-name\n        return self._W\n\n    @W.setter\n    def W(self, value):\n        self._check_unlocked(self._Unlocked_W)\n        self._W = value\n\n    def __setstate__(self, state):\n        # Backward compatibility with pickles before table locking\n        self._initialize_unlocked()  # __dict__ seems to be cleared before calling __setstate__\n        with self.unlocked():\n            for k in (\"X\", \"W\", \"metas\"):\n                if k in state:\n                    setattr(self, k, state.pop(k))\n            if \"_Y\" in state:\n                setattr(self, \"Y\", state.pop(\"_Y\"))  # state[\"_Y\"] is a 2d array\n            self.__dict__.update(state)\n\n    def __getstate__(self):\n        # Compatibility with pickles before table locking:\n        # return the same state as before table lock\n        state = self.__dict__.copy()\n        for k in [\"X\", \"metas\", \"W\"]:\n            if \"_\" + k in state:  # Check existence; SQL tables do not contain them\n                state[k] = state.pop(\"_\" + k)\n        # before locking, _Y was always a 2d array: save it as such\n        if \"_Y\" in state:\n            y = state.pop(\"_Y\")\n            y2d = y.reshape(-1, 1) if y.ndim == 1 else y\n            state[\"_Y\"] = y2d\n        return state\n\n    def _lock_parts(self):\n        return ((self._X, self._Unlocked_X, \"X\"),\n                (self._Y, self._Unlocked_Y, \"Y\"),\n                (self._metas, self._Unlocked_metas, \"metas\"),\n                (self._W, self._Unlocked_W, \"weights\"))\n\n    def _initialize_unlocked(self):\n        if Table.LOCKING:\n            self._unlocked = 0\n        else:\n            self._unlocked = sum(f for _, f, _ in self._lock_parts())\n\n    def _update_locks(self, force=False, unlock_bases=()):\n        if not Table.LOCKING:\n            return\n\n        def sync(*xs):\n            for x in xs:\n                try:\n                    undo_on_fail.append((x, x.flags.writeable))\n                    x.flags.writeable = writeable\n                except ValueError:\n                    if force \\\n                            and writeable \\\n                            and x.base is not None \\\n                            and not x.base.flags.writeable:\n                        x.base.flags.writeable = writeable\n                        x.flags.writeable = writeable\n                        forced_bases.append(x.base)\n                    else:\n                        raise\n\n        forced_bases = []\n        undo_on_fail = []\n        for base in unlock_bases:\n            base.flags.writeable = False\n        try:\n            for part, flag, _ in self._lock_parts():\n                if part is None:\n                    continue\n                writeable = bool(self._unlocked & flag)\n                if sp.isspmatrix_csr(part) or sp.isspmatrix_csc(part):\n                    sync(part.data, part.indices, part.indptr)\n                elif sp.isspmatrix_coo(part):\n                    sync(part.data, part.row, part.col)\n                elif sp.issparse(part):\n                    raise ValueError(\"Unsupported sparse data type\")\n                else:\n                    sync(part)\n        except:\n            for part, flag in undo_on_fail:\n                part.flags.writeable = flag\n            raise\n        return tuple(forced_bases)\n\n    def __unlocked(self, *parts, force=False):\n        prev_state = self._unlocked\n        for part, flag, _ in self._lock_parts():\n            if not parts or any(ppart is part for ppart in parts):\n                self._unlocked |= flag\n        try:\n            forced_bases = self._update_locks(force)\n            yield\n        finally:\n            self._unlocked = prev_state\n            self._update_locks(unlock_bases=forced_bases)\n\n    def force_unlocked(self, *parts):\n        \"\"\"\n        Unlocking without any checks.\n\n        Use with extreme caution. This is meant primarily for 3rd party\n        functions in Cython that expect read-write buffer, but do not\n        actually modify it. the given parts (default: all parts) of the table.\n\n        The function will still fail to unlock and raise an exception if the\n        table contains view to another table.\n        \"\"\"\n        return contextmanager(self.__unlocked)(*parts, force=True)\n\n    def unlocked(self, *parts):\n        \"\"\"\n        Unlock the given parts (default: all parts) of the table.\n\n        The caller must ensure that the table is safe to modify. The function\n        will raise an exception if the table contains view to other table.\n        \"\"\"\n        def can_unlock(x):\n            if sp.issparse(x):\n                return can_unlock(x.data)\n            return x.flags.writeable or x.flags.owndata\n\n        for part, flag, name in self._lock_parts():\n            if not flag & self._unlocked \\\n                    and (not parts or any(ppart is part for ppart in parts)) \\\n                    and part is not None and not can_unlock(part):\n                raise ValueError(f\"'{name}' is a view into another table \"\n                                 \"and cannot be unlocked\")\n        return contextmanager(self.__unlocked)(*parts)\n\n    def __new__(cls, *args, **kwargs):\n        def warn_deprecated(method):\n            warnings.warn(\"Direct calls to Table's constructor are deprecated \"\n                          \"and will be removed. Replace this call with \"\n                          f\"Table.{method}\", OrangeDeprecationWarning,\n                          stacklevel=3)\n\n        if not args:\n            if not kwargs:\n                return super().__new__(cls)\n            else:\n                raise TypeError(\"Table() must not be called directly\")\n\n        if isinstance(args[0], str):\n            if len(args) > 1:\n                raise TypeError(\"Table(name: str) expects just one argument\")\n            if args[0].startswith('https://') or args[0].startswith('http://'):\n                return cls.from_url(args[0], **kwargs)\n            else:\n                return cls.from_file(args[0], **kwargs)\n\n        elif isinstance(args[0], Table):\n            if len(args) > 1:\n                raise TypeError(\"Table(table: Table) expects just one argument\")\n            return cls.from_table(args[0].domain, args[0], **kwargs)\n        elif isinstance(args[0], Domain):\n            domain, args = args[0], args[1:]\n            if not args:\n                warn_deprecated(\"from_domain\")\n                return cls.from_domain(domain, **kwargs)\n            if isinstance(args[0], Table):\n                warn_deprecated(\"from_table\")\n                return cls.from_table(domain, *args, **kwargs)\n            elif isinstance(args[0], list):\n                warn_deprecated(\"from_list\")\n                return cls.from_list(domain, *args, **kwargs)\n        else:\n            warnings.warn(\"Omitting domain in a call to Table(X, Y, metas), is \"\n                          \"deprecated and will be removed. \"\n                          \"Call Table.from_numpy(None, X, Y, metas) instead.\",\n                          OrangeDeprecationWarning, stacklevel=2)\n            domain = None\n\n        return cls.from_numpy(domain, *args, **kwargs)\n\n    def __init__(self, *args, **kwargs):  # pylint: disable=unused-argument\n        self._initialize_unlocked()\n        self._update_locks()\n\n    @classmethod\n    def from_domain(cls, domain, n_rows=0, weights=False):\n        \"\"\"\n        Construct a new `Table` with the given number of rows for the given\n        domain. The optional vector of weights is initialized to 1's.\n\n        :param domain: domain for the `Table`\n        :type domain: Orange.data.Domain\n        :param n_rows: number of rows in the new table\n        :type n_rows: int\n        :param weights: indicates whether to construct a vector of weights\n        :type weights: bool\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n        self = cls()\n        self.domain = domain\n        self.n_rows = n_rows\n        with self.unlocked():\n            self.X = np.zeros((n_rows, len(domain.attributes)))\n            if len(domain.class_vars) != 1:\n                self.Y = np.zeros((n_rows, len(domain.class_vars)))\n            else:\n                self.Y = np.zeros(n_rows)\n            if weights:\n                self.W = np.ones(n_rows)\n            else:\n                self.W = np.empty((n_rows, 0))\n            self.metas = np.empty((n_rows, len(self.domain.metas)), object)\n            cls._init_ids(self)\n            self.attributes = {}\n        return self\n\n    @classmethod\n    def from_table(cls, domain, source, row_indices=...):\n        \"\"\"\n        Create a new table from selected columns and/or rows of an existing\n        one. The columns are chosen using a domain. The domain may also include\n        variables that do not appear in the source table; they are computed\n        from source variables if possible.\n\n        The resulting data may be a view or a copy of the existing data.\n\n        :param domain: the domain for the new table\n        :type domain: Orange.data.Domain\n        :param source: the source table\n        :type source: Orange.data.Table\n        :param row_indices: indices of the rows to include\n        :type row_indices: a slice or a sequence\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n\n        PART = 5000\n\n        new_cache = _thread_local.conversion_cache is None\n        try:\n            if new_cache:\n                _thread_local.conversion_cache = {}\n                _thread_local.domain_cache = {}\n            else:\n                cached = _idcache_restore(_thread_local.conversion_cache, (domain, source))\n                if cached is not None:\n                    return cached\n            if domain is source.domain:\n                table = cls.from_table_rows(source, row_indices)\n                # assure resulting domain is the instance passed on input\n                table.domain = domain\n                # since sparse flags are not considered when checking for\n                # domain equality, fix manually.\n                with table.unlocked():\n                    table = assure_domain_conversion_sparsity(table, source)\n                return table\n\n            if row_indices is ...:\n                n_rows = len(source)\n            elif isinstance(row_indices, slice):\n                row_indices_range = range(*row_indices.indices(source.X.shape[0]))\n                n_rows = len(row_indices_range)\n            else:\n                n_rows = len(row_indices)\n\n            self = cls()\n            self.domain = domain\n\n            table_conversion = \\\n                _idcache_restore(_thread_local.domain_cache, (domain, source.domain))\n            if table_conversion is None:\n                table_conversion = _FromTableConversion(source.domain, domain)\n                _idcache_save(_thread_local.domain_cache, (domain, source.domain),\n                              table_conversion)\n\n            # if an array can be a subarray of the input table, this needs to be done\n            # on the whole table, because this avoids needless copies of contents\n\n            with self.unlocked():\n                for array_conv in table_conversion.subarray:\n                    out = array_conv.get_subarray(source, row_indices, n_rows)\n                    setattr(self, array_conv.target, out)\n\n                parts = {}\n\n                for array_conv in table_conversion.columnwise:\n                    if array_conv.is_sparse:\n                        parts[array_conv.target] = []\n                    else:\n                        # F-order enables faster writing to the array while accessing and\n                        # matrix operations work with same speed (e.g. dot)\n                        parts[array_conv.target] = \\\n                            np.zeros((n_rows, len(array_conv.src_cols)),\n                                     order=\"F\", dtype=array_conv.dtype)\n\n                if n_rows <= PART:\n                    for array_conv in table_conversion.columnwise:\n                        out = array_conv.get_columns(source, row_indices, n_rows,\n                                                     parts[array_conv.target],\n                                                     ...)\n                        setattr(self, array_conv.target, out)\n                else:\n                    i_done = 0\n\n                    while i_done < n_rows:\n                        target_indices = slice(i_done, min(n_rows, i_done + PART))\n                        if row_indices is ...:\n                            source_indices = target_indices\n                        elif isinstance(row_indices, slice):\n                            r = row_indices_range[target_indices]\n                            source_indices = slice(r.start, r.stop, r.step)\n                        else:\n                            source_indices = row_indices[target_indices]\n                        part_rows = min(n_rows, i_done+PART) - i_done\n\n                        for array_conv in table_conversion.columnwise:\n                            out = array_conv.get_columns(source, source_indices, part_rows,\n                                                         parts[array_conv.target],\n                                                         target_indices)\n                            if array_conv.is_sparse:  # dense arrays are populated in-place\n                                parts[array_conv.target].append(out)\n\n                        i_done += PART\n\n                        # clear cache after a part is done\n                        if new_cache:\n                            _thread_local.conversion_cache = {}\n\n                    for array_conv in table_conversion.columnwise:\n                        cparts = parts[array_conv.target]\n                        out = cparts if not array_conv.is_sparse else sp.vstack(cparts)\n                        setattr(self, array_conv.target, out)\n\n                if source.has_weights():\n                    self.W = source.W[row_indices]\n                else:\n                    self.W = np.empty((n_rows, 0))\n                self.name = getattr(source, 'name', '')\n                if hasattr(source, 'ids'):\n                    self.ids = source.ids[row_indices]\n                else:\n                    cls._init_ids(self)\n                self.attributes = getattr(source, 'attributes', {})\n                _idcache_save(_thread_local.conversion_cache, (domain, source), self)\n            return self\n        finally:\n            if new_cache:\n                _thread_local.conversion_cache = None\n                _thread_local.domain_cache = None\n\n    def transform(self, domain):\n        \"\"\"\n        Construct a table with a different domain.\n\n        The new table keeps the row ids and other information. If the table\n        is a subclass of :obj:`Table`, the resulting table will be of the same\n        type.\n\n        In a typical scenario, an existing table is augmented with a new\n        column by ::\n\n            domain = Domain(old_domain.attributes + [new_attribute],\n                            old_domain.class_vars,\n                            old_domain.metas)\n            table = data.transform(domain)\n            table[:, new_attribute] = new_column\n\n        Args:\n            domain (Domain): new domain\n\n        Returns:\n            A new table\n        \"\"\"\n        return type(self).from_table(domain, self)\n\n    @classmethod\n    def from_table_rows(cls, source, row_indices):\n        \"\"\"\n        Construct a new table by selecting rows from the source table.\n\n        :param source: an existing table\n        :type source: Orange.data.Table\n        :param row_indices: indices of the rows to include\n        :type row_indices: a slice or a sequence\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n        def get_rows(a):\n            a = a[row_indices]\n            if isinstance(row_indices, slice) or row_indices is ...:\n                a = a.copy()\n            return a\n\n        self = cls()\n        self.domain = source.domain\n        with self.unlocked():\n            self.X = get_rows(source.X)\n            if self.X.ndim == 1:\n                self.X = self.X.reshape(-1, len(self.domain.attributes))\n            self.Y = get_rows(source.Y)\n            self.metas = get_rows(source.metas)\n            if self.metas.ndim == 1:\n                self.metas = self.metas.reshape(-1, len(self.domain.metas))\n            self.W = get_rows(source.W)\n            self.name = getattr(source, 'name', '')\n            self.ids = np.array(source.ids[row_indices])\n            self.attributes = getattr(source, 'attributes', {})\n        return self\n\n    @classmethod\n    def from_numpy(cls, domain, X, Y=None, metas=None, W=None,\n                   attributes=None, ids=None):\n        \"\"\"\n        Construct a table from numpy arrays with the given domain. The number\n        of variables in the domain must match the number of columns in the\n        corresponding arrays. All arrays must have the same number of rows.\n        Arrays may be of different numpy types, and may be dense or sparse.\n\n        :param domain: the domain for the new table\n        :type domain: Orange.data.Domain\n        :param X: array with attribute values\n        :type X: np.array\n        :param Y: array with class values\n        :type Y: np.array\n        :param metas: array with meta attributes\n        :type metas: np.array\n        :param W: array with weights\n        :type W: np.array\n        :return:\n        \"\"\"\n        X, Y, W = _check_arrays(X, Y, W, dtype='float64')\n        metas, = _check_arrays(metas, dtype=object, shape_1=X.shape[0])\n        ids, = _check_arrays(ids, dtype=int, shape_1=X.shape[0])\n\n        if domain is None:\n            domain = Domain.from_numpy(X, Y, metas)\n\n        if Y is None:\n            if not domain.class_vars or sp.issparse(X):\n                Y = np.empty((X.shape[0], 0), dtype=np.float64)\n            else:\n                own_data = X.flags.owndata and X.base is None\n                Y = X[:, len(domain.attributes):]\n                X = X[:, :len(domain.attributes)]\n                if own_data:\n                    Y = Y.copy()\n                    X = X.copy()\n        if metas is None:\n            metas = np.empty((X.shape[0], 0), object)\n        if W is None or W.size == 0:\n            W = np.empty((X.shape[0], 0))\n        elif W.shape != (W.size, ):\n            W = W.reshape(W.size).copy()\n\n        if X.shape[1] != len(domain.attributes):\n            raise ValueError(\n                \"Invalid number of variable columns ({} != {})\".format(\n                    X.shape[1], len(domain.attributes))\n            )\n        if Y.ndim == 1:\n            if not domain.class_var:\n                raise ValueError(\n                    \"Invalid number of class columns \"\n                    f\"(1 != {len(domain.class_vars)})\")\n        elif Y.shape[1] != len(domain.class_vars):\n            raise ValueError(\n                \"Invalid number of class columns ({} != {})\".format(\n                    Y.shape[1], len(domain.class_vars))\n            )\n        if metas.shape[1] != len(domain.metas):\n            raise ValueError(\n                \"Invalid number of meta attribute columns ({} != {})\".format(\n                    metas.shape[1], len(domain.metas))\n            )\n        if not X.shape[0] == Y.shape[0] == metas.shape[0] == W.shape[0]:\n            raise ValueError(\n                \"Parts of data contain different numbers of rows.\")\n\n        self = cls()\n        with self.unlocked():\n            self.domain = domain\n            self.X = X\n            self.Y = Y\n            self.metas = metas\n            self.W = W\n            self.n_rows = self.X.shape[0]\n            if ids is None:\n                cls._init_ids(self)\n            else:\n                self.ids = ids\n            self.attributes = {} if attributes is None else attributes\n        return self\n\n    @classmethod\n    def from_list(cls, domain, rows, weights=None):\n        if weights is not None and len(rows) != len(weights):\n            raise ValueError(\"mismatching number of instances and weights\")\n        self = cls.from_domain(domain, len(rows), weights is not None)\n        all_vars = domain.variables + domain.metas\n        nattrs = len(domain.attributes)\n        nattrscls = len(domain.variables)\n        with self.unlocked():\n            for i, row in enumerate(rows):\n                if isinstance(row, Instance):\n                    row = row.list\n                vals = [var.to_val(val) for var, val in zip(all_vars, row)]\n                self.X[i] = vals[:nattrs]\n                if self._Y.ndim == 1:\n                    self._Y[i] = vals[nattrs] if nattrs < len(vals) else np.nan\n                else:\n                    self._Y[i] = vals[nattrs:nattrscls]\n                # for backward compatibility: allow omittine some (or all) metas\n                self.metas[i, :len(vals) - nattrscls] = vals[nattrscls:]\n            if weights is not None:\n                self.W = np.array(weights)\n            self.attributes = {}\n        return self\n\n    @classmethod\n    def _init_ids(cls, obj):\n        with cls._next_instance_lock:\n            obj.ids = np.array(range(cls._next_instance_id, cls._next_instance_id + obj.X.shape[0]))\n            cls._next_instance_id += obj.X.shape[0]\n\n    @classmethod\n    def new_id(cls):\n        with cls._next_instance_lock:\n            id = cls._next_instance_id\n            cls._next_instance_id += 1\n            return id\n\n    def to_pandas_dfs(self):\n        return Orange.data.pandas_compat.table_to_frames(self)\n\n    @staticmethod\n    def from_pandas_dfs(xdf, ydf, mdf):\n        return Orange.data.pandas_compat.table_from_frames(xdf, ydf, mdf)\n\n    @property\n    def X_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.Attribute\n        )\n\n    @X_df.setter\n    def X_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.Attribute\n        )\n\n    @property\n    def Y_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.ClassAttribute\n        )\n\n    @Y_df.setter\n    def Y_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.ClassAttribute\n        )\n\n    @property\n    def metas_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.Meta\n        )\n\n    @metas_df.setter\n    def metas_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.Meta\n        )\n\n    def save(self, filename):\n        \"\"\"\n        Save a data table to a file. The path can be absolute or relative.\n\n        :param filename: File name\n        :type filename: str\n        \"\"\"\n        ext = os.path.splitext(filename)[1]\n        from Orange.data.io import FileFormat\n        writer = FileFormat.writers.get(ext)\n        if not writer:\n            desc = FileFormat.names.get(ext)\n            if desc:\n                raise IOError(\n                    \"Writing of {}s is not supported\".format(desc.lower()))\n            else:\n                raise IOError(\"Unknown file name extension.\")\n        writer.write_file(filename, self)\n\n    @classmethod\n    def from_file(cls, filename, sheet=None):\n        \"\"\"\n        Read a data table from a file. The path can be absolute or relative.\n\n        :param filename: File name\n        :type filename: str\n        :param sheet: Sheet in a file (optional)\n        :type sheet: str\n        :return: a new data table\n        :rtype: Orange.data.Table\n        \"\"\"\n        from Orange.data.io import FileFormat\n\n        absolute_filename = FileFormat.locate(filename, dataset_dirs)\n        reader = FileFormat.get_reader(absolute_filename)\n        reader.select_sheet(sheet)\n        data = reader.read()\n\n        # Readers return plain table. Make sure to cast it to appropriate\n        # (subclass) type\n        if cls != data.__class__:\n            data = cls(data)\n\n        # no need to call _init_ids as fuctions from .io already\n        # construct a table with .ids\n\n        data.__file__ = absolute_filename\n        return data\n\n    @classmethod\n    def from_url(cls, url):\n        from Orange.data.io import UrlReader\n        reader = UrlReader(url)\n        data = reader.read()\n        if cls != data.__class__:\n            data = cls(data)\n        return data\n\n    # Helper function for __setitem__:\n    # Set the row of table data matrices\n    # noinspection PyProtectedMember\n    def _set_row(self, example, row):\n        # pylint: disable=protected-access\n        domain = self.domain\n        if isinstance(example, Instance):\n            if example.domain == domain:\n                self.X[row] = example._x\n                if self._Y.ndim == 1:\n                    self._Y[row] = float(example._y)\n                else:\n                    self._Y[row] = np.atleast_1d(example._y)\n                self.metas[row] = example._metas\n                return\n\n            self.X[row], self._Y[row], self.metas[row] = \\\n                self.domain.convert(example)\n            try:\n                self.ids[row] = example.id\n            except:\n                with type(self)._next_instance_lock:\n                    self.ids[row] = type(self)._next_instance_id\n                    type(self)._next_instance_id += 1\n\n        else:\n            attrs = domain.attributes\n            if len(example) != len(domain.variables):\n                raise ValueError(\"invalid length\")\n            self._X[row] = [var.to_val(val) for var, val in zip(attrs, example)]\n            if self._Y.ndim == 1:\n                self._Y[row] = domain.class_var.to_val(example[len(attrs)])\n            else:\n                self._Y[row] = [var.to_val(val)\n                                for var, val in zip(domain.class_vars,\n                                                    example[len(attrs):])]\n            self.metas[row] = np.array([var.Unknown for var in domain.metas],\n                                       dtype=object)\n\n    def _check_all_dense(self):\n        return all(x in (Storage.DENSE, Storage.MISSING)\n                   for x in (self.X_density(), self.Y_density(),\n                             self.metas_density()))\n\n    def __getitem__(self, key):\n        if isinstance(key, Integral):\n            return RowInstance(self, key)\n        if not isinstance(key, tuple):\n            return self.from_table_rows(self, key)\n\n        if len(key) != 2:\n            raise IndexError(\"Table indices must be one- or two-dimensional\")\n\n        row_idx, col_idx = key\n        if isinstance(row_idx, Integral):\n            if isinstance(col_idx, (str, Integral, Variable)):\n                col_idx = self.domain.index(col_idx)\n                var = self.domain[col_idx]\n                if 0 <= col_idx < len(self.domain.attributes):\n                    val = self.X[row_idx, col_idx]\n                elif col_idx == len(self.domain.attributes) and self._Y.ndim == 1:\n                    val = self._Y[row_idx]\n                elif col_idx >= len(self.domain.attributes):\n                    val = self._Y[row_idx,\n                                  col_idx - len(self.domain.attributes)]\n                else:\n                    val = self.metas[row_idx, -1 - col_idx]\n                if isinstance(col_idx, DiscreteVariable) and var is not col_idx:\n                    val = col_idx.get_mapper_from(var)(val)\n                return Value(var, val)\n            else:\n                row_idx = [row_idx]\n\n        # multiple rows OR single row but multiple columns:\n        # construct a new table\n        attributes, col_indices = self.domain._compute_col_indices(col_idx)\n        if attributes is not None:\n            n_attrs = len(self.domain.attributes)\n            r_attrs = [attributes[i]\n                       for i, col in enumerate(col_indices)\n                       if 0 <= col < n_attrs]\n            r_classes = [attributes[i]\n                         for i, col in enumerate(col_indices)\n                         if col >= n_attrs]\n            r_metas = [attributes[i]\n                       for i, col in enumerate(col_indices) if col < 0]\n            domain = Domain(r_attrs, r_classes, r_metas)\n        else:\n            domain = self.domain\n        return self.from_table(domain, self, row_idx)\n\n    def __setitem__(self, key, value):\n        if not isinstance(key, tuple):\n            if isinstance(value, Real):\n                self.X[key, :] = value\n                return\n            self._set_row(value, key)\n            return\n\n        if len(key) != 2:\n            raise IndexError(\"Table indices must be one- or two-dimensional\")\n        row_idx, col_idx = key\n\n        # single row\n        if isinstance(row_idx, Integral):\n            if isinstance(col_idx, slice):\n                col_idx = range(*slice.indices(col_idx, self.X.shape[1]))\n            if not isinstance(col_idx, str) and isinstance(col_idx, Iterable):\n                col_idx = list(col_idx)\n            if not isinstance(col_idx, str) and isinstance(col_idx, Sized):\n                if isinstance(value, (Sequence, np.ndarray)):\n                    values = value\n                elif isinstance(value, Iterable):\n                    values = list(value)\n                else:\n                    raise TypeError(\"Setting multiple values requires a \"\n                                    \"sequence or numpy array\")\n                if len(values) != len(col_idx):\n                    raise ValueError(\"Invalid number of values\")\n            else:\n                col_idx, values = [col_idx], [value]\n            if isinstance(col_idx, DiscreteVariable) \\\n                    and self.domain[col_idx] != col_idx:\n                values = self.domain[col_idx].get_mapper_from(col_idx)(values)\n            for val, col_idx in zip(values, col_idx):\n                if not isinstance(val, Integral):\n                    val = self.domain[col_idx].to_val(val)\n                if not isinstance(col_idx, Integral):\n                    col_idx = self.domain.index(col_idx)\n                if col_idx >= 0:\n                    if col_idx < self.X.shape[1]:\n                        self.X[row_idx, col_idx] = val\n                    elif self._Y.ndim == 1 and col_idx == self.X.shape[1]:\n                        self._Y[row_idx] = val\n                    else:\n                        self._Y[row_idx, col_idx - self.X.shape[1]] = val\n                else:\n                    self.metas[row_idx, -1 - col_idx] = val\n\n        # multiple rows, multiple columns\n        attributes, col_indices = self.domain._compute_col_indices(col_idx)\n        if col_indices is ...:\n            col_indices = range(len(self.domain.variables))\n        n_attrs = self.X.shape[1]\n        if isinstance(value, str):\n            if not attributes:\n                attributes = self.domain.attributes\n            for var, col in zip(attributes, col_indices):\n                val = var.to_val(value)\n                if 0 <= col < n_attrs:\n                    self.X[row_idx, col] = val\n                elif col >= n_attrs:\n                    if self._Y.ndim == 1 and col == n_attrs:\n                        self._Y[row_idx] = val\n                    else:\n                        self._Y[row_idx, col - n_attrs] = val\n                else:\n                    self.metas[row_idx, -1 - col] = val\n        else:\n            attr_cols = np.fromiter(\n                (col for col in col_indices if 0 <= col < n_attrs), int)\n            class_cols = np.fromiter(\n                (col - n_attrs for col in col_indices if col >= n_attrs), int)\n            meta_cols = np.fromiter(\n                (-1 - col for col in col_indices if col < 0), int)\n            if value is None:\n                value = Unknown\n\n            if not isinstance(value, (Real, np.ndarray)) and \\\n                    (len(attr_cols) or len(class_cols)):\n                raise TypeError(\n                    \"Ordinary attributes can only have primitive values\")\n            if len(attr_cols):\n                self.X[row_idx, attr_cols] = value\n            if len(class_cols):\n                if self._Y.ndim == 1 and np.all(class_cols == 0):\n                    if isinstance(value, np.ndarray):\n                        yshape = self._Y[row_idx].shape\n                        if value.shape != yshape:\n                            value = value.reshape(yshape)\n                    self._Y[row_idx] = value\n                else:\n                    self._Y[row_idx, class_cols] = value\n            if len(meta_cols):\n                self.metas[row_idx, meta_cols] = value\n\n    def __len__(self):\n        return self.X.shape[0]\n\n    def __str__(self):\n        return \"[\" + \",\\n \".join(str(ex) for ex in self) + \"]\"\n\n    def __repr__(self):\n        head = 5\n        if self.is_sparse():\n            head = min(self.X.shape[0], head)\n        s = \"[\" + \",\\n \".join(repr(ex) for ex in self[:head])\n        if len(self) > head:\n            s += \",\\n ...\"\n        s += \"\\n]\"\n        return s\n\n    @classmethod\n    def concatenate(cls, tables, axis=0):\n        \"\"\"\n        Concatenate tables into a new table, either vertically or horizontally.\n\n        If axis=0 (vertical concatenate), all tables must have the same domain.\n\n        If axis=1 (horizontal),\n        - all variable names must be unique.\n        - ids are copied from the first table.\n        - weights are copied from the first table in which they are defined.\n        - the dictionary of table's attributes are merged. If the same attribute\n          appears in multiple dictionaries, the earlier are used.\n\n        Args:\n            tables (Table): tables to be joined\n\n        Returns:\n            table (Table)\n        \"\"\"\n        if axis not in (0, 1):\n            raise ValueError(\"invalid axis\")\n        if not tables:\n            raise ValueError('need at least one table to concatenate')\n\n        if len(tables) == 1:\n            return tables[0].copy()\n\n        if axis == 0:\n            conc = cls._concatenate_vertical(tables)\n        else:\n            conc = cls._concatenate_horizontal(tables)\n\n        # TODO: Add attributes = {} to __init__\n        conc.attributes = getattr(conc, \"attributes\", {})\n        for table in reversed(tables):\n            conc.attributes.update(table.attributes)\n\n        names = [table.name for table in tables if table.name != \"untitled\"]\n        if names:\n            conc.name = names[0]\n        return conc\n\n    @classmethod\n    def _concatenate_vertical(cls, tables):\n        def vstack(arrs):\n            return [np, sp][any(sp.issparse(arr) for arr in arrs)].vstack(arrs)\n\n        def merge1d(arrs):\n            arrs = list(arrs)\n            ydims = {arr.ndim for arr in arrs}\n            if ydims == {1}:\n                return np.hstack(arrs)\n            else:\n                return vstack([\n                    arr if arr.ndim == 2 else np.atleast_2d(arr).T\n                    for arr in arrs\n                ])\n\n        def collect(attr):\n            return [getattr(arr, attr) for arr in tables]\n\n        domain = tables[0].domain\n        if any(table.domain != domain for table in tables):\n            raise ValueError('concatenated tables must have the same domain')\n\n        conc = cls.from_numpy(\n            domain,\n            vstack(collect(\"X\")),\n            merge1d(collect(\"Y\")),\n            vstack(collect(\"metas\")),\n            merge1d(collect(\"W\"))\n        )\n        conc.ids = np.hstack([t.ids for t in tables])\n        return conc\n\n    @classmethod\n    def _concatenate_horizontal(cls, tables):\n        \"\"\"\n        \"\"\"\n        def all_of(objs, names):\n            return (tuple(getattr(obj, name) for obj in objs)\n                    for name in names)\n\n        def stack(arrs):\n            non_empty = tuple(arr if arr.ndim == 2 else arr[:, np.newaxis]\n                              for arr in arrs\n                              if arr is not None and arr.size > 0)\n            return np.hstack(non_empty) if non_empty else None\n\n        doms, Ws = all_of(tables, (\"domain\", \"W\"))\n        Xs, Ys, Ms = map(stack, all_of(tables, (\"X\", \"Y\", \"metas\")))\n        # pylint: disable=undefined-loop-variable\n        for W in Ws:\n            if W.size:\n                break\n\n        parts = all_of(doms, (\"attributes\", \"class_vars\", \"metas\"))\n        domain = Domain(*(tuple(chain(*lst)) for lst in parts))\n        return cls.from_numpy(domain, Xs, Ys, Ms, W, ids=tables[0].ids)\n\n    def add_column(self, variable, data, to_metas=None):\n        \"\"\"\n        Create a new table with an additional column\n\n        Column's name must be unique\n\n        Args:\n            variable (Variable): variable for the new column\n            data (np.ndarray): data for the new column\n            to_metas (bool, optional): if `True` the column is added as meta\n                column. Otherwise, primitive variables are added to attributes\n                and non-primitive to metas.\n\n        Returns:\n            table (Table): a new table with the additional column\n        \"\"\"\n        dom = self.domain\n        attrs, classes, metavars = dom.attributes, dom.class_vars, dom.metas\n        to_metas = to_metas or not variable.is_primitive()\n        if to_metas:\n            metavars += (variable, )\n        else:\n            attrs += (variable, )\n        domain = Domain(attrs, classes, metavars)\n        new_table = self.transform(domain)\n        with new_table.unlocked(new_table.metas if to_metas else new_table.X):\n            new_table.get_column_view(variable)[0][:] = data\n        return new_table\n\n    def is_view(self):\n        \"\"\"\n        Return `True` if all arrays represent a view referring to another table\n        \"\"\"\n        return ((not self._X.shape[-1] or self._X.base is not None) and\n                (not self._Y.shape[-1] or self._Y.base is not None) and\n                (not self._metas.shape[-1] or self._metas.base is not None) and\n                (not self._weights.shape[-1] or self._W.base is not None))\n\n    def is_copy(self):\n        \"\"\"\n        Return `True` if the table owns its data\n        \"\"\"\n        return ((not self._X.shape[-1] or self._X.base is None) and\n                (self._Y.base is None) and\n                (self._metas.base is None) and\n                (self._W.base is None))\n\n    def is_sparse(self):\n        \"\"\"\n        Return `True` if the table stores data in sparse format\n        \"\"\"\n        return any(sp.issparse(i) for i in [self._X, self._Y, self._metas])\n\n    def ensure_copy(self):\n        \"\"\"\n        Ensure that the table owns its data; copy arrays when necessary.\n        \"\"\"\n\n        def is_view(x):\n            # Sparse matrices don't have views like numpy arrays. Since indexing on\n            # them creates copies in constructor we can skip this check here.\n            return not sp.issparse(x) and x.base is not None\n\n        if is_view(self._X):\n            self._X = self._X.copy()\n        if is_view(self._Y):\n            self._Y = self._Y.copy()\n        if is_view(self._metas):\n            self._metas = self._metas.copy()\n        if is_view(self._W):\n            self._W = self._W.copy()\n\n    def copy(self):\n        \"\"\"\n        Return a copy of the table\n        \"\"\"\n        t = self.__class__(self)\n        t.ensure_copy()\n        return t\n\n    @staticmethod\n    def __determine_density(data):\n        if data is None:\n            return Storage.Missing\n        if data is not None and sp.issparse(data):\n            return Storage.SPARSE_BOOL if (data.data == 1).all() else Storage.SPARSE\n        else:\n            return Storage.DENSE\n\n    def X_density(self):\n        if not hasattr(self, \"_X_density\"):\n            self._X_density = self.__determine_density(self.X)\n        return self._X_density\n\n    def Y_density(self):\n        if not hasattr(self, \"_Y_density\"):\n            self._Y_density = self.__determine_density(self._Y)\n        return self._Y_density\n\n    def metas_density(self):\n        if not hasattr(self, \"_metas_density\"):\n            self._metas_density = self.__determine_density(self.metas)\n        return self._metas_density\n\n    def set_weights(self, weight=1):\n        \"\"\"\n        Set weights of data instances; create a vector of weights if necessary.\n        \"\"\"\n        if not self.W.shape[-1]:\n            self.W = np.empty(len(self))\n        self.W[:] = weight\n\n    def has_weights(self):\n        \"\"\"Return `True` if the data instances are weighed. \"\"\"\n        return self.W.shape[-1] != 0\n\n    def total_weight(self):\n        \"\"\"\n        Return the total weight of instances in the table, or their number if\n        they are unweighted.\n        \"\"\"\n        if self.W.shape[-1]:\n            return sum(self.W)\n        return len(self)\n\n    def has_missing(self):\n        \"\"\"Return `True` if there are any missing attribute or class values.\"\"\"\n        missing_x = not sp.issparse(self.X) and bn.anynan(self.X)  # do not check for sparse X\n        return missing_x or bn.anynan(self._Y)\n\n    def has_missing_attribute(self):\n        \"\"\"Return `True` if there are any missing attribute values.\"\"\"\n        return not sp.issparse(self.X) and bn.anynan(self.X)  # do not check for sparse X\n\n    def has_missing_class(self):\n        \"\"\"Return `True` if there are any missing class values.\"\"\"\n        return bn.anynan(self._Y)\n\n    def get_nan_frequency_attribute(self):\n        if self.X.size == 0:\n            return 0\n        return np.isnan(self.X).sum() / self.X.size\n\n    def get_nan_frequency_class(self):\n        if self.Y.size == 0:\n            return 0\n        return np.isnan(self._Y).sum() / self._Y.size\n\n    def checksum(self, include_metas=True):\n        # TODO: zlib.adler32 does not work for numpy arrays with dtype object\n        # (after pickling and unpickling such arrays, checksum changes)\n        # Why, and should we fix it or remove it?\n        \"\"\"Return a checksum over X, Y, metas and W.\"\"\"\n        cs = zlib.adler32(np.ascontiguousarray(self._X))\n        cs = zlib.adler32(np.ascontiguousarray(self._Y), cs)\n        if include_metas:\n            cs = zlib.adler32(np.ascontiguousarray(self._metas), cs)\n        cs = zlib.adler32(np.ascontiguousarray(self._W), cs)\n        return cs\n\n    def shuffle(self):\n        \"\"\"Randomly shuffle the rows of the table.\"\"\"\n        if not self._check_all_dense():\n            raise ValueError(\"Rows of sparse data cannot be shuffled\")\n        ind = np.arange(self.X.shape[0])\n        np.random.shuffle(ind)\n        self.X = self.X[ind]\n        self._Y = self._Y[ind]\n        self.metas = self.metas[ind]\n        self.W = self.W[ind]\n\n    def get_column_view(self, index):\n        \"\"\"\n        Return a vector - as a view, not a copy - with a column of the table,\n        and a bool flag telling whether this column is sparse. Note that\n        vertical slicing of sparse matrices is inefficient.\n\n        :param index: the index of the column\n        :type index: int, str or Orange.data.Variable\n        :return: (one-dimensional numpy array, sparse)\n        \"\"\"\n\n        def rx(M):\n            if sp.issparse(M):\n                return np.asarray(M.todense())[:, 0], True\n            else:\n                return M, False\n\n        if isinstance(index, Integral):\n            col_index = index\n        else:\n            col_index = self.domain.index(index)\n        if col_index >= 0:\n            if col_index < self.X.shape[1]:\n                col = rx(self.X[:, col_index])\n            elif self._Y.ndim == 1 and col_index == self._X.shape[1]:\n                col = rx(self._Y)\n            else:\n                col = rx(self._Y[:, col_index - self.X.shape[1]])\n        else:\n            col = rx(self.metas[:, -1 - col_index])\n\n        if isinstance(index, DiscreteVariable) \\\n                and index.values != self.domain[col_index].values:\n            col = index.get_mapper_from(self.domain[col_index])(col[0]), col[1]\n            col[0].flags.writeable = False\n        return col\n\n    def _filter_is_defined(self, columns=None, negate=False):\n        # structure of function is obvious; pylint: disable=too-many-branches\n        def _sp_anynan(a):\n            return a.indptr[1:] != a[-1:] + a.shape[1]\n\n        if columns is None:\n            if sp.issparse(self.X):\n                remove = _sp_anynan(self.X)\n            else:\n                remove = bn.anynan(self.X, axis=1)\n            if sp.issparse(self._Y):\n                remove += _sp_anynan(self._Y)\n            else:\n                if self._Y.ndim == 1:\n                    remove += np.isnan(self._Y)\n                else:\n                    remove += bn.anynan(self._Y, axis=1)\n            if sp.issparse(self.metas):\n                remove += _sp_anynan(self._metas)\n            else:\n                for i, var in enumerate(self.domain.metas):\n                    col = self.metas[:, i].flatten()\n                    if var.is_primitive():\n                        remove += np.isnan(col.astype(float))\n                    else:\n                        remove += ~col.astype(bool)\n        else:\n            remove = np.zeros(len(self), dtype=bool)\n            for column in columns:\n                col, sparse = self.get_column_view(column)\n                if sparse:\n                    remove += col == 0\n                elif self.domain[column].is_primitive():\n                    remove += bn.anynan([col.astype(float)], axis=0)\n                else:\n                    remove += col.astype(bool)\n        retain = remove if negate else np.logical_not(remove)\n        return self.from_table_rows(self, retain)\n\n    def _filter_has_class(self, negate=False):\n        if sp.issparse(self._Y):\n            if negate:\n                retain = (self._Y.indptr[1:] !=\n                          self._Y.indptr[-1:] + self._Y.shape[1])\n            else:\n                retain = (self._Y.indptr[1:] ==\n                          self._Y.indptr[-1:] + self._Y.shape[1])\n        else:\n            if self._Y.ndim == 1:\n                retain = np.isnan(self._Y)\n            else:\n                retain = bn.anynan(self._Y, axis=1)\n            if not negate:\n                retain = np.logical_not(retain)\n        return self.from_table_rows(self, retain)\n\n    def _filter_same_value(self, column, value, negate=False):\n        if not isinstance(value, Real):\n            value = self.domain[column].to_val(value)\n        sel = self.get_column_view(column)[0] == value\n        if negate:\n            sel = np.logical_not(sel)\n        return self.from_table_rows(self, sel)\n\n    def _filter_values(self, filter):\n        selection = self._values_filter_to_indicator(filter)\n        return self.from_table(self.domain, self, selection)\n\n    def _values_filter_to_indicator(self, filter):\n        \"\"\"Return selection of rows matching the filter conditions\n\n        Handles conjunction/disjunction and negate modifiers\n\n        Parameters\n        ----------\n        filter: Values object containing the conditions\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        from Orange.data.filter import Values\n\n        if isinstance(filter, Values):\n            conditions = filter.conditions\n            conjunction = filter.conjunction\n        else:\n            conditions = [filter]\n            conjunction = True\n        if conjunction:\n            sel = np.ones(len(self), dtype=bool)\n        else:\n            sel = np.zeros(len(self), dtype=bool)\n\n        for f in conditions:\n            selection = self._filter_to_indicator(f)\n\n            if conjunction:\n                sel *= selection\n            else:\n                sel += selection\n\n        if filter.negate:\n            sel = ~sel\n        return sel\n\n    def _filter_to_indicator(self, filter):\n        \"\"\"Return selection of rows that match the condition.\n\n        Parameters\n        ----------\n        filter: ValueFilter describing the condition\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        from Orange.data.filter import (\n            FilterContinuous, FilterDiscrete, FilterRegex, FilterString,\n            FilterStringList, IsDefined, Values\n        )\n        if isinstance(filter, Values):\n            return self._values_filter_to_indicator(filter)\n\n        def get_col_indices():\n            cols = chain(self.domain.variables, self.domain.metas)\n            if isinstance(filter, IsDefined):\n                if filter.columns is not None:\n                    return list(filter.columns)\n                else:\n                    return list(cols)\n\n            if filter.column is not None:\n                return [filter.column]\n\n            if isinstance(filter, FilterDiscrete):\n                raise ValueError(\"Discrete filter can't be applied across rows\")\n            if isinstance(filter, FilterContinuous):\n                return [col for col in cols if col.is_continuous]\n            if isinstance(filter,\n                          (FilterString, FilterStringList, FilterRegex)):\n                return [col for col in cols if col.is_string]\n            raise TypeError(\"Invalid filter\")\n\n        def col_filter(col_idx):\n            col = self.get_column_view(col_idx)[0]\n            if isinstance(filter, IsDefined):\n                if self.domain[col_idx].is_primitive():\n                    return ~np.isnan(col.astype(float))\n                else:\n                    return col.astype(bool)\n            if isinstance(filter, FilterDiscrete):\n                return self._discrete_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterContinuous):\n                return self._continuous_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterString):\n                return self._string_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterStringList):\n                if not filter.case_sensitive:\n                    col = np.char.lower(np.array(col, dtype=str))\n                    vals = [val.lower() for val in filter.values]\n                else:\n                    vals = filter.values\n                return reduce(operator.add, (col == val for val in vals))\n            if isinstance(filter, FilterRegex):\n                return np.vectorize(filter)(col)\n            raise TypeError(\"Invalid filter\")\n\n        col_indices = get_col_indices()\n        if len(col_indices) == 1:\n            sel = col_filter(col_indices[0])\n        else:\n            sel = np.ones(len(self), dtype=bool)\n            for col_idx in col_indices:\n                sel *= col_filter(col_idx)\n\n        if isinstance(filter, IsDefined) and filter.negate:\n            sel = ~sel\n        return sel\n\n    def _discrete_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given discrete filter.\n\n        Parameters\n        ----------\n        filter: FilterDiscrete\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.values is None:  # <- is defined filter\n            col = col.astype(float)\n            return ~np.isnan(col)\n\n        sel = np.zeros(len(self), dtype=bool)\n        for val in filter.values:\n            if not isinstance(val, Real):\n                val = self.domain[filter.column].to_val(val)\n            sel += (col == val)\n        return sel\n\n    def _continuous_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given continuous filter.\n\n        Parameters\n        ----------\n        filter: FilterContinuous\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.oper == filter.IsDefined:\n            col = col.astype(float)\n            return ~np.isnan(col)\n\n        return self._range_filter_to_indicator(filter, col, filter.min, filter.max)\n\n    def _string_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given string filter.\n\n        Parameters\n        ----------\n        filter: FilterString\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.oper == filter.IsDefined:\n            return col.astype(bool)\n\n        col = col.astype(str)\n        fmin = filter.min or \"\"\n        fmax = filter.max or \"\"\n\n        if not filter.case_sensitive:\n            # convert all to lower case\n            col = np.char.lower(col)\n            fmin = fmin.lower()\n            fmax = fmax.lower()\n\n        if filter.oper == filter.Contains:\n            return np.fromiter((fmin in e for e in col),\n                               dtype=bool)\n        if filter.oper == filter.StartsWith:\n            return np.fromiter((e.startswith(fmin) for e in col),\n                               dtype=bool)\n        if filter.oper == filter.EndsWith:\n            return np.fromiter((e.endswith(fmin) for e in col),\n                               dtype=bool)\n\n        return self._range_filter_to_indicator(filter, col, fmin, fmax)\n\n    @staticmethod\n    def _range_filter_to_indicator(filter, col, fmin, fmax):\n        with np.errstate(invalid=\"ignore\"):  # nan's are properly discarded\n            if filter.oper == filter.Equal:\n                return col == fmin\n            if filter.oper == filter.NotEqual:\n                return col != fmin\n            if filter.oper == filter.Less:\n                return col < fmin\n            if filter.oper == filter.LessEqual:\n                return col <= fmin\n            if filter.oper == filter.Greater:\n                return col > fmin\n            if filter.oper == filter.GreaterEqual:\n                return col >= fmin\n            if filter.oper == filter.Between:\n                return (col >= fmin) * (col <= fmax)\n            if filter.oper == filter.Outside:\n                return (col < fmin) + (col > fmax)\n\n            raise TypeError(\"Invalid operator\")\n\n    def _compute_basic_stats(self, columns=None,\n                             include_metas=False, compute_variance=False):\n        if compute_variance:\n            raise NotImplementedError(\"computation of variance is \"\n                                      \"not implemented yet\")\n        W = self._W if self.has_weights() else None\n        rr = []\n        stats = []\n        if not columns:\n            if self.domain.attributes:\n                rr.append(fast_stats(self._X, W))\n            if self.domain.class_vars:\n                rr.append(fast_stats(self._Y, W))\n            if include_metas and self.domain.metas:\n                rr.append(fast_stats(self.metas, W))\n            if len(rr):\n                stats = np.vstack(tuple(rr))\n        else:\n            nattrs = len(self.domain.attributes)\n            for column in columns:\n                c = self.domain.index(column)\n                if 0 <= c < nattrs:\n                    S = fast_stats(self._X[:, [c]], W and W[:, [c]])\n                elif c >= nattrs:\n                    if self._Y.ndim == 1 and c == nattrs:\n                        S = fast_stats(self._Y[:, None], W and W[:, None])\n                    else:\n                        S = fast_stats(self._Y[:, [c - nattrs]], W and W[:, [c - nattrs]])\n                else:\n                    S = fast_stats(self._metas[:, [-1 - c]], W and W[:, [-1 - c]])\n                stats.append(S[0])\n        return stats\n\n    def _compute_distributions(self, columns=None):\n        if columns is None:\n            columns = range(len(self.domain.variables))\n        else:\n            columns = [self.domain.index(var) for var in columns]\n\n        distributions = []\n        X = self.X\n        if sp.issparse(X):\n            X = X.tocsc()\n\n\n        W = self.W.ravel() if self.has_weights() else None\n\n        for col in columns:\n            variable = self.domain[col]\n\n            # Select the correct data column from X, Y or metas\n            if 0 <= col < X.shape[1]:\n                x = X[:, col]\n            elif col < 0:\n                x = self.metas[:, col * (-1) - 1]\n                if np.issubdtype(x.dtype, np.dtype(object)):\n                    x = x.astype(float)\n            elif self._Y.ndim == 1 and col == X.shape[1]:\n                x = self._Y\n            else:\n                x = self._Y[:, col - X.shape[1]]\n\n            if variable.is_discrete:\n                dist, unknowns = bincount(x, weights=W, max_val=len(variable.values) - 1)\n            elif not x.shape[0]:\n                dist, unknowns = np.zeros((2, 0)), 0\n            else:\n                if W is not None:\n                    if sp.issparse(x):\n                        arg_sort = np.argsort(x.data)\n                        ranks = x.indices[arg_sort]\n                        vals = np.vstack((x.data[arg_sort], W[ranks]))\n                    else:\n                        ranks = np.argsort(x)\n                        vals = np.vstack((x[ranks], W[ranks]))\n                else:\n                    x_values = x.data if sp.issparse(x) else x\n                    vals = np.ones((2, x_values.shape[0]))\n                    vals[0, :] = x_values\n                    vals[0, :].sort()\n\n                dist = np.array(_valuecount.valuecount(vals))\n                # If sparse, then 0s will not be counted with `valuecount`, so\n                # we have to add them to the result manually.\n                if sp.issparse(x) and sparse_has_implicit_zeros(x):\n                    if W is not None:\n                        zero_weights = sparse_implicit_zero_weights(x, W).sum()\n                    else:\n                        zero_weights = sparse_count_implicit_zeros(x)\n                    zero_vec = [0, zero_weights]\n                    dist = np.insert(dist, np.searchsorted(dist[0], 0), zero_vec, axis=1)\n                # Since `countnans` assumes vector shape to be (1, n) and `x`\n                # shape is (n, 1), we pass the transpose\n                unknowns = countnans(x.T, W)\n            distributions.append((dist, unknowns))\n\n        return distributions\n\n    def _compute_contingency(self, col_vars=None, row_var=None):\n        n_atts = self.X.shape[1]\n\n        if col_vars is None:\n            col_vars = range(len(self.domain.variables))\n        else:\n            col_vars = [self.domain.index(var) for var in col_vars]\n        if row_var is None:\n            row_var = self.domain.class_var\n            if row_var is None:\n                raise ValueError(\"No row variable\")\n\n        row_desc = self.domain[row_var]\n        if not row_desc.is_discrete:\n            raise TypeError(\"Row variable must be discrete\")\n        row_indi = self.domain.index(row_var)\n        n_rows = len(row_desc.values)\n        if 0 <= row_indi < n_atts:\n            row_data = self.X[:, row_indi]\n        elif row_indi < 0:\n            row_data = self.metas[:, -1 - row_indi]\n        elif self._Y.ndim == 1 and row_indi == n_atts:\n            row_data = self._Y\n        else:\n            row_data = self._Y[:, row_indi - n_atts]\n\n        W = self.W if self.has_weights() else None\n\n        col_desc = [self.domain[var] for var in col_vars]\n        col_indi = [self.domain.index(var) for var in col_vars]\n\n        if any(not (var.is_discrete or var.is_continuous)\n               for var in col_desc):\n            raise ValueError(\"Contingency can be computed only for categorical \"\n                             \"and numeric values.\")\n\n        # when we select a column in sparse matrix it is still two dimensional\n        # and sparse - since it is just a column we can afford to transform\n        # it to dense and make it 1D\n        if issparse(row_data):\n            row_data = row_data.toarray().ravel()\n        if row_data.dtype.kind != \"f\":  # meta attributes can be stored as type object\n            row_data = row_data.astype(float)\n\n        contingencies = [None] * len(col_desc)\n        for arr, f_cond, f_ind in (\n                (self.X, lambda i: 0 <= i < n_atts, lambda i: i),\n                (self._Y, lambda i: i >= n_atts, lambda i: i - n_atts),\n                (self.metas, lambda i: i < 0, lambda i: -1 - i)):\n\n            arr_indi = [e for e, ind in enumerate(col_indi) if f_cond(ind)]\n\n            vars = [(e, f_ind(col_indi[e]), col_desc[e]) for e in arr_indi]\n            disc_vars = [v for v in vars if v[2].is_discrete]\n            if disc_vars:\n                if sp.issparse(arr):\n                    max_vals = max(len(v[2].values) for v in disc_vars)\n                    disc_indi = {i for _, i, _ in disc_vars}\n                    mask = [i in disc_indi for i in range(arr.shape[1])]\n                    conts, nans_cols, nans_rows, nans = contingency(\n                        arr, row_data, max_vals - 1, n_rows - 1, W, mask)\n                    for col_i, arr_i, var in disc_vars:\n                        n_vals = len(var.values)\n                        contingencies[col_i] = (\n                            conts[arr_i][:, :n_vals], nans_cols[arr_i],\n                            nans_rows[arr_i], nans[arr_i])\n                else:\n                    for col_i, arr_i, var in disc_vars:\n                        col = arr if arr.ndim == 1 else arr[:, arr_i]\n                        contingencies[col_i] = contingency(\n                            col.astype(float),\n                            row_data, len(var.values) - 1, n_rows - 1, W)\n\n            cont_vars = [v for v in vars if v[2].is_continuous]\n            if cont_vars:\n                W_ = None\n                if W is not None:\n                    W_ = W.astype(dtype=np.float64)\n                if sp.issparse(arr):\n                    arr = sp.csc_matrix(arr)\n\n                for col_i, arr_i, _ in cont_vars:\n                    if sp.issparse(arr):\n                        col_data = arr.data[arr.indptr[arr_i]:arr.indptr[arr_i + 1]]\n                        rows = arr.indices[arr.indptr[arr_i]:arr.indptr[arr_i + 1]]\n                        W_ = None if W_ is None else W_[rows]\n                        classes_ = row_data[rows]\n                    else:\n                        col_data, W_, classes_ = arr[:, arr_i], W_, row_data\n\n                    col_data = col_data.astype(dtype=np.float64)\n                    contingencies[col_i] = _contingency.contingency_floatarray(\n                        col_data, classes_, n_rows, W_)\n\n        return contingencies\n\n    @classmethod\n    def transpose(cls, table, feature_names_column=\"\",\n                  meta_attr_name=\"Feature name\", feature_name=\"Feature\",\n                  remove_redundant_inst=False, progress_callback=None):\n        \"\"\"\n        Transpose the table.\n\n        :param table: Table - table to transpose\n        :param feature_names_column: str - name of (String) meta attribute to\n            use for feature names\n        :param meta_attr_name: str - name of new meta attribute into which\n            feature names are mapped\n        :param feature_name: str - default feature name prefix\n        :param remove_redundant_inst: bool - remove instance that\n            represents feature_names_column\n        :param progress_callback: callable - to report the progress\n        :return: Table - transposed table\n        \"\"\"\n        if progress_callback is None:\n            progress_callback = dummy_callback\n        progress_callback(0, \"Transposing...\")\n\n        if isinstance(feature_names_column, Variable):\n            feature_names_column = feature_names_column.name\n\n        self = cls()\n        n_cols, self.n_rows = table.X.shape\n        old_domain = table.attributes.get(\"old_domain\")\n        table_domain_attributes = list(table.domain.attributes)\n        attr_index = None\n        if remove_redundant_inst:\n            attr_names = [a.name for a in table_domain_attributes]\n            if feature_names_column and feature_names_column in attr_names:\n                attr_index = attr_names.index(feature_names_column)\n                self.n_rows = self.n_rows - 1\n                table_domain_attributes.remove(\n                    table_domain_attributes[attr_index])\n\n        # attributes\n        # - classes and metas to attributes of attributes\n        # - arbitrary meta column to feature names\n        with self.unlocked():\n            self.X = table.X.T\n            if attr_index is not None:\n                self.X = np.delete(self.X, attr_index, 0)\n            if feature_names_column:\n                names = [str(row[feature_names_column]) for row in table]\n                progress_callback(0.1)\n                names = get_unique_names_duplicates(names)\n                progress_callback(0.3)\n                attributes = [ContinuousVariable(name) for name in names]\n            else:\n                places = int(np.ceil(np.log10(n_cols))) if n_cols else 1\n                attributes = [ContinuousVariable(f\"{feature_name} {i:0{places}}\")\n                              for i in range(1, n_cols + 1)]\n            progress_callback(0.4)\n\n            if old_domain is not None and feature_names_column:\n                for i, _ in enumerate(attributes):\n                    if attributes[i].name in old_domain:\n                        var = old_domain[attributes[i].name]\n                        attr = ContinuousVariable(var.name) if var.is_continuous \\\n                            else DiscreteVariable(var.name, var.values)\n                        attr.attributes = var.attributes.copy()\n                        attributes[i] = attr\n\n            def set_attributes_of_attributes(_vars, _table):\n                for i, variable in enumerate(_vars):\n                    if variable.name == feature_names_column:\n                        continue\n                    for j, row in enumerate(_table):\n                        value = variable.repr_val(row) if np.isscalar(row) \\\n                            else row[i] if isinstance(row[i], str) \\\n                            else variable.repr_val(row[i])\n\n                        if value not in MISSING_VALUES:\n                            attributes[j].attributes[variable.name] = value\n\n            set_attributes_of_attributes(table.domain.class_vars, table.Y)\n            progress_callback(0.5)\n            set_attributes_of_attributes(table.domain.metas, table.metas)\n\n            # weights\n            self.W = np.empty((self.n_rows, 0))\n\n            def get_table_from_attributes_of_attributes(_vars, _dtype=float):\n                T = np.empty((self.n_rows, len(_vars)), dtype=_dtype)\n                for i, _attr in enumerate(table_domain_attributes):\n                    for j, _var in enumerate(_vars):\n                        val = str(_attr.attributes.get(_var.name, \"\"))\n                        if not _var.is_string:\n                            val = np.nan if val in MISSING_VALUES else \\\n                                _var.values.index(val) if \\\n                                    _var.is_discrete else float(val)\n                        T[i, j] = val\n                return T\n\n            # class_vars - attributes of attributes to class - from old domain\n            class_vars = []\n            if old_domain is not None:\n                class_vars = old_domain.class_vars\n            self.Y = get_table_from_attributes_of_attributes(class_vars)\n\n            # metas\n            # - feature names and attributes of attributes to metas\n            self.metas, metas = np.empty((self.n_rows, 0), dtype=object), []\n            if meta_attr_name not in [m.name for m in table.domain.metas] and \\\n                    table_domain_attributes:\n                self.metas = np.array([[a.name] for a in table_domain_attributes],\n                                      dtype=object)\n                metas.append(StringVariable(meta_attr_name))\n\n            names = chain.from_iterable(list(attr.attributes)\n                                        for attr in table_domain_attributes)\n            names = sorted(set(names) - {var.name for var in class_vars})\n            progress_callback(0.6)\n\n            def guessed_var(i, var_name):\n                orig_vals = M[:, i]\n                val_map, vals, var_type = Orange.data.io.guess_data_type(orig_vals)\n                values, variable = Orange.data.io.sanitize_variable(\n                    val_map, vals, orig_vals, var_type, {}, name=var_name)\n                M[:, i] = values\n                return variable\n\n            _metas = [StringVariable(n) for n in names]\n            if old_domain is not None:\n                _metas = [m for m in old_domain.metas if m.name != meta_attr_name]\n            M = get_table_from_attributes_of_attributes(_metas, _dtype=object)\n            progress_callback(0.7)\n            if old_domain is None:\n                _metas = [guessed_var(i, m.name) for i, m in enumerate(_metas)]\n            if _metas:\n                self.metas = np.hstack((self.metas, M))\n                metas.extend(_metas)\n\n            self.domain = Domain(attributes, class_vars, metas)\n            progress_callback(0.9)\n            cls._init_ids(self)\n            self.attributes = table.attributes.copy()\n            self.attributes[\"old_domain\"] = table.domain\n            progress_callback(1)\n            return self\n\n    def to_sparse(self, sparse_attributes=True, sparse_class=False,\n                  sparse_metas=False):\n        def sparsify(features):\n            for f in features:\n                f.sparse = True\n\n        new_domain = self.domain.copy()\n\n        if sparse_attributes:\n            sparsify(new_domain.attributes)\n        if sparse_class:\n            sparsify(new_domain.class_vars)\n        if sparse_metas:\n            sparsify(new_domain.metas)\n        return self.transform(new_domain)\n\n    def to_dense(self, dense_attributes=True, dense_class=True,\n                 dense_metas=True):\n        def densify(features):\n            for f in features:\n                f.sparse = False\n\n        new_domain = self.domain.copy()\n\n        if dense_attributes:\n            densify(new_domain.attributes)\n        if dense_class:\n            densify(new_domain.class_vars)\n        if dense_metas:\n            densify(new_domain.metas)\n        t = self.transform(new_domain)\n        t.ids = self.ids  # preserve indices\n        return t",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 361,
                                "end_lineno": 2227,
                                "parent": null
                            }
                        }
                    ],
                    "added_entities": [
                        {
                            "file_name": "Orange/data/table.py",
                            "type": "method",
                            "name": "Table.__getstate__",
                            "content": "class Table(Sequence, Storage):\n\n    LOCKING = None\n    \"\"\" If the class attribute LOCKING is True, tables will throw exceptions\n    on in-place modifications unless unlocked explicitly. LOCKING is supposed\n    to be set to True for testing to help us find bugs. If set to False\n    or None, no safeguards are in place. Two different values are used for\n    the same behaviour to distinguish the unchanged default (None) form\n    explicit deactivation (False) that some add-ons might need. \"\"\"\n\n    __file__ = None\n    name = \"untitled\"\n\n    domain = Domain([])\n    _X = _Y = _metas = _W = np.zeros((0, 0))  # pylint: disable=invalid-name\n    ids = np.zeros(0)\n    ids.setflags(write=False)\n    attributes = frozendict()\n\n    _Unlocked_X, _Unlocked_Y, _Unlocked_metas, _Unlocked_W = 1, 2, 4, 8\n    _unlocked = _Unlocked_X + _Unlocked_Y + \\\n                _Unlocked_metas + _Unlocked_W  # pylint: disable=invalid-name\n\n    @property\n    def columns(self):\n        \"\"\"\n        A class whose attributes contain attribute descriptors for columns.\n        For a table `table`, setting `c = table.columns` will allow accessing\n        the table's variables with, for instance `c.gender`, `c.age` ets.\n        Spaces are replaced with underscores.\n        \"\"\"\n        return Columns(self.domain)\n\n    _next_instance_id = 0\n    _next_instance_lock = Lock()\n\n    def _check_unlocked(self, partflag):\n        if not self._unlocked & partflag:\n            raise ValueError(\"Table is read-only unless unlocked\")\n\n    @property\n    def X(self):  # pylint: disable=invalid-name\n        return self._X\n\n    @X.setter\n    def X(self, value):\n        self._check_unlocked(self._Unlocked_X)\n        self._X = _dereferenced(value)\n\n    @property\n    def Y(self):  # pylint: disable=invalid-name\n        return self._Y\n\n    @Y.setter\n    def Y(self, value):\n        self._check_unlocked(self._Unlocked_Y)\n        if sp.issparse(value) and len(self) != value.shape[0]:\n            value = value.T\n        if sp.issparse(value):\n            value = _dereferenced(value.toarray())\n        if value.ndim == 2 and value.shape[1] == 1:\n            value = value[:, 0].copy()  # no views!\n        self._Y = value\n\n    @property\n    def metas(self):\n        return self._metas\n\n    @metas.setter\n    def metas(self, value):\n        self._check_unlocked(self._Unlocked_metas)\n        self._metas = _dereferenced(value)\n\n    @property\n    def W(self):  # pylint: disable=invalid-name\n        return self._W\n\n    @W.setter\n    def W(self, value):\n        self._check_unlocked(self._Unlocked_W)\n        self._W = value\n\n    def __setstate__(self, state):\n        # Backward compatibility with pickles before table locking\n        self._initialize_unlocked()  # __dict__ seems to be cleared before calling __setstate__\n        with self.unlocked():\n            for k in (\"X\", \"W\", \"metas\"):\n                if k in state:\n                    setattr(self, k, state.pop(k))\n            if \"_Y\" in state:\n                setattr(self, \"Y\", state.pop(\"_Y\"))  # state[\"_Y\"] is a 2d array\n            self.__dict__.update(state)\n\n    def __getstate__(self):\n        # Compatibility with pickles before table locking:\n        # return the same state as before table lock\n        state = self.__dict__.copy()\n        for k in [\"X\", \"metas\", \"W\"]:\n            if \"_\" + k in state:  # Check existence; SQL tables do not contain them\n                state[k] = state.pop(\"_\" + k)\n        # before locking, _Y was always a 2d array: save it as such\n        if \"_Y\" in state:\n            y = state.pop(\"_Y\")\n            y2d = y.reshape(-1, 1) if y.ndim == 1 else y\n            state[\"_Y\"] = y2d\n        return state\n\n    def _lock_parts(self):\n        return ((self._X, self._Unlocked_X, \"X\"),\n                (self._Y, self._Unlocked_Y, \"Y\"),\n                (self._metas, self._Unlocked_metas, \"metas\"),\n                (self._W, self._Unlocked_W, \"weights\"))\n\n    def _initialize_unlocked(self):\n        if Table.LOCKING:\n            self._unlocked = 0\n        else:\n            self._unlocked = sum(f for _, f, _ in self._lock_parts())\n\n    def _update_locks(self, force=False, unlock_bases=()):\n        if not Table.LOCKING:\n            return\n\n        def sync(*xs):\n            for x in xs:\n                try:\n                    undo_on_fail.append((x, x.flags.writeable))\n                    x.flags.writeable = writeable\n                except ValueError:\n                    if force \\\n                            and writeable \\\n                            and x.base is not None \\\n                            and not x.base.flags.writeable:\n                        x.base.flags.writeable = writeable\n                        x.flags.writeable = writeable\n                        forced_bases.append(x.base)\n                    else:\n                        raise\n\n        forced_bases = []\n        undo_on_fail = []\n        for base in unlock_bases:\n            base.flags.writeable = False\n        try:\n            for part, flag, _ in self._lock_parts():\n                if part is None:\n                    continue\n                writeable = bool(self._unlocked & flag)\n                if sp.isspmatrix_csr(part) or sp.isspmatrix_csc(part):\n                    sync(part.data, part.indices, part.indptr)\n                elif sp.isspmatrix_coo(part):\n                    sync(part.data, part.row, part.col)\n                elif sp.issparse(part):\n                    raise ValueError(\"Unsupported sparse data type\")\n                else:\n                    sync(part)\n        except:\n            for part, flag in undo_on_fail:\n                part.flags.writeable = flag\n            raise\n        return tuple(forced_bases)\n\n    def __unlocked(self, *parts, force=False):\n        prev_state = self._unlocked\n        for part, flag, _ in self._lock_parts():\n            if not parts or any(ppart is part for ppart in parts):\n                self._unlocked |= flag\n        try:\n            forced_bases = self._update_locks(force)\n            yield\n        finally:\n            self._unlocked = prev_state\n            self._update_locks(unlock_bases=forced_bases)\n\n    def force_unlocked(self, *parts):\n        \"\"\"\n        Unlocking without any checks.\n\n        Use with extreme caution. This is meant primarily for 3rd party\n        functions in Cython that expect read-write buffer, but do not\n        actually modify it. the given parts (default: all parts) of the table.\n\n        The function will still fail to unlock and raise an exception if the\n        table contains view to another table.\n        \"\"\"\n        return contextmanager(self.__unlocked)(*parts, force=True)\n\n    def unlocked(self, *parts):\n        \"\"\"\n        Unlock the given parts (default: all parts) of the table.\n\n        The caller must ensure that the table is safe to modify. The function\n        will raise an exception if the table contains view to other table.\n        \"\"\"\n        def can_unlock(x):\n            if sp.issparse(x):\n                return can_unlock(x.data)\n            return x.flags.writeable or x.flags.owndata\n\n        for part, flag, name in self._lock_parts():\n            if not flag & self._unlocked \\\n                    and (not parts or any(ppart is part for ppart in parts)) \\\n                    and part is not None and not can_unlock(part):\n                raise ValueError(f\"'{name}' is a view into another table \"\n                                 \"and cannot be unlocked\")\n        return contextmanager(self.__unlocked)(*parts)\n\n    def __new__(cls, *args, **kwargs):\n        def warn_deprecated(method):\n            warnings.warn(\"Direct calls to Table's constructor are deprecated \"\n                          \"and will be removed. Replace this call with \"\n                          f\"Table.{method}\", OrangeDeprecationWarning,\n                          stacklevel=3)\n\n        if not args:\n            if not kwargs:\n                return super().__new__(cls)\n            else:\n                raise TypeError(\"Table() must not be called directly\")\n\n        if isinstance(args[0], str):\n            if len(args) > 1:\n                raise TypeError(\"Table(name: str) expects just one argument\")\n            if args[0].startswith('https://') or args[0].startswith('http://'):\n                return cls.from_url(args[0], **kwargs)\n            else:\n                return cls.from_file(args[0], **kwargs)\n\n        elif isinstance(args[0], Table):\n            if len(args) > 1:\n                raise TypeError(\"Table(table: Table) expects just one argument\")\n            return cls.from_table(args[0].domain, args[0], **kwargs)\n        elif isinstance(args[0], Domain):\n            domain, args = args[0], args[1:]\n            if not args:\n                warn_deprecated(\"from_domain\")\n                return cls.from_domain(domain, **kwargs)\n            if isinstance(args[0], Table):\n                warn_deprecated(\"from_table\")\n                return cls.from_table(domain, *args, **kwargs)\n            elif isinstance(args[0], list):\n                warn_deprecated(\"from_list\")\n                return cls.from_list(domain, *args, **kwargs)\n        else:\n            warnings.warn(\"Omitting domain in a call to Table(X, Y, metas), is \"\n                          \"deprecated and will be removed. \"\n                          \"Call Table.from_numpy(None, X, Y, metas) instead.\",\n                          OrangeDeprecationWarning, stacklevel=2)\n            domain = None\n\n        return cls.from_numpy(domain, *args, **kwargs)\n\n    def __init__(self, *args, **kwargs):  # pylint: disable=unused-argument\n        self._initialize_unlocked()\n        self._update_locks()\n\n    @classmethod\n    def from_domain(cls, domain, n_rows=0, weights=False):\n        \"\"\"\n        Construct a new `Table` with the given number of rows for the given\n        domain. The optional vector of weights is initialized to 1's.\n\n        :param domain: domain for the `Table`\n        :type domain: Orange.data.Domain\n        :param n_rows: number of rows in the new table\n        :type n_rows: int\n        :param weights: indicates whether to construct a vector of weights\n        :type weights: bool\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n        self = cls()\n        self.domain = domain\n        self.n_rows = n_rows\n        with self.unlocked():\n            self.X = np.zeros((n_rows, len(domain.attributes)))\n            if len(domain.class_vars) != 1:\n                self.Y = np.zeros((n_rows, len(domain.class_vars)))\n            else:\n                self.Y = np.zeros(n_rows)\n            if weights:\n                self.W = np.ones(n_rows)\n            else:\n                self.W = np.empty((n_rows, 0))\n            self.metas = np.empty((n_rows, len(self.domain.metas)), object)\n            cls._init_ids(self)\n            self.attributes = {}\n        return self\n\n    @classmethod\n    def from_table(cls, domain, source, row_indices=...):\n        \"\"\"\n        Create a new table from selected columns and/or rows of an existing\n        one. The columns are chosen using a domain. The domain may also include\n        variables that do not appear in the source table; they are computed\n        from source variables if possible.\n\n        The resulting data may be a view or a copy of the existing data.\n\n        :param domain: the domain for the new table\n        :type domain: Orange.data.Domain\n        :param source: the source table\n        :type source: Orange.data.Table\n        :param row_indices: indices of the rows to include\n        :type row_indices: a slice or a sequence\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n\n        PART = 5000\n\n        new_cache = _thread_local.conversion_cache is None\n        try:\n            if new_cache:\n                _thread_local.conversion_cache = {}\n                _thread_local.domain_cache = {}\n            else:\n                cached = _idcache_restore(_thread_local.conversion_cache, (domain, source))\n                if cached is not None:\n                    return cached\n            if domain is source.domain:\n                table = cls.from_table_rows(source, row_indices)\n                # assure resulting domain is the instance passed on input\n                table.domain = domain\n                # since sparse flags are not considered when checking for\n                # domain equality, fix manually.\n                with table.unlocked():\n                    table = assure_domain_conversion_sparsity(table, source)\n                return table\n\n            if row_indices is ...:\n                n_rows = len(source)\n            elif isinstance(row_indices, slice):\n                row_indices_range = range(*row_indices.indices(source.X.shape[0]))\n                n_rows = len(row_indices_range)\n            else:\n                n_rows = len(row_indices)\n\n            self = cls()\n            self.domain = domain\n\n            table_conversion = \\\n                _idcache_restore(_thread_local.domain_cache, (domain, source.domain))\n            if table_conversion is None:\n                table_conversion = _FromTableConversion(source.domain, domain)\n                _idcache_save(_thread_local.domain_cache, (domain, source.domain),\n                              table_conversion)\n\n            # if an array can be a subarray of the input table, this needs to be done\n            # on the whole table, because this avoids needless copies of contents\n\n            with self.unlocked():\n                for array_conv in table_conversion.subarray:\n                    out = array_conv.get_subarray(source, row_indices, n_rows)\n                    setattr(self, array_conv.target, out)\n\n                parts = {}\n\n                for array_conv in table_conversion.columnwise:\n                    if array_conv.is_sparse:\n                        parts[array_conv.target] = []\n                    else:\n                        # F-order enables faster writing to the array while accessing and\n                        # matrix operations work with same speed (e.g. dot)\n                        parts[array_conv.target] = \\\n                            np.zeros((n_rows, len(array_conv.src_cols)),\n                                     order=\"F\", dtype=array_conv.dtype)\n\n                if n_rows <= PART:\n                    for array_conv in table_conversion.columnwise:\n                        out = array_conv.get_columns(source, row_indices, n_rows,\n                                                     parts[array_conv.target],\n                                                     ...)\n                        setattr(self, array_conv.target, out)\n                else:\n                    i_done = 0\n\n                    while i_done < n_rows:\n                        target_indices = slice(i_done, min(n_rows, i_done + PART))\n                        if row_indices is ...:\n                            source_indices = target_indices\n                        elif isinstance(row_indices, slice):\n                            r = row_indices_range[target_indices]\n                            source_indices = slice(r.start, r.stop, r.step)\n                        else:\n                            source_indices = row_indices[target_indices]\n                        part_rows = min(n_rows, i_done+PART) - i_done\n\n                        for array_conv in table_conversion.columnwise:\n                            out = array_conv.get_columns(source, source_indices, part_rows,\n                                                         parts[array_conv.target],\n                                                         target_indices)\n                            if array_conv.is_sparse:  # dense arrays are populated in-place\n                                parts[array_conv.target].append(out)\n\n                        i_done += PART\n\n                        # clear cache after a part is done\n                        if new_cache:\n                            _thread_local.conversion_cache = {}\n\n                    for array_conv in table_conversion.columnwise:\n                        cparts = parts[array_conv.target]\n                        out = cparts if not array_conv.is_sparse else sp.vstack(cparts)\n                        setattr(self, array_conv.target, out)\n\n                if source.has_weights():\n                    self.W = source.W[row_indices]\n                else:\n                    self.W = np.empty((n_rows, 0))\n                self.name = getattr(source, 'name', '')\n                if hasattr(source, 'ids'):\n                    self.ids = source.ids[row_indices]\n                else:\n                    cls._init_ids(self)\n                self.attributes = getattr(source, 'attributes', {})\n                _idcache_save(_thread_local.conversion_cache, (domain, source), self)\n            return self\n        finally:\n            if new_cache:\n                _thread_local.conversion_cache = None\n                _thread_local.domain_cache = None\n\n    def transform(self, domain):\n        \"\"\"\n        Construct a table with a different domain.\n\n        The new table keeps the row ids and other information. If the table\n        is a subclass of :obj:`Table`, the resulting table will be of the same\n        type.\n\n        In a typical scenario, an existing table is augmented with a new\n        column by ::\n\n            domain = Domain(old_domain.attributes + [new_attribute],\n                            old_domain.class_vars,\n                            old_domain.metas)\n            table = data.transform(domain)\n            table[:, new_attribute] = new_column\n\n        Args:\n            domain (Domain): new domain\n\n        Returns:\n            A new table\n        \"\"\"\n        return type(self).from_table(domain, self)\n\n    @classmethod\n    def from_table_rows(cls, source, row_indices):\n        \"\"\"\n        Construct a new table by selecting rows from the source table.\n\n        :param source: an existing table\n        :type source: Orange.data.Table\n        :param row_indices: indices of the rows to include\n        :type row_indices: a slice or a sequence\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n        def get_rows(a):\n            a = a[row_indices]\n            if isinstance(row_indices, slice) or row_indices is ...:\n                a = a.copy()\n            return a\n\n        self = cls()\n        self.domain = source.domain\n        with self.unlocked():\n            self.X = get_rows(source.X)\n            if self.X.ndim == 1:\n                self.X = self.X.reshape(-1, len(self.domain.attributes))\n            self.Y = get_rows(source.Y)\n            self.metas = get_rows(source.metas)\n            if self.metas.ndim == 1:\n                self.metas = self.metas.reshape(-1, len(self.domain.metas))\n            self.W = get_rows(source.W)\n            self.name = getattr(source, 'name', '')\n            self.ids = np.array(source.ids[row_indices])\n            self.attributes = getattr(source, 'attributes', {})\n        return self\n\n    @classmethod\n    def from_numpy(cls, domain, X, Y=None, metas=None, W=None,\n                   attributes=None, ids=None):\n        \"\"\"\n        Construct a table from numpy arrays with the given domain. The number\n        of variables in the domain must match the number of columns in the\n        corresponding arrays. All arrays must have the same number of rows.\n        Arrays may be of different numpy types, and may be dense or sparse.\n\n        :param domain: the domain for the new table\n        :type domain: Orange.data.Domain\n        :param X: array with attribute values\n        :type X: np.array\n        :param Y: array with class values\n        :type Y: np.array\n        :param metas: array with meta attributes\n        :type metas: np.array\n        :param W: array with weights\n        :type W: np.array\n        :return:\n        \"\"\"\n        X, Y, W = _check_arrays(X, Y, W, dtype='float64')\n        metas, = _check_arrays(metas, dtype=object, shape_1=X.shape[0])\n        ids, = _check_arrays(ids, dtype=int, shape_1=X.shape[0])\n\n        if domain is None:\n            domain = Domain.from_numpy(X, Y, metas)\n\n        if Y is None:\n            if not domain.class_vars or sp.issparse(X):\n                Y = np.empty((X.shape[0], 0), dtype=np.float64)\n            else:\n                own_data = X.flags.owndata and X.base is None\n                Y = X[:, len(domain.attributes):]\n                X = X[:, :len(domain.attributes)]\n                if own_data:\n                    Y = Y.copy()\n                    X = X.copy()\n        if metas is None:\n            metas = np.empty((X.shape[0], 0), object)\n        if W is None or W.size == 0:\n            W = np.empty((X.shape[0], 0))\n        elif W.shape != (W.size, ):\n            W = W.reshape(W.size).copy()\n\n        if X.shape[1] != len(domain.attributes):\n            raise ValueError(\n                \"Invalid number of variable columns ({} != {})\".format(\n                    X.shape[1], len(domain.attributes))\n            )\n        if Y.ndim == 1:\n            if not domain.class_var:\n                raise ValueError(\n                    \"Invalid number of class columns \"\n                    f\"(1 != {len(domain.class_vars)})\")\n        elif Y.shape[1] != len(domain.class_vars):\n            raise ValueError(\n                \"Invalid number of class columns ({} != {})\".format(\n                    Y.shape[1], len(domain.class_vars))\n            )\n        if metas.shape[1] != len(domain.metas):\n            raise ValueError(\n                \"Invalid number of meta attribute columns ({} != {})\".format(\n                    metas.shape[1], len(domain.metas))\n            )\n        if not X.shape[0] == Y.shape[0] == metas.shape[0] == W.shape[0]:\n            raise ValueError(\n                \"Parts of data contain different numbers of rows.\")\n\n        self = cls()\n        with self.unlocked():\n            self.domain = domain\n            self.X = X\n            self.Y = Y\n            self.metas = metas\n            self.W = W\n            self.n_rows = self.X.shape[0]\n            if ids is None:\n                cls._init_ids(self)\n            else:\n                self.ids = ids\n            self.attributes = {} if attributes is None else attributes\n        return self\n\n    @classmethod\n    def from_list(cls, domain, rows, weights=None):\n        if weights is not None and len(rows) != len(weights):\n            raise ValueError(\"mismatching number of instances and weights\")\n        self = cls.from_domain(domain, len(rows), weights is not None)\n        all_vars = domain.variables + domain.metas\n        nattrs = len(domain.attributes)\n        nattrscls = len(domain.variables)\n        with self.unlocked():\n            for i, row in enumerate(rows):\n                if isinstance(row, Instance):\n                    row = row.list\n                vals = [var.to_val(val) for var, val in zip(all_vars, row)]\n                self.X[i] = vals[:nattrs]\n                if self._Y.ndim == 1:\n                    self._Y[i] = vals[nattrs] if nattrs < len(vals) else np.nan\n                else:\n                    self._Y[i] = vals[nattrs:nattrscls]\n                # for backward compatibility: allow omittine some (or all) metas\n                self.metas[i, :len(vals) - nattrscls] = vals[nattrscls:]\n            if weights is not None:\n                self.W = np.array(weights)\n            self.attributes = {}\n        return self\n\n    @classmethod\n    def _init_ids(cls, obj):\n        with cls._next_instance_lock:\n            obj.ids = np.array(range(cls._next_instance_id, cls._next_instance_id + obj.X.shape[0]))\n            cls._next_instance_id += obj.X.shape[0]\n\n    @classmethod\n    def new_id(cls):\n        with cls._next_instance_lock:\n            id = cls._next_instance_id\n            cls._next_instance_id += 1\n            return id\n\n    def to_pandas_dfs(self):\n        return Orange.data.pandas_compat.table_to_frames(self)\n\n    @staticmethod\n    def from_pandas_dfs(xdf, ydf, mdf):\n        return Orange.data.pandas_compat.table_from_frames(xdf, ydf, mdf)\n\n    @property\n    def X_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.Attribute\n        )\n\n    @X_df.setter\n    def X_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.Attribute\n        )\n\n    @property\n    def Y_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.ClassAttribute\n        )\n\n    @Y_df.setter\n    def Y_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.ClassAttribute\n        )\n\n    @property\n    def metas_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.Meta\n        )\n\n    @metas_df.setter\n    def metas_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.Meta\n        )\n\n    def save(self, filename):\n        \"\"\"\n        Save a data table to a file. The path can be absolute or relative.\n\n        :param filename: File name\n        :type filename: str\n        \"\"\"\n        ext = os.path.splitext(filename)[1]\n        from Orange.data.io import FileFormat\n        writer = FileFormat.writers.get(ext)\n        if not writer:\n            desc = FileFormat.names.get(ext)\n            if desc:\n                raise IOError(\n                    \"Writing of {}s is not supported\".format(desc.lower()))\n            else:\n                raise IOError(\"Unknown file name extension.\")\n        writer.write_file(filename, self)\n\n    @classmethod\n    def from_file(cls, filename, sheet=None):\n        \"\"\"\n        Read a data table from a file. The path can be absolute or relative.\n\n        :param filename: File name\n        :type filename: str\n        :param sheet: Sheet in a file (optional)\n        :type sheet: str\n        :return: a new data table\n        :rtype: Orange.data.Table\n        \"\"\"\n        from Orange.data.io import FileFormat\n\n        absolute_filename = FileFormat.locate(filename, dataset_dirs)\n        reader = FileFormat.get_reader(absolute_filename)\n        reader.select_sheet(sheet)\n        data = reader.read()\n\n        # Readers return plain table. Make sure to cast it to appropriate\n        # (subclass) type\n        if cls != data.__class__:\n            data = cls(data)\n\n        # no need to call _init_ids as fuctions from .io already\n        # construct a table with .ids\n\n        data.__file__ = absolute_filename\n        return data\n\n    @classmethod\n    def from_url(cls, url):\n        from Orange.data.io import UrlReader\n        reader = UrlReader(url)\n        data = reader.read()\n        if cls != data.__class__:\n            data = cls(data)\n        return data\n\n    # Helper function for __setitem__:\n    # Set the row of table data matrices\n    # noinspection PyProtectedMember\n    def _set_row(self, example, row):\n        # pylint: disable=protected-access\n        domain = self.domain\n        if isinstance(example, Instance):\n            if example.domain == domain:\n                self.X[row] = example._x\n                if self._Y.ndim == 1:\n                    self._Y[row] = float(example._y)\n                else:\n                    self._Y[row] = np.atleast_1d(example._y)\n                self.metas[row] = example._metas\n                return\n\n            self.X[row], self._Y[row], self.metas[row] = \\\n                self.domain.convert(example)\n            try:\n                self.ids[row] = example.id\n            except:\n                with type(self)._next_instance_lock:\n                    self.ids[row] = type(self)._next_instance_id\n                    type(self)._next_instance_id += 1\n\n        else:\n            attrs = domain.attributes\n            if len(example) != len(domain.variables):\n                raise ValueError(\"invalid length\")\n            self._X[row] = [var.to_val(val) for var, val in zip(attrs, example)]\n            if self._Y.ndim == 1:\n                self._Y[row] = domain.class_var.to_val(example[len(attrs)])\n            else:\n                self._Y[row] = [var.to_val(val)\n                                for var, val in zip(domain.class_vars,\n                                                    example[len(attrs):])]\n            self.metas[row] = np.array([var.Unknown for var in domain.metas],\n                                       dtype=object)\n\n    def _check_all_dense(self):\n        return all(x in (Storage.DENSE, Storage.MISSING)\n                   for x in (self.X_density(), self.Y_density(),\n                             self.metas_density()))\n\n    def __getitem__(self, key):\n        if isinstance(key, Integral):\n            return RowInstance(self, key)\n        if not isinstance(key, tuple):\n            return self.from_table_rows(self, key)\n\n        if len(key) != 2:\n            raise IndexError(\"Table indices must be one- or two-dimensional\")\n\n        row_idx, col_idx = key\n        if isinstance(row_idx, Integral):\n            if isinstance(col_idx, (str, Integral, Variable)):\n                col_idx = self.domain.index(col_idx)\n                var = self.domain[col_idx]\n                if 0 <= col_idx < len(self.domain.attributes):\n                    val = self.X[row_idx, col_idx]\n                elif col_idx == len(self.domain.attributes) and self._Y.ndim == 1:\n                    val = self._Y[row_idx]\n                elif col_idx >= len(self.domain.attributes):\n                    val = self._Y[row_idx,\n                                  col_idx - len(self.domain.attributes)]\n                else:\n                    val = self.metas[row_idx, -1 - col_idx]\n                if isinstance(col_idx, DiscreteVariable) and var is not col_idx:\n                    val = col_idx.get_mapper_from(var)(val)\n                return Value(var, val)\n            else:\n                row_idx = [row_idx]\n\n        # multiple rows OR single row but multiple columns:\n        # construct a new table\n        attributes, col_indices = self.domain._compute_col_indices(col_idx)\n        if attributes is not None:\n            n_attrs = len(self.domain.attributes)\n            r_attrs = [attributes[i]\n                       for i, col in enumerate(col_indices)\n                       if 0 <= col < n_attrs]\n            r_classes = [attributes[i]\n                         for i, col in enumerate(col_indices)\n                         if col >= n_attrs]\n            r_metas = [attributes[i]\n                       for i, col in enumerate(col_indices) if col < 0]\n            domain = Domain(r_attrs, r_classes, r_metas)\n        else:\n            domain = self.domain\n        return self.from_table(domain, self, row_idx)\n\n    def __setitem__(self, key, value):\n        if not isinstance(key, tuple):\n            if isinstance(value, Real):\n                self.X[key, :] = value\n                return\n            self._set_row(value, key)\n            return\n\n        if len(key) != 2:\n            raise IndexError(\"Table indices must be one- or two-dimensional\")\n        row_idx, col_idx = key\n\n        # single row\n        if isinstance(row_idx, Integral):\n            if isinstance(col_idx, slice):\n                col_idx = range(*slice.indices(col_idx, self.X.shape[1]))\n            if not isinstance(col_idx, str) and isinstance(col_idx, Iterable):\n                col_idx = list(col_idx)\n            if not isinstance(col_idx, str) and isinstance(col_idx, Sized):\n                if isinstance(value, (Sequence, np.ndarray)):\n                    values = value\n                elif isinstance(value, Iterable):\n                    values = list(value)\n                else:\n                    raise TypeError(\"Setting multiple values requires a \"\n                                    \"sequence or numpy array\")\n                if len(values) != len(col_idx):\n                    raise ValueError(\"Invalid number of values\")\n            else:\n                col_idx, values = [col_idx], [value]\n            if isinstance(col_idx, DiscreteVariable) \\\n                    and self.domain[col_idx] != col_idx:\n                values = self.domain[col_idx].get_mapper_from(col_idx)(values)\n            for val, col_idx in zip(values, col_idx):\n                if not isinstance(val, Integral):\n                    val = self.domain[col_idx].to_val(val)\n                if not isinstance(col_idx, Integral):\n                    col_idx = self.domain.index(col_idx)\n                if col_idx >= 0:\n                    if col_idx < self.X.shape[1]:\n                        self.X[row_idx, col_idx] = val\n                    elif self._Y.ndim == 1 and col_idx == self.X.shape[1]:\n                        self._Y[row_idx] = val\n                    else:\n                        self._Y[row_idx, col_idx - self.X.shape[1]] = val\n                else:\n                    self.metas[row_idx, -1 - col_idx] = val\n\n        # multiple rows, multiple columns\n        attributes, col_indices = self.domain._compute_col_indices(col_idx)\n        if col_indices is ...:\n            col_indices = range(len(self.domain.variables))\n        n_attrs = self.X.shape[1]\n        if isinstance(value, str):\n            if not attributes:\n                attributes = self.domain.attributes\n            for var, col in zip(attributes, col_indices):\n                val = var.to_val(value)\n                if 0 <= col < n_attrs:\n                    self.X[row_idx, col] = val\n                elif col >= n_attrs:\n                    if self._Y.ndim == 1 and col == n_attrs:\n                        self._Y[row_idx] = val\n                    else:\n                        self._Y[row_idx, col - n_attrs] = val\n                else:\n                    self.metas[row_idx, -1 - col] = val\n        else:\n            attr_cols = np.fromiter(\n                (col for col in col_indices if 0 <= col < n_attrs), int)\n            class_cols = np.fromiter(\n                (col - n_attrs for col in col_indices if col >= n_attrs), int)\n            meta_cols = np.fromiter(\n                (-1 - col for col in col_indices if col < 0), int)\n            if value is None:\n                value = Unknown\n\n            if not isinstance(value, (Real, np.ndarray)) and \\\n                    (len(attr_cols) or len(class_cols)):\n                raise TypeError(\n                    \"Ordinary attributes can only have primitive values\")\n            if len(attr_cols):\n                self.X[row_idx, attr_cols] = value\n            if len(class_cols):\n                if self._Y.ndim == 1 and np.all(class_cols == 0):\n                    if isinstance(value, np.ndarray):\n                        yshape = self._Y[row_idx].shape\n                        if value.shape != yshape:\n                            value = value.reshape(yshape)\n                    self._Y[row_idx] = value\n                else:\n                    self._Y[row_idx, class_cols] = value\n            if len(meta_cols):\n                self.metas[row_idx, meta_cols] = value\n\n    def __len__(self):\n        return self.X.shape[0]\n\n    def __str__(self):\n        return \"[\" + \",\\n \".join(str(ex) for ex in self) + \"]\"\n\n    def __repr__(self):\n        head = 5\n        if self.is_sparse():\n            head = min(self.X.shape[0], head)\n        s = \"[\" + \",\\n \".join(repr(ex) for ex in self[:head])\n        if len(self) > head:\n            s += \",\\n ...\"\n        s += \"\\n]\"\n        return s\n\n    @classmethod\n    def concatenate(cls, tables, axis=0):\n        \"\"\"\n        Concatenate tables into a new table, either vertically or horizontally.\n\n        If axis=0 (vertical concatenate), all tables must have the same domain.\n\n        If axis=1 (horizontal),\n        - all variable names must be unique.\n        - ids are copied from the first table.\n        - weights are copied from the first table in which they are defined.\n        - the dictionary of table's attributes are merged. If the same attribute\n          appears in multiple dictionaries, the earlier are used.\n\n        Args:\n            tables (Table): tables to be joined\n\n        Returns:\n            table (Table)\n        \"\"\"\n        if axis not in (0, 1):\n            raise ValueError(\"invalid axis\")\n        if not tables:\n            raise ValueError('need at least one table to concatenate')\n\n        if len(tables) == 1:\n            return tables[0].copy()\n\n        if axis == 0:\n            conc = cls._concatenate_vertical(tables)\n        else:\n            conc = cls._concatenate_horizontal(tables)\n\n        # TODO: Add attributes = {} to __init__\n        conc.attributes = getattr(conc, \"attributes\", {})\n        for table in reversed(tables):\n            conc.attributes.update(table.attributes)\n\n        names = [table.name for table in tables if table.name != \"untitled\"]\n        if names:\n            conc.name = names[0]\n        return conc\n\n    @classmethod\n    def _concatenate_vertical(cls, tables):\n        def vstack(arrs):\n            return [np, sp][any(sp.issparse(arr) for arr in arrs)].vstack(arrs)\n\n        def merge1d(arrs):\n            arrs = list(arrs)\n            ydims = {arr.ndim for arr in arrs}\n            if ydims == {1}:\n                return np.hstack(arrs)\n            else:\n                return vstack([\n                    arr if arr.ndim == 2 else np.atleast_2d(arr).T\n                    for arr in arrs\n                ])\n\n        def collect(attr):\n            return [getattr(arr, attr) for arr in tables]\n\n        domain = tables[0].domain\n        if any(table.domain != domain for table in tables):\n            raise ValueError('concatenated tables must have the same domain')\n\n        conc = cls.from_numpy(\n            domain,\n            vstack(collect(\"X\")),\n            merge1d(collect(\"Y\")),\n            vstack(collect(\"metas\")),\n            merge1d(collect(\"W\"))\n        )\n        conc.ids = np.hstack([t.ids for t in tables])\n        return conc\n\n    @classmethod\n    def _concatenate_horizontal(cls, tables):\n        \"\"\"\n        \"\"\"\n        def all_of(objs, names):\n            return (tuple(getattr(obj, name) for obj in objs)\n                    for name in names)\n\n        def stack(arrs):\n            non_empty = tuple(arr if arr.ndim == 2 else arr[:, np.newaxis]\n                              for arr in arrs\n                              if arr is not None and arr.size > 0)\n            return np.hstack(non_empty) if non_empty else None\n\n        doms, Ws = all_of(tables, (\"domain\", \"W\"))\n        Xs, Ys, Ms = map(stack, all_of(tables, (\"X\", \"Y\", \"metas\")))\n        # pylint: disable=undefined-loop-variable\n        for W in Ws:\n            if W.size:\n                break\n\n        parts = all_of(doms, (\"attributes\", \"class_vars\", \"metas\"))\n        domain = Domain(*(tuple(chain(*lst)) for lst in parts))\n        return cls.from_numpy(domain, Xs, Ys, Ms, W, ids=tables[0].ids)\n\n    def add_column(self, variable, data, to_metas=None):\n        \"\"\"\n        Create a new table with an additional column\n\n        Column's name must be unique\n\n        Args:\n            variable (Variable): variable for the new column\n            data (np.ndarray): data for the new column\n            to_metas (bool, optional): if `True` the column is added as meta\n                column. Otherwise, primitive variables are added to attributes\n                and non-primitive to metas.\n\n        Returns:\n            table (Table): a new table with the additional column\n        \"\"\"\n        dom = self.domain\n        attrs, classes, metavars = dom.attributes, dom.class_vars, dom.metas\n        to_metas = to_metas or not variable.is_primitive()\n        if to_metas:\n            metavars += (variable, )\n        else:\n            attrs += (variable, )\n        domain = Domain(attrs, classes, metavars)\n        new_table = self.transform(domain)\n        with new_table.unlocked(new_table.metas if to_metas else new_table.X):\n            new_table.get_column_view(variable)[0][:] = data\n        return new_table\n\n    def is_view(self):\n        \"\"\"\n        Return `True` if all arrays represent a view referring to another table\n        \"\"\"\n        return ((not self._X.shape[-1] or self._X.base is not None) and\n                (not self._Y.shape[-1] or self._Y.base is not None) and\n                (not self._metas.shape[-1] or self._metas.base is not None) and\n                (not self._weights.shape[-1] or self._W.base is not None))\n\n    def is_copy(self):\n        \"\"\"\n        Return `True` if the table owns its data\n        \"\"\"\n        return ((not self._X.shape[-1] or self._X.base is None) and\n                (self._Y.base is None) and\n                (self._metas.base is None) and\n                (self._W.base is None))\n\n    def is_sparse(self):\n        \"\"\"\n        Return `True` if the table stores data in sparse format\n        \"\"\"\n        return any(sp.issparse(i) for i in [self._X, self._Y, self._metas])\n\n    def ensure_copy(self):\n        \"\"\"\n        Ensure that the table owns its data; copy arrays when necessary.\n        \"\"\"\n\n        def is_view(x):\n            # Sparse matrices don't have views like numpy arrays. Since indexing on\n            # them creates copies in constructor we can skip this check here.\n            return not sp.issparse(x) and x.base is not None\n\n        if is_view(self._X):\n            self._X = self._X.copy()\n        if is_view(self._Y):\n            self._Y = self._Y.copy()\n        if is_view(self._metas):\n            self._metas = self._metas.copy()\n        if is_view(self._W):\n            self._W = self._W.copy()\n\n    def copy(self):\n        \"\"\"\n        Return a copy of the table\n        \"\"\"\n        t = self.__class__(self)\n        t.ensure_copy()\n        return t\n\n    @staticmethod\n    def __determine_density(data):\n        if data is None:\n            return Storage.Missing\n        if data is not None and sp.issparse(data):\n            return Storage.SPARSE_BOOL if (data.data == 1).all() else Storage.SPARSE\n        else:\n            return Storage.DENSE\n\n    def X_density(self):\n        if not hasattr(self, \"_X_density\"):\n            self._X_density = self.__determine_density(self.X)\n        return self._X_density\n\n    def Y_density(self):\n        if not hasattr(self, \"_Y_density\"):\n            self._Y_density = self.__determine_density(self._Y)\n        return self._Y_density\n\n    def metas_density(self):\n        if not hasattr(self, \"_metas_density\"):\n            self._metas_density = self.__determine_density(self.metas)\n        return self._metas_density\n\n    def set_weights(self, weight=1):\n        \"\"\"\n        Set weights of data instances; create a vector of weights if necessary.\n        \"\"\"\n        if not self.W.shape[-1]:\n            self.W = np.empty(len(self))\n        self.W[:] = weight\n\n    def has_weights(self):\n        \"\"\"Return `True` if the data instances are weighed. \"\"\"\n        return self.W.shape[-1] != 0\n\n    def total_weight(self):\n        \"\"\"\n        Return the total weight of instances in the table, or their number if\n        they are unweighted.\n        \"\"\"\n        if self.W.shape[-1]:\n            return sum(self.W)\n        return len(self)\n\n    def has_missing(self):\n        \"\"\"Return `True` if there are any missing attribute or class values.\"\"\"\n        missing_x = not sp.issparse(self.X) and bn.anynan(self.X)  # do not check for sparse X\n        return missing_x or bn.anynan(self._Y)\n\n    def has_missing_attribute(self):\n        \"\"\"Return `True` if there are any missing attribute values.\"\"\"\n        return not sp.issparse(self.X) and bn.anynan(self.X)  # do not check for sparse X\n\n    def has_missing_class(self):\n        \"\"\"Return `True` if there are any missing class values.\"\"\"\n        return bn.anynan(self._Y)\n\n    def get_nan_frequency_attribute(self):\n        if self.X.size == 0:\n            return 0\n        return np.isnan(self.X).sum() / self.X.size\n\n    def get_nan_frequency_class(self):\n        if self.Y.size == 0:\n            return 0\n        return np.isnan(self._Y).sum() / self._Y.size\n\n    def checksum(self, include_metas=True):\n        # TODO: zlib.adler32 does not work for numpy arrays with dtype object\n        # (after pickling and unpickling such arrays, checksum changes)\n        # Why, and should we fix it or remove it?\n        \"\"\"Return a checksum over X, Y, metas and W.\"\"\"\n        cs = zlib.adler32(np.ascontiguousarray(self._X))\n        cs = zlib.adler32(np.ascontiguousarray(self._Y), cs)\n        if include_metas:\n            cs = zlib.adler32(np.ascontiguousarray(self._metas), cs)\n        cs = zlib.adler32(np.ascontiguousarray(self._W), cs)\n        return cs\n\n    def shuffle(self):\n        \"\"\"Randomly shuffle the rows of the table.\"\"\"\n        if not self._check_all_dense():\n            raise ValueError(\"Rows of sparse data cannot be shuffled\")\n        ind = np.arange(self.X.shape[0])\n        np.random.shuffle(ind)\n        self.X = self.X[ind]\n        self._Y = self._Y[ind]\n        self.metas = self.metas[ind]\n        self.W = self.W[ind]\n\n    def get_column_view(self, index):\n        \"\"\"\n        Return a vector - as a view, not a copy - with a column of the table,\n        and a bool flag telling whether this column is sparse. Note that\n        vertical slicing of sparse matrices is inefficient.\n\n        :param index: the index of the column\n        :type index: int, str or Orange.data.Variable\n        :return: (one-dimensional numpy array, sparse)\n        \"\"\"\n\n        def rx(M):\n            if sp.issparse(M):\n                return np.asarray(M.todense())[:, 0], True\n            else:\n                return M, False\n\n        if isinstance(index, Integral):\n            col_index = index\n        else:\n            col_index = self.domain.index(index)\n        if col_index >= 0:\n            if col_index < self.X.shape[1]:\n                col = rx(self.X[:, col_index])\n            elif self._Y.ndim == 1 and col_index == self._X.shape[1]:\n                col = rx(self._Y)\n            else:\n                col = rx(self._Y[:, col_index - self.X.shape[1]])\n        else:\n            col = rx(self.metas[:, -1 - col_index])\n\n        if isinstance(index, DiscreteVariable) \\\n                and index.values != self.domain[col_index].values:\n            col = index.get_mapper_from(self.domain[col_index])(col[0]), col[1]\n            col[0].flags.writeable = False\n        return col\n\n    def _filter_is_defined(self, columns=None, negate=False):\n        # structure of function is obvious; pylint: disable=too-many-branches\n        def _sp_anynan(a):\n            return a.indptr[1:] != a[-1:] + a.shape[1]\n\n        if columns is None:\n            if sp.issparse(self.X):\n                remove = _sp_anynan(self.X)\n            else:\n                remove = bn.anynan(self.X, axis=1)\n            if sp.issparse(self._Y):\n                remove += _sp_anynan(self._Y)\n            else:\n                if self._Y.ndim == 1:\n                    remove += np.isnan(self._Y)\n                else:\n                    remove += bn.anynan(self._Y, axis=1)\n            if sp.issparse(self.metas):\n                remove += _sp_anynan(self._metas)\n            else:\n                for i, var in enumerate(self.domain.metas):\n                    col = self.metas[:, i].flatten()\n                    if var.is_primitive():\n                        remove += np.isnan(col.astype(float))\n                    else:\n                        remove += ~col.astype(bool)\n        else:\n            remove = np.zeros(len(self), dtype=bool)\n            for column in columns:\n                col, sparse = self.get_column_view(column)\n                if sparse:\n                    remove += col == 0\n                elif self.domain[column].is_primitive():\n                    remove += bn.anynan([col.astype(float)], axis=0)\n                else:\n                    remove += col.astype(bool)\n        retain = remove if negate else np.logical_not(remove)\n        return self.from_table_rows(self, retain)\n\n    def _filter_has_class(self, negate=False):\n        if sp.issparse(self._Y):\n            if negate:\n                retain = (self._Y.indptr[1:] !=\n                          self._Y.indptr[-1:] + self._Y.shape[1])\n            else:\n                retain = (self._Y.indptr[1:] ==\n                          self._Y.indptr[-1:] + self._Y.shape[1])\n        else:\n            if self._Y.ndim == 1:\n                retain = np.isnan(self._Y)\n            else:\n                retain = bn.anynan(self._Y, axis=1)\n            if not negate:\n                retain = np.logical_not(retain)\n        return self.from_table_rows(self, retain)\n\n    def _filter_same_value(self, column, value, negate=False):\n        if not isinstance(value, Real):\n            value = self.domain[column].to_val(value)\n        sel = self.get_column_view(column)[0] == value\n        if negate:\n            sel = np.logical_not(sel)\n        return self.from_table_rows(self, sel)\n\n    def _filter_values(self, filter):\n        selection = self._values_filter_to_indicator(filter)\n        return self.from_table(self.domain, self, selection)\n\n    def _values_filter_to_indicator(self, filter):\n        \"\"\"Return selection of rows matching the filter conditions\n\n        Handles conjunction/disjunction and negate modifiers\n\n        Parameters\n        ----------\n        filter: Values object containing the conditions\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        from Orange.data.filter import Values\n\n        if isinstance(filter, Values):\n            conditions = filter.conditions\n            conjunction = filter.conjunction\n        else:\n            conditions = [filter]\n            conjunction = True\n        if conjunction:\n            sel = np.ones(len(self), dtype=bool)\n        else:\n            sel = np.zeros(len(self), dtype=bool)\n\n        for f in conditions:\n            selection = self._filter_to_indicator(f)\n\n            if conjunction:\n                sel *= selection\n            else:\n                sel += selection\n\n        if filter.negate:\n            sel = ~sel\n        return sel\n\n    def _filter_to_indicator(self, filter):\n        \"\"\"Return selection of rows that match the condition.\n\n        Parameters\n        ----------\n        filter: ValueFilter describing the condition\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        from Orange.data.filter import (\n            FilterContinuous, FilterDiscrete, FilterRegex, FilterString,\n            FilterStringList, IsDefined, Values\n        )\n        if isinstance(filter, Values):\n            return self._values_filter_to_indicator(filter)\n\n        def get_col_indices():\n            cols = chain(self.domain.variables, self.domain.metas)\n            if isinstance(filter, IsDefined):\n                if filter.columns is not None:\n                    return list(filter.columns)\n                else:\n                    return list(cols)\n\n            if filter.column is not None:\n                return [filter.column]\n\n            if isinstance(filter, FilterDiscrete):\n                raise ValueError(\"Discrete filter can't be applied across rows\")\n            if isinstance(filter, FilterContinuous):\n                return [col for col in cols if col.is_continuous]\n            if isinstance(filter,\n                          (FilterString, FilterStringList, FilterRegex)):\n                return [col for col in cols if col.is_string]\n            raise TypeError(\"Invalid filter\")\n\n        def col_filter(col_idx):\n            col = self.get_column_view(col_idx)[0]\n            if isinstance(filter, IsDefined):\n                if self.domain[col_idx].is_primitive():\n                    return ~np.isnan(col.astype(float))\n                else:\n                    return col.astype(bool)\n            if isinstance(filter, FilterDiscrete):\n                return self._discrete_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterContinuous):\n                return self._continuous_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterString):\n                return self._string_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterStringList):\n                if not filter.case_sensitive:\n                    col = np.char.lower(np.array(col, dtype=str))\n                    vals = [val.lower() for val in filter.values]\n                else:\n                    vals = filter.values\n                return reduce(operator.add, (col == val for val in vals))\n            if isinstance(filter, FilterRegex):\n                return np.vectorize(filter)(col)\n            raise TypeError(\"Invalid filter\")\n\n        col_indices = get_col_indices()\n        if len(col_indices) == 1:\n            sel = col_filter(col_indices[0])\n        else:\n            sel = np.ones(len(self), dtype=bool)\n            for col_idx in col_indices:\n                sel *= col_filter(col_idx)\n\n        if isinstance(filter, IsDefined) and filter.negate:\n            sel = ~sel\n        return sel\n\n    def _discrete_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given discrete filter.\n\n        Parameters\n        ----------\n        filter: FilterDiscrete\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.values is None:  # <- is defined filter\n            col = col.astype(float)\n            return ~np.isnan(col)\n\n        sel = np.zeros(len(self), dtype=bool)\n        for val in filter.values:\n            if not isinstance(val, Real):\n                val = self.domain[filter.column].to_val(val)\n            sel += (col == val)\n        return sel\n\n    def _continuous_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given continuous filter.\n\n        Parameters\n        ----------\n        filter: FilterContinuous\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.oper == filter.IsDefined:\n            col = col.astype(float)\n            return ~np.isnan(col)\n\n        return self._range_filter_to_indicator(filter, col, filter.min, filter.max)\n\n    def _string_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given string filter.\n\n        Parameters\n        ----------\n        filter: FilterString\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.oper == filter.IsDefined:\n            return col.astype(bool)\n\n        col = col.astype(str)\n        fmin = filter.min or \"\"\n        fmax = filter.max or \"\"\n\n        if not filter.case_sensitive:\n            # convert all to lower case\n            col = np.char.lower(col)\n            fmin = fmin.lower()\n            fmax = fmax.lower()\n\n        if filter.oper == filter.Contains:\n            return np.fromiter((fmin in e for e in col),\n                               dtype=bool)\n        if filter.oper == filter.StartsWith:\n            return np.fromiter((e.startswith(fmin) for e in col),\n                               dtype=bool)\n        if filter.oper == filter.EndsWith:\n            return np.fromiter((e.endswith(fmin) for e in col),\n                               dtype=bool)\n\n        return self._range_filter_to_indicator(filter, col, fmin, fmax)\n\n    @staticmethod\n    def _range_filter_to_indicator(filter, col, fmin, fmax):\n        with np.errstate(invalid=\"ignore\"):  # nan's are properly discarded\n            if filter.oper == filter.Equal:\n                return col == fmin\n            if filter.oper == filter.NotEqual:\n                return col != fmin\n            if filter.oper == filter.Less:\n                return col < fmin\n            if filter.oper == filter.LessEqual:\n                return col <= fmin\n            if filter.oper == filter.Greater:\n                return col > fmin\n            if filter.oper == filter.GreaterEqual:\n                return col >= fmin\n            if filter.oper == filter.Between:\n                return (col >= fmin) * (col <= fmax)\n            if filter.oper == filter.Outside:\n                return (col < fmin) + (col > fmax)\n\n            raise TypeError(\"Invalid operator\")\n\n    def _compute_basic_stats(self, columns=None,\n                             include_metas=False, compute_variance=False):\n        if compute_variance:\n            raise NotImplementedError(\"computation of variance is \"\n                                      \"not implemented yet\")\n        W = self._W if self.has_weights() else None\n        rr = []\n        stats = []\n        if not columns:\n            if self.domain.attributes:\n                rr.append(fast_stats(self._X, W))\n            if self.domain.class_vars:\n                rr.append(fast_stats(self._Y, W))\n            if include_metas and self.domain.metas:\n                rr.append(fast_stats(self.metas, W))\n            if len(rr):\n                stats = np.vstack(tuple(rr))\n        else:\n            nattrs = len(self.domain.attributes)\n            for column in columns:\n                c = self.domain.index(column)\n                if 0 <= c < nattrs:\n                    S = fast_stats(self._X[:, [c]], W and W[:, [c]])\n                elif c >= nattrs:\n                    if self._Y.ndim == 1 and c == nattrs:\n                        S = fast_stats(self._Y[:, None], W and W[:, None])\n                    else:\n                        S = fast_stats(self._Y[:, [c - nattrs]], W and W[:, [c - nattrs]])\n                else:\n                    S = fast_stats(self._metas[:, [-1 - c]], W and W[:, [-1 - c]])\n                stats.append(S[0])\n        return stats\n\n    def _compute_distributions(self, columns=None):\n        if columns is None:\n            columns = range(len(self.domain.variables))\n        else:\n            columns = [self.domain.index(var) for var in columns]\n\n        distributions = []\n        X = self.X\n        if sp.issparse(X):\n            X = X.tocsc()\n\n\n        W = self.W.ravel() if self.has_weights() else None\n\n        for col in columns:\n            variable = self.domain[col]\n\n            # Select the correct data column from X, Y or metas\n            if 0 <= col < X.shape[1]:\n                x = X[:, col]\n            elif col < 0:\n                x = self.metas[:, col * (-1) - 1]\n                if np.issubdtype(x.dtype, np.dtype(object)):\n                    x = x.astype(float)\n            elif self._Y.ndim == 1 and col == X.shape[1]:\n                x = self._Y\n            else:\n                x = self._Y[:, col - X.shape[1]]\n\n            if variable.is_discrete:\n                dist, unknowns = bincount(x, weights=W, max_val=len(variable.values) - 1)\n            elif not x.shape[0]:\n                dist, unknowns = np.zeros((2, 0)), 0\n            else:\n                if W is not None:\n                    if sp.issparse(x):\n                        arg_sort = np.argsort(x.data)\n                        ranks = x.indices[arg_sort]\n                        vals = np.vstack((x.data[arg_sort], W[ranks]))\n                    else:\n                        ranks = np.argsort(x)\n                        vals = np.vstack((x[ranks], W[ranks]))\n                else:\n                    x_values = x.data if sp.issparse(x) else x\n                    vals = np.ones((2, x_values.shape[0]))\n                    vals[0, :] = x_values\n                    vals[0, :].sort()\n\n                dist = np.array(_valuecount.valuecount(vals))\n                # If sparse, then 0s will not be counted with `valuecount`, so\n                # we have to add them to the result manually.\n                if sp.issparse(x) and sparse_has_implicit_zeros(x):\n                    if W is not None:\n                        zero_weights = sparse_implicit_zero_weights(x, W).sum()\n                    else:\n                        zero_weights = sparse_count_implicit_zeros(x)\n                    zero_vec = [0, zero_weights]\n                    dist = np.insert(dist, np.searchsorted(dist[0], 0), zero_vec, axis=1)\n                # Since `countnans` assumes vector shape to be (1, n) and `x`\n                # shape is (n, 1), we pass the transpose\n                unknowns = countnans(x.T, W)\n            distributions.append((dist, unknowns))\n\n        return distributions\n\n    def _compute_contingency(self, col_vars=None, row_var=None):\n        n_atts = self.X.shape[1]\n\n        if col_vars is None:\n            col_vars = range(len(self.domain.variables))\n        else:\n            col_vars = [self.domain.index(var) for var in col_vars]\n        if row_var is None:\n            row_var = self.domain.class_var\n            if row_var is None:\n                raise ValueError(\"No row variable\")\n\n        row_desc = self.domain[row_var]\n        if not row_desc.is_discrete:\n            raise TypeError(\"Row variable must be discrete\")\n        row_indi = self.domain.index(row_var)\n        n_rows = len(row_desc.values)\n        if 0 <= row_indi < n_atts:\n            row_data = self.X[:, row_indi]\n        elif row_indi < 0:\n            row_data = self.metas[:, -1 - row_indi]\n        elif self._Y.ndim == 1 and row_indi == n_atts:\n            row_data = self._Y\n        else:\n            row_data = self._Y[:, row_indi - n_atts]\n\n        W = self.W if self.has_weights() else None\n\n        col_desc = [self.domain[var] for var in col_vars]\n        col_indi = [self.domain.index(var) for var in col_vars]\n\n        if any(not (var.is_discrete or var.is_continuous)\n               for var in col_desc):\n            raise ValueError(\"Contingency can be computed only for categorical \"\n                             \"and numeric values.\")\n\n        # when we select a column in sparse matrix it is still two dimensional\n        # and sparse - since it is just a column we can afford to transform\n        # it to dense and make it 1D\n        if issparse(row_data):\n            row_data = row_data.toarray().ravel()\n        if row_data.dtype.kind != \"f\":  # meta attributes can be stored as type object\n            row_data = row_data.astype(float)\n\n        contingencies = [None] * len(col_desc)\n        for arr, f_cond, f_ind in (\n                (self.X, lambda i: 0 <= i < n_atts, lambda i: i),\n                (self._Y, lambda i: i >= n_atts, lambda i: i - n_atts),\n                (self.metas, lambda i: i < 0, lambda i: -1 - i)):\n\n            arr_indi = [e for e, ind in enumerate(col_indi) if f_cond(ind)]\n\n            vars = [(e, f_ind(col_indi[e]), col_desc[e]) for e in arr_indi]\n            disc_vars = [v for v in vars if v[2].is_discrete]\n            if disc_vars:\n                if sp.issparse(arr):\n                    max_vals = max(len(v[2].values) for v in disc_vars)\n                    disc_indi = {i for _, i, _ in disc_vars}\n                    mask = [i in disc_indi for i in range(arr.shape[1])]\n                    conts, nans_cols, nans_rows, nans = contingency(\n                        arr, row_data, max_vals - 1, n_rows - 1, W, mask)\n                    for col_i, arr_i, var in disc_vars:\n                        n_vals = len(var.values)\n                        contingencies[col_i] = (\n                            conts[arr_i][:, :n_vals], nans_cols[arr_i],\n                            nans_rows[arr_i], nans[arr_i])\n                else:\n                    for col_i, arr_i, var in disc_vars:\n                        col = arr if arr.ndim == 1 else arr[:, arr_i]\n                        contingencies[col_i] = contingency(\n                            col.astype(float),\n                            row_data, len(var.values) - 1, n_rows - 1, W)\n\n            cont_vars = [v for v in vars if v[2].is_continuous]\n            if cont_vars:\n                W_ = None\n                if W is not None:\n                    W_ = W.astype(dtype=np.float64)\n                if sp.issparse(arr):\n                    arr = sp.csc_matrix(arr)\n\n                for col_i, arr_i, _ in cont_vars:\n                    if sp.issparse(arr):\n                        col_data = arr.data[arr.indptr[arr_i]:arr.indptr[arr_i + 1]]\n                        rows = arr.indices[arr.indptr[arr_i]:arr.indptr[arr_i + 1]]\n                        W_ = None if W_ is None else W_[rows]\n                        classes_ = row_data[rows]\n                    else:\n                        col_data, W_, classes_ = arr[:, arr_i], W_, row_data\n\n                    col_data = col_data.astype(dtype=np.float64)\n                    contingencies[col_i] = _contingency.contingency_floatarray(\n                        col_data, classes_, n_rows, W_)\n\n        return contingencies\n\n    @classmethod\n    def transpose(cls, table, feature_names_column=\"\",\n                  meta_attr_name=\"Feature name\", feature_name=\"Feature\",\n                  remove_redundant_inst=False, progress_callback=None):\n        \"\"\"\n        Transpose the table.\n\n        :param table: Table - table to transpose\n        :param feature_names_column: str - name of (String) meta attribute to\n            use for feature names\n        :param meta_attr_name: str - name of new meta attribute into which\n            feature names are mapped\n        :param feature_name: str - default feature name prefix\n        :param remove_redundant_inst: bool - remove instance that\n            represents feature_names_column\n        :param progress_callback: callable - to report the progress\n        :return: Table - transposed table\n        \"\"\"\n        if progress_callback is None:\n            progress_callback = dummy_callback\n        progress_callback(0, \"Transposing...\")\n\n        if isinstance(feature_names_column, Variable):\n            feature_names_column = feature_names_column.name\n\n        self = cls()\n        n_cols, self.n_rows = table.X.shape\n        old_domain = table.attributes.get(\"old_domain\")\n        table_domain_attributes = list(table.domain.attributes)\n        attr_index = None\n        if remove_redundant_inst:\n            attr_names = [a.name for a in table_domain_attributes]\n            if feature_names_column and feature_names_column in attr_names:\n                attr_index = attr_names.index(feature_names_column)\n                self.n_rows = self.n_rows - 1\n                table_domain_attributes.remove(\n                    table_domain_attributes[attr_index])\n\n        # attributes\n        # - classes and metas to attributes of attributes\n        # - arbitrary meta column to feature names\n        with self.unlocked():\n            self.X = table.X.T\n            if attr_index is not None:\n                self.X = np.delete(self.X, attr_index, 0)\n            if feature_names_column:\n                names = [str(row[feature_names_column]) for row in table]\n                progress_callback(0.1)\n                names = get_unique_names_duplicates(names)\n                progress_callback(0.3)\n                attributes = [ContinuousVariable(name) for name in names]\n            else:\n                places = int(np.ceil(np.log10(n_cols))) if n_cols else 1\n                attributes = [ContinuousVariable(f\"{feature_name} {i:0{places}}\")\n                              for i in range(1, n_cols + 1)]\n            progress_callback(0.4)\n\n            if old_domain is not None and feature_names_column:\n                for i, _ in enumerate(attributes):\n                    if attributes[i].name in old_domain:\n                        var = old_domain[attributes[i].name]\n                        attr = ContinuousVariable(var.name) if var.is_continuous \\\n                            else DiscreteVariable(var.name, var.values)\n                        attr.attributes = var.attributes.copy()\n                        attributes[i] = attr\n\n            def set_attributes_of_attributes(_vars, _table):\n                for i, variable in enumerate(_vars):\n                    if variable.name == feature_names_column:\n                        continue\n                    for j, row in enumerate(_table):\n                        value = variable.repr_val(row) if np.isscalar(row) \\\n                            else row[i] if isinstance(row[i], str) \\\n                            else variable.repr_val(row[i])\n\n                        if value not in MISSING_VALUES:\n                            attributes[j].attributes[variable.name] = value\n\n            set_attributes_of_attributes(table.domain.class_vars, table.Y)\n            progress_callback(0.5)\n            set_attributes_of_attributes(table.domain.metas, table.metas)\n\n            # weights\n            self.W = np.empty((self.n_rows, 0))\n\n            def get_table_from_attributes_of_attributes(_vars, _dtype=float):\n                T = np.empty((self.n_rows, len(_vars)), dtype=_dtype)\n                for i, _attr in enumerate(table_domain_attributes):\n                    for j, _var in enumerate(_vars):\n                        val = str(_attr.attributes.get(_var.name, \"\"))\n                        if not _var.is_string:\n                            val = np.nan if val in MISSING_VALUES else \\\n                                _var.values.index(val) if \\\n                                    _var.is_discrete else float(val)\n                        T[i, j] = val\n                return T\n\n            # class_vars - attributes of attributes to class - from old domain\n            class_vars = []\n            if old_domain is not None:\n                class_vars = old_domain.class_vars\n            self.Y = get_table_from_attributes_of_attributes(class_vars)\n\n            # metas\n            # - feature names and attributes of attributes to metas\n            self.metas, metas = np.empty((self.n_rows, 0), dtype=object), []\n            if meta_attr_name not in [m.name for m in table.domain.metas] and \\\n                    table_domain_attributes:\n                self.metas = np.array([[a.name] for a in table_domain_attributes],\n                                      dtype=object)\n                metas.append(StringVariable(meta_attr_name))\n\n            names = chain.from_iterable(list(attr.attributes)\n                                        for attr in table_domain_attributes)\n            names = sorted(set(names) - {var.name for var in class_vars})\n            progress_callback(0.6)\n\n            def guessed_var(i, var_name):\n                orig_vals = M[:, i]\n                val_map, vals, var_type = Orange.data.io.guess_data_type(orig_vals)\n                values, variable = Orange.data.io.sanitize_variable(\n                    val_map, vals, orig_vals, var_type, {}, name=var_name)\n                M[:, i] = values\n                return variable\n\n            _metas = [StringVariable(n) for n in names]\n            if old_domain is not None:\n                _metas = [m for m in old_domain.metas if m.name != meta_attr_name]\n            M = get_table_from_attributes_of_attributes(_metas, _dtype=object)\n            progress_callback(0.7)\n            if old_domain is None:\n                _metas = [guessed_var(i, m.name) for i, m in enumerate(_metas)]\n            if _metas:\n                self.metas = np.hstack((self.metas, M))\n                metas.extend(_metas)\n\n            self.domain = Domain(attributes, class_vars, metas)\n            progress_callback(0.9)\n            cls._init_ids(self)\n            self.attributes = table.attributes.copy()\n            self.attributes[\"old_domain\"] = table.domain\n            progress_callback(1)\n            return self\n\n    def to_sparse(self, sparse_attributes=True, sparse_class=False,\n                  sparse_metas=False):\n        def sparsify(features):\n            for f in features:\n                f.sparse = True\n\n        new_domain = self.domain.copy()\n\n        if sparse_attributes:\n            sparsify(new_domain.attributes)\n        if sparse_class:\n            sparsify(new_domain.class_vars)\n        if sparse_metas:\n            sparsify(new_domain.metas)\n        return self.transform(new_domain)\n\n    def to_dense(self, dense_attributes=True, dense_class=True,\n                 dense_metas=True):\n        def densify(features):\n            for f in features:\n                f.sparse = False\n\n        new_domain = self.domain.copy()\n\n        if dense_attributes:\n            densify(new_domain.attributes)\n        if dense_class:\n            densify(new_domain.class_vars)\n        if dense_metas:\n            densify(new_domain.metas)\n        t = self.transform(new_domain)\n        t.ids = self.ids  # preserve indices\n        return t",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 454,
                            "end_lineno": 466,
                            "parent": {
                                "file_name": "Orange/data/table.py",
                                "type": "class",
                                "name": "Table",
                                "content": "class Table(Sequence, Storage):\n\n    LOCKING = None\n    \"\"\" If the class attribute LOCKING is True, tables will throw exceptions\n    on in-place modifications unless unlocked explicitly. LOCKING is supposed\n    to be set to True for testing to help us find bugs. If set to False\n    or None, no safeguards are in place. Two different values are used for\n    the same behaviour to distinguish the unchanged default (None) form\n    explicit deactivation (False) that some add-ons might need. \"\"\"\n\n    __file__ = None\n    name = \"untitled\"\n\n    domain = Domain([])\n    _X = _Y = _metas = _W = np.zeros((0, 0))  # pylint: disable=invalid-name\n    ids = np.zeros(0)\n    ids.setflags(write=False)\n    attributes = frozendict()\n\n    _Unlocked_X, _Unlocked_Y, _Unlocked_metas, _Unlocked_W = 1, 2, 4, 8\n    _unlocked = _Unlocked_X + _Unlocked_Y + \\\n                _Unlocked_metas + _Unlocked_W  # pylint: disable=invalid-name\n\n    @property\n    def columns(self):\n        \"\"\"\n        A class whose attributes contain attribute descriptors for columns.\n        For a table `table`, setting `c = table.columns` will allow accessing\n        the table's variables with, for instance `c.gender`, `c.age` ets.\n        Spaces are replaced with underscores.\n        \"\"\"\n        return Columns(self.domain)\n\n    _next_instance_id = 0\n    _next_instance_lock = Lock()\n\n    def _check_unlocked(self, partflag):\n        if not self._unlocked & partflag:\n            raise ValueError(\"Table is read-only unless unlocked\")\n\n    @property\n    def X(self):  # pylint: disable=invalid-name\n        return self._X\n\n    @X.setter\n    def X(self, value):\n        self._check_unlocked(self._Unlocked_X)\n        self._X = _dereferenced(value)\n\n    @property\n    def Y(self):  # pylint: disable=invalid-name\n        return self._Y\n\n    @Y.setter\n    def Y(self, value):\n        self._check_unlocked(self._Unlocked_Y)\n        if sp.issparse(value) and len(self) != value.shape[0]:\n            value = value.T\n        if sp.issparse(value):\n            value = _dereferenced(value.toarray())\n        if value.ndim == 2 and value.shape[1] == 1:\n            value = value[:, 0].copy()  # no views!\n        self._Y = value\n\n    @property\n    def metas(self):\n        return self._metas\n\n    @metas.setter\n    def metas(self, value):\n        self._check_unlocked(self._Unlocked_metas)\n        self._metas = _dereferenced(value)\n\n    @property\n    def W(self):  # pylint: disable=invalid-name\n        return self._W\n\n    @W.setter\n    def W(self, value):\n        self._check_unlocked(self._Unlocked_W)\n        self._W = value\n\n    def __setstate__(self, state):\n        # Backward compatibility with pickles before table locking\n        self._initialize_unlocked()  # __dict__ seems to be cleared before calling __setstate__\n        with self.unlocked():\n            for k in (\"X\", \"W\", \"metas\"):\n                if k in state:\n                    setattr(self, k, state.pop(k))\n            if \"_Y\" in state:\n                setattr(self, \"Y\", state.pop(\"_Y\"))  # state[\"_Y\"] is a 2d array\n            self.__dict__.update(state)\n\n    def __getstate__(self):\n        # Compatibility with pickles before table locking:\n        # return the same state as before table lock\n        state = self.__dict__.copy()\n        for k in [\"X\", \"metas\", \"W\"]:\n            if \"_\" + k in state:  # Check existence; SQL tables do not contain them\n                state[k] = state.pop(\"_\" + k)\n        # before locking, _Y was always a 2d array: save it as such\n        if \"_Y\" in state:\n            y = state.pop(\"_Y\")\n            y2d = y.reshape(-1, 1) if y.ndim == 1 else y\n            state[\"_Y\"] = y2d\n        return state\n\n    def _lock_parts(self):\n        return ((self._X, self._Unlocked_X, \"X\"),\n                (self._Y, self._Unlocked_Y, \"Y\"),\n                (self._metas, self._Unlocked_metas, \"metas\"),\n                (self._W, self._Unlocked_W, \"weights\"))\n\n    def _initialize_unlocked(self):\n        if Table.LOCKING:\n            self._unlocked = 0\n        else:\n            self._unlocked = sum(f for _, f, _ in self._lock_parts())\n\n    def _update_locks(self, force=False, unlock_bases=()):\n        if not Table.LOCKING:\n            return\n\n        def sync(*xs):\n            for x in xs:\n                try:\n                    undo_on_fail.append((x, x.flags.writeable))\n                    x.flags.writeable = writeable\n                except ValueError:\n                    if force \\\n                            and writeable \\\n                            and x.base is not None \\\n                            and not x.base.flags.writeable:\n                        x.base.flags.writeable = writeable\n                        x.flags.writeable = writeable\n                        forced_bases.append(x.base)\n                    else:\n                        raise\n\n        forced_bases = []\n        undo_on_fail = []\n        for base in unlock_bases:\n            base.flags.writeable = False\n        try:\n            for part, flag, _ in self._lock_parts():\n                if part is None:\n                    continue\n                writeable = bool(self._unlocked & flag)\n                if sp.isspmatrix_csr(part) or sp.isspmatrix_csc(part):\n                    sync(part.data, part.indices, part.indptr)\n                elif sp.isspmatrix_coo(part):\n                    sync(part.data, part.row, part.col)\n                elif sp.issparse(part):\n                    raise ValueError(\"Unsupported sparse data type\")\n                else:\n                    sync(part)\n        except:\n            for part, flag in undo_on_fail:\n                part.flags.writeable = flag\n            raise\n        return tuple(forced_bases)\n\n    def __unlocked(self, *parts, force=False):\n        prev_state = self._unlocked\n        for part, flag, _ in self._lock_parts():\n            if not parts or any(ppart is part for ppart in parts):\n                self._unlocked |= flag\n        try:\n            forced_bases = self._update_locks(force)\n            yield\n        finally:\n            self._unlocked = prev_state\n            self._update_locks(unlock_bases=forced_bases)\n\n    def force_unlocked(self, *parts):\n        \"\"\"\n        Unlocking without any checks.\n\n        Use with extreme caution. This is meant primarily for 3rd party\n        functions in Cython that expect read-write buffer, but do not\n        actually modify it. the given parts (default: all parts) of the table.\n\n        The function will still fail to unlock and raise an exception if the\n        table contains view to another table.\n        \"\"\"\n        return contextmanager(self.__unlocked)(*parts, force=True)\n\n    def unlocked(self, *parts):\n        \"\"\"\n        Unlock the given parts (default: all parts) of the table.\n\n        The caller must ensure that the table is safe to modify. The function\n        will raise an exception if the table contains view to other table.\n        \"\"\"\n        def can_unlock(x):\n            if sp.issparse(x):\n                return can_unlock(x.data)\n            return x.flags.writeable or x.flags.owndata\n\n        for part, flag, name in self._lock_parts():\n            if not flag & self._unlocked \\\n                    and (not parts or any(ppart is part for ppart in parts)) \\\n                    and part is not None and not can_unlock(part):\n                raise ValueError(f\"'{name}' is a view into another table \"\n                                 \"and cannot be unlocked\")\n        return contextmanager(self.__unlocked)(*parts)\n\n    def __new__(cls, *args, **kwargs):\n        def warn_deprecated(method):\n            warnings.warn(\"Direct calls to Table's constructor are deprecated \"\n                          \"and will be removed. Replace this call with \"\n                          f\"Table.{method}\", OrangeDeprecationWarning,\n                          stacklevel=3)\n\n        if not args:\n            if not kwargs:\n                return super().__new__(cls)\n            else:\n                raise TypeError(\"Table() must not be called directly\")\n\n        if isinstance(args[0], str):\n            if len(args) > 1:\n                raise TypeError(\"Table(name: str) expects just one argument\")\n            if args[0].startswith('https://') or args[0].startswith('http://'):\n                return cls.from_url(args[0], **kwargs)\n            else:\n                return cls.from_file(args[0], **kwargs)\n\n        elif isinstance(args[0], Table):\n            if len(args) > 1:\n                raise TypeError(\"Table(table: Table) expects just one argument\")\n            return cls.from_table(args[0].domain, args[0], **kwargs)\n        elif isinstance(args[0], Domain):\n            domain, args = args[0], args[1:]\n            if not args:\n                warn_deprecated(\"from_domain\")\n                return cls.from_domain(domain, **kwargs)\n            if isinstance(args[0], Table):\n                warn_deprecated(\"from_table\")\n                return cls.from_table(domain, *args, **kwargs)\n            elif isinstance(args[0], list):\n                warn_deprecated(\"from_list\")\n                return cls.from_list(domain, *args, **kwargs)\n        else:\n            warnings.warn(\"Omitting domain in a call to Table(X, Y, metas), is \"\n                          \"deprecated and will be removed. \"\n                          \"Call Table.from_numpy(None, X, Y, metas) instead.\",\n                          OrangeDeprecationWarning, stacklevel=2)\n            domain = None\n\n        return cls.from_numpy(domain, *args, **kwargs)\n\n    def __init__(self, *args, **kwargs):  # pylint: disable=unused-argument\n        self._initialize_unlocked()\n        self._update_locks()\n\n    @classmethod\n    def from_domain(cls, domain, n_rows=0, weights=False):\n        \"\"\"\n        Construct a new `Table` with the given number of rows for the given\n        domain. The optional vector of weights is initialized to 1's.\n\n        :param domain: domain for the `Table`\n        :type domain: Orange.data.Domain\n        :param n_rows: number of rows in the new table\n        :type n_rows: int\n        :param weights: indicates whether to construct a vector of weights\n        :type weights: bool\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n        self = cls()\n        self.domain = domain\n        self.n_rows = n_rows\n        with self.unlocked():\n            self.X = np.zeros((n_rows, len(domain.attributes)))\n            if len(domain.class_vars) != 1:\n                self.Y = np.zeros((n_rows, len(domain.class_vars)))\n            else:\n                self.Y = np.zeros(n_rows)\n            if weights:\n                self.W = np.ones(n_rows)\n            else:\n                self.W = np.empty((n_rows, 0))\n            self.metas = np.empty((n_rows, len(self.domain.metas)), object)\n            cls._init_ids(self)\n            self.attributes = {}\n        return self\n\n    @classmethod\n    def from_table(cls, domain, source, row_indices=...):\n        \"\"\"\n        Create a new table from selected columns and/or rows of an existing\n        one. The columns are chosen using a domain. The domain may also include\n        variables that do not appear in the source table; they are computed\n        from source variables if possible.\n\n        The resulting data may be a view or a copy of the existing data.\n\n        :param domain: the domain for the new table\n        :type domain: Orange.data.Domain\n        :param source: the source table\n        :type source: Orange.data.Table\n        :param row_indices: indices of the rows to include\n        :type row_indices: a slice or a sequence\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n\n        PART = 5000\n\n        new_cache = _thread_local.conversion_cache is None\n        try:\n            if new_cache:\n                _thread_local.conversion_cache = {}\n                _thread_local.domain_cache = {}\n            else:\n                cached = _idcache_restore(_thread_local.conversion_cache, (domain, source))\n                if cached is not None:\n                    return cached\n            if domain is source.domain:\n                table = cls.from_table_rows(source, row_indices)\n                # assure resulting domain is the instance passed on input\n                table.domain = domain\n                # since sparse flags are not considered when checking for\n                # domain equality, fix manually.\n                with table.unlocked():\n                    table = assure_domain_conversion_sparsity(table, source)\n                return table\n\n            if row_indices is ...:\n                n_rows = len(source)\n            elif isinstance(row_indices, slice):\n                row_indices_range = range(*row_indices.indices(source.X.shape[0]))\n                n_rows = len(row_indices_range)\n            else:\n                n_rows = len(row_indices)\n\n            self = cls()\n            self.domain = domain\n\n            table_conversion = \\\n                _idcache_restore(_thread_local.domain_cache, (domain, source.domain))\n            if table_conversion is None:\n                table_conversion = _FromTableConversion(source.domain, domain)\n                _idcache_save(_thread_local.domain_cache, (domain, source.domain),\n                              table_conversion)\n\n            # if an array can be a subarray of the input table, this needs to be done\n            # on the whole table, because this avoids needless copies of contents\n\n            with self.unlocked():\n                for array_conv in table_conversion.subarray:\n                    out = array_conv.get_subarray(source, row_indices, n_rows)\n                    setattr(self, array_conv.target, out)\n\n                parts = {}\n\n                for array_conv in table_conversion.columnwise:\n                    if array_conv.is_sparse:\n                        parts[array_conv.target] = []\n                    else:\n                        # F-order enables faster writing to the array while accessing and\n                        # matrix operations work with same speed (e.g. dot)\n                        parts[array_conv.target] = \\\n                            np.zeros((n_rows, len(array_conv.src_cols)),\n                                     order=\"F\", dtype=array_conv.dtype)\n\n                if n_rows <= PART:\n                    for array_conv in table_conversion.columnwise:\n                        out = array_conv.get_columns(source, row_indices, n_rows,\n                                                     parts[array_conv.target],\n                                                     ...)\n                        setattr(self, array_conv.target, out)\n                else:\n                    i_done = 0\n\n                    while i_done < n_rows:\n                        target_indices = slice(i_done, min(n_rows, i_done + PART))\n                        if row_indices is ...:\n                            source_indices = target_indices\n                        elif isinstance(row_indices, slice):\n                            r = row_indices_range[target_indices]\n                            source_indices = slice(r.start, r.stop, r.step)\n                        else:\n                            source_indices = row_indices[target_indices]\n                        part_rows = min(n_rows, i_done+PART) - i_done\n\n                        for array_conv in table_conversion.columnwise:\n                            out = array_conv.get_columns(source, source_indices, part_rows,\n                                                         parts[array_conv.target],\n                                                         target_indices)\n                            if array_conv.is_sparse:  # dense arrays are populated in-place\n                                parts[array_conv.target].append(out)\n\n                        i_done += PART\n\n                        # clear cache after a part is done\n                        if new_cache:\n                            _thread_local.conversion_cache = {}\n\n                    for array_conv in table_conversion.columnwise:\n                        cparts = parts[array_conv.target]\n                        out = cparts if not array_conv.is_sparse else sp.vstack(cparts)\n                        setattr(self, array_conv.target, out)\n\n                if source.has_weights():\n                    self.W = source.W[row_indices]\n                else:\n                    self.W = np.empty((n_rows, 0))\n                self.name = getattr(source, 'name', '')\n                if hasattr(source, 'ids'):\n                    self.ids = source.ids[row_indices]\n                else:\n                    cls._init_ids(self)\n                self.attributes = getattr(source, 'attributes', {})\n                _idcache_save(_thread_local.conversion_cache, (domain, source), self)\n            return self\n        finally:\n            if new_cache:\n                _thread_local.conversion_cache = None\n                _thread_local.domain_cache = None\n\n    def transform(self, domain):\n        \"\"\"\n        Construct a table with a different domain.\n\n        The new table keeps the row ids and other information. If the table\n        is a subclass of :obj:`Table`, the resulting table will be of the same\n        type.\n\n        In a typical scenario, an existing table is augmented with a new\n        column by ::\n\n            domain = Domain(old_domain.attributes + [new_attribute],\n                            old_domain.class_vars,\n                            old_domain.metas)\n            table = data.transform(domain)\n            table[:, new_attribute] = new_column\n\n        Args:\n            domain (Domain): new domain\n\n        Returns:\n            A new table\n        \"\"\"\n        return type(self).from_table(domain, self)\n\n    @classmethod\n    def from_table_rows(cls, source, row_indices):\n        \"\"\"\n        Construct a new table by selecting rows from the source table.\n\n        :param source: an existing table\n        :type source: Orange.data.Table\n        :param row_indices: indices of the rows to include\n        :type row_indices: a slice or a sequence\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n        def get_rows(a):\n            a = a[row_indices]\n            if isinstance(row_indices, slice) or row_indices is ...:\n                a = a.copy()\n            return a\n\n        self = cls()\n        self.domain = source.domain\n        with self.unlocked():\n            self.X = get_rows(source.X)\n            if self.X.ndim == 1:\n                self.X = self.X.reshape(-1, len(self.domain.attributes))\n            self.Y = get_rows(source.Y)\n            self.metas = get_rows(source.metas)\n            if self.metas.ndim == 1:\n                self.metas = self.metas.reshape(-1, len(self.domain.metas))\n            self.W = get_rows(source.W)\n            self.name = getattr(source, 'name', '')\n            self.ids = np.array(source.ids[row_indices])\n            self.attributes = getattr(source, 'attributes', {})\n        return self\n\n    @classmethod\n    def from_numpy(cls, domain, X, Y=None, metas=None, W=None,\n                   attributes=None, ids=None):\n        \"\"\"\n        Construct a table from numpy arrays with the given domain. The number\n        of variables in the domain must match the number of columns in the\n        corresponding arrays. All arrays must have the same number of rows.\n        Arrays may be of different numpy types, and may be dense or sparse.\n\n        :param domain: the domain for the new table\n        :type domain: Orange.data.Domain\n        :param X: array with attribute values\n        :type X: np.array\n        :param Y: array with class values\n        :type Y: np.array\n        :param metas: array with meta attributes\n        :type metas: np.array\n        :param W: array with weights\n        :type W: np.array\n        :return:\n        \"\"\"\n        X, Y, W = _check_arrays(X, Y, W, dtype='float64')\n        metas, = _check_arrays(metas, dtype=object, shape_1=X.shape[0])\n        ids, = _check_arrays(ids, dtype=int, shape_1=X.shape[0])\n\n        if domain is None:\n            domain = Domain.from_numpy(X, Y, metas)\n\n        if Y is None:\n            if not domain.class_vars or sp.issparse(X):\n                Y = np.empty((X.shape[0], 0), dtype=np.float64)\n            else:\n                own_data = X.flags.owndata and X.base is None\n                Y = X[:, len(domain.attributes):]\n                X = X[:, :len(domain.attributes)]\n                if own_data:\n                    Y = Y.copy()\n                    X = X.copy()\n        if metas is None:\n            metas = np.empty((X.shape[0], 0), object)\n        if W is None or W.size == 0:\n            W = np.empty((X.shape[0], 0))\n        elif W.shape != (W.size, ):\n            W = W.reshape(W.size).copy()\n\n        if X.shape[1] != len(domain.attributes):\n            raise ValueError(\n                \"Invalid number of variable columns ({} != {})\".format(\n                    X.shape[1], len(domain.attributes))\n            )\n        if Y.ndim == 1:\n            if not domain.class_var:\n                raise ValueError(\n                    \"Invalid number of class columns \"\n                    f\"(1 != {len(domain.class_vars)})\")\n        elif Y.shape[1] != len(domain.class_vars):\n            raise ValueError(\n                \"Invalid number of class columns ({} != {})\".format(\n                    Y.shape[1], len(domain.class_vars))\n            )\n        if metas.shape[1] != len(domain.metas):\n            raise ValueError(\n                \"Invalid number of meta attribute columns ({} != {})\".format(\n                    metas.shape[1], len(domain.metas))\n            )\n        if not X.shape[0] == Y.shape[0] == metas.shape[0] == W.shape[0]:\n            raise ValueError(\n                \"Parts of data contain different numbers of rows.\")\n\n        self = cls()\n        with self.unlocked():\n            self.domain = domain\n            self.X = X\n            self.Y = Y\n            self.metas = metas\n            self.W = W\n            self.n_rows = self.X.shape[0]\n            if ids is None:\n                cls._init_ids(self)\n            else:\n                self.ids = ids\n            self.attributes = {} if attributes is None else attributes\n        return self\n\n    @classmethod\n    def from_list(cls, domain, rows, weights=None):\n        if weights is not None and len(rows) != len(weights):\n            raise ValueError(\"mismatching number of instances and weights\")\n        self = cls.from_domain(domain, len(rows), weights is not None)\n        all_vars = domain.variables + domain.metas\n        nattrs = len(domain.attributes)\n        nattrscls = len(domain.variables)\n        with self.unlocked():\n            for i, row in enumerate(rows):\n                if isinstance(row, Instance):\n                    row = row.list\n                vals = [var.to_val(val) for var, val in zip(all_vars, row)]\n                self.X[i] = vals[:nattrs]\n                if self._Y.ndim == 1:\n                    self._Y[i] = vals[nattrs] if nattrs < len(vals) else np.nan\n                else:\n                    self._Y[i] = vals[nattrs:nattrscls]\n                # for backward compatibility: allow omittine some (or all) metas\n                self.metas[i, :len(vals) - nattrscls] = vals[nattrscls:]\n            if weights is not None:\n                self.W = np.array(weights)\n            self.attributes = {}\n        return self\n\n    @classmethod\n    def _init_ids(cls, obj):\n        with cls._next_instance_lock:\n            obj.ids = np.array(range(cls._next_instance_id, cls._next_instance_id + obj.X.shape[0]))\n            cls._next_instance_id += obj.X.shape[0]\n\n    @classmethod\n    def new_id(cls):\n        with cls._next_instance_lock:\n            id = cls._next_instance_id\n            cls._next_instance_id += 1\n            return id\n\n    def to_pandas_dfs(self):\n        return Orange.data.pandas_compat.table_to_frames(self)\n\n    @staticmethod\n    def from_pandas_dfs(xdf, ydf, mdf):\n        return Orange.data.pandas_compat.table_from_frames(xdf, ydf, mdf)\n\n    @property\n    def X_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.Attribute\n        )\n\n    @X_df.setter\n    def X_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.Attribute\n        )\n\n    @property\n    def Y_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.ClassAttribute\n        )\n\n    @Y_df.setter\n    def Y_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.ClassAttribute\n        )\n\n    @property\n    def metas_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.Meta\n        )\n\n    @metas_df.setter\n    def metas_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.Meta\n        )\n\n    def save(self, filename):\n        \"\"\"\n        Save a data table to a file. The path can be absolute or relative.\n\n        :param filename: File name\n        :type filename: str\n        \"\"\"\n        ext = os.path.splitext(filename)[1]\n        from Orange.data.io import FileFormat\n        writer = FileFormat.writers.get(ext)\n        if not writer:\n            desc = FileFormat.names.get(ext)\n            if desc:\n                raise IOError(\n                    \"Writing of {}s is not supported\".format(desc.lower()))\n            else:\n                raise IOError(\"Unknown file name extension.\")\n        writer.write_file(filename, self)\n\n    @classmethod\n    def from_file(cls, filename, sheet=None):\n        \"\"\"\n        Read a data table from a file. The path can be absolute or relative.\n\n        :param filename: File name\n        :type filename: str\n        :param sheet: Sheet in a file (optional)\n        :type sheet: str\n        :return: a new data table\n        :rtype: Orange.data.Table\n        \"\"\"\n        from Orange.data.io import FileFormat\n\n        absolute_filename = FileFormat.locate(filename, dataset_dirs)\n        reader = FileFormat.get_reader(absolute_filename)\n        reader.select_sheet(sheet)\n        data = reader.read()\n\n        # Readers return plain table. Make sure to cast it to appropriate\n        # (subclass) type\n        if cls != data.__class__:\n            data = cls(data)\n\n        # no need to call _init_ids as fuctions from .io already\n        # construct a table with .ids\n\n        data.__file__ = absolute_filename\n        return data\n\n    @classmethod\n    def from_url(cls, url):\n        from Orange.data.io import UrlReader\n        reader = UrlReader(url)\n        data = reader.read()\n        if cls != data.__class__:\n            data = cls(data)\n        return data\n\n    # Helper function for __setitem__:\n    # Set the row of table data matrices\n    # noinspection PyProtectedMember\n    def _set_row(self, example, row):\n        # pylint: disable=protected-access\n        domain = self.domain\n        if isinstance(example, Instance):\n            if example.domain == domain:\n                self.X[row] = example._x\n                if self._Y.ndim == 1:\n                    self._Y[row] = float(example._y)\n                else:\n                    self._Y[row] = np.atleast_1d(example._y)\n                self.metas[row] = example._metas\n                return\n\n            self.X[row], self._Y[row], self.metas[row] = \\\n                self.domain.convert(example)\n            try:\n                self.ids[row] = example.id\n            except:\n                with type(self)._next_instance_lock:\n                    self.ids[row] = type(self)._next_instance_id\n                    type(self)._next_instance_id += 1\n\n        else:\n            attrs = domain.attributes\n            if len(example) != len(domain.variables):\n                raise ValueError(\"invalid length\")\n            self._X[row] = [var.to_val(val) for var, val in zip(attrs, example)]\n            if self._Y.ndim == 1:\n                self._Y[row] = domain.class_var.to_val(example[len(attrs)])\n            else:\n                self._Y[row] = [var.to_val(val)\n                                for var, val in zip(domain.class_vars,\n                                                    example[len(attrs):])]\n            self.metas[row] = np.array([var.Unknown for var in domain.metas],\n                                       dtype=object)\n\n    def _check_all_dense(self):\n        return all(x in (Storage.DENSE, Storage.MISSING)\n                   for x in (self.X_density(), self.Y_density(),\n                             self.metas_density()))\n\n    def __getitem__(self, key):\n        if isinstance(key, Integral):\n            return RowInstance(self, key)\n        if not isinstance(key, tuple):\n            return self.from_table_rows(self, key)\n\n        if len(key) != 2:\n            raise IndexError(\"Table indices must be one- or two-dimensional\")\n\n        row_idx, col_idx = key\n        if isinstance(row_idx, Integral):\n            if isinstance(col_idx, (str, Integral, Variable)):\n                col_idx = self.domain.index(col_idx)\n                var = self.domain[col_idx]\n                if 0 <= col_idx < len(self.domain.attributes):\n                    val = self.X[row_idx, col_idx]\n                elif col_idx == len(self.domain.attributes) and self._Y.ndim == 1:\n                    val = self._Y[row_idx]\n                elif col_idx >= len(self.domain.attributes):\n                    val = self._Y[row_idx,\n                                  col_idx - len(self.domain.attributes)]\n                else:\n                    val = self.metas[row_idx, -1 - col_idx]\n                if isinstance(col_idx, DiscreteVariable) and var is not col_idx:\n                    val = col_idx.get_mapper_from(var)(val)\n                return Value(var, val)\n            else:\n                row_idx = [row_idx]\n\n        # multiple rows OR single row but multiple columns:\n        # construct a new table\n        attributes, col_indices = self.domain._compute_col_indices(col_idx)\n        if attributes is not None:\n            n_attrs = len(self.domain.attributes)\n            r_attrs = [attributes[i]\n                       for i, col in enumerate(col_indices)\n                       if 0 <= col < n_attrs]\n            r_classes = [attributes[i]\n                         for i, col in enumerate(col_indices)\n                         if col >= n_attrs]\n            r_metas = [attributes[i]\n                       for i, col in enumerate(col_indices) if col < 0]\n            domain = Domain(r_attrs, r_classes, r_metas)\n        else:\n            domain = self.domain\n        return self.from_table(domain, self, row_idx)\n\n    def __setitem__(self, key, value):\n        if not isinstance(key, tuple):\n            if isinstance(value, Real):\n                self.X[key, :] = value\n                return\n            self._set_row(value, key)\n            return\n\n        if len(key) != 2:\n            raise IndexError(\"Table indices must be one- or two-dimensional\")\n        row_idx, col_idx = key\n\n        # single row\n        if isinstance(row_idx, Integral):\n            if isinstance(col_idx, slice):\n                col_idx = range(*slice.indices(col_idx, self.X.shape[1]))\n            if not isinstance(col_idx, str) and isinstance(col_idx, Iterable):\n                col_idx = list(col_idx)\n            if not isinstance(col_idx, str) and isinstance(col_idx, Sized):\n                if isinstance(value, (Sequence, np.ndarray)):\n                    values = value\n                elif isinstance(value, Iterable):\n                    values = list(value)\n                else:\n                    raise TypeError(\"Setting multiple values requires a \"\n                                    \"sequence or numpy array\")\n                if len(values) != len(col_idx):\n                    raise ValueError(\"Invalid number of values\")\n            else:\n                col_idx, values = [col_idx], [value]\n            if isinstance(col_idx, DiscreteVariable) \\\n                    and self.domain[col_idx] != col_idx:\n                values = self.domain[col_idx].get_mapper_from(col_idx)(values)\n            for val, col_idx in zip(values, col_idx):\n                if not isinstance(val, Integral):\n                    val = self.domain[col_idx].to_val(val)\n                if not isinstance(col_idx, Integral):\n                    col_idx = self.domain.index(col_idx)\n                if col_idx >= 0:\n                    if col_idx < self.X.shape[1]:\n                        self.X[row_idx, col_idx] = val\n                    elif self._Y.ndim == 1 and col_idx == self.X.shape[1]:\n                        self._Y[row_idx] = val\n                    else:\n                        self._Y[row_idx, col_idx - self.X.shape[1]] = val\n                else:\n                    self.metas[row_idx, -1 - col_idx] = val\n\n        # multiple rows, multiple columns\n        attributes, col_indices = self.domain._compute_col_indices(col_idx)\n        if col_indices is ...:\n            col_indices = range(len(self.domain.variables))\n        n_attrs = self.X.shape[1]\n        if isinstance(value, str):\n            if not attributes:\n                attributes = self.domain.attributes\n            for var, col in zip(attributes, col_indices):\n                val = var.to_val(value)\n                if 0 <= col < n_attrs:\n                    self.X[row_idx, col] = val\n                elif col >= n_attrs:\n                    if self._Y.ndim == 1 and col == n_attrs:\n                        self._Y[row_idx] = val\n                    else:\n                        self._Y[row_idx, col - n_attrs] = val\n                else:\n                    self.metas[row_idx, -1 - col] = val\n        else:\n            attr_cols = np.fromiter(\n                (col for col in col_indices if 0 <= col < n_attrs), int)\n            class_cols = np.fromiter(\n                (col - n_attrs for col in col_indices if col >= n_attrs), int)\n            meta_cols = np.fromiter(\n                (-1 - col for col in col_indices if col < 0), int)\n            if value is None:\n                value = Unknown\n\n            if not isinstance(value, (Real, np.ndarray)) and \\\n                    (len(attr_cols) or len(class_cols)):\n                raise TypeError(\n                    \"Ordinary attributes can only have primitive values\")\n            if len(attr_cols):\n                self.X[row_idx, attr_cols] = value\n            if len(class_cols):\n                if self._Y.ndim == 1 and np.all(class_cols == 0):\n                    if isinstance(value, np.ndarray):\n                        yshape = self._Y[row_idx].shape\n                        if value.shape != yshape:\n                            value = value.reshape(yshape)\n                    self._Y[row_idx] = value\n                else:\n                    self._Y[row_idx, class_cols] = value\n            if len(meta_cols):\n                self.metas[row_idx, meta_cols] = value\n\n    def __len__(self):\n        return self.X.shape[0]\n\n    def __str__(self):\n        return \"[\" + \",\\n \".join(str(ex) for ex in self) + \"]\"\n\n    def __repr__(self):\n        head = 5\n        if self.is_sparse():\n            head = min(self.X.shape[0], head)\n        s = \"[\" + \",\\n \".join(repr(ex) for ex in self[:head])\n        if len(self) > head:\n            s += \",\\n ...\"\n        s += \"\\n]\"\n        return s\n\n    @classmethod\n    def concatenate(cls, tables, axis=0):\n        \"\"\"\n        Concatenate tables into a new table, either vertically or horizontally.\n\n        If axis=0 (vertical concatenate), all tables must have the same domain.\n\n        If axis=1 (horizontal),\n        - all variable names must be unique.\n        - ids are copied from the first table.\n        - weights are copied from the first table in which they are defined.\n        - the dictionary of table's attributes are merged. If the same attribute\n          appears in multiple dictionaries, the earlier are used.\n\n        Args:\n            tables (Table): tables to be joined\n\n        Returns:\n            table (Table)\n        \"\"\"\n        if axis not in (0, 1):\n            raise ValueError(\"invalid axis\")\n        if not tables:\n            raise ValueError('need at least one table to concatenate')\n\n        if len(tables) == 1:\n            return tables[0].copy()\n\n        if axis == 0:\n            conc = cls._concatenate_vertical(tables)\n        else:\n            conc = cls._concatenate_horizontal(tables)\n\n        # TODO: Add attributes = {} to __init__\n        conc.attributes = getattr(conc, \"attributes\", {})\n        for table in reversed(tables):\n            conc.attributes.update(table.attributes)\n\n        names = [table.name for table in tables if table.name != \"untitled\"]\n        if names:\n            conc.name = names[0]\n        return conc\n\n    @classmethod\n    def _concatenate_vertical(cls, tables):\n        def vstack(arrs):\n            return [np, sp][any(sp.issparse(arr) for arr in arrs)].vstack(arrs)\n\n        def merge1d(arrs):\n            arrs = list(arrs)\n            ydims = {arr.ndim for arr in arrs}\n            if ydims == {1}:\n                return np.hstack(arrs)\n            else:\n                return vstack([\n                    arr if arr.ndim == 2 else np.atleast_2d(arr).T\n                    for arr in arrs\n                ])\n\n        def collect(attr):\n            return [getattr(arr, attr) for arr in tables]\n\n        domain = tables[0].domain\n        if any(table.domain != domain for table in tables):\n            raise ValueError('concatenated tables must have the same domain')\n\n        conc = cls.from_numpy(\n            domain,\n            vstack(collect(\"X\")),\n            merge1d(collect(\"Y\")),\n            vstack(collect(\"metas\")),\n            merge1d(collect(\"W\"))\n        )\n        conc.ids = np.hstack([t.ids for t in tables])\n        return conc\n\n    @classmethod\n    def _concatenate_horizontal(cls, tables):\n        \"\"\"\n        \"\"\"\n        def all_of(objs, names):\n            return (tuple(getattr(obj, name) for obj in objs)\n                    for name in names)\n\n        def stack(arrs):\n            non_empty = tuple(arr if arr.ndim == 2 else arr[:, np.newaxis]\n                              for arr in arrs\n                              if arr is not None and arr.size > 0)\n            return np.hstack(non_empty) if non_empty else None\n\n        doms, Ws = all_of(tables, (\"domain\", \"W\"))\n        Xs, Ys, Ms = map(stack, all_of(tables, (\"X\", \"Y\", \"metas\")))\n        # pylint: disable=undefined-loop-variable\n        for W in Ws:\n            if W.size:\n                break\n\n        parts = all_of(doms, (\"attributes\", \"class_vars\", \"metas\"))\n        domain = Domain(*(tuple(chain(*lst)) for lst in parts))\n        return cls.from_numpy(domain, Xs, Ys, Ms, W, ids=tables[0].ids)\n\n    def add_column(self, variable, data, to_metas=None):\n        \"\"\"\n        Create a new table with an additional column\n\n        Column's name must be unique\n\n        Args:\n            variable (Variable): variable for the new column\n            data (np.ndarray): data for the new column\n            to_metas (bool, optional): if `True` the column is added as meta\n                column. Otherwise, primitive variables are added to attributes\n                and non-primitive to metas.\n\n        Returns:\n            table (Table): a new table with the additional column\n        \"\"\"\n        dom = self.domain\n        attrs, classes, metavars = dom.attributes, dom.class_vars, dom.metas\n        to_metas = to_metas or not variable.is_primitive()\n        if to_metas:\n            metavars += (variable, )\n        else:\n            attrs += (variable, )\n        domain = Domain(attrs, classes, metavars)\n        new_table = self.transform(domain)\n        with new_table.unlocked(new_table.metas if to_metas else new_table.X):\n            new_table.get_column_view(variable)[0][:] = data\n        return new_table\n\n    def is_view(self):\n        \"\"\"\n        Return `True` if all arrays represent a view referring to another table\n        \"\"\"\n        return ((not self._X.shape[-1] or self._X.base is not None) and\n                (not self._Y.shape[-1] or self._Y.base is not None) and\n                (not self._metas.shape[-1] or self._metas.base is not None) and\n                (not self._weights.shape[-1] or self._W.base is not None))\n\n    def is_copy(self):\n        \"\"\"\n        Return `True` if the table owns its data\n        \"\"\"\n        return ((not self._X.shape[-1] or self._X.base is None) and\n                (self._Y.base is None) and\n                (self._metas.base is None) and\n                (self._W.base is None))\n\n    def is_sparse(self):\n        \"\"\"\n        Return `True` if the table stores data in sparse format\n        \"\"\"\n        return any(sp.issparse(i) for i in [self._X, self._Y, self._metas])\n\n    def ensure_copy(self):\n        \"\"\"\n        Ensure that the table owns its data; copy arrays when necessary.\n        \"\"\"\n\n        def is_view(x):\n            # Sparse matrices don't have views like numpy arrays. Since indexing on\n            # them creates copies in constructor we can skip this check here.\n            return not sp.issparse(x) and x.base is not None\n\n        if is_view(self._X):\n            self._X = self._X.copy()\n        if is_view(self._Y):\n            self._Y = self._Y.copy()\n        if is_view(self._metas):\n            self._metas = self._metas.copy()\n        if is_view(self._W):\n            self._W = self._W.copy()\n\n    def copy(self):\n        \"\"\"\n        Return a copy of the table\n        \"\"\"\n        t = self.__class__(self)\n        t.ensure_copy()\n        return t\n\n    @staticmethod\n    def __determine_density(data):\n        if data is None:\n            return Storage.Missing\n        if data is not None and sp.issparse(data):\n            return Storage.SPARSE_BOOL if (data.data == 1).all() else Storage.SPARSE\n        else:\n            return Storage.DENSE\n\n    def X_density(self):\n        if not hasattr(self, \"_X_density\"):\n            self._X_density = self.__determine_density(self.X)\n        return self._X_density\n\n    def Y_density(self):\n        if not hasattr(self, \"_Y_density\"):\n            self._Y_density = self.__determine_density(self._Y)\n        return self._Y_density\n\n    def metas_density(self):\n        if not hasattr(self, \"_metas_density\"):\n            self._metas_density = self.__determine_density(self.metas)\n        return self._metas_density\n\n    def set_weights(self, weight=1):\n        \"\"\"\n        Set weights of data instances; create a vector of weights if necessary.\n        \"\"\"\n        if not self.W.shape[-1]:\n            self.W = np.empty(len(self))\n        self.W[:] = weight\n\n    def has_weights(self):\n        \"\"\"Return `True` if the data instances are weighed. \"\"\"\n        return self.W.shape[-1] != 0\n\n    def total_weight(self):\n        \"\"\"\n        Return the total weight of instances in the table, or their number if\n        they are unweighted.\n        \"\"\"\n        if self.W.shape[-1]:\n            return sum(self.W)\n        return len(self)\n\n    def has_missing(self):\n        \"\"\"Return `True` if there are any missing attribute or class values.\"\"\"\n        missing_x = not sp.issparse(self.X) and bn.anynan(self.X)  # do not check for sparse X\n        return missing_x or bn.anynan(self._Y)\n\n    def has_missing_attribute(self):\n        \"\"\"Return `True` if there are any missing attribute values.\"\"\"\n        return not sp.issparse(self.X) and bn.anynan(self.X)  # do not check for sparse X\n\n    def has_missing_class(self):\n        \"\"\"Return `True` if there are any missing class values.\"\"\"\n        return bn.anynan(self._Y)\n\n    def get_nan_frequency_attribute(self):\n        if self.X.size == 0:\n            return 0\n        return np.isnan(self.X).sum() / self.X.size\n\n    def get_nan_frequency_class(self):\n        if self.Y.size == 0:\n            return 0\n        return np.isnan(self._Y).sum() / self._Y.size\n\n    def checksum(self, include_metas=True):\n        # TODO: zlib.adler32 does not work for numpy arrays with dtype object\n        # (after pickling and unpickling such arrays, checksum changes)\n        # Why, and should we fix it or remove it?\n        \"\"\"Return a checksum over X, Y, metas and W.\"\"\"\n        cs = zlib.adler32(np.ascontiguousarray(self._X))\n        cs = zlib.adler32(np.ascontiguousarray(self._Y), cs)\n        if include_metas:\n            cs = zlib.adler32(np.ascontiguousarray(self._metas), cs)\n        cs = zlib.adler32(np.ascontiguousarray(self._W), cs)\n        return cs\n\n    def shuffle(self):\n        \"\"\"Randomly shuffle the rows of the table.\"\"\"\n        if not self._check_all_dense():\n            raise ValueError(\"Rows of sparse data cannot be shuffled\")\n        ind = np.arange(self.X.shape[0])\n        np.random.shuffle(ind)\n        self.X = self.X[ind]\n        self._Y = self._Y[ind]\n        self.metas = self.metas[ind]\n        self.W = self.W[ind]\n\n    def get_column_view(self, index):\n        \"\"\"\n        Return a vector - as a view, not a copy - with a column of the table,\n        and a bool flag telling whether this column is sparse. Note that\n        vertical slicing of sparse matrices is inefficient.\n\n        :param index: the index of the column\n        :type index: int, str or Orange.data.Variable\n        :return: (one-dimensional numpy array, sparse)\n        \"\"\"\n\n        def rx(M):\n            if sp.issparse(M):\n                return np.asarray(M.todense())[:, 0], True\n            else:\n                return M, False\n\n        if isinstance(index, Integral):\n            col_index = index\n        else:\n            col_index = self.domain.index(index)\n        if col_index >= 0:\n            if col_index < self.X.shape[1]:\n                col = rx(self.X[:, col_index])\n            elif self._Y.ndim == 1 and col_index == self._X.shape[1]:\n                col = rx(self._Y)\n            else:\n                col = rx(self._Y[:, col_index - self.X.shape[1]])\n        else:\n            col = rx(self.metas[:, -1 - col_index])\n\n        if isinstance(index, DiscreteVariable) \\\n                and index.values != self.domain[col_index].values:\n            col = index.get_mapper_from(self.domain[col_index])(col[0]), col[1]\n            col[0].flags.writeable = False\n        return col\n\n    def _filter_is_defined(self, columns=None, negate=False):\n        # structure of function is obvious; pylint: disable=too-many-branches\n        def _sp_anynan(a):\n            return a.indptr[1:] != a[-1:] + a.shape[1]\n\n        if columns is None:\n            if sp.issparse(self.X):\n                remove = _sp_anynan(self.X)\n            else:\n                remove = bn.anynan(self.X, axis=1)\n            if sp.issparse(self._Y):\n                remove += _sp_anynan(self._Y)\n            else:\n                if self._Y.ndim == 1:\n                    remove += np.isnan(self._Y)\n                else:\n                    remove += bn.anynan(self._Y, axis=1)\n            if sp.issparse(self.metas):\n                remove += _sp_anynan(self._metas)\n            else:\n                for i, var in enumerate(self.domain.metas):\n                    col = self.metas[:, i].flatten()\n                    if var.is_primitive():\n                        remove += np.isnan(col.astype(float))\n                    else:\n                        remove += ~col.astype(bool)\n        else:\n            remove = np.zeros(len(self), dtype=bool)\n            for column in columns:\n                col, sparse = self.get_column_view(column)\n                if sparse:\n                    remove += col == 0\n                elif self.domain[column].is_primitive():\n                    remove += bn.anynan([col.astype(float)], axis=0)\n                else:\n                    remove += col.astype(bool)\n        retain = remove if negate else np.logical_not(remove)\n        return self.from_table_rows(self, retain)\n\n    def _filter_has_class(self, negate=False):\n        if sp.issparse(self._Y):\n            if negate:\n                retain = (self._Y.indptr[1:] !=\n                          self._Y.indptr[-1:] + self._Y.shape[1])\n            else:\n                retain = (self._Y.indptr[1:] ==\n                          self._Y.indptr[-1:] + self._Y.shape[1])\n        else:\n            if self._Y.ndim == 1:\n                retain = np.isnan(self._Y)\n            else:\n                retain = bn.anynan(self._Y, axis=1)\n            if not negate:\n                retain = np.logical_not(retain)\n        return self.from_table_rows(self, retain)\n\n    def _filter_same_value(self, column, value, negate=False):\n        if not isinstance(value, Real):\n            value = self.domain[column].to_val(value)\n        sel = self.get_column_view(column)[0] == value\n        if negate:\n            sel = np.logical_not(sel)\n        return self.from_table_rows(self, sel)\n\n    def _filter_values(self, filter):\n        selection = self._values_filter_to_indicator(filter)\n        return self.from_table(self.domain, self, selection)\n\n    def _values_filter_to_indicator(self, filter):\n        \"\"\"Return selection of rows matching the filter conditions\n\n        Handles conjunction/disjunction and negate modifiers\n\n        Parameters\n        ----------\n        filter: Values object containing the conditions\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        from Orange.data.filter import Values\n\n        if isinstance(filter, Values):\n            conditions = filter.conditions\n            conjunction = filter.conjunction\n        else:\n            conditions = [filter]\n            conjunction = True\n        if conjunction:\n            sel = np.ones(len(self), dtype=bool)\n        else:\n            sel = np.zeros(len(self), dtype=bool)\n\n        for f in conditions:\n            selection = self._filter_to_indicator(f)\n\n            if conjunction:\n                sel *= selection\n            else:\n                sel += selection\n\n        if filter.negate:\n            sel = ~sel\n        return sel\n\n    def _filter_to_indicator(self, filter):\n        \"\"\"Return selection of rows that match the condition.\n\n        Parameters\n        ----------\n        filter: ValueFilter describing the condition\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        from Orange.data.filter import (\n            FilterContinuous, FilterDiscrete, FilterRegex, FilterString,\n            FilterStringList, IsDefined, Values\n        )\n        if isinstance(filter, Values):\n            return self._values_filter_to_indicator(filter)\n\n        def get_col_indices():\n            cols = chain(self.domain.variables, self.domain.metas)\n            if isinstance(filter, IsDefined):\n                if filter.columns is not None:\n                    return list(filter.columns)\n                else:\n                    return list(cols)\n\n            if filter.column is not None:\n                return [filter.column]\n\n            if isinstance(filter, FilterDiscrete):\n                raise ValueError(\"Discrete filter can't be applied across rows\")\n            if isinstance(filter, FilterContinuous):\n                return [col for col in cols if col.is_continuous]\n            if isinstance(filter,\n                          (FilterString, FilterStringList, FilterRegex)):\n                return [col for col in cols if col.is_string]\n            raise TypeError(\"Invalid filter\")\n\n        def col_filter(col_idx):\n            col = self.get_column_view(col_idx)[0]\n            if isinstance(filter, IsDefined):\n                if self.domain[col_idx].is_primitive():\n                    return ~np.isnan(col.astype(float))\n                else:\n                    return col.astype(bool)\n            if isinstance(filter, FilterDiscrete):\n                return self._discrete_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterContinuous):\n                return self._continuous_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterString):\n                return self._string_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterStringList):\n                if not filter.case_sensitive:\n                    col = np.char.lower(np.array(col, dtype=str))\n                    vals = [val.lower() for val in filter.values]\n                else:\n                    vals = filter.values\n                return reduce(operator.add, (col == val for val in vals))\n            if isinstance(filter, FilterRegex):\n                return np.vectorize(filter)(col)\n            raise TypeError(\"Invalid filter\")\n\n        col_indices = get_col_indices()\n        if len(col_indices) == 1:\n            sel = col_filter(col_indices[0])\n        else:\n            sel = np.ones(len(self), dtype=bool)\n            for col_idx in col_indices:\n                sel *= col_filter(col_idx)\n\n        if isinstance(filter, IsDefined) and filter.negate:\n            sel = ~sel\n        return sel\n\n    def _discrete_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given discrete filter.\n\n        Parameters\n        ----------\n        filter: FilterDiscrete\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.values is None:  # <- is defined filter\n            col = col.astype(float)\n            return ~np.isnan(col)\n\n        sel = np.zeros(len(self), dtype=bool)\n        for val in filter.values:\n            if not isinstance(val, Real):\n                val = self.domain[filter.column].to_val(val)\n            sel += (col == val)\n        return sel\n\n    def _continuous_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given continuous filter.\n\n        Parameters\n        ----------\n        filter: FilterContinuous\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.oper == filter.IsDefined:\n            col = col.astype(float)\n            return ~np.isnan(col)\n\n        return self._range_filter_to_indicator(filter, col, filter.min, filter.max)\n\n    def _string_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given string filter.\n\n        Parameters\n        ----------\n        filter: FilterString\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.oper == filter.IsDefined:\n            return col.astype(bool)\n\n        col = col.astype(str)\n        fmin = filter.min or \"\"\n        fmax = filter.max or \"\"\n\n        if not filter.case_sensitive:\n            # convert all to lower case\n            col = np.char.lower(col)\n            fmin = fmin.lower()\n            fmax = fmax.lower()\n\n        if filter.oper == filter.Contains:\n            return np.fromiter((fmin in e for e in col),\n                               dtype=bool)\n        if filter.oper == filter.StartsWith:\n            return np.fromiter((e.startswith(fmin) for e in col),\n                               dtype=bool)\n        if filter.oper == filter.EndsWith:\n            return np.fromiter((e.endswith(fmin) for e in col),\n                               dtype=bool)\n\n        return self._range_filter_to_indicator(filter, col, fmin, fmax)\n\n    @staticmethod\n    def _range_filter_to_indicator(filter, col, fmin, fmax):\n        with np.errstate(invalid=\"ignore\"):  # nan's are properly discarded\n            if filter.oper == filter.Equal:\n                return col == fmin\n            if filter.oper == filter.NotEqual:\n                return col != fmin\n            if filter.oper == filter.Less:\n                return col < fmin\n            if filter.oper == filter.LessEqual:\n                return col <= fmin\n            if filter.oper == filter.Greater:\n                return col > fmin\n            if filter.oper == filter.GreaterEqual:\n                return col >= fmin\n            if filter.oper == filter.Between:\n                return (col >= fmin) * (col <= fmax)\n            if filter.oper == filter.Outside:\n                return (col < fmin) + (col > fmax)\n\n            raise TypeError(\"Invalid operator\")\n\n    def _compute_basic_stats(self, columns=None,\n                             include_metas=False, compute_variance=False):\n        if compute_variance:\n            raise NotImplementedError(\"computation of variance is \"\n                                      \"not implemented yet\")\n        W = self._W if self.has_weights() else None\n        rr = []\n        stats = []\n        if not columns:\n            if self.domain.attributes:\n                rr.append(fast_stats(self._X, W))\n            if self.domain.class_vars:\n                rr.append(fast_stats(self._Y, W))\n            if include_metas and self.domain.metas:\n                rr.append(fast_stats(self.metas, W))\n            if len(rr):\n                stats = np.vstack(tuple(rr))\n        else:\n            nattrs = len(self.domain.attributes)\n            for column in columns:\n                c = self.domain.index(column)\n                if 0 <= c < nattrs:\n                    S = fast_stats(self._X[:, [c]], W and W[:, [c]])\n                elif c >= nattrs:\n                    if self._Y.ndim == 1 and c == nattrs:\n                        S = fast_stats(self._Y[:, None], W and W[:, None])\n                    else:\n                        S = fast_stats(self._Y[:, [c - nattrs]], W and W[:, [c - nattrs]])\n                else:\n                    S = fast_stats(self._metas[:, [-1 - c]], W and W[:, [-1 - c]])\n                stats.append(S[0])\n        return stats\n\n    def _compute_distributions(self, columns=None):\n        if columns is None:\n            columns = range(len(self.domain.variables))\n        else:\n            columns = [self.domain.index(var) for var in columns]\n\n        distributions = []\n        X = self.X\n        if sp.issparse(X):\n            X = X.tocsc()\n\n\n        W = self.W.ravel() if self.has_weights() else None\n\n        for col in columns:\n            variable = self.domain[col]\n\n            # Select the correct data column from X, Y or metas\n            if 0 <= col < X.shape[1]:\n                x = X[:, col]\n            elif col < 0:\n                x = self.metas[:, col * (-1) - 1]\n                if np.issubdtype(x.dtype, np.dtype(object)):\n                    x = x.astype(float)\n            elif self._Y.ndim == 1 and col == X.shape[1]:\n                x = self._Y\n            else:\n                x = self._Y[:, col - X.shape[1]]\n\n            if variable.is_discrete:\n                dist, unknowns = bincount(x, weights=W, max_val=len(variable.values) - 1)\n            elif not x.shape[0]:\n                dist, unknowns = np.zeros((2, 0)), 0\n            else:\n                if W is not None:\n                    if sp.issparse(x):\n                        arg_sort = np.argsort(x.data)\n                        ranks = x.indices[arg_sort]\n                        vals = np.vstack((x.data[arg_sort], W[ranks]))\n                    else:\n                        ranks = np.argsort(x)\n                        vals = np.vstack((x[ranks], W[ranks]))\n                else:\n                    x_values = x.data if sp.issparse(x) else x\n                    vals = np.ones((2, x_values.shape[0]))\n                    vals[0, :] = x_values\n                    vals[0, :].sort()\n\n                dist = np.array(_valuecount.valuecount(vals))\n                # If sparse, then 0s will not be counted with `valuecount`, so\n                # we have to add them to the result manually.\n                if sp.issparse(x) and sparse_has_implicit_zeros(x):\n                    if W is not None:\n                        zero_weights = sparse_implicit_zero_weights(x, W).sum()\n                    else:\n                        zero_weights = sparse_count_implicit_zeros(x)\n                    zero_vec = [0, zero_weights]\n                    dist = np.insert(dist, np.searchsorted(dist[0], 0), zero_vec, axis=1)\n                # Since `countnans` assumes vector shape to be (1, n) and `x`\n                # shape is (n, 1), we pass the transpose\n                unknowns = countnans(x.T, W)\n            distributions.append((dist, unknowns))\n\n        return distributions\n\n    def _compute_contingency(self, col_vars=None, row_var=None):\n        n_atts = self.X.shape[1]\n\n        if col_vars is None:\n            col_vars = range(len(self.domain.variables))\n        else:\n            col_vars = [self.domain.index(var) for var in col_vars]\n        if row_var is None:\n            row_var = self.domain.class_var\n            if row_var is None:\n                raise ValueError(\"No row variable\")\n\n        row_desc = self.domain[row_var]\n        if not row_desc.is_discrete:\n            raise TypeError(\"Row variable must be discrete\")\n        row_indi = self.domain.index(row_var)\n        n_rows = len(row_desc.values)\n        if 0 <= row_indi < n_atts:\n            row_data = self.X[:, row_indi]\n        elif row_indi < 0:\n            row_data = self.metas[:, -1 - row_indi]\n        elif self._Y.ndim == 1 and row_indi == n_atts:\n            row_data = self._Y\n        else:\n            row_data = self._Y[:, row_indi - n_atts]\n\n        W = self.W if self.has_weights() else None\n\n        col_desc = [self.domain[var] for var in col_vars]\n        col_indi = [self.domain.index(var) for var in col_vars]\n\n        if any(not (var.is_discrete or var.is_continuous)\n               for var in col_desc):\n            raise ValueError(\"Contingency can be computed only for categorical \"\n                             \"and numeric values.\")\n\n        # when we select a column in sparse matrix it is still two dimensional\n        # and sparse - since it is just a column we can afford to transform\n        # it to dense and make it 1D\n        if issparse(row_data):\n            row_data = row_data.toarray().ravel()\n        if row_data.dtype.kind != \"f\":  # meta attributes can be stored as type object\n            row_data = row_data.astype(float)\n\n        contingencies = [None] * len(col_desc)\n        for arr, f_cond, f_ind in (\n                (self.X, lambda i: 0 <= i < n_atts, lambda i: i),\n                (self._Y, lambda i: i >= n_atts, lambda i: i - n_atts),\n                (self.metas, lambda i: i < 0, lambda i: -1 - i)):\n\n            arr_indi = [e for e, ind in enumerate(col_indi) if f_cond(ind)]\n\n            vars = [(e, f_ind(col_indi[e]), col_desc[e]) for e in arr_indi]\n            disc_vars = [v for v in vars if v[2].is_discrete]\n            if disc_vars:\n                if sp.issparse(arr):\n                    max_vals = max(len(v[2].values) for v in disc_vars)\n                    disc_indi = {i for _, i, _ in disc_vars}\n                    mask = [i in disc_indi for i in range(arr.shape[1])]\n                    conts, nans_cols, nans_rows, nans = contingency(\n                        arr, row_data, max_vals - 1, n_rows - 1, W, mask)\n                    for col_i, arr_i, var in disc_vars:\n                        n_vals = len(var.values)\n                        contingencies[col_i] = (\n                            conts[arr_i][:, :n_vals], nans_cols[arr_i],\n                            nans_rows[arr_i], nans[arr_i])\n                else:\n                    for col_i, arr_i, var in disc_vars:\n                        col = arr if arr.ndim == 1 else arr[:, arr_i]\n                        contingencies[col_i] = contingency(\n                            col.astype(float),\n                            row_data, len(var.values) - 1, n_rows - 1, W)\n\n            cont_vars = [v for v in vars if v[2].is_continuous]\n            if cont_vars:\n                W_ = None\n                if W is not None:\n                    W_ = W.astype(dtype=np.float64)\n                if sp.issparse(arr):\n                    arr = sp.csc_matrix(arr)\n\n                for col_i, arr_i, _ in cont_vars:\n                    if sp.issparse(arr):\n                        col_data = arr.data[arr.indptr[arr_i]:arr.indptr[arr_i + 1]]\n                        rows = arr.indices[arr.indptr[arr_i]:arr.indptr[arr_i + 1]]\n                        W_ = None if W_ is None else W_[rows]\n                        classes_ = row_data[rows]\n                    else:\n                        col_data, W_, classes_ = arr[:, arr_i], W_, row_data\n\n                    col_data = col_data.astype(dtype=np.float64)\n                    contingencies[col_i] = _contingency.contingency_floatarray(\n                        col_data, classes_, n_rows, W_)\n\n        return contingencies\n\n    @classmethod\n    def transpose(cls, table, feature_names_column=\"\",\n                  meta_attr_name=\"Feature name\", feature_name=\"Feature\",\n                  remove_redundant_inst=False, progress_callback=None):\n        \"\"\"\n        Transpose the table.\n\n        :param table: Table - table to transpose\n        :param feature_names_column: str - name of (String) meta attribute to\n            use for feature names\n        :param meta_attr_name: str - name of new meta attribute into which\n            feature names are mapped\n        :param feature_name: str - default feature name prefix\n        :param remove_redundant_inst: bool - remove instance that\n            represents feature_names_column\n        :param progress_callback: callable - to report the progress\n        :return: Table - transposed table\n        \"\"\"\n        if progress_callback is None:\n            progress_callback = dummy_callback\n        progress_callback(0, \"Transposing...\")\n\n        if isinstance(feature_names_column, Variable):\n            feature_names_column = feature_names_column.name\n\n        self = cls()\n        n_cols, self.n_rows = table.X.shape\n        old_domain = table.attributes.get(\"old_domain\")\n        table_domain_attributes = list(table.domain.attributes)\n        attr_index = None\n        if remove_redundant_inst:\n            attr_names = [a.name for a in table_domain_attributes]\n            if feature_names_column and feature_names_column in attr_names:\n                attr_index = attr_names.index(feature_names_column)\n                self.n_rows = self.n_rows - 1\n                table_domain_attributes.remove(\n                    table_domain_attributes[attr_index])\n\n        # attributes\n        # - classes and metas to attributes of attributes\n        # - arbitrary meta column to feature names\n        with self.unlocked():\n            self.X = table.X.T\n            if attr_index is not None:\n                self.X = np.delete(self.X, attr_index, 0)\n            if feature_names_column:\n                names = [str(row[feature_names_column]) for row in table]\n                progress_callback(0.1)\n                names = get_unique_names_duplicates(names)\n                progress_callback(0.3)\n                attributes = [ContinuousVariable(name) for name in names]\n            else:\n                places = int(np.ceil(np.log10(n_cols))) if n_cols else 1\n                attributes = [ContinuousVariable(f\"{feature_name} {i:0{places}}\")\n                              for i in range(1, n_cols + 1)]\n            progress_callback(0.4)\n\n            if old_domain is not None and feature_names_column:\n                for i, _ in enumerate(attributes):\n                    if attributes[i].name in old_domain:\n                        var = old_domain[attributes[i].name]\n                        attr = ContinuousVariable(var.name) if var.is_continuous \\\n                            else DiscreteVariable(var.name, var.values)\n                        attr.attributes = var.attributes.copy()\n                        attributes[i] = attr\n\n            def set_attributes_of_attributes(_vars, _table):\n                for i, variable in enumerate(_vars):\n                    if variable.name == feature_names_column:\n                        continue\n                    for j, row in enumerate(_table):\n                        value = variable.repr_val(row) if np.isscalar(row) \\\n                            else row[i] if isinstance(row[i], str) \\\n                            else variable.repr_val(row[i])\n\n                        if value not in MISSING_VALUES:\n                            attributes[j].attributes[variable.name] = value\n\n            set_attributes_of_attributes(table.domain.class_vars, table.Y)\n            progress_callback(0.5)\n            set_attributes_of_attributes(table.domain.metas, table.metas)\n\n            # weights\n            self.W = np.empty((self.n_rows, 0))\n\n            def get_table_from_attributes_of_attributes(_vars, _dtype=float):\n                T = np.empty((self.n_rows, len(_vars)), dtype=_dtype)\n                for i, _attr in enumerate(table_domain_attributes):\n                    for j, _var in enumerate(_vars):\n                        val = str(_attr.attributes.get(_var.name, \"\"))\n                        if not _var.is_string:\n                            val = np.nan if val in MISSING_VALUES else \\\n                                _var.values.index(val) if \\\n                                    _var.is_discrete else float(val)\n                        T[i, j] = val\n                return T\n\n            # class_vars - attributes of attributes to class - from old domain\n            class_vars = []\n            if old_domain is not None:\n                class_vars = old_domain.class_vars\n            self.Y = get_table_from_attributes_of_attributes(class_vars)\n\n            # metas\n            # - feature names and attributes of attributes to metas\n            self.metas, metas = np.empty((self.n_rows, 0), dtype=object), []\n            if meta_attr_name not in [m.name for m in table.domain.metas] and \\\n                    table_domain_attributes:\n                self.metas = np.array([[a.name] for a in table_domain_attributes],\n                                      dtype=object)\n                metas.append(StringVariable(meta_attr_name))\n\n            names = chain.from_iterable(list(attr.attributes)\n                                        for attr in table_domain_attributes)\n            names = sorted(set(names) - {var.name for var in class_vars})\n            progress_callback(0.6)\n\n            def guessed_var(i, var_name):\n                orig_vals = M[:, i]\n                val_map, vals, var_type = Orange.data.io.guess_data_type(orig_vals)\n                values, variable = Orange.data.io.sanitize_variable(\n                    val_map, vals, orig_vals, var_type, {}, name=var_name)\n                M[:, i] = values\n                return variable\n\n            _metas = [StringVariable(n) for n in names]\n            if old_domain is not None:\n                _metas = [m for m in old_domain.metas if m.name != meta_attr_name]\n            M = get_table_from_attributes_of_attributes(_metas, _dtype=object)\n            progress_callback(0.7)\n            if old_domain is None:\n                _metas = [guessed_var(i, m.name) for i, m in enumerate(_metas)]\n            if _metas:\n                self.metas = np.hstack((self.metas, M))\n                metas.extend(_metas)\n\n            self.domain = Domain(attributes, class_vars, metas)\n            progress_callback(0.9)\n            cls._init_ids(self)\n            self.attributes = table.attributes.copy()\n            self.attributes[\"old_domain\"] = table.domain\n            progress_callback(1)\n            return self\n\n    def to_sparse(self, sparse_attributes=True, sparse_class=False,\n                  sparse_metas=False):\n        def sparsify(features):\n            for f in features:\n                f.sparse = True\n\n        new_domain = self.domain.copy()\n\n        if sparse_attributes:\n            sparsify(new_domain.attributes)\n        if sparse_class:\n            sparsify(new_domain.class_vars)\n        if sparse_metas:\n            sparsify(new_domain.metas)\n        return self.transform(new_domain)\n\n    def to_dense(self, dense_attributes=True, dense_class=True,\n                 dense_metas=True):\n        def densify(features):\n            for f in features:\n                f.sparse = False\n\n        new_domain = self.domain.copy()\n\n        if dense_attributes:\n            densify(new_domain.attributes)\n        if dense_class:\n            densify(new_domain.class_vars)\n        if dense_metas:\n            densify(new_domain.metas)\n        t = self.transform(new_domain)\n        t.ids = self.ids  # preserve indices\n        return t",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 361,
                                "end_lineno": 2227,
                                "parent": null
                            }
                        }
                    ],
                    "deleted_entities": []
                }
            ]
        },
        {
            "old_file_content": "# Test methods with long descriptive names can omit docstrings\n# pylint: disable=missing-docstring\n\nimport copy\nimport os\nimport random\nimport unittest\nimport warnings\nfrom unittest.mock import Mock, MagicMock, patch\nfrom itertools import chain\nfrom math import isnan\nfrom threading import Thread\nfrom time import sleep, time\n\nimport numpy as np\nimport scipy.sparse as sp\n\nfrom Orange import data\nfrom Orange.data import (filter, Unknown, Variable, Table, DiscreteVariable,\n                         ContinuousVariable, Domain, StringVariable)\nfrom Orange.data.util import SharedComputeValue\nfrom Orange.tests import test_dirname\nfrom Orange.data.table import _optimize_indices\n\n\nclass TableTestCase(unittest.TestCase):\n    def setUp(self):\n        data.table.dataset_dirs.append(test_dirname())\n\n    def tearDown(self):\n        data.table.dataset_dirs.remove(test_dirname())\n\n    def test_indexing_class(self):\n        d = data.Table(\"datasets/test1\")\n        self.assertEqual([e.get_class() for e in d], [\"t\", \"t\", \"f\"])\n        cind = len(d.domain.variables) - 1\n        self.assertEqual([e[cind] for e in d], [\"t\", \"t\", \"f\"])\n        self.assertEqual([e[\"d\"] for e in d], [\"t\", \"t\", \"f\"])\n        cvar = d.domain.class_var\n        self.assertEqual([e[cvar] for e in d], [\"t\", \"t\", \"f\"])\n\n    def test_filename(self):\n        dir = data.table.get_sample_datasets_dir()\n        d = data.Table(\"iris\")\n        self.assertEqual(d.__file__, os.path.join(dir, \"iris.tab\"))\n\n        d = data.Table(\"datasets/test2.tab\")\n        self.assertTrue(d.__file__.endswith(\"test2.tab\"))  # platform dependent\n\n    def test_indexing(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            # regular, discrete\n            varc = d.domain[\"c\"]\n            self.assertEqual(d[0, 1], \"0\")\n            self.assertEqual(d[0, varc], \"0\")\n            self.assertEqual(d[0, \"c\"], \"0\")\n            self.assertEqual(d[0][1], \"0\")\n            self.assertEqual(d[0][varc], \"0\")\n            self.assertEqual(d[0][\"c\"], \"0\")\n            self.assertEqual(d[np.int_(0), np.int_(1)], \"0\")\n            self.assertEqual(d[np.int_(0)][np.int_(1)], \"0\")\n\n            # regular, continuous\n            varb = d.domain[\"b\"]\n            self.assertEqual(d[0, 0], 0)\n            self.assertEqual(d[0, varb], 0)\n            self.assertEqual(d[0, \"b\"], 0)\n            self.assertEqual(d[0][0], 0)\n            self.assertEqual(d[0][varb], 0)\n            self.assertEqual(d[0][\"b\"], 0)\n            self.assertEqual(d[np.int_(0), np.int_(0)], 0)\n            self.assertEqual(d[np.int_(0)][np.int_(0)], 0)\n\n            # negative\n            varb = d.domain[\"b\"]\n            self.assertEqual(d[-2, 0], 3.333)\n            self.assertEqual(d[-2, varb], 3.333)\n            self.assertEqual(d[-2, \"b\"], 3.333)\n            self.assertEqual(d[-2][0], 3.333)\n            self.assertEqual(d[-2][varb], 3.333)\n            self.assertEqual(d[-2][\"b\"], 3.333)\n            self.assertEqual(d[np.int_(-2), np.int_(0)], 3.333)\n            self.assertEqual(d[np.int_(-2)][np.int_(0)], 3.333)\n\n            # meta, discrete\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n            self.assertEqual(d[0, metaa], \"A\")\n            self.assertEqual(d[0, vara], \"A\")\n            self.assertEqual(d[0, \"a\"], \"A\")\n            self.assertEqual(d[0][metaa], \"A\")\n            self.assertEqual(d[0][vara], \"A\")\n            self.assertEqual(d[0][\"a\"], \"A\")\n            self.assertEqual(d[np.int_(0), np.int_(metaa)], \"A\")\n            self.assertEqual(d[np.int_(0)][np.int_(metaa)], \"A\")\n\n            # meta, string\n            vare = d.domain[\"e\"]\n            metae = d.domain.index(\"e\")\n            self.assertEqual(d[0, metae], \"i\")\n            self.assertEqual(d[0, vare], \"i\")\n            self.assertEqual(d[0, \"e\"], \"i\")\n            self.assertEqual(d[0][metae], \"i\")\n            self.assertEqual(d[0][vare], \"i\")\n            self.assertEqual(d[0][\"e\"], \"i\")\n            self.assertEqual(d[np.int_(0), np.int_(metae)], \"i\")\n            self.assertEqual(d[np.int_(0)][np.int_(metae)], \"i\")\n\n    def test_indexing_example(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            e = d[0]\n\n            # regular, discrete\n            varc = d.domain[\"c\"]\n            self.assertEqual(e[1], \"0\")\n            self.assertEqual(e[varc], \"0\")\n            self.assertEqual(e[\"c\"], \"0\")\n            self.assertEqual(e[np.int_(1)], \"0\")\n\n            # regular, continuous\n            varb = d.domain[\"b\"]\n            self.assertEqual(e[0], 0)\n            self.assertEqual(e[varb], 0)\n            self.assertEqual(e[\"b\"], 0)\n            self.assertEqual(e[np.int_(0)], 0)\n\n            # meta, discrete\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n            self.assertEqual(e[metaa], \"A\")\n            self.assertEqual(e[vara], \"A\")\n            self.assertEqual(e[\"a\"], \"A\")\n            self.assertEqual(e[np.int_(metaa)], \"A\")\n\n            # meta, string\n            vare = d.domain[\"e\"]\n            metae = d.domain.index(\"e\")\n            self.assertEqual(e[metae], \"i\")\n            self.assertEqual(e[vare], \"i\")\n            self.assertEqual(e[\"e\"], \"i\")\n            self.assertEqual(e[np.int_(metae)], \"i\")\n\n    def test_indexing_assign_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            # meta\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, \"a\"] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][\"a\"] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, vara] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][vara] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, metaa] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][metaa] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, np.int_(metaa)] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][np.int_(metaa)] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            # regular\n            varb = d.domain[\"b\"]\n\n            self.assertEqual(d[0, \"b\"], 0)\n            with d.unlocked():\n                d[0, \"b\"] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][\"b\"] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, varb] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][varb] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, 0] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][0] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, np.int_(0)] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][np.int_(0)] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n    def test_indexing_assign_example(self):\n        def almost_equal_list(s, t):\n            for e, f in zip(s, t):\n                self.assertAlmostEqual(e, f)\n\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            self.assertFalse(isnan(d[0, \"a\"]))\n            with d.unlocked():\n                d[0] = [\"3.14\", \"1\", \"f\"]\n            almost_equal_list(d[0].values(), [3.14, \"1\", \"f\"])\n            self.assertTrue(isnan(d[0, \"a\"]))\n\n            with d.unlocked():\n                d[0] = [3.15, 1, \"t\"]\n            almost_equal_list(d[0].values(), [3.15, \"0\", \"t\"])\n\n            with d.unlocked():\n                d[np.int_(0)] = [3.15, 2, \"f\"]\n            almost_equal_list(d[0].values(), [3.15, 2, \"f\"])\n\n            with d.unlocked(), self.assertRaises(ValueError):\n                d[0] = [\"3.14\", \"1\"]\n\n            with d.unlocked(), self.assertRaises(ValueError):\n                d[np.int_(0)] = [\"3.14\", \"1\"]\n\n            ex = data.Instance(d.domain, [\"3.16\", \"1\", \"f\"])\n            with d.unlocked():\n                d[0] = ex\n            almost_equal_list(d[0].values(), [3.16, \"1\", \"f\"])\n\n            ex = data.Instance(d.domain, [\"3.16\", 2, \"t\"])\n            with d.unlocked():\n                d[np.int_(0)] = ex\n            almost_equal_list(d[0].values(), [3.16, 2, \"t\"])\n\n            ex = data.Instance(d.domain, [\"3.16\", \"1\", \"f\"])\n            ex[\"e\"] = \"mmmapp\"\n            with d.unlocked():\n                d[0] = ex\n            almost_equal_list(d[0].values(), [3.16, \"1\", \"f\"])\n            self.assertEqual(d[0, \"e\"], \"mmmapp\")\n\n    def test_slice(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            x = d[:3]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [0, 1.1, 2.22])\n\n            x = d[2:5]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.22, 2.23, 2.24])\n\n            x = d[4:1:-1]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.24, 2.23, 2.22])\n\n            x = d[-3:]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.26, 3.333, Unknown])\n\n    def test_assign_slice_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            with d.unlocked():\n                d[2:5, 0] = 42\n            self.assertEqual([e[0] for e in d],\n                             [0, 1.1, 42, 42, 42, 2.25, 2.26, 3.333, Unknown])\n            with d.unlocked():\n                d[:3, \"b\"] = 43\n            self.assertEqual([e[0] for e in d],\n                             [43, 43, 43, 42, 42, 2.25, 2.26, 3.333, None])\n            with d.unlocked():\n                d[-2:, d.domain[0]] = 44\n            self.assertEqual([e[0] for e in d],\n                             [43, 43, 43, 42, 42, 2.25, 2.26, 44, 44])\n\n            with d.unlocked():\n                d[2:5, \"a\"] = \"A\"\n            self.assertEqual([e[\"a\"] for e in d], list(\"ABAAACCDE\"))\n\n    def test_multiple_indices(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            with self.assertRaises(IndexError):\n                x = d[2, 5, 1]\n\n            with self.assertRaises(IndexError):\n                x = d[(2, 5, 1)]\n\n            x = d[[2, 5, 1]]\n            self.assertEqual([e[0] for e in x], [2.22, 2.25, 1.1])\n\n    def test_assign_multiple_indices_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            with d.unlocked():\n                d[1:4, \"b\"] = 42\n            self.assertEqual([e[0] for e in d],\n                             [0, 42, 42, 42, 2.24, 2.25, 2.26, 3.333, None])\n\n            with d.unlocked():\n                d[range(5, 2, -1), \"b\"] = None\n            self.assertEqual([e[d.domain[0]] for e in d],\n                             [0, 42, 42, None, \"?\", \"\", 2.26, 3.333, None])\n\n    def test_set_multiple_indices_example(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            vals = [e[0] for e in d]\n            with d.unlocked():\n                d[[1, 2, 5]] = [42, None, None]\n            vals[1] = vals[2] = vals[5] = 42\n            self.assertEqual([e[0] for e in d], vals)\n\n    def test_bool(self):\n        d = data.Table(\"iris\")\n        self.assertTrue(d)\n\n        d = data.Table(\"datasets/test3\")\n        self.assertFalse(d)\n\n        d = data.Table(\"iris\")\n        self.assertTrue(d)\n\n    def test_checksum(self):\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d[42, 3] = 0\n        crc1 = d.checksum(False)\n\n        with d.unlocked():\n            d[42, 3] = 1\n        crc2 = d.checksum(False)\n        self.assertNotEqual(crc1, crc2)\n\n        with d.unlocked():\n            d[42, 3] = 0\n        crc3 = d.checksum(False)\n        self.assertEqual(crc1, crc3)\n\n        _ = d[42, \"name\"]\n        with d.unlocked():\n            d[42, \"name\"] = \"non-animal\"\n        crc4 = d.checksum(False)\n        self.assertEqual(crc1, crc4)\n        crc4 = d.checksum(True)\n        crc5 = d.checksum(1)\n        crc6 = d.checksum(False)\n        self.assertNotEqual(crc1, crc4)\n        self.assertNotEqual(crc1, crc5)\n        self.assertEqual(crc1, crc6)\n\n    def test_total_weight(self):\n        d = data.Table(\"zoo\")\n        self.assertEqual(d.total_weight(), len(d))\n\n        with d.unlocked():\n            d.set_weights(0)\n            d[0].weight = 0.1\n            d[10].weight = 0.2\n            d[-1].weight = 0.3\n        self.assertAlmostEqual(d.total_weight(), 0.6)\n\n    def test_has_missing(self):\n        d = data.Table(\"zoo\")\n        self.assertFalse(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n        with d.unlocked():\n            d[10, 3] = \"?\"\n        self.assertTrue(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n        with d.unlocked():\n            d[10].set_class(\"?\")\n        self.assertTrue(d.has_missing())\n        self.assertTrue(d.has_missing_class())\n\n        with d.unlocked():\n            d = data.Table(\"datasets/test3\")\n        self.assertFalse(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n    def test_shuffle(self):\n        d = data.Table(\"zoo\")\n        crc = d.checksum()\n        names = set(str(x[\"name\"]) for x in d)\n\n        with d.unlocked():\n            d.shuffle()\n        self.assertNotEqual(crc, d.checksum())\n        self.assertSetEqual(names, set(str(x[\"name\"]) for x in d))\n        crc2 = d.checksum()\n\n        x = d[2:10]\n        crcx = x.checksum()\n        with d.unlocked():\n            d.shuffle()\n        self.assertNotEqual(crc2, d.checksum())\n        self.assertEqual(crcx, x.checksum())\n\n        crc2 = d.checksum()\n        with x.unlocked():\n            x.shuffle()\n        self.assertNotEqual(crcx, x.checksum())\n        self.assertEqual(crc2, d.checksum())\n\n    @staticmethod\n    def not_less_ex(ex1, ex2):\n        for v1, v2 in zip(ex1, ex2):\n            if v1 != v2:\n                return v1 < v2\n        return True\n\n    @staticmethod\n    def sorted(d):\n        for i in range(1, len(d)):\n            if not TableTestCase.not_less_ex(d[i - 1], d[i]):\n                return False\n        return True\n\n    @staticmethod\n    def not_less_ex_ord(ex1, ex2, ord):\n        for a in ord:\n            if ex1[a] != ex2[a]:\n                return ex1[a] < ex2[a]\n        return True\n\n    @staticmethod\n    def sorted_ord(d, ord):\n        for i in range(1, len(d)):\n            if not TableTestCase.not_less_ex_ord(d[i - 1], d[i], ord):\n                return False\n        return True\n\n    def test_copy(self):\n        t = data.Table.from_numpy(\n            None, np.zeros((5, 3)), np.arange(5), np.zeros((5, 3)))\n\n        copy = t.copy()\n        self.assertTrue(np.all(t.X == copy.X))\n        self.assertTrue(np.all(t.Y == copy.Y))\n        self.assertTrue(np.all(t.metas == copy.metas))\n        with copy.unlocked():\n            copy[0] = [1, 1, 1, 1]\n        self.assertFalse(np.all(t.X == copy.X))\n        self.assertFalse(np.all(t.Y == copy.Y))\n        self.assertFalse(np.all(t.metas == copy.metas))\n\n    def test_copy_sparse(self):\n        t = data.Table('iris').to_sparse()\n        copy = t.copy()\n\n        self.assertEqual((t.X != copy.X).nnz, 0)      # sparse matrices match by content\n        np.testing.assert_equal(t.Y, copy.Y)\n        np.testing.assert_equal(t.metas, copy.metas)\n\n        self.assertNotEqual(id(t.X), id(copy.X))\n        self.assertNotEqual(id(t._Y), id(copy._Y))\n        self.assertNotEqual(id(t.metas), id(copy.metas))\n\n        # ensure that copied sparse arrays do not share data\n        with t.unlocked():\n            t.X[0, 0] = 42\n        self.assertEqual(copy.X[0, 0], 5.1)\n\n    def test_concatenate(self):\n        d1 = data.Domain(\n            [data.ContinuousVariable(n) for n in \"abc\"],\n            data.DiscreteVariable(\"y\", values=\"ABC\"),\n            [data.StringVariable(n) for n in [\"m1\", \"m2\"]],\n        )\n        x1 = np.arange(6).reshape(2, 3)\n        y1 = np.array([0, 1])\n        m1 = np.array([[\"foo\", \"bar\"], [\"baz\", \"qux\"]])\n        w1 = np.random.random((2,))\n        t1 = data.Table.from_numpy(d1, x1, y1, m1, w1)\n        t1.ids = ids1 = np.array([100, 101])\n        t1.attributes = {\"a\": 42, \"c\": 43}\n\n        x2 = np.arange(6, 15).reshape(3, 3)\n        y2 = np.array([1, 2, 0])\n        m2 = np.array([[\"a\", \"b\"], [\"c\", \"d\"], [\"e\", \"f\"]])\n        w2 = np.random.random((3,))\n        t2 = data.Table.from_numpy(d1, x2, y2, m2, w2)\n        t2.ids = ids2 = np.array([102, 103, 104])\n        t2.name = \"t2\"\n        t2.attributes = {\"a\": 44, \"b\": 45}\n\n        x3 = np.arange(15, 27).reshape(4, 3)\n        y3 = np.array([2, 1, 1, 0])\n        m3 = np.array([[\"g\", \"h\"], [\"i\", \"j\"], [\"k\", \"l\"], [\"m\", \"n\"]])\n        w3 = np.random.random((4,))\n        t3 = data.Table.from_numpy(d1, x3, y3, m3, w3)\n        t3.ids = ids3 = np.array([102, 103, 104, 105])\n        t3.name = \"t3\"\n\n        t1b = data.Table.concatenate((t1,))\n        self.assertEqual(t1b.domain, t1.domain)\n        np.testing.assert_almost_equal(t1b.X, x1)\n        np.testing.assert_almost_equal(t1b.Y, y1)\n        self.assertEqual(list(t1b.metas.flatten()),\n                         list(m1.flatten()))\n        np.testing.assert_almost_equal(t1b.W, w1)\n        np.testing.assert_almost_equal(t1b.ids, ids1)\n        self.assertEqual(t1b.name, t1.name)\n        self.assertEqual(t1b.attributes, {\"a\": 42, \"c\": 43})\n\n        t12 = data.Table.concatenate((t1, t2))\n        self.assertEqual(t12.domain, t1.domain)\n        np.testing.assert_almost_equal(t12.X, np.vstack((x1, x2)))\n        np.testing.assert_almost_equal(t12.Y, np.hstack((y1, y2)))\n        self.assertEqual(list(t12.metas.flatten()),\n                         list(np.vstack((m1, m2)).flatten()))\n        np.testing.assert_almost_equal(t12.W, np.hstack((w1, w2)))\n        np.testing.assert_almost_equal(t12.ids, np.hstack((ids1, ids2)))\n        self.assertEqual(t12.name, \"t2\")\n        self.assertEqual(t12.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n        t123 = data.Table.concatenate((t1, t2, t3))\n        self.assertEqual(t123.domain, t1.domain)\n        np.testing.assert_almost_equal(t123.X, np.vstack((x1, x2, x3)))\n        np.testing.assert_almost_equal(t123.Y, np.hstack((y1, y2, y3)))\n        self.assertEqual(list(t123.metas.flatten()),\n                         list(np.vstack((m1, m2, m3)).flatten()))\n        np.testing.assert_almost_equal(t123.W, np.hstack((w1, w2, w3)))\n        np.testing.assert_almost_equal(t123.ids, np.hstack((ids1, ids2, ids3)))\n        self.assertEqual(t123.name, \"t2\")\n        self.assertEqual(t123.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n        with t2.unlocked(t2.Y):\n            t2.Y = np.atleast_2d(t2.Y).T\n        t12 = data.Table.concatenate((t1, t2))\n        self.assertEqual(t12.domain, t1.domain)\n        np.testing.assert_almost_equal(t12.X, np.vstack((x1, x2)))\n        np.testing.assert_almost_equal(t12.Y, np.hstack((y1, y2)))\n        self.assertEqual(list(t12.metas.flatten()),\n                         list(np.vstack((m1, m2)).flatten()))\n        np.testing.assert_almost_equal(t12.W, np.hstack((w1, w2)))\n        np.testing.assert_almost_equal(t12.ids, np.hstack((ids1, ids2)))\n        self.assertEqual(t12.name, \"t2\")\n        self.assertEqual(t12.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n    def test_concatenate_exceptions(self):\n        zoo = data.Table(\"zoo\")\n        iris = data.Table(\"iris\")\n\n        self.assertRaises(ValueError, data.Table.concatenate, [])\n        self.assertRaises(ValueError, data.Table.concatenate, [zoo, iris])\n\n    def test_concatenate_sparse(self):\n        iris = Table(\"iris\")\n        with iris.unlocked():\n            iris.X = sp.csc_matrix(iris.X)\n        new = Table.concatenate([iris, iris])\n        self.assertEqual(len(new), 300)\n        self.assertTrue(sp.issparse(new.X), \"Concatenated X is not sparse.\")\n        self.assertFalse(sp.issparse(new.Y), \"Concatenated Y is not dense.\")\n        self.assertFalse(sp.issparse(new.metas), \"Concatenated metas is not dense.\")\n        self.assertEqual(len(new.ids), 300)\n\n    def test_pickle(self):\n        import pickle\n\n        d = data.Table(\"zoo\")\n        s = pickle.dumps(d)\n        d2 = pickle.loads(s)\n        self.assertEqual(d[0], d2[0])\n\n        self.assertEqual(d.checksum(include_metas=False),\n                         d2.checksum(include_metas=False))\n\n        d = data.Table(\"iris\")\n        s = pickle.dumps(d)\n        d2 = pickle.loads(s)\n        self.assertEqual(d[0], d2[0])\n        self.assertEqual(d.checksum(include_metas=False),\n                         d2.checksum(include_metas=False))\n\n    def test_translate_through_slice(self):\n        d = data.Table(\"iris\")\n        dom = data.Domain([\"petal length\", \"sepal length\", \"iris\"],\n                          source=d.domain)\n        d_ref = d[:10, dom.variables]\n        self.assertEqual(d_ref.domain.class_var, d.domain.class_var)\n        self.assertEqual(d_ref[0, \"petal length\"], d[0, \"petal length\"])\n        self.assertEqual(d_ref[0, \"sepal length\"], d[0, \"sepal length\"])\n        self.assertEqual(d_ref.X.shape, (10, 2))\n        self.assertEqual(d_ref.Y.shape, (10,))\n\n    def test_saveTab(self):\n        d = data.Table(\"iris\")[:3]\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            for e1, e2 in zip(d, d2):\n                self.assertEqual(e1, e2)\n        finally:\n            os.remove(\"test-save.tab\")\n            os.remove(\"test-save.tab.metadata\")\n\n        dom = data.Domain([data.ContinuousVariable(\"a\")])\n        d = data.Table.from_list(dom, [[i] for i in range(3)])\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            self.assertEqual(len(d.domain.attributes), 1)\n            self.assertEqual(d.domain.class_var, None)\n            for i in range(3):\n                self.assertEqual(d2[i], [i])\n        finally:\n            os.remove(\"test-save.tab\")\n\n        dom = data.Domain([data.ContinuousVariable(\"a\")], None)\n        d = data.Table.from_list(dom, [[i] for i in range(3)])\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            self.assertEqual(len(d.domain.attributes), 1)\n            for i in range(3):\n                self.assertEqual(d2[i], [i])\n        finally:\n            os.remove(\"test-save.tab\")\n\n        d = data.Table(\"zoo\")\n        d.save(\"test-zoo.tab\")\n        dd = data.Table(\"test-zoo\")\n        try:\n            self.assertTupleEqual(d.domain.metas, dd.domain.metas,\n                                  msg=\"Meta attributes don't match.\")\n            self.assertTupleEqual(d.domain.variables, dd.domain.variables,\n                                  msg=\"Attributes don't match.\")\n\n            np.testing.assert_almost_equal(d.W, dd.W,\n                                           err_msg=\"Weights don't match.\")\n            for i in range(10):\n                for j in d.domain.variables:\n                    self.assertEqual(d[i][j], dd[i][j])\n        finally:\n            os.remove(\"test-zoo.tab\")\n            os.remove(\"test-zoo.tab.metadata\")\n\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d.set_weights(range(len(d)))\n        d.save(\"test-zoo-weights.tab\")\n        dd = data.Table(\"test-zoo-weights\")\n        try:\n            self.assertTupleEqual(d.domain.metas, dd.domain.metas,\n                                  msg=\"Meta attributes don't match.\")\n            self.assertTupleEqual(d.domain.variables, dd.domain.variables,\n                                  msg=\"Attributes don't match.\")\n\n            np.testing.assert_almost_equal(d.W, dd.W,\n                                           err_msg=\"Weights don't match.\")\n            for i in range(10):\n                for j in d.domain.variables:\n                    self.assertEqual(d[i][j], dd[i][j])\n        finally:\n            os.remove(\"test-zoo-weights.tab\")\n            os.remove(\"test-zoo-weights.tab.metadata\")\n\n    def test_save_pickle(self):\n        table = data.Table(\"iris\")\n        try:\n            table.save(\"iris.pickle\")\n            table2 = data.Table.from_file(\"iris.pickle\")\n            np.testing.assert_almost_equal(table.X, table2.X)\n            np.testing.assert_almost_equal(table.Y, table2.Y)\n            self.assertEqual(table.domain[0], table2.domain[0])\n        finally:\n            os.remove(\"iris.pickle\")\n\n    def test_from_numpy(self):\n        a = np.arange(20, dtype=\"d\").reshape((4, 5)).copy()\n        a[:, -1] = [0, 0, 0, 1]\n        dom = data.Domain([data.ContinuousVariable(x) for x in \"abcd\"],\n                          data.DiscreteVariable(\"e\", values=(\"no\", \"yes\")))\n        table = data.Table(dom, a)\n        with table.unlocked():\n            for i in range(4):\n                self.assertEqual(table[i].get_class(), \"no\" if i < 3 else \"yes\")\n                for j in range(5):\n                    self.assertEqual(a[i, j], table[i, j])\n\n        with table.unlocked(), self.assertRaises(IndexError):\n            table[0, -5] = 5\n\n    def test_filter_is_defined(self):\n        d = data.Table(\"iris\")\n        with d.unlocked():\n            d[1, 4] = Unknown\n        self.assertTrue(isnan(d[1, 4]))\n        with d.unlocked():\n            d[140, 0] = Unknown\n        e = filter.IsDefined()(d)\n        self.assertEqual(len(e), len(d) - 2)\n        self.assertEqual(e[0], d[0])\n        self.assertEqual(e[1], d[2])\n        self.assertEqual(e[147], d[149])\n        self.assertTrue(d.has_missing())\n        self.assertFalse(e.has_missing())\n\n    def test_filter_has_class(self):\n        d = data.Table(\"iris\")\n        with d.unlocked():\n            d[1, 4] = Unknown\n        self.assertTrue(isnan(d[1, 4]))\n        with d.unlocked():\n            d[140, 0] = Unknown\n        e = filter.HasClass()(d)\n        self.assertEqual(len(e), len(d) - 1)\n        self.assertEqual(e[0], d[0])\n        self.assertEqual(e[1], d[2])\n        self.assertEqual(e[148], d[149])\n        self.assertTrue(d.has_missing())\n        self.assertTrue(e.has_missing())\n        self.assertFalse(e.has_missing_class())\n\n    def test_filter_random(self):\n        d = data.Table(\"iris\")\n        e = filter.Random(50)(d)\n        self.assertEqual(len(e), 50)\n        e = filter.Random(50, negate=True)(d)\n        self.assertEqual(len(e), 100)\n        for _ in range(5):\n            e = filter.Random(0.2)(d)\n            self.assertEqual(len(e), 30)\n            bc = np.bincount(np.array(e.Y[:], dtype=int))\n            if min(bc) > 7:\n                break\n        else:\n            self.fail(\"Filter returns too uneven distributions\")\n\n    def test_filter_values_nested(self):\n        d = data.Table(\"iris\")\n        f1 = filter.FilterContinuous(d.columns.sepal_length,\n                                     filter.FilterContinuous.Between,\n                                     min=4.5, max=5.0)\n        f2 = filter.FilterContinuous(d.columns.sepal_width,\n                                     filter.FilterContinuous.Between,\n                                     min=3.1, max=3.4)\n        f3 = filter.FilterDiscrete(d.columns.iris, [0, 1])\n        f = filter.Values([filter.Values([f1, f2], conjunction=False), f3])\n        self.assertEqual(41, len(f(d)))\n\n    def test_filter_string_works_for_numeric_columns(self):\n        var = StringVariable(\"s\")\n        data = Table.from_list(Domain([], metas=[var]),\n                               [[x] for x in range(21)])\n        # 1, 2, 3, ..., 18, 19, 20\n\n        fs = filter.FilterString\n        filters = [\n            ((fs.Greater, \"5\"), dict(rows=4)),\n            # 6, 7, 8, 9\n            ((fs.Between, \"15\", \"2\"), dict(rows=6)),\n            # 15, 16, 17, 18, 19, 2\n            ((fs.Contains, \"2\"), dict(rows=3)),\n            # 2, 12, 20\n        ]\n\n        for args, expected in filters:\n            f = fs(var, *args)\n            filtered_data = filter.Values([f])(data)\n            self.assertEqual(len(filtered_data), expected[\"rows\"],\n                             \"{} returned wrong number of rows\".format(args))\n\n    def test_filter_value_continuous(self):\n        d = data.Table(\"iris\")\n        col = d.X[:, 2]\n\n        v = d.columns\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Between,\n                                    min=4.5, max=5.1)\n\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] >= 4.5))\n        self.assertTrue(np.all(x.X[:, 2] <= 5.1))\n        self.assertEqual(sum((col >= 4.5) * (col <= 5.1)), len(x))\n\n        f.ref = 5.1\n        f.oper = filter.FilterContinuous.Equal\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.NotEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] != 5.1))\n        self.assertEqual(sum(col != 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Less\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] < 5.1))\n        self.assertEqual(sum(col < 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.LessEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] <= 5.1))\n        self.assertEqual(sum(col <= 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Greater\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] > 5.1))\n        self.assertEqual(sum(col > 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] >= 5.1))\n        self.assertEqual(sum(col >= 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Outside\n        f.ref, f.max = 4.5, 5.1\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(e[2] < 4.5 or e[2] > 5.1)\n        self.assertEqual(sum((col < 4.5) + (col > 5.1)), len(x))\n\n        f.oper = filter.FilterContinuous.IsDefined\n        f.ref = f.max = None\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d))\n\n        with d.unlocked():\n            d[:30, v.petal_length] = Unknown\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 30)\n\n    def test_filter_value_continuous_args(self):\n        d = data.Table(\"iris\")\n        col = d.X[:, 2]\n        v = d.columns\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(2,\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"petal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"sepal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        f.column = 2\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"sepal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        f.column = v.petal_length\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=18)\n        f.ref = 5.1\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=18)\n        f.ref = 5.1\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n    def test_valueFilter_discrete(self):\n        d = data.Table(\"zoo\")\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, 3, 4])\n        for e in filter.Values([f])(d):\n            self.assertTrue(e.get_class() in [2, 3, 4])\n\n        f.values = [\"mammal\"]\n        for e in filter.Values([f])(d):\n            self.assertEqual(e.get_class(), \"mammal\")\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, \"mammal\"])\n        for e in filter.Values([f])(d):\n            self.assertTrue(e.get_class() in [2, \"mammal\"])\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, \"martian\"])\n        self.assertRaises(ValueError, d._filter_values, f)\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=(2, data.Table))\n        self.assertRaises(TypeError, d._filter_values, f)\n\n        v = d.columns\n        f = filter.FilterDiscrete(v.hair, values=None)\n        self.assertEqual(len(filter.Values([f])(d)), len(d))\n\n        with d.unlocked():\n            d[:5, v.hair] = Unknown\n        self.assertEqual(len(filter.Values([f])(d)), len(d) - 5)\n\n    def test_valueFilter_string_is_defined(self):\n        d = data.Table(\"datasets/test9.tab\")\n        f = filter.FilterString(-5, filter.FilterString.IsDefined)\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 7)\n\n    def test_valueFilter_discrete_meta_is_defined(self):\n        d = data.Table(\"datasets/test9.tab\")\n        f = filter.FilterDiscrete(-4, None)\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 8)\n\n    def test_valueFilter_string_case_sens(self):\n        d = data.Table(\"zoo\")\n        col = d[:, \"name\"].metas[:, 0]\n\n        f = filter.FilterString(\"name\",\n                                filter.FilterString.Equal, \"girl\")\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 1)\n        self.assertEqual(x[0, \"name\"], \"girl\")\n        self.assertTrue(np.all(x.metas == \"girl\"))\n\n        f.oper = f.NotEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 1)\n        self.assertTrue(np.all(x[:, \"name\"] != \"girl\"))\n\n        f.oper = f.Less\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"girl\"))\n        self.assertTrue(np.all(x.metas < \"girl\"))\n\n        f.oper = f.LessEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col <= \"girl\"))\n        self.assertTrue(np.all(x.metas <= \"girl\"))\n\n        f.oper = f.Greater\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col > \"girl\"))\n        self.assertTrue(np.all(x.metas > \"girl\"))\n\n        f.oper = f.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col >= \"girl\"))\n        self.assertTrue(np.all(x.metas >= \"girl\"))\n\n        f.oper = f.Between\n        f.max = \"lion\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum((col >= \"girl\") * (col <= \"lion\")))\n        self.assertTrue(np.all(x.metas >= \"girl\"))\n        self.assertTrue(np.all(x.metas <= \"lion\"))\n\n        f.oper = f.Outside\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"girl\") + sum(col > \"lion\"))\n        self.assertTrue(np.all((x.metas < \"girl\") + (x.metas > \"lion\")))\n\n        f.oper = f.Contains\n        f.ref = \"ea\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(\"ea\" in e[\"name\"])\n        self.assertEqual(len(x), len([e for e in col if \"ea\" in e]))\n\n        f.oper = f.StartsWith\n        f.ref = \"sea\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).startswith(\"sea\"))\n        self.assertEqual(len(x), len([e for e in col if e.startswith(\"sea\")]))\n\n        f.oper = f.EndsWith\n        f.ref = \"ion\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n        self.assertEqual(len(x), len([e for e in col if e.endswith(\"ion\")]))\n\n    def test_valueFilter_string_case_insens(self):\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d[d[:, \"name\"].metas[:, 0] == \"girl\", \"name\"] = \"GIrl\"\n\n        col = d[:, \"name\"].metas[:, 0]\n\n        f = filter.FilterString(\"name\",\n                                filter.FilterString.Equal, \"giRL\")\n        f.case_sensitive = False\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 1)\n        self.assertEqual(x[0, \"name\"], \"GIrl\")\n        self.assertTrue(np.all(x.metas == \"GIrl\"))\n\n        f.oper = f.NotEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 1)\n        self.assertTrue(np.all(x[:, \"name\"] != \"GIrl\"))\n\n        f.oper = f.Less\n        f.ref = \"CHiCKEN\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"chicken\") - 1)  # girl!\n        self.assertTrue(np.all(x.metas < \"chicken\"))\n\n        f.oper = f.LessEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col <= \"chicken\") - 1)\n        self.assertTrue(np.all(x.metas <= \"chicken\"))\n\n        f.oper = f.Greater\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col > \"chicken\") + 1)\n        for e in x:\n            self.assertGreater(str(e[\"name\"]).lower(), \"chicken\")\n\n        f.oper = f.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col >= \"chicken\") + 1)\n        for e in x:\n            self.assertGreaterEqual(str(e[\"name\"]).lower(), \"chicken\")\n\n        f.oper = f.Between\n        f.max = \"liOn\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum((col >= \"chicken\") * (col <= \"lion\")) + 1)\n        for e in x:\n            self.assertTrue(\"chicken\" <= str(e[\"name\"]).lower() <= \"lion\")\n\n        f.oper = f.Outside\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"chicken\") + sum(col > \"lion\") - 1)\n        self.assertTrue(np.all((x.metas < \"chicken\") + (x.metas > \"lion\")))\n\n        f.oper = f.Contains\n        f.ref = \"iR\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(\"ir\" in str(e[\"name\"]).lower())\n        self.assertEqual(len(x), len([e for e in col if \"ir\" in e]) + 1)\n\n        f.oper = f.StartsWith\n        f.ref = \"GI\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).lower().startswith(\"gi\"))\n        self.assertEqual(len(x),\n                         len([e for e in col if e.lower().startswith(\"gi\")]))\n\n        f.oper = f.EndsWith\n        f.ref = \"ion\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n        self.assertEqual(len(x), len([e for e in col if e.endswith(\"ion\")]))\n\n    def test_valueFilter_regex(self):\n        d = data.Table(\"zoo\")\n        f = filter.FilterRegex(d.domain['name'], '^c...$')\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 7)\n\n    def test_valueFilter_stringList(self):\n        data = Table(\"zoo\")\n        var = data.domain[\"name\"]\n\n        fs = filter.FilterStringList\n        filters = [\n            (([\"swan\", \"tuna\", \"wasp\"], True), dict(rows=3)),\n            (([\"swan\", \"tuna\", \"wasp\"], False), dict(rows=3)),\n            (([\"WoRm\", \"TOad\", \"vOLe\"], True), dict(rows=0)),\n            (([\"WoRm\", \"TOad\", \"vOLe\"], False), dict(rows=3)),\n        ]\n\n        for args, expected in filters:\n            f = fs(var, *args)\n            filtered_data = filter.Values([f])(data)\n            self.assertEqual(len(filtered_data), expected[\"rows\"],\n                             \"{} returned wrong number of rows\".format(args))\n\n    def test_table_dtypes(self):\n        table = data.Table(\"iris\")\n        metas = np.hstack((table.metas, table.Y.reshape(len(table), 1)))\n        attributes_metas = table.domain.metas + table.domain.class_vars\n        domain_metas = data.Domain(table.domain.attributes[:2],\n                                   table.domain.attributes[2:],\n                                   attributes_metas)\n        table_metas = data.Table(domain_metas, table.X[:, : 2], table.X[:, 2:],\n                                 metas)\n        new_table = data.Table.from_table(data.Domain(table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.X.dtype, np.float64)\n        new_table = data.Table.from_table(data.Domain((), table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.Y.dtype, np.float64)\n        new_table = data.Table.from_table(data.Domain((), (), table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.metas.dtype, np.float64)\n\n    def test_attributes(self):\n        table = data.Table(\"iris\")\n        table.attributes = {1: \"test\"}\n        table2 = table[:4]\n        self.assertEqual(table2.attributes[1], \"test\")\n        table2.attributes[1] = \"modified\"\n        self.assertEqual(table.attributes[1], \"modified\")\n\n    # TODO Test conjunctions and disjunctions of conditions\n\n    def test_is_sparse(self):\n        table = data.Table(\"iris\")\n        self.assertFalse(table.is_sparse())\n\n        with table.unlocked():\n            table.X = sp.csr_matrix(table.X)\n            self.assertTrue(table.is_sparse())\n\n    def test_repr_sparse_with_one_row(self):\n        table = data.Table(\"iris\")[:1]\n        with table.unlocked():\n            table.X = sp.csr_matrix(table.X)\n        repr(table)     # make sure repr does not crash\n\n    def test_inf(self):\n        a = np.array([[2, 0, 0, 0],\n                      [0, np.nan, np.nan, 1],\n                      [0, 0, np.inf, 0]])\n        with self.assertWarns(Warning):\n            tab = data.Table.from_numpy(None, a)\n        self.assertEqual(tab.get_nan_frequency_attribute(), 3/12)\n\n\ndef column_sizes(table):\n    return (len(table.domain.attributes),\n            len(table.domain.class_vars),\n            len(table.domain.metas))\n\n\nclass TableTests(unittest.TestCase):\n    attributes = [\"Feature %i\" % i for i in range(10)]\n    class_vars = [\"Class %i\" % i for i in range(1)]\n    metas = [\"Meta %i\" % i for i in range(5)]\n    nrows = 10\n    row_indices = (1, 5, 7, 9)\n\n    def setUp(self):\n        self.data = np.random.random((self.nrows, len(self.attributes)))\n        self.class_data = np.random.random((self.nrows, len(self.class_vars)))\n        if len(self.class_vars) == 1:\n            self.class_data = self.class_data.flatten()\n        self.meta_data = np.random.randint(0, 5, (self.nrows, len(self.metas))\n                                          ).astype(object)\n        self.weight_data = np.random.random((self.nrows, 1))\n\n    def mock_domain(self, with_classes=False, with_metas=False):\n        attributes = self.attributes\n        class_var = self.class_vars[0] if with_classes else None\n        class_vars = self.class_vars if with_classes else []\n        metas = self.metas if with_metas else []\n        variables = attributes + class_vars\n        return MagicMock(data.Domain,\n                         attributes=attributes,\n                         class_var=class_var,\n                         class_vars=class_vars,\n                         metas=metas,\n                         variables=variables)\n\n    def create_domain(self, attributes=(), classes=(), metas=()):\n        attr_vars = [data.ContinuousVariable(name=a) if isinstance(a, str)\n                     else a for a in attributes]\n        class_vars = [data.ContinuousVariable(name=c) if isinstance(c, str)\n                      else c for c in classes]\n        meta_vars = [data.DiscreteVariable(name=m, values=map(str, range(5)))\n                     if isinstance(m, str) else m for m in metas]\n\n        domain = data.Domain(attr_vars, class_vars, meta_vars)\n        return domain\n\n\nclass CreateEmptyTable(TableTests):\n    def test_calling_new_with_no_parameters_constructs_a_new_instance(self):\n        table = data.Table()\n        self.assertIsInstance(table, data.Table)\n\n    def test_table_has_file(self):\n        table = data.Table()\n        self.assertIsNone(table.__file__)\n\n\nclass CreateTableWithFilename(TableTests):\n    filename = \"data.tab\"\n\n    @patch(\"os.path.exists\", Mock(return_value=True))\n    def test_read_data_calls_reader(self):\n        table_mock = Mock(data.Table)\n        reader_instance = Mock(read=Mock(return_value=table_mock))\n        reader_mock = Mock(return_value=reader_instance)\n\n        with patch.dict(data.io.FileFormat.readers,\n                        {'.xlsx': reader_mock}):\n            table = data.Table.from_file(\"test.xlsx\")\n\n        reader_mock.assert_called_with(\"test.xlsx\")\n        reader_instance.read.assert_called_with()\n        self.assertEqual(table, table_mock)\n\n    @patch(\"os.path.exists\", Mock(return_value=False))\n    def test_raises_error_if_file_does_not_exist(self):\n        with self.assertRaises(IOError):\n            data.Table.from_file(self.filename)\n\n    @patch(\"os.path.exists\", Mock(return_value=True))\n    def test_raises_error_if_file_has_unknown_extension(self):\n        with self.assertRaises(IOError):\n            data.Table.from_file(\"file.invalid_extension\")\n\n    @patch(\"Orange.data.table.Table.from_file\")\n    def test_calling_new_with_string_argument_calls_read_data(self, read_data):\n        data.Table(self.filename)\n\n        read_data.assert_called_with(self.filename)\n\n    @patch(\"Orange.data.table.Table.from_file\")\n    def test_calling_new_with_keyword_argument_filename_calls_read_data(\n            self, read_data):\n        data.Table(self.filename)\n        read_data.assert_called_with(self.filename)\n\n\nclass CreateTableWithUrl(TableTests):\n    def test_url_no_scheme(self):\n\n        class SkipRest(Exception):\n            pass\n\n        mock_urlopen = Mock(side_effect=SkipRest())\n        url = 'www.foo.bar/xx.csv'\n\n        with patch('Orange.data.io.UrlReader.urlopen', mock_urlopen):\n            try:\n                Table.from_url(url)\n            except SkipRest:\n                pass\n\n        mock_urlopen.assert_called_once_with('http://' + url)\n\n    class _MockUrlOpen(MagicMock):\n        headers = {'content-disposition': 'attachment; filename=\"Something-FormResponses.tsv\"; '\n                                          'filename*=UTF-8''Something%20%28Responses%29.tsv'}\n        def __enter__(self):\n            return self\n\n        def __exit__(self, *args, **kwargs):\n            pass\n\n        def read(self):\n            return b'''\\\na\\tb\\tc\n1\\t2\\t3\n2\\t3\\t4'''\n\n    urlopen = _MockUrlOpen()\n\n    @patch('Orange.data.io.urlopen', urlopen)\n    def test_trimmed_urls(self):\n        for url in ('https://docs.google.com/spreadsheets/d/ABCD/edit',\n                    'https://www.dropbox.com/s/ABCD/filename.csv'):\n            self._MockUrlOpen.url = url\n            d = data.Table(url)\n            request = self.urlopen.call_args[0][0]\n            self.assertNotEqual(url, request.full_url)\n            self.assertIn('Mozilla/5.0', request.headers.get('User-agent', ''))\n            self.assertEqual(len(d), 2)\n            self.assertEqual(d.name, 'Something-FormResponses')\n\n\nclass CreateTableWithDomain(TableTests):\n    def test_creates_an_empty_table_with_given_domain(self):\n        domain = self.mock_domain()\n        table = data.Table.from_domain(domain)\n\n        self.assertEqual(table.domain, domain)\n\n    def test_creates_zero_filled_rows_in_X_if_domain_contains_attributes(self):\n        domain = self.mock_domain()\n        table = data.Table.from_domain(domain, self.nrows)\n\n        self.assertEqual(table.X.shape, (self.nrows, len(domain.attributes)))\n        self.assertFalse(table.X.any())\n\n    def test_creates_zero_filled_rows_in_Y_if_domain_contains_class_vars(self):\n        domain = self.mock_domain(with_classes=True)\n        table = data.Table.from_domain(domain, self.nrows)\n\n        if len(domain.class_vars) != 1:\n            self.assertEqual(table.Y.shape,\n                             (self.nrows, len(domain.class_vars)))\n        else:\n            self.assertEqual(table.Y.shape, (self.nrows,))\n        self.assertFalse(table.Y.any())\n\n    def test_creates_zero_filled_rows_in_metas_if_domain_contains_metas(self):\n        domain = self.mock_domain(with_metas=True)\n        table = data.Table.from_domain(domain, self.nrows)\n\n        self.assertEqual(table.metas.shape, (self.nrows, len(domain.metas)))\n        self.assertFalse(table.metas.any())\n\n    def test_creates_weights_if_weights_are_true(self):\n        domain = self.mock_domain()\n        table = data.Table.from_domain(domain, self.nrows, True)\n\n        self.assertEqual(table.W.shape, (self.nrows, ))\n\n    def test_does_not_create_weights_if_weights_are_false(self):\n        domain = self.mock_domain()\n        table = data.Table.from_domain(domain, self.nrows, False)\n\n        self.assertEqual(table.W.shape, (self.nrows, 0))\n\n    @patch(\"Orange.data.table.Table.from_domain\")\n    def test_calling_new_with_domain_calls_new_from_domain(\n            self, new_from_domain):\n        domain = self.mock_domain()\n        data.Table.from_domain(domain)\n\n        new_from_domain.assert_called_with(domain)\n\n\nclass CreateTableWithData(TableTests):\n    def test_creates_a_table_with_given_X(self):\n        # from numpy\n        table = data.Table.from_numpy(None, np.array(self.data))\n        self.assertIsInstance(table.domain, data.Domain)\n        np.testing.assert_almost_equal(table.X, self.data)\n\n        # from list\n        table = data.Table.from_numpy(None, list(self.data))\n        self.assertIsInstance(table.domain, data.Domain)\n        np.testing.assert_almost_equal(table.X, self.data)\n\n        # from tuple\n        table = data.Table.from_numpy(None, tuple(self.data))\n        self.assertIsInstance(table.domain, data.Domain)\n        np.testing.assert_almost_equal(table.X, self.data)\n\n    def test_creates_a_table_from_domain_and_list(self):\n        domain = data.Domain([data.DiscreteVariable(name=\"a\", values=\"mf\"),\n                              data.ContinuousVariable(name=\"b\")],\n                             data.DiscreteVariable(name=\"y\", values=\"abc\"))\n        table = data.Table.from_list(domain, [[0, 1, 2],\n                                              [1, 2, \"?\"],\n                                              [\"m\", 3, \"a\"],\n                                              [\"?\", \"?\", \"c\"]])\n        self.assertIs(table.domain, domain)\n        np.testing.assert_almost_equal(\n            table.X, np.array([[0, 1], [1, 2], [0, 3], [np.nan, np.nan]]))\n        np.testing.assert_almost_equal(table.Y, np.array([2, np.nan, 0, 2]))\n\n    def test_creates_a_table_from_domain_and_list_and_weights(self):\n        domain = data.Domain([data.DiscreteVariable(name=\"a\", values=\"mf\"),\n                              data.ContinuousVariable(name=\"b\")],\n                             data.DiscreteVariable(name=\"y\", values=\"abc\"))\n        table = data.Table.from_list(domain, [[0, 1, 2],\n                                              [1, 2, \"?\"],\n                                              [\"m\", 3, \"a\"],\n                                              [\"?\", \"?\", \"c\"]], [1, 2, 3, 4])\n        self.assertIs(table.domain, domain)\n        np.testing.assert_almost_equal(\n            table.X, np.array([[0, 1], [1, 2], [0, 3], [np.nan, np.nan]]))\n        np.testing.assert_almost_equal(table.Y, np.array([2, np.nan, 0, 2]))\n        np.testing.assert_almost_equal(table.W, np.array([1, 2, 3, 4]))\n\n    def test_creates_a_table_from_domain_and_list_and_metas(self):\n        metas = [data.DiscreteVariable(\"Meta 1\", values=\"XYZ\"),\n                 data.ContinuousVariable(\"Meta 2\"),\n                 data.StringVariable(\"Meta 3\")]\n        domain = data.Domain([data.DiscreteVariable(name=\"a\", values=\"mf\"),\n                              data.ContinuousVariable(name=\"b\")],\n                             data.DiscreteVariable(name=\"y\", values=\"abc\"),\n                             metas=metas)\n        table = data.Table.from_list(domain, [[0, 1, 2, \"X\", 2, \"bb\"],\n                                              [1, 2, \"?\", \"Y\", 1, \"aa\"],\n                                              [\"m\", 3, \"a\", \"Z\", 3, \"bb\"],\n                                              [\"?\", \"?\", \"c\", \"X\", 1, \"aa\"]])\n        self.assertIs(table.domain, domain)\n        np.testing.assert_almost_equal(\n            table.X, np.array([[0, 1], [1, 2], [0, 3], [np.nan, np.nan]]))\n        np.testing.assert_almost_equal(table.Y, np.array([2, np.nan, 0, 2]))\n        np.testing.assert_array_equal(table.metas,\n                                      np.array([[0, 2., \"bb\"],\n                                                [1, 1., \"aa\"],\n                                                [2, 3., \"bb\"],\n                                                [0, 1., \"aa\"]],\n                                               dtype=object))\n\n    def test_creates_a_table_from_list_of_instances(self):\n        table = data.Table('iris')\n        new_table = data.Table.from_list(table.domain, [d for d in table])\n        self.assertIs(table.domain, new_table.domain)\n        np.testing.assert_almost_equal(table.X, new_table.X)\n        np.testing.assert_almost_equal(table.Y, new_table.Y)\n        np.testing.assert_almost_equal(table.W, new_table.W)\n        self.assertEqual(table.domain, new_table.domain)\n        np.testing.assert_array_equal(table.metas, new_table.metas)\n\n    def test_creates_a_table_from_list_of_instances_with_metas(self):\n        table = data.Table('zoo')\n        new_table = data.Table.from_list(table.domain, [d for d in table])\n        self.assertIs(table.domain, new_table.domain)\n        np.testing.assert_almost_equal(table.X, new_table.X)\n        np.testing.assert_almost_equal(table.Y, new_table.Y)\n        np.testing.assert_almost_equal(table.W, new_table.W)\n        self.assertEqual(table.domain, new_table.domain)\n        np.testing.assert_array_equal(table.metas, new_table.metas)\n\n    def test_creates_a_table_with_domain_and_given_X(self):\n        domain = self.mock_domain()\n\n        table = data.Table(domain, self.data)\n        self.assertIsInstance(table.domain, data.Domain)\n        self.assertEqual(table.domain, domain)\n        np.testing.assert_almost_equal(table.X, self.data)\n\n    def test_creates_a_table_with_given_X_and_Y(self):\n        table = data.Table.from_numpy(None, self.data, self.class_data)\n\n        self.assertIsInstance(table.domain, data.Domain)\n        np.testing.assert_almost_equal(table.X, self.data)\n        np.testing.assert_almost_equal(table.Y, self.class_data)\n\n    def test_creates_a_table_with_given_X_Y_and_metas(self):\n        table = data.Table.from_numpy(\n            None, self.data, self.class_data, self.meta_data)\n\n        self.assertIsInstance(table.domain, data.Domain)\n        np.testing.assert_almost_equal(table.X, self.data)\n        np.testing.assert_almost_equal(table.Y, self.class_data)\n        np.testing.assert_almost_equal(table.metas, self.meta_data)\n\n    def test_creates_a_discrete_class_if_Y_has_few_distinct_values(self):\n        Y = np.array([float(np.random.randint(0, 2)) for i in self.data])\n        table = data.Table.from_numpy(None, self.data, Y, self.meta_data)\n\n        np.testing.assert_almost_equal(table.Y, Y)\n        self.assertIsInstance(table.domain.class_vars[0],\n                              data.DiscreteVariable)\n        self.assertEqual(table.domain.class_vars[0].values, (\"v1\", \"v2\"))\n\n    def test_creates_a_table_with_given_domain(self):\n        domain = self.mock_domain()\n        table = data.Table.from_numpy(domain, self.data)\n\n        self.assertEqual(table.domain, domain)\n\n    def test_sets_Y_if_given(self):\n        domain = self.mock_domain(with_classes=True)\n        table = data.Table.from_numpy(domain, self.data, self.class_data)\n\n        np.testing.assert_almost_equal(table.Y, self.class_data)\n\n    def test_sets_metas_if_given(self):\n        domain = self.mock_domain(with_metas=True)\n        table = data.Table.from_numpy(domain, self.data, metas=self.meta_data)\n\n        np.testing.assert_almost_equal(table.metas, self.meta_data)\n\n    def test_sets_weights_if_given(self):\n        domain = self.mock_domain()\n        table = data.Table.from_numpy(domain, self.data, W=self.weight_data)\n\n        np.testing.assert_equal(table.W.shape, (len(self.data), ))\n        np.testing.assert_almost_equal(table.W.flatten(),\n                                       self.weight_data.flatten())\n\n    def test_splits_X_and_Y_if_given_in_same_array(self):\n        joined_data = np.column_stack((self.data, self.class_data))\n        domain = self.mock_domain(with_classes=True)\n        table = data.Table.from_numpy(domain, joined_data)\n\n        np.testing.assert_almost_equal(table.X, self.data)\n        np.testing.assert_almost_equal(table.Y, self.class_data)\n\n    def test_initializes_Y_metas_and_W_if_not_given(self):\n        domain = self.mock_domain()\n        table = data.Table.from_numpy(domain, self.data)\n\n        self.assertEqual(table.Y.shape, (self.nrows, len(domain.class_vars)))\n        self.assertEqual(table.metas.shape, (self.nrows, len(domain.metas)))\n        self.assertEqual(table.W.shape, (self.nrows, 0))\n\n    def test_raises_error_if_columns_in_domain_and_data_do_not_match(self):\n        domain = self.mock_domain(with_classes=True, with_metas=True)\n        ones = np.zeros((self.nrows, 1))\n\n        with self.assertRaises(ValueError):\n            data_ = np.hstack((self.data, ones))\n            data.Table.from_numpy(domain, data_, self.class_data,\n                                  self.meta_data)\n\n        with self.assertRaises(ValueError):\n            classes_ = np.hstack((self.class_data, ones))\n            data.Table.from_numpy(domain, self.data, classes_,\n                                  self.meta_data)\n\n        with self.assertRaises(ValueError):\n            metas_ = np.hstack((self.meta_data, ones))\n            data.Table.from_numpy(domain, self.data, self.class_data,\n                                  metas_)\n\n    def test_raises_error_if_lengths_of_data_do_not_match(self):\n        domain = self.mock_domain(with_classes=True, with_metas=True)\n\n        with self.assertRaises(ValueError):\n            data_ = np.vstack((self.data, np.zeros((1, len(self.attributes)))))\n            data.Table(domain, data_, self.class_data, self.meta_data)\n\n        with self.assertRaises(ValueError):\n            class_data_ = np.vstack((self.class_data,\n                                     np.zeros((1, len(self.class_vars)))))\n            data.Table(domain, self.data, class_data_, self.meta_data)\n\n        with self.assertRaises(ValueError):\n            meta_data_ = np.vstack((self.meta_data,\n                                    np.zeros((1, len(self.metas)))))\n            data.Table(domain, self.data, self.class_data, meta_data_)\n\n    @patch(\"Orange.data.table.Table.from_numpy\")\n    def test_calling_new_with_domain_and_numpy_arrays_calls_new_from_numpy(\n            self, new_from_numpy):\n        domain = self.mock_domain()\n        data.Table(domain, self.data)\n        new_from_numpy.assert_called_with(domain, self.data)\n\n        domain = self.mock_domain(with_classes=True)\n        data.Table(domain, self.data, self.class_data)\n        new_from_numpy.assert_called_with(domain, self.data, self.class_data)\n\n        domain = self.mock_domain(with_classes=True, with_metas=True)\n        data.Table(domain, self.data, self.class_data, self.meta_data)\n        new_from_numpy.assert_called_with(\n            domain, self.data, self.class_data, self.meta_data)\n\n        data.Table(domain, self.data, self.class_data,\n                   self.meta_data, self.weight_data)\n        new_from_numpy.assert_called_with(domain, self.data, self.class_data,\n                                          self.meta_data, self.weight_data)\n\n    def test_from_numpy_reconstructable(self):\n        def assert_equal(t1, t2):\n            np.testing.assert_array_equal(t1.X, t2.X)\n            np.testing.assert_array_equal(t1.Y, t2.Y)\n            np.testing.assert_array_equal(t1.metas, t2.metas)\n            np.testing.assert_array_equal(t1.W, t2.W)\n\n        nullcol = np.empty((self.nrows, 0))\n        domain = self.create_domain(self.attributes)\n        table = data.Table(domain, self.data)\n\n        table_1 = data.Table.from_numpy(\n            domain, table.X, table.Y, table.metas, table.W)\n        assert_equal(table, table_1)\n\n        domain = self.create_domain(classes=self.class_vars)\n        table = data.Table(domain, nullcol, self.class_data)\n\n        table_1 = data.Table.from_numpy(\n            domain, table.X, table.Y, table.metas, table.W)\n        assert_equal(table, table_1)\n\n        domain = self.create_domain(metas=self.metas)\n        table = data.Table(domain, nullcol, nullcol, self.meta_data)\n\n        table_1 = data.Table.from_numpy(\n            domain, table.X, table.Y, table.metas, table.W)\n        assert_equal(table, table_1)\n\n\nclass CreateTableWithDomainAndTable(TableTests):\n    interesting_slices = [\n        slice(0, 0),  # [0:0] - empty slice\n        slice(1),  # [:1]  - only first element\n        slice(1, None),  # [1:]  - all but first\n        slice(-1, None),  # [-1:] - only last element\n        slice(-1),  # [:-1] - all but last\n        slice(None),  # [:]   - all elements\n        slice(None, None, 2),  # [::2] - even elements\n        slice(None, None, -1),  # [::-1]- all elements reversed\n        slice(9, 5, -10),  # slice a big negative stride and thus 1 element\n    ]\n\n    row_indices = [1, 5, 6, 7]\n\n    def setUp(self):\n        super().setUp()\n        self.domain = self.create_domain(\n            self.attributes, self.class_vars, self.metas)\n        self.table = data.Table(\n            self.domain, self.data, self.class_data, self.meta_data)\n\n    def test_creates_table_with_given_domain(self):\n        new_table = data.Table.from_table(self.table.domain, self.table)\n\n        self.assertIsInstance(new_table, data.Table)\n        self.assertIsNot(self.table, new_table)\n        self.assertEqual(new_table.domain, self.domain)\n\n    def test_transform(self):\n        class MyTableClass(data.Table):\n            pass\n\n        table = MyTableClass.from_table(self.table.domain, self.table)\n        domain = table.domain\n        attr = ContinuousVariable(\"x\")\n        new_domain = data.Domain(list(domain.attributes) + [attr], None)\n        new_table = table.transform(new_domain)\n\n        self.assertIsInstance(new_table, MyTableClass)\n        self.assertIsNot(table, new_table)\n        self.assertIs(new_table.domain, new_domain)\n\n    def test_transform_same_domain(self):\n        iris = data.Table(\"iris\")\n        new_domain = copy.copy(iris.domain)\n        new_data = iris.transform(new_domain)\n        self.assertIs(new_data.domain, new_domain)\n\n    def test_can_copy_table(self):\n        new_table = data.Table.from_table(self.domain, self.table)\n        self.assert_table_with_filter_matches(new_table, self.table)\n\n    def test_can_filter_rows_with_list(self):\n        for indices in ([0], [1, 5, 6, 7]):\n            new_table = data.Table.from_table(\n                self.domain, self.table, row_indices=indices)\n            self.assert_table_with_filter_matches(\n                new_table, self.table, rows=indices)\n\n    @patch.object(Table, \"from_table_rows\", wraps=Table.from_table_rows)\n    def test_can_filter_row_with_slice_from_table_rows(self, from_table_rows):\n        # calling from_table with the same domain will forward to from_table_rows\n        for slice_ in self.interesting_slices:\n            from_table_rows.reset_mock()\n            new_table = data.Table.from_table(\n                self.domain, self.table, row_indices=slice_)\n            self.assert_table_with_filter_matches(\n                new_table, self.table, rows=slice_)\n            from_table_rows.assert_called()\n\n    def test_can_filter_row_with_slice_from_table(self):\n        # calling from_table with a domain copy will use indexing in from_table\n        for slice_ in self.interesting_slices:\n            new_table = data.Table.from_table(\n                self.domain.copy(), self.table, row_indices=slice_)\n            self.assert_table_with_filter_matches(\n                new_table, self.table, rows=slice_)\n\n    def test_can_use_attributes_as_new_columns(self):\n        a, _, _ = column_sizes(self.table)\n        order = np.random.permutation(a)\n        new_attributes = [self.domain.attributes[i] for i in order]\n        new_domain = self.create_domain(\n            new_attributes[:2], new_attributes[2:4], new_attributes[4:])\n        new_table = data.Table.from_table(new_domain, self.table)\n\n        self.assert_table_with_filter_matches(\n            new_table, self.table, xcols=order[:2], ycols=order[2:4], mcols=order[4:])\n\n    def test_can_use_class_vars_as_new_columns(self):\n        a, _, _ = column_sizes(self.table)\n        order = np.random.permutation(range(a))\n        cvs = [self.domain.attributes[i] for i in order[:2]]\n        metas = [self.domain.attributes[i] for i in order[2:]]\n        new_domain = self.create_domain(self.domain.class_vars,\n                                        cvs,\n                                        metas)\n        new_table = data.Table.from_table(new_domain, self.table)\n\n        self.assert_table_with_filter_matches(\n            new_table, self.table, xcols=[a], ycols=order[:2], mcols=order[2:])\n\n    def test_can_use_metas_as_new_columns(self):\n        _, _, m = column_sizes(self.table)\n        order = np.random.permutation(range(-m, 0))\n        new_metas = [self.domain.metas[::-1][i] for i in order]\n        new_domain = self.create_domain(new_metas[0:2], [new_metas[2]], new_metas[3:5])\n        new_table = data.Table.from_table(new_domain, self.table)\n\n        self.assert_table_with_filter_matches(\n            new_table, self.table, xcols=order[0:2], ycols=order[2], mcols=order[3:5])\n\n    def test_can_use_combination_of_all_as_new_columns(self):\n        a, c, m = column_sizes(self.table)\n        order = (list(range(a+c)) + list(range(-m+1, 0)))\n        random. shuffle(order)\n        vars_ = list(self.domain.variables) + list(self.domain.metas[::-1])\n        atrs = [vars_[order[i]] for i in range(a)]\n        cv = [vars_[order[i]] for i in range(a, a+c)]\n        metas = [vars_[order[i]] for i in range(a+c, a+c+m-1)]\n\n        new_domain = self.create_domain(atrs, cv, metas)\n        new_table = data.Table.from_table(new_domain, self.table)\n        self.assert_table_with_filter_matches(\n            new_table, self.table, xcols=order[:a], ycols=order[a:a+c], mcols=order[a+c:])\n\n    def test_creates_table_with_given_domain_and_row_filter(self):\n        a, c, m = column_sizes(self.table)\n        order = (list(range(a+c)) + list(range(-m+1, 0)))\n        random.shuffle(order)\n        vars_ = list(self.domain.variables) + list(self.domain.metas[::-1])\n        atrs = [vars_[order[i]] for i in range(a)]\n        cv = [vars_[order[i]] for i in range(a, a+c)]\n        metas = [vars_[order[i]] for i in range(a+c, a+c+m-1)]\n\n        new_domain = self.create_domain(atrs, cv, metas)\n        new_table = data.Table.from_table(new_domain, self.table, [0])\n        self.assert_table_with_filter_matches(\n            new_table, self.table[:1], xcols=order[:a], ycols=order[a:a+c], mcols=order[a+c:])\n\n        new_table = data.Table.from_table(new_domain, self.table, [2, 1, 0])\n        self.assert_table_with_filter_matches(\n            new_table, self.table[2::-1], xcols=order[:a], ycols=order[a:a+c], mcols=order[a+c:])\n\n        new_table = data.Table.from_table(new_domain, self.table, [])\n        self.assert_table_with_filter_matches(\n            new_table, self.table[:0], xcols=order[:a], ycols=order[a:a+c], mcols=order[a+c:])\n\n    def test_from_table_sparse_move_some_to_empty_metas(self):\n        iris = data.Table(\"iris\").to_sparse()\n        new_domain = data.domain.Domain(\n            iris.domain.attributes[:2], iris.domain.class_vars,\n            iris.domain.attributes[2:], source=iris.domain)\n        new_iris = iris.transform(new_domain)\n\n        self.assertTrue(sp.issparse(new_iris.X))\n        self.assertTrue(sp.issparse(new_iris.metas))\n        self.assertEqual(new_iris.X.shape, (len(iris), 2))\n        self.assertEqual(new_iris.metas.shape, (len(iris), 2))\n\n        # move back\n        back_iris = new_iris.transform(iris.domain)\n        self.assertEqual(back_iris.domain, iris.domain)\n        self.assertTrue(sp.issparse(back_iris.X))\n        self.assertFalse(sp.issparse(back_iris.metas))\n        self.assertEqual(back_iris.X.shape, iris.X.shape)\n        self.assertEqual(back_iris.metas.shape, iris.metas.shape)\n\n    def test_from_table_sparse_move_all_to_empty_metas(self):\n        iris = data.Table(\"iris\").to_sparse()\n        new_domain = data.domain.Domain(\n            [], iris.domain.class_vars, iris.domain.attributes,\n            source=iris.domain)\n        new_iris = iris.transform(new_domain)\n\n        self.assertFalse(sp.issparse(new_iris.X))\n        self.assertTrue(sp.issparse(new_iris.metas))\n        self.assertEqual(new_iris.X.shape, (len(iris), 0))\n        self.assertEqual(new_iris.metas.shape, (len(iris), 4))\n\n        # move back\n        back_iris = new_iris.transform(iris.domain)\n        self.assertEqual(back_iris.domain, iris.domain)\n        self.assertTrue(sp.issparse(back_iris.X))\n        self.assertFalse(sp.issparse(back_iris.metas))\n        self.assertEqual(back_iris.X.shape, iris.X.shape)\n        self.assertEqual(back_iris.metas.shape, iris.metas.shape)\n\n    def test_from_table_sparse_move_to_nonempty_metas(self):\n        brown = data.Table(\"brown-selected\").to_sparse()\n        n_attr = len(brown.domain.attributes)\n        n_metas = len(brown.domain.metas)\n        new_domain = data.domain.Domain(\n            brown.domain.attributes[:-10],\n            brown.domain.class_vars,\n            brown.domain.attributes[-10:] + brown.domain.metas,\n            source=brown.domain)\n        new_brown = data.Table.from_table(new_domain, brown)\n\n        self.assertTrue(sp.issparse(new_brown.X))\n        self.assertFalse(sp.issparse(new_brown.metas))\n        self.assertEqual(new_brown.X.shape, (len(new_brown), n_attr-10))\n        self.assertEqual(new_brown.metas.shape, (len(new_brown), n_metas+10))\n\n        # move back\n        back_brown = data.Table.from_table(brown.domain, new_brown)\n        self.assertEqual(brown.domain, back_brown.domain)\n        self.assertTrue(sp.issparse(back_brown.X))\n        self.assertFalse(sp.issparse(back_brown.metas))\n        self.assertEqual(back_brown.X.shape, brown.X.shape)\n        self.assertEqual(back_brown.metas.shape, brown.metas.shape)\n\n    def test_from_table_shared_compute_value(self):\n        iris = data.Table(\"iris\").to_sparse()\n        d1 = Domain(\n            [\n                ContinuousVariable(\n                    name=at.name,\n                    compute_value=PreprocessSharedComputeValue(\n                        i, None, PreprocessShared(iris.domain, None)\n                    )\n                )\n                for i, at in enumerate(iris.domain.attributes)\n            ]\n        )\n\n        new_table = Table.from_table(d1, iris)\n        np.testing.assert_array_equal(new_table.X, iris.X.todense() * 2)\n\n        new_table = Table.from_table(d1, iris, row_indices=[0, 1, 2])\n        np.testing.assert_array_equal(new_table.X, iris.X.todense()[:3] * 2)\n\n    def assert_table_with_filter_matches(\n            self, new_table, old_table,\n            rows=..., xcols=..., ycols=..., mcols=...):\n        a, c, m = column_sizes(old_table)\n        xcols = slice(a) if xcols is Ellipsis else xcols\n        ycols = slice(a, a + c) if ycols is Ellipsis else ycols\n        mcols = slice(None, -m - 1, -1) if mcols is Ellipsis else mcols\n\n        # Indexing used by convert_domain uses positive indices for variables\n        # and classes (classes come after attributes) and negative indices for\n        # meta features. This is equivalent to ordinary indexing in a magic\n        # table below.\n        magic = np.hstack((old_table.X, old_table.Y[:, None],\n                           old_table.metas[:, ::-1]))\n        np.testing.assert_almost_equal(new_table.X, magic[rows, xcols])\n        Y = magic[rows, ycols]\n        if len(Y.shape) == 2 and Y.shape[1] == 1:\n            Y = Y.flatten()\n        np.testing.assert_almost_equal(new_table.Y, Y)\n        np.testing.assert_almost_equal(new_table.metas, magic[rows, mcols])\n        np.testing.assert_almost_equal(new_table.W, old_table.W[rows])\n\n\ndef isspecial(s):\n    return isinstance(s, slice) or s is Ellipsis\n\n\ndef split_columns(indices, t):\n    a, c, m = column_sizes(t)\n    if indices is ...:\n        return slice(a), slice(c), slice(m)\n    elif isinstance(indices, slice):\n        return indices, slice(0, 0), slice(0, 0)\n    elif not isinstance(indices, list) and not isinstance(indices, tuple):\n        indices = [indices]\n    return (\n        [t.domain.index(x)\n         for x in indices if 0 <= t.domain.index(x) < a] or slice(0, 0),\n        [t.domain.index(x) - a\n         for x in indices if t.domain.index(x) >= a] or slice(0, 0),\n        [-t.domain.index(x) - 1\n         for x in indices if t.domain.index(x) < 0] or slice(0, 0))\n\n\ndef getname(variable):\n    return variable.name\n\n\nclass TableIndexingTests(TableTests):\n    def setUp(self):\n        super().setUp()\n        d = self.domain = \\\n            self.create_domain(self.attributes, self.class_vars, self.metas)\n        t = self.table = \\\n            data.Table(self.domain, self.data, self.class_data, self.meta_data)\n        self.magic_table = \\\n            np.column_stack((self.table.X, self.table.Y,\n                             self.table.metas[:, ::-1]))\n\n        self.rows = [0, -1]\n        self.multiple_rows = [slice(0, 0), ..., slice(1, -1, -1)]\n        a, c, m = column_sizes(t)\n        columns = [0, a - 1, a, a + c - 1, -1, -m]\n        self.columns = chain(columns,\n                             map(lambda x: d[x], columns),\n                             map(lambda x: d[x].name, columns))\n        self.multiple_columns = chain(\n            self.multiple_rows,\n            [d.attributes, d.class_vars, d.metas, [0, a, -1]],\n            [self.attributes, self.class_vars, self.metas],\n            [self.attributes + self.class_vars + self.metas])\n\n        # TODO: indexing with [[0,1], [0,1]] produces weird results\n        # TODO: what should be the results of table[1, :]\n\n    def test_can_select_a_single_value(self):\n        for r in self.rows:\n            for c in self.columns:\n                value = self.table[r, c]\n                self.assertAlmostEqual(\n                    value, self.magic_table[r, self.domain.index(c)])\n\n                value = self.table[r][c]\n                self.assertAlmostEqual(\n                    value, self.magic_table[r, self.domain.index(c)])\n\n    def test_can_select_a_single_row(self):\n        for r in self.rows:\n            row = self.table[r]\n            new_row = np.hstack(\n                (self.data[r, :],\n                 self.class_data[r, None]))\n            np.testing.assert_almost_equal(\n                np.array(list(row)), new_row)\n\n\n    def test_can_select_a_subset_of_rows_and_columns(self):\n        for r in self.rows:\n            for c in self.multiple_columns:\n                table = self.table[r, c]\n\n                attr, cls, metas = split_columns(c, self.table)\n                X = self.table.X[[r], attr]\n                if X.ndim == 1:\n                    X = X.reshape(-1, len(table.domain.attributes))\n                np.testing.assert_almost_equal(table.X, X)\n                Y = self.table.Y[:, None][[r], cls]\n                if len(Y.shape) == 1 or Y.shape[1] == 1:\n                    Y = Y.flatten()\n                np.testing.assert_almost_equal(table.Y, Y)\n                metas_ = self.table.metas[[r], metas]\n                if metas_.ndim == 1:\n                    metas_ = metas_.reshape(-1, len(table.domain.metas))\n                np.testing.assert_almost_equal(table.metas, metas_)\n\n        for r in self.multiple_rows:\n            for c in chain(self.columns, self.multiple_rows):\n                table = self.table[r, c]\n\n                attr, cls, metas = split_columns(c, self.table)\n                np.testing.assert_almost_equal(table.X, self.table.X[r, attr])\n                Y = self.table.Y[:, None][r, cls]\n                if len(Y.shape) > 1 and Y.shape[1] == 1:\n                    Y = Y.flatten()\n                np.testing.assert_almost_equal(table.Y, Y)\n                np.testing.assert_almost_equal(table.metas,\n                                               self.table.metas[r, metas])\n\n\n    def test_optimize_indices(self):\n        # ordinary conversion\n        self.assertEqual(_optimize_indices([1, 2, 3], 4), slice(1, 4, 1))\n        self.assertEqual(_optimize_indices([], 1), [])\n        self.assertEqual(_optimize_indices([0, 2], 3), slice(0, 4, 2))\n\n        # not slices\n        np.testing.assert_equal(_optimize_indices([1, 2, 4], 5), [1, 2, 4])\n        np.testing.assert_equal(_optimize_indices((1, 2, 4), 5), [1, 2, 4])\n\n        # leave boolean arrays\n        np.testing.assert_equal(_optimize_indices([True, False, True], 3), [True, False, True])\n\n        # do not convert if step is negative\n        np.testing.assert_equal(_optimize_indices([4, 2, 0], 5), [4, 2, 0])\n\n        # try range\n        np.testing.assert_equal(_optimize_indices([3, 4, 5], 5), [3, 4, 5])  # out of range\n        self.assertEqual(_optimize_indices((3, 4, 5), 6), slice(3, 6, 1))\n\n        # negative elements\n        np.testing.assert_equal(_optimize_indices([-1, 0, 1], 5), [-1, 0, 1])\n\n        # single element\n        self.assertEqual(_optimize_indices([1], 2), slice(1, 2, 1))\n        self.assertEqual(_optimize_indices([-2], 5), slice(-2, -3, -1))\n\n\nclass TableElementAssignmentTest(TableTests):\n    def setUp(self):\n        super().setUp()\n        self.domain = \\\n            self.create_domain(self.attributes, self.class_vars, self.metas)\n        self.table = \\\n            data.Table(self.domain, self.data, self.class_data, self.meta_data)\n\n    def test_can_assign_values(self):\n        with self.table.unlocked():\n            self.table[0, 0] = 42.\n        self.assertAlmostEqual(self.table.X[0, 0], 42.)\n\n    def test_can_assign_values_to_classes(self):\n        a, _, _ = column_sizes(self.table)\n        with self.table.unlocked():\n            self.table[0, a] = 42.\n        self.assertAlmostEqual(self.table.Y[0], 42.)\n\n    def test_can_assign_values_to_metas(self):\n        with self.table.unlocked():\n            self.table[0, -1] = 42.\n        self.assertAlmostEqual(self.table.metas[0, 0], 42.)\n\n    def test_can_assign_rows_to_rows(self):\n        with self.table.unlocked():\n            self.table[0] = self.table[1]\n        np.testing.assert_almost_equal(\n            self.table.X[0], self.table.X[1])\n        np.testing.assert_almost_equal(\n            self.table.Y[0], self.table.Y[1])\n        np.testing.assert_almost_equal(\n            self.table.metas[0], self.table.metas[1])\n\n    def test_can_assign_lists(self):\n        a, _, _ = column_sizes(self.table)\n        new_example = [float(i)\n                       for i in range(len(self.attributes + self.class_vars))]\n        with self.table.unlocked():\n            self.table[0] = new_example\n        np.testing.assert_almost_equal(\n            self.table.X[0], np.array(new_example[:a]))\n        np.testing.assert_almost_equal(\n            self.table.Y[0], np.array(new_example[a:]))\n\n    def test_can_assign_np_array(self):\n        a, _, _ = column_sizes(self.table)\n        new_example = \\\n            np.array([float(i)\n                      for i in range(len(self.attributes + self.class_vars))])\n        with self.table.unlocked():\n            self.table[0] = new_example\n        np.testing.assert_almost_equal(self.table.X[0], new_example[:a])\n        np.testing.assert_almost_equal(self.table.Y[0], new_example[a:])\n\n\nclass InterfaceTest(unittest.TestCase):\n    \"\"\"Basic tests each implementation of Table should pass.\"\"\"\n\n    features = (\n        data.ContinuousVariable(name=\"Continuous Feature 1\"),\n        data.ContinuousVariable(name=\"Continuous Feature 2\"),\n        data.DiscreteVariable(name=\"Discrete Feature 1\", values=(\"0\", \"1\")),\n        data.DiscreteVariable(name=\"Discrete Feature 2\",\n                              values=(\"value1\", \"value2\")),\n    )\n\n    class_vars = (\n        data.ContinuousVariable(name=\"Continuous Class\"),\n        data.DiscreteVariable(name=\"Discrete Class\", values=(\"m\", \"f\"))\n    )\n\n    feature_data = (\n        (1, 0, 0, 0),\n        (0, 1, 0, 0),\n        (0, 0, 1, 0),\n        (0, 0, 0, 1),\n    )\n\n    class_data = (\n        (1, 0),\n        (0, 1),\n        (1, 0),\n        (0, 1)\n    )\n\n    data = tuple(a + c for a, c in zip(feature_data, class_data))\n\n    nrows = 4\n\n    def setUp(self):\n        self.domain = data.Domain(attributes=self.features,\n                                  class_vars=self.class_vars)\n        self.table = data.Table.from_numpy(\n            self.domain,\n            np.array(self.feature_data),\n            np.array(self.class_data),\n        )\n\n    def test_len(self):\n        self.assertEqual(len(self.table), self.nrows)\n\n    def test_row_len(self):\n        for i in range(self.nrows):\n            self.assertEqual(len(self.table[i]), len(self.data[i]))\n\n    def test_iteration(self):\n        for row, expected_data in zip(self.table, self.data):\n            self.assertEqual(tuple(row), expected_data)\n\n    def test_row_indexing(self):\n        for i in range(self.nrows):\n            self.assertEqual(tuple(self.table[i]), self.data[i])\n\n    def test_row_slicing(self):\n        t = self.table[1:]\n        self.assertEqual(len(t), self.nrows - 1)\n\n    def test_value_indexing(self):\n        for i in range(self.nrows):\n            for j in range(len(self.table[i])):\n                self.assertEqual(self.table[i, j], self.data[i][j])\n\n    def test_row_assignment(self):\n        new_value = 2.\n        with self.table.unlocked():\n            for i in range(self.nrows):\n                new_row = [new_value] * len(self.data[i])\n                self.table[i] = np.array(new_row)\n                self.assertEqual(list(self.table[i]), new_row)\n\n    def test_value_assignment(self):\n        new_value = 0.\n        with self.table.unlocked():\n            for i in range(self.nrows):\n                for j in range(len(self.table[i])):\n                    self.table[i, j] = new_value\n                    self.assertEqual(self.table[i, j], new_value)\n\n    def test_subclasses(self):\n        from pathlib import Path\n\n        class _ExtendedTable(data.Table):\n            pass\n\n        data_file = _ExtendedTable('iris')\n        data_url = _ExtendedTable.from_url(\n            Path(os.path.dirname(__file__), 'datasets/test1.tab').as_uri())\n\n        self.assertIsInstance(data_file, _ExtendedTable)\n        self.assertIsInstance(data_url, _ExtendedTable)\n\n\nclass TestTableStats(TableTests):\n    def test_get_nan_frequency(self):\n        domain = self.create_domain(self.attributes, self.class_vars)\n        table = data.Table(domain, self.data, self.class_data)\n        self.assertEqual(table.get_nan_frequency_attribute(), 0)\n        self.assertEqual(table.get_nan_frequency_class(), 0)\n\n        with table.unlocked():\n            table.X[1, 2] = table.X[4, 5] = np.nan\n        self.assertEqual(table.get_nan_frequency_attribute(), 2 / table.X.size)\n        self.assertEqual(table.get_nan_frequency_class(), 0)\n\n        with table.unlocked():\n            table.Y[3:6] = np.nan\n        self.assertEqual(table.get_nan_frequency_attribute(), 2 / table.X.size)\n        self.assertEqual(table.get_nan_frequency_class(), 3 / table.Y.size)\n\n        with table.unlocked():\n            table.X[1, 2] = table.X[4, 5] = 0\n        self.assertEqual(table.get_nan_frequency_attribute(), 0)\n        self.assertEqual(table.get_nan_frequency_class(), 3 / table.Y.size)\n\n    def test_get_nan_frequency_empty_table(self):\n        domain = self.create_domain(self.attributes, self.class_vars)\n        table = data.Table.from_domain(domain)\n        self.assertEqual(table.get_nan_frequency_attribute(), 0)\n        self.assertEqual(table.get_nan_frequency_class(), 0)\n\n\nclass TestRowInstance(unittest.TestCase):\n    def test_assignment(self):\n        table = data.Table(\"zoo\")\n        inst = table[2]\n        self.assertIsInstance(inst, data.RowInstance)\n\n        with table.unlocked():\n            inst[1] = 0\n        self.assertEqual(table[2, 1], 0)\n        with table.unlocked():\n            inst[1] = 1\n        self.assertEqual(table[2, 1], 1)\n\n        with table.unlocked():\n            inst.set_class(\"mammal\")\n        self.assertEqual(table[2, len(table.domain.attributes)], \"mammal\")\n        with table.unlocked():\n            inst.set_class(\"fish\")\n        self.assertEqual(table[2, len(table.domain.attributes)], \"fish\")\n\n        with table.unlocked():\n            inst[-1] = \"Foo\"\n        self.assertEqual(table[2, -1], \"Foo\")\n\n    def test_iteration_with_assignment(self):\n        table = data.Table(\"iris\")\n        with table.unlocked():\n            for i, row in enumerate(table):\n                row[0] = i\n        np.testing.assert_array_equal(table.X[:, 0], np.arange(len(table)))\n\n    def test_sparse_assignment(self):\n        X = np.eye(4)\n        Y = X[2].copy()\n        table = data.Table.from_numpy(None, X, Y)\n        row = table[1]\n        self.assertFalse(sp.issparse(row.sparse_x))\n        self.assertEqual(row[0], 0)\n        self.assertEqual(row[1], 1)\n\n        with table.unlocked():\n            table.X = sp.csr_matrix(table.X)\n            table.Y = sp.csr_matrix(table.Y)\n        sparse_row = table[1]\n        self.assertTrue(sp.issparse(sparse_row.sparse_x))\n        self.assertEqual(sparse_row[0], 0)\n        self.assertEqual(sparse_row[1], 1)\n\n        with table.unlocked():\n            sparse_row[1] = 0\n        self.assertEqual(sparse_row[1], 0)\n        self.assertEqual(table.X[1, 1], 0)\n        self.assertEqual(table[2][4], 1)\n\n        with table.unlocked():\n            table[2][4] = 0\n        self.assertEqual(table[2][4], 0)\n\n\nclass TestTableTranspose(unittest.TestCase):\n    def test_transpose_no_class(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        table = Table(Domain(attrs), np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose is original\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_discrete_class(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        domain = Domain(attrs, [DiscreteVariable(\"cls\", values=(\"a\", \"b\"))])\n        table = Table(domain, np.arange(8).reshape((4, 2)),\n                     np.array([1, 1, 0, 0]))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"cls\": \"b\"}\n        att[1].attributes = {\"cls\": \"b\"}\n        att[2].attributes = {\"cls\": \"a\"}\n        att[3].attributes = {\"cls\": \"a\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose is original\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_continuous_class(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")])\n        table = Table(domain, np.arange(8).reshape((4, 2)), np.arange(4, 0, -1))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"cls\": \"4\"}\n        att[1].attributes = {\"cls\": \"3\"}\n        att[2].attributes = {\"cls\": \"2\"}\n        att[3].attributes = {\"cls\": \"1\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_missing_class(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")])\n        table = Table(domain, np.arange(8).reshape((4, 2)),\n                     np.array([np.nan, 3, 2, 1]))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[1].attributes = {\"cls\": \"3\"}\n        att[2].attributes = {\"cls\": \"2\"}\n        att[3].attributes = {\"cls\": \"1\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_multiple_class(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        class_vars = [ContinuousVariable(\"cls1\"), ContinuousVariable(\"cls2\")]\n        domain = Domain(attrs, class_vars)\n        table = Table(domain, np.arange(8).reshape((4, 2)),\n                      np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"cls1\": \"0\", \"cls2\": \"1\"}\n        att[1].attributes = {\"cls1\": \"2\", \"cls2\": \"3\"}\n        att[2].attributes = {\"cls1\": \"4\", \"cls2\": \"5\"}\n        att[3].attributes = {\"cls1\": \"6\", \"cls2\": \"7\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_metas(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([\"aa\", \"bb\", \"cc\", \"dd\"])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"m1\": \"aa\"}\n        att[1].attributes = {\"m1\": \"bb\"}\n        att[2].attributes = {\"m1\": \"cc\"}\n        att[3].attributes = {\"m1\": \"dd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_discrete_metas(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [DiscreteVariable(\"m1\", values=(\"aa\", \"bb\"))]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([0, 1, 0, 1])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"m1\": \"aa\"}\n        att[1].attributes = {\"m1\": \"bb\"}\n        att[2].attributes = {\"m1\": \"aa\"}\n        att[3].attributes = {\"m1\": \"bb\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose is original\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_continuous_metas(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [ContinuousVariable(\"m1\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([0.0, 1.0, 0.0, 1.0])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"m1\": \"0\"}\n        att[1].attributes = {\"m1\": \"1\"}\n        att[2].attributes = {\"m1\": \"0\"}\n        att[3].attributes = {\"m1\": \"1\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose is original\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_missing_metas(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([\"aa\", \"bb\", \"\", \"dd\"])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"m1\": \"aa\"}\n        att[1].attributes = {\"m1\": \"bb\"}\n        att[3].attributes = {\"m1\": \"dd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_multiple_metas(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\"), StringVariable(\"m2\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([[\"aa\", \"aaa\"], [\"bb\", \"bbb\"],\n                      [\"cc\", \"ccc\"], [\"dd\", \"ddd\"]])\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"m1\": \"aa\", \"m2\": \"aaa\"}\n        att[1].attributes = {\"m1\": \"bb\", \"m2\": \"bbb\"}\n        att[2].attributes = {\"m1\": \"cc\", \"m2\": \"ccc\"}\n        att[3].attributes = {\"m1\": \"dd\", \"m2\": \"ddd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_class_and_metas(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\"), StringVariable(\"m2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")], metas)\n        M = np.array([[\"aa\", \"aaa\"], [\"bb\", \"bbb\"],\n                      [\"cc\", \"ccc\"], [\"dd\", \"ddd\"]])\n        table = Table(domain, np.arange(8).reshape((4, 2)), np.arange(1, 5), M)\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"cls\": \"1\", \"m1\": \"aa\", \"m2\": \"aaa\"}\n        att[1].attributes = {\"cls\": \"2\", \"m1\": \"bb\", \"m2\": \"bbb\"}\n        att[2].attributes = {\"cls\": \"3\", \"m1\": \"cc\", \"m2\": \"ccc\"}\n        att[3].attributes = {\"cls\": \"4\", \"m1\": \"dd\", \"m2\": \"ddd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_attributes_of_attributes_discrete(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"a\", \"attr2\": \"aa\"}\n        attrs[1].attributes = {\"attr1\": \"b\", \"attr2\": \"bb\"}\n        domain = Domain(attrs)\n        table = Table(domain, np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        metas = [StringVariable(\"Feature name\"),\n                 DiscreteVariable(\"attr1\", values=(\"a\", \"b\")),\n                 DiscreteVariable(\"attr2\", values=(\"aa\", \"bb\"))]\n        domain = Domain(att, metas=metas)\n        M = np.array([[\"c1\", 0.0, 0.0], [\"c2\", 1.0, 1.0]], dtype=object)\n        result = Table(domain, np.arange(8).reshape((4, 2)).T, metas=M)\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"a\", \"attr2\": \"aa\"})\n\n    def test_transpose_attributes_of_attributes_continuous(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"1.1\", \"attr2\": \"1.3\"}\n        attrs[1].attributes = {\"attr1\": \"2.2\", \"attr2\": \"2.3\"}\n        domain = Domain(attrs)\n        table = Table(domain, np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        metas = [StringVariable(\"Feature name\"), ContinuousVariable(\"attr1\"),\n                 ContinuousVariable(\"attr2\")]\n        domain = Domain(att, metas=metas)\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([[\"c1\", 1.1, 1.3],\n                                       [\"c2\", 2.2, 2.3]], dtype=object))\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"1.1\", \"attr2\": \"1.3\"})\n\n    def test_transpose_attributes_of_attributes_missings(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"a\", \"attr2\": \"aa\"}\n        attrs[1].attributes = {\"attr1\": \"b\"}\n        domain = Domain(attrs)\n        table = Table(domain, np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        metas = [StringVariable(\"Feature name\"),\n                 DiscreteVariable(\"attr1\", values=(\"a\", \"b\")),\n                 DiscreteVariable(\"attr2\", values=(\"aa\",))]\n        domain = Domain(att, metas=metas)\n        M = np.array([[\"c1\", 0.0, 0.0], [\"c2\", 1.0, np.nan]], dtype=object)\n        result = Table(domain, np.arange(8).reshape((4, 2)).T, metas=M)\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"a\", \"attr2\": \"aa\"})\n\n    def test_transpose_class_metas_attributes(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"a1\", \"attr2\": \"aa1\"}\n        attrs[1].attributes = {\"attr1\": \"b1\", \"attr2\": \"bb1\"}\n        metas = [StringVariable(\"m1\"), StringVariable(\"m2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")], metas)\n        M = np.array([[\"aa\", \"aaa\"], [\"bb\", \"bbb\"],\n                      [\"cc\", \"ccc\"], [\"dd\", \"ddd\"]])\n        table = Table(domain, np.arange(8).reshape((4, 2)), np.arange(1, 5), M)\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"cls\": \"1\", \"m1\": \"aa\", \"m2\": \"aaa\"}\n        att[1].attributes = {\"cls\": \"2\", \"m1\": \"bb\", \"m2\": \"bbb\"}\n        att[2].attributes = {\"cls\": \"3\", \"m1\": \"cc\", \"m2\": \"ccc\"}\n        att[3].attributes = {\"cls\": \"4\", \"m1\": \"dd\", \"m2\": \"ddd\"}\n        metas = [StringVariable(\"Feature name\"),\n                 DiscreteVariable(\"attr1\", values=(\"a1\", \"b1\")),\n                 DiscreteVariable(\"attr2\", values=(\"aa1\", \"bb1\"))]\n        domain = Domain(att, metas=metas)\n        M = np.array([[\"c1\", 0.0, 0.0], [\"c2\", 1.0, 1.0]], dtype=object)\n        result = Table(domain, np.arange(8).reshape((4, 2)).T, metas=M)\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"a1\", \"attr2\": \"aa1\"})\n\n    def test_transpose_duplicate_feature_names(self):\n        table = Table(\"iris\")\n        domain = table.domain\n        attrs, metas = domain.attributes[:3], domain.attributes[3:]\n        table = table.transform(Domain(attrs, domain.class_vars, metas))\n        transposed = Table.transpose(table, domain.attributes[3].name)\n        names = [f.name for f in transposed.domain.attributes]\n        self.assertEqual(len(names), len(set(names)))\n\n    def test_transpose(self):\n        zoo = Table(\"zoo\")\n        t1 = Table.transpose(zoo)\n        t2 = Table.transpose(t1, \"Feature name\")\n        t3 = Table.transpose(t2)\n        self._compare_tables(zoo, t2)\n        self._compare_tables(t1, t3)\n\n    def test_transpose_callback(self):\n        zoo = Table(\"zoo\")\n        cb = Mock()\n        Table.transpose(zoo, progress_callback=cb)\n        cb.assert_called()\n\n    def test_transpose_no_class_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        table = Table(Domain(attrs), np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_discrete_class_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        domain = Domain(attrs, [DiscreteVariable(\"cls\", values=(\"a\", \"b\"))])\n        table = Table(domain, np.arange(8).reshape((4, 2)),\n                     np.array([1, 1, 0, 0]))\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"cls\": \"b\"}\n        att[1].attributes = {\"cls\": \"b\"}\n        att[2].attributes = {\"cls\": \"a\"}\n        att[3].attributes = {\"cls\": \"a\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_continuous_class_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")])\n        table = Table(domain, np.arange(8).reshape((4, 2)), np.arange(4, 0, -1))\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"cls\": \"4\"}\n        att[1].attributes = {\"cls\": \"3\"}\n        att[2].attributes = {\"cls\": \"2\"}\n        att[3].attributes = {\"cls\": \"1\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_missing_class_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")])\n        table = Table(domain, np.arange(8).reshape((4, 2)),\n                     np.array([np.nan, 3, 2, 1]))\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[1].attributes = {\"cls\": \"3\"}\n        att[2].attributes = {\"cls\": \"2\"}\n        att[3].attributes = {\"cls\": \"1\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_multiple_class_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        class_vars = [ContinuousVariable(\"cls1\"), ContinuousVariable(\"cls2\")]\n        domain = Domain(attrs, class_vars)\n        table = Table(domain, np.arange(8).reshape((4, 2)),\n                     np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"cls1\": \"0\", \"cls2\": \"1\"}\n        att[1].attributes = {\"cls1\": \"2\", \"cls2\": \"3\"}\n        att[2].attributes = {\"cls1\": \"4\", \"cls2\": \"5\"}\n        att[3].attributes = {\"cls1\": \"6\", \"cls2\": \"7\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_metas_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([\"aa\", \"bb\", \"cc\", \"dd\"])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"m1\": \"aa\"}\n        att[1].attributes = {\"m1\": \"bb\"}\n        att[2].attributes = {\"m1\": \"cc\"}\n        att[3].attributes = {\"m1\": \"dd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_discrete_metas_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [DiscreteVariable(\"m1\", values=(\"aa\", \"bb\"))]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([0, 1, 0, 1])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"m1\": \"aa\"}\n        att[1].attributes = {\"m1\": \"bb\"}\n        att[2].attributes = {\"m1\": \"aa\"}\n        att[3].attributes = {\"m1\": \"bb\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_continuous_metas_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [ContinuousVariable(\"m1\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([0.0, 1.0, 0.0, 1.0])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"m1\": \"0\"}\n        att[1].attributes = {\"m1\": \"1\"}\n        att[2].attributes = {\"m1\": \"0\"}\n        att[3].attributes = {\"m1\": \"1\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_missing_metas_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([\"aa\", \"bb\", \"\", \"dd\"])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"m1\": \"aa\"}\n        att[1].attributes = {\"m1\": \"bb\"}\n        att[3].attributes = {\"m1\": \"dd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_multiple_metas_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\"), StringVariable(\"m2\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([[\"aa\", \"aaa\"], [\"bb\", \"bbb\"],\n                      [\"cc\", \"ccc\"], [\"dd\", \"ddd\"]])\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"m1\": \"aa\", \"m2\": \"aaa\"}\n        att[1].attributes = {\"m1\": \"bb\", \"m2\": \"bbb\"}\n        att[2].attributes = {\"m1\": \"cc\", \"m2\": \"ccc\"}\n        att[3].attributes = {\"m1\": \"dd\", \"m2\": \"ddd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_class_and_metas_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\"), StringVariable(\"m2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")], metas)\n        M = np.array([[\"aa\", \"aaa\"], [\"bb\", \"bbb\"],\n                      [\"cc\", \"ccc\"], [\"dd\", \"ddd\"]])\n        table = Table(domain, np.arange(8).reshape((4, 2)), np.arange(1, 5), M)\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"cls\": \"1\", \"m1\": \"aa\", \"m2\": \"aaa\"}\n        att[1].attributes = {\"cls\": \"2\", \"m1\": \"bb\", \"m2\": \"bbb\"}\n        att[2].attributes = {\"cls\": \"3\", \"m1\": \"cc\", \"m2\": \"ccc\"}\n        att[3].attributes = {\"cls\": \"4\", \"m1\": \"dd\", \"m2\": \"ddd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_attributes_of_attributes_discrete_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"a\", \"attr2\": \"aa\"}\n        attrs[1].attributes = {\"attr1\": \"b\", \"attr2\": \"bb\"}\n        domain = Domain(attrs)\n        table = Table(domain, np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        metas = [StringVariable(\"Feature name\"),\n                 DiscreteVariable(\"attr1\", values=(\"a\", \"b\")),\n                 DiscreteVariable(\"attr2\", values=(\"aa\", \"bb\"))]\n        domain = Domain(att, metas=metas)\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\", 0.0, 0.0]], dtype=object))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"a\", \"attr2\": \"aa\"})\n\n    def test_transpose_attributes_of_attributes_continuous_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"1.1\", \"attr2\": \"1.3\"}\n        attrs[1].attributes = {\"attr1\": \"2.2\", \"attr2\": \"2.3\"}\n        domain = Domain(attrs)\n        table = Table(domain, np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        metas = [StringVariable(\"Feature name\"), ContinuousVariable(\"attr1\"),\n                 ContinuousVariable(\"attr2\")]\n        domain = Domain(att, metas=metas)\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\", 1.1, 1.3]], dtype=object))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"1.1\", \"attr2\": \"1.3\"})\n\n    def test_transpose_attributes_of_attributes_missings_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"a\", \"attr2\": \"aa\"}\n        attrs[1].attributes = {\"attr1\": \"b\"}\n        domain = Domain(attrs)\n        table = Table(domain, np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"0\"), ContinuousVariable(\"2\"),\n               ContinuousVariable(\"4\"), ContinuousVariable(\"6\")]\n        metas = [StringVariable(\"Feature name\"),\n                 DiscreteVariable(\"attr1\", values=(\"b\",))]\n        domain = Domain(att, metas=metas)\n        result = Table(domain, np.array([[1, 3, 5, 7]]),\n                       metas=np.array([[\"c2\", 0.0]], dtype=object))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c1\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"2\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"a\", \"attr2\": \"aa\"})\n\n    def test_transpose_class_metas_attributes_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"a1\", \"attr2\": \"aa1\"}\n        attrs[1].attributes = {\"attr1\": \"b1\", \"attr2\": \"bb1\"}\n        metas = [StringVariable(\"m1\"), StringVariable(\"m2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")], metas)\n        M = np.array([[\"aa\", \"aaa\"], [\"bb\", \"bbb\"],\n                      [\"cc\", \"ccc\"], [\"dd\", \"ddd\"]])\n        table = Table(domain, np.arange(8).reshape((4, 2)), np.arange(1, 5), M)\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"cls\": \"1\", \"m1\": \"aa\", \"m2\": \"aaa\"}\n        att[1].attributes = {\"cls\": \"2\", \"m1\": \"bb\", \"m2\": \"bbb\"}\n        att[2].attributes = {\"cls\": \"3\", \"m1\": \"cc\", \"m2\": \"ccc\"}\n        att[3].attributes = {\"cls\": \"4\", \"m1\": \"dd\", \"m2\": \"ddd\"}\n        metas = [StringVariable(\"Feature name\"),\n                 DiscreteVariable(\"attr1\", values=(\"a1\", \"b1\")),\n                 DiscreteVariable(\"attr2\", values=(\"aa1\", \"bb1\"))]\n        domain = Domain(att, metas=metas)\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\", 0.0, 0.0]], dtype=object))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"a1\", \"attr2\": \"aa1\"})\n\n    def _compare_tables(self, table1, table2):\n        self.assertEqual(table1.n_rows, table2.n_rows)\n        np.testing.assert_array_equal(table1.X, table2.X)\n        np.testing.assert_array_equal(table1.Y, table2.Y)\n        np.testing.assert_array_equal(table1.metas.astype(str),\n                                      table2.metas.astype(str))\n        np.testing.assert_array_equal(table1.W, table2.W)\n\n        self.assertEqual([(type(x), x.name, x.attributes)\n                          for x in table1.domain.attributes],\n                         [(type(x), x.name, x.attributes)\n                          for x in table2.domain.attributes])\n        self.assertEqual([(type(x), x.name, x.attributes)\n                          for x in table1.domain.class_vars],\n                         [(type(x), x.name, x.attributes)\n                          for x in table2.domain.class_vars])\n        self.assertEqual([(type(x), x.name, x.attributes)\n                          for x in table1.domain.metas],\n                         [(type(x), x.name, x.attributes)\n                          for x in table2.domain.metas])\n\n\nclass SparseCV:\n    def __call__(self, data):\n        return sp.csr_matrix((len(data), 1))\n\n\nclass TestTableSparseDense(unittest.TestCase):\n    def setUp(self):\n        self.iris = Table('iris')\n\n    def test_sparse_dense_transformation(self):\n        iris = Table('iris')\n        iris_sparse = iris.to_sparse(sparse_attributes=True)\n        self.assertTrue(sp.issparse(iris_sparse.X))\n        self.assertFalse(sp.issparse(iris_sparse.Y))\n        self.assertFalse(sp.issparse(iris_sparse.metas))\n\n        iris_sparse = iris.to_sparse(sparse_attributes=True, sparse_class=True)\n        self.assertTrue(sp.issparse(iris_sparse.X))\n        self.assertFalse(sp.issparse(iris_sparse.Y))\n        self.assertFalse(sp.issparse(iris_sparse.metas))\n\n        dense_iris = iris_sparse.to_dense()\n        self.assertFalse(sp.issparse(dense_iris.X))\n        self.assertFalse(sp.issparse(dense_iris.Y))\n        self.assertFalse(sp.issparse(dense_iris.metas))\n\n    def test_from_table_add_one_sparse_column(self):\n        # add one sparse feature, should remain dense\n        domain = self.iris.domain.copy()\n        domain.attributes += (\n            ContinuousVariable('S1', compute_value=SparseCV(), sparse=True),\n        )\n        d = self.iris.transform(domain)\n        self.assertFalse(sp.issparse(d.X))\n\n        # try with indices that are not Ellipsis\n        d = Table.from_table(domain, self.iris, row_indices=[0, 1, 2])\n        np.testing.assert_array_equal(\n            d.X,\n            [[5.1, 3.5, 1.4, 0.2, 0],\n             [4.9, 3.0, 1.4, 0.2, 0],\n             [4.7, 3.2, 1.3, 0.2, 0]]\n        )\n        self.assertFalse(sp.issparse(d.X))\n\n    def test_from_table_add_lots_of_sparse_columns(self):\n        n_attrs = len(self.iris.domain.attributes)\n\n        # add 2*n_attrs+1 sparse feature, should became sparse\n        domain = self.iris.domain.copy()\n        domain.attributes += tuple(\n            ContinuousVariable('S' + str(i), compute_value=SparseCV(), sparse=True)\n            for i in range(2*n_attrs + 1)\n        )\n        d = self.iris.transform(domain)\n        self.assertTrue(sp.issparse(d.X))\n\n    def test_from_table_replace_attrs_with_sparse(self):\n        # replace attrs with a sparse feature, should became sparse\n        domain = self.iris.domain.copy()\n        domain.attributes = (\n            ContinuousVariable('S1', compute_value=SparseCV(), sparse=True),\n        )\n        d = self.iris.transform(domain)\n        self.assertTrue(sp.issparse(d.X))\n\n    def test_from_table_sparse_metas(self):\n        # replace metas with a sparse feature, should became sparse\n        domain = self.iris.domain.copy()\n        domain._metas = (\n            ContinuousVariable('S1', compute_value=SparseCV(), sparse=True),\n        )\n        d = self.iris.transform(domain)\n        self.assertTrue(sp.issparse(d.metas))\n\n    def test_from_table_sparse_metas_with_strings(self):\n        # replace metas with text and 100 sparse features, should be dense\n        domain = self.iris.domain.copy()\n        domain._metas = (StringVariable('text'),) + tuple(\n            ContinuousVariable('S' + str(i), compute_value=SparseCV(), sparse=True)\n            for i in range(100)\n        )\n        d = self.iris.transform(domain)\n        self.assertFalse(sp.issparse(d.metas))\n\n\nclass ConcurrencyTests(unittest.TestCase):\n\n    def test_from_table_non_blocking(self):\n        iris = Table(\"iris\")[:10]\n\n        def slow_compute_value(d):\n            sleep(0.1)\n            return d.X[:, 0]\n\n        ndom = Domain([ContinuousVariable(\"a\", compute_value=slow_compute_value)])\n\n        def run_from_table():\n            Table.from_table(ndom, iris)\n\n        start = time()\n\n        threads = []\n        for _ in range(10):\n            thread = Thread(target=run_from_table)\n            thread.start()\n            threads.append(thread)\n        for t in threads:\n            t.join()\n\n        # if from_table was blocking these threads would need at least 0.1*10s\n        duration = time() - start\n        self.assertLess(duration, 0.5)\n\n\nclass PreprocessComputeValue:\n\n    def __init__(self, domain, callback):\n        self.domain = domain\n        self.callback = callback\n\n    def __call__(self, data_):\n        if self.callback:\n            self.callback(data_)\n        transformed = data_.transform(self.domain)\n        return transformed.X[:, 0] * 2\n\n\nclass PreprocessShared:\n\n    def __init__(self, domain, callback):\n        self.domain = domain\n        self.callback = callback\n\n    def __call__(self, data_):\n        if self.callback:\n            self.callback(data_)\n        transformed = data_.transform(self.domain)\n        return transformed.X * 2\n\n\nclass PreprocessSharedComputeValue(SharedComputeValue):\n\n    def __init__(self, col, callback, shared):\n        super().__init__(compute_shared=shared)\n        self.col = col\n        self.callback = callback\n\n    # pylint: disable=arguments-differ\n    def compute(self, data_, shared_data):\n        if self.callback:\n            self.callback(data_)\n        return shared_data[:, self.col]\n\n\ndef preprocess_domain_single(domain, callback):\n    \"\"\" Preprocess domain with single-source compute values.\n    \"\"\"\n    return Domain([\n        ContinuousVariable(name=at.name,\n                           compute_value=PreprocessComputeValue(Domain([at]), callback))\n        for at in domain.attributes])\n\n\ndef preprocess_domain_shared(domain, callback, callback_shared):\n    \"\"\" Preprocess domain with shared compute values.\n    \"\"\"\n    shared = PreprocessShared(domain, callback_shared)\n    return Domain([\n        ContinuousVariable(name=at.name,\n                           compute_value=PreprocessSharedComputeValue(i, callback, shared))\n        for i, at in enumerate(domain.attributes)])\n\n\ndef preprocess_domain_single_stupid(domain, callback):\n    \"\"\" Preprocess domain with single-source compute values with stupid\n    implementation: before applying it, instead of transforming just one column\n    into the input domain, do a needless transform of the whole domain.\n    \"\"\"\n    return Domain([\n        ContinuousVariable(name=at.name,\n                           compute_value=PreprocessComputeValue(domain, callback))\n        for at in domain.attributes])\n\n\nclass EfficientTransformTests(unittest.TestCase):\n\n    def setUp(self):\n        self.iris = Table(\"iris\")[:10]\n\n    def test_simple(self):\n        call_cv = Mock()\n        d1 = preprocess_domain_single(self.iris.domain, call_cv)\n        t = self.iris.transform(d1)\n        self.assertEqual(4, call_cv.call_count)\n        np.testing.assert_equal(t.X, self.iris.X * 2)\n\n    def test_shared(self):\n        call_cv = Mock()\n        call_shared = Mock()\n        d1 = preprocess_domain_shared(self.iris.domain, call_cv, call_shared)\n        t = self.iris.transform(d1)\n        self.assertEqual(4, call_cv.call_count)\n        self.assertEqual(1, call_shared.call_count)\n        np.testing.assert_equal(t.X, self.iris.X * 2)\n\n    def test_simple_simple_shared(self):\n        call_cv = Mock()\n        d1 = preprocess_domain_single(self.iris.domain, call_cv)\n        d2 = preprocess_domain_single(d1, call_cv)\n        call_shared = Mock()\n        d3 = preprocess_domain_shared(d2, call_cv, call_shared)\n        t = self.iris.transform(d3)\n        self.assertEqual(1, call_shared.call_count)\n        self.assertEqual(12, call_cv.call_count)\n        np.testing.assert_equal(t.X, self.iris.X * 2**3)\n\n    def test_simple_simple_shared_simple(self):\n        call_cv = Mock()\n        d1 = preprocess_domain_single(self.iris.domain, call_cv)\n        d2 = preprocess_domain_single(d1, call_cv)\n        call_shared = Mock()\n        d3 = preprocess_domain_shared(d2, call_cv, call_shared)\n        d4 = preprocess_domain_single(d3, call_cv)\n        t = self.iris.transform(d4)\n        self.assertEqual(1, call_shared.call_count)\n        self.assertEqual(16, call_cv.call_count)\n        np.testing.assert_equal(t.X, self.iris.X * 2**4)\n\n    def test_simple_simple_shared_simple_shared_simple(self):\n        call_cv = Mock()\n        d1 = preprocess_domain_single(self.iris.domain, call_cv)\n        d2 = preprocess_domain_single(d1, call_cv)\n        call_shared = Mock()\n        d3 = preprocess_domain_shared(d2, call_cv, call_shared)\n        d4 = preprocess_domain_single(d3, call_cv)\n        d5 = preprocess_domain_shared(d4, call_cv, call_shared)\n        d6 = preprocess_domain_single(d5, call_cv)\n        t = self.iris.transform(d6)\n        self.assertEqual(2, call_shared.call_count)\n        self.assertEqual(24, call_cv.call_count)\n        np.testing.assert_equal(t.X, self.iris.X * 2**6)\n\n    def test_simple_simple_stupid(self):\n        call_cv = Mock()\n        d1 = preprocess_domain_single_stupid(self.iris.domain, call_cv)\n        d2 = preprocess_domain_single_stupid(d1, call_cv)\n        t = self.iris.transform(d2)\n        self.assertEqual(8, call_cv.call_count)\n        np.testing.assert_equal(t.X[:, 0], self.iris.X[:, 0] * 4)\n\n\nif __name__ == \"__main__\":\n    unittest.main()\n",
            "new_file_content": "# Test methods with long descriptive names can omit docstrings\n# pylint: disable=missing-docstring\n\nimport copy\nimport os\nimport pickle\nimport random\nimport unittest\nimport warnings\nfrom unittest.mock import Mock, MagicMock, patch\nfrom itertools import chain\nfrom math import isnan\nfrom threading import Thread\nfrom time import sleep, time\n\nimport numpy as np\nimport scipy.sparse as sp\n\nfrom Orange import data\nfrom Orange.data import (filter, Unknown, Variable, Table, DiscreteVariable,\n                         ContinuousVariable, Domain, StringVariable)\nfrom Orange.data.util import SharedComputeValue\nfrom Orange.tests import test_dirname\nfrom Orange.data.table import _optimize_indices\n\n\nclass TableTestCase(unittest.TestCase):\n    def setUp(self):\n        data.table.dataset_dirs.append(test_dirname())\n\n    def tearDown(self):\n        data.table.dataset_dirs.remove(test_dirname())\n\n    def test_indexing_class(self):\n        d = data.Table(\"datasets/test1\")\n        self.assertEqual([e.get_class() for e in d], [\"t\", \"t\", \"f\"])\n        cind = len(d.domain.variables) - 1\n        self.assertEqual([e[cind] for e in d], [\"t\", \"t\", \"f\"])\n        self.assertEqual([e[\"d\"] for e in d], [\"t\", \"t\", \"f\"])\n        cvar = d.domain.class_var\n        self.assertEqual([e[cvar] for e in d], [\"t\", \"t\", \"f\"])\n\n    def test_filename(self):\n        dir = data.table.get_sample_datasets_dir()\n        d = data.Table(\"iris\")\n        self.assertEqual(d.__file__, os.path.join(dir, \"iris.tab\"))\n\n        d = data.Table(\"datasets/test2.tab\")\n        self.assertTrue(d.__file__.endswith(\"test2.tab\"))  # platform dependent\n\n    def test_indexing(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            # regular, discrete\n            varc = d.domain[\"c\"]\n            self.assertEqual(d[0, 1], \"0\")\n            self.assertEqual(d[0, varc], \"0\")\n            self.assertEqual(d[0, \"c\"], \"0\")\n            self.assertEqual(d[0][1], \"0\")\n            self.assertEqual(d[0][varc], \"0\")\n            self.assertEqual(d[0][\"c\"], \"0\")\n            self.assertEqual(d[np.int_(0), np.int_(1)], \"0\")\n            self.assertEqual(d[np.int_(0)][np.int_(1)], \"0\")\n\n            # regular, continuous\n            varb = d.domain[\"b\"]\n            self.assertEqual(d[0, 0], 0)\n            self.assertEqual(d[0, varb], 0)\n            self.assertEqual(d[0, \"b\"], 0)\n            self.assertEqual(d[0][0], 0)\n            self.assertEqual(d[0][varb], 0)\n            self.assertEqual(d[0][\"b\"], 0)\n            self.assertEqual(d[np.int_(0), np.int_(0)], 0)\n            self.assertEqual(d[np.int_(0)][np.int_(0)], 0)\n\n            # negative\n            varb = d.domain[\"b\"]\n            self.assertEqual(d[-2, 0], 3.333)\n            self.assertEqual(d[-2, varb], 3.333)\n            self.assertEqual(d[-2, \"b\"], 3.333)\n            self.assertEqual(d[-2][0], 3.333)\n            self.assertEqual(d[-2][varb], 3.333)\n            self.assertEqual(d[-2][\"b\"], 3.333)\n            self.assertEqual(d[np.int_(-2), np.int_(0)], 3.333)\n            self.assertEqual(d[np.int_(-2)][np.int_(0)], 3.333)\n\n            # meta, discrete\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n            self.assertEqual(d[0, metaa], \"A\")\n            self.assertEqual(d[0, vara], \"A\")\n            self.assertEqual(d[0, \"a\"], \"A\")\n            self.assertEqual(d[0][metaa], \"A\")\n            self.assertEqual(d[0][vara], \"A\")\n            self.assertEqual(d[0][\"a\"], \"A\")\n            self.assertEqual(d[np.int_(0), np.int_(metaa)], \"A\")\n            self.assertEqual(d[np.int_(0)][np.int_(metaa)], \"A\")\n\n            # meta, string\n            vare = d.domain[\"e\"]\n            metae = d.domain.index(\"e\")\n            self.assertEqual(d[0, metae], \"i\")\n            self.assertEqual(d[0, vare], \"i\")\n            self.assertEqual(d[0, \"e\"], \"i\")\n            self.assertEqual(d[0][metae], \"i\")\n            self.assertEqual(d[0][vare], \"i\")\n            self.assertEqual(d[0][\"e\"], \"i\")\n            self.assertEqual(d[np.int_(0), np.int_(metae)], \"i\")\n            self.assertEqual(d[np.int_(0)][np.int_(metae)], \"i\")\n\n    def test_indexing_example(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            e = d[0]\n\n            # regular, discrete\n            varc = d.domain[\"c\"]\n            self.assertEqual(e[1], \"0\")\n            self.assertEqual(e[varc], \"0\")\n            self.assertEqual(e[\"c\"], \"0\")\n            self.assertEqual(e[np.int_(1)], \"0\")\n\n            # regular, continuous\n            varb = d.domain[\"b\"]\n            self.assertEqual(e[0], 0)\n            self.assertEqual(e[varb], 0)\n            self.assertEqual(e[\"b\"], 0)\n            self.assertEqual(e[np.int_(0)], 0)\n\n            # meta, discrete\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n            self.assertEqual(e[metaa], \"A\")\n            self.assertEqual(e[vara], \"A\")\n            self.assertEqual(e[\"a\"], \"A\")\n            self.assertEqual(e[np.int_(metaa)], \"A\")\n\n            # meta, string\n            vare = d.domain[\"e\"]\n            metae = d.domain.index(\"e\")\n            self.assertEqual(e[metae], \"i\")\n            self.assertEqual(e[vare], \"i\")\n            self.assertEqual(e[\"e\"], \"i\")\n            self.assertEqual(e[np.int_(metae)], \"i\")\n\n    def test_indexing_assign_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            # meta\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, \"a\"] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][\"a\"] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, vara] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][vara] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, metaa] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][metaa] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, np.int_(metaa)] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][np.int_(metaa)] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            # regular\n            varb = d.domain[\"b\"]\n\n            self.assertEqual(d[0, \"b\"], 0)\n            with d.unlocked():\n                d[0, \"b\"] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][\"b\"] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, varb] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][varb] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, 0] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][0] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, np.int_(0)] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][np.int_(0)] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n    def test_indexing_assign_example(self):\n        def almost_equal_list(s, t):\n            for e, f in zip(s, t):\n                self.assertAlmostEqual(e, f)\n\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            self.assertFalse(isnan(d[0, \"a\"]))\n            with d.unlocked():\n                d[0] = [\"3.14\", \"1\", \"f\"]\n            almost_equal_list(d[0].values(), [3.14, \"1\", \"f\"])\n            self.assertTrue(isnan(d[0, \"a\"]))\n\n            with d.unlocked():\n                d[0] = [3.15, 1, \"t\"]\n            almost_equal_list(d[0].values(), [3.15, \"0\", \"t\"])\n\n            with d.unlocked():\n                d[np.int_(0)] = [3.15, 2, \"f\"]\n            almost_equal_list(d[0].values(), [3.15, 2, \"f\"])\n\n            with d.unlocked(), self.assertRaises(ValueError):\n                d[0] = [\"3.14\", \"1\"]\n\n            with d.unlocked(), self.assertRaises(ValueError):\n                d[np.int_(0)] = [\"3.14\", \"1\"]\n\n            ex = data.Instance(d.domain, [\"3.16\", \"1\", \"f\"])\n            with d.unlocked():\n                d[0] = ex\n            almost_equal_list(d[0].values(), [3.16, \"1\", \"f\"])\n\n            ex = data.Instance(d.domain, [\"3.16\", 2, \"t\"])\n            with d.unlocked():\n                d[np.int_(0)] = ex\n            almost_equal_list(d[0].values(), [3.16, 2, \"t\"])\n\n            ex = data.Instance(d.domain, [\"3.16\", \"1\", \"f\"])\n            ex[\"e\"] = \"mmmapp\"\n            with d.unlocked():\n                d[0] = ex\n            almost_equal_list(d[0].values(), [3.16, \"1\", \"f\"])\n            self.assertEqual(d[0, \"e\"], \"mmmapp\")\n\n    def test_slice(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            x = d[:3]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [0, 1.1, 2.22])\n\n            x = d[2:5]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.22, 2.23, 2.24])\n\n            x = d[4:1:-1]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.24, 2.23, 2.22])\n\n            x = d[-3:]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.26, 3.333, Unknown])\n\n    def test_assign_slice_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            with d.unlocked():\n                d[2:5, 0] = 42\n            self.assertEqual([e[0] for e in d],\n                             [0, 1.1, 42, 42, 42, 2.25, 2.26, 3.333, Unknown])\n            with d.unlocked():\n                d[:3, \"b\"] = 43\n            self.assertEqual([e[0] for e in d],\n                             [43, 43, 43, 42, 42, 2.25, 2.26, 3.333, None])\n            with d.unlocked():\n                d[-2:, d.domain[0]] = 44\n            self.assertEqual([e[0] for e in d],\n                             [43, 43, 43, 42, 42, 2.25, 2.26, 44, 44])\n\n            with d.unlocked():\n                d[2:5, \"a\"] = \"A\"\n            self.assertEqual([e[\"a\"] for e in d], list(\"ABAAACCDE\"))\n\n    def test_multiple_indices(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            with self.assertRaises(IndexError):\n                x = d[2, 5, 1]\n\n            with self.assertRaises(IndexError):\n                x = d[(2, 5, 1)]\n\n            x = d[[2, 5, 1]]\n            self.assertEqual([e[0] for e in x], [2.22, 2.25, 1.1])\n\n    def test_assign_multiple_indices_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            with d.unlocked():\n                d[1:4, \"b\"] = 42\n            self.assertEqual([e[0] for e in d],\n                             [0, 42, 42, 42, 2.24, 2.25, 2.26, 3.333, None])\n\n            with d.unlocked():\n                d[range(5, 2, -1), \"b\"] = None\n            self.assertEqual([e[d.domain[0]] for e in d],\n                             [0, 42, 42, None, \"?\", \"\", 2.26, 3.333, None])\n\n    def test_set_multiple_indices_example(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            vals = [e[0] for e in d]\n            with d.unlocked():\n                d[[1, 2, 5]] = [42, None, None]\n            vals[1] = vals[2] = vals[5] = 42\n            self.assertEqual([e[0] for e in d], vals)\n\n    def test_bool(self):\n        d = data.Table(\"iris\")\n        self.assertTrue(d)\n\n        d = data.Table(\"datasets/test3\")\n        self.assertFalse(d)\n\n        d = data.Table(\"iris\")\n        self.assertTrue(d)\n\n    def test_checksum(self):\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d[42, 3] = 0\n        crc1 = d.checksum(False)\n\n        with d.unlocked():\n            d[42, 3] = 1\n        crc2 = d.checksum(False)\n        self.assertNotEqual(crc1, crc2)\n\n        with d.unlocked():\n            d[42, 3] = 0\n        crc3 = d.checksum(False)\n        self.assertEqual(crc1, crc3)\n\n        _ = d[42, \"name\"]\n        with d.unlocked():\n            d[42, \"name\"] = \"non-animal\"\n        crc4 = d.checksum(False)\n        self.assertEqual(crc1, crc4)\n        crc4 = d.checksum(True)\n        crc5 = d.checksum(1)\n        crc6 = d.checksum(False)\n        self.assertNotEqual(crc1, crc4)\n        self.assertNotEqual(crc1, crc5)\n        self.assertEqual(crc1, crc6)\n\n    def test_total_weight(self):\n        d = data.Table(\"zoo\")\n        self.assertEqual(d.total_weight(), len(d))\n\n        with d.unlocked():\n            d.set_weights(0)\n            d[0].weight = 0.1\n            d[10].weight = 0.2\n            d[-1].weight = 0.3\n        self.assertAlmostEqual(d.total_weight(), 0.6)\n\n    def test_has_missing(self):\n        d = data.Table(\"zoo\")\n        self.assertFalse(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n        with d.unlocked():\n            d[10, 3] = \"?\"\n        self.assertTrue(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n        with d.unlocked():\n            d[10].set_class(\"?\")\n        self.assertTrue(d.has_missing())\n        self.assertTrue(d.has_missing_class())\n\n        with d.unlocked():\n            d = data.Table(\"datasets/test3\")\n        self.assertFalse(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n    def test_shuffle(self):\n        d = data.Table(\"zoo\")\n        crc = d.checksum()\n        names = set(str(x[\"name\"]) for x in d)\n\n        with d.unlocked():\n            d.shuffle()\n        self.assertNotEqual(crc, d.checksum())\n        self.assertSetEqual(names, set(str(x[\"name\"]) for x in d))\n        crc2 = d.checksum()\n\n        x = d[2:10]\n        crcx = x.checksum()\n        with d.unlocked():\n            d.shuffle()\n        self.assertNotEqual(crc2, d.checksum())\n        self.assertEqual(crcx, x.checksum())\n\n        crc2 = d.checksum()\n        with x.unlocked():\n            x.shuffle()\n        self.assertNotEqual(crcx, x.checksum())\n        self.assertEqual(crc2, d.checksum())\n\n    @staticmethod\n    def not_less_ex(ex1, ex2):\n        for v1, v2 in zip(ex1, ex2):\n            if v1 != v2:\n                return v1 < v2\n        return True\n\n    @staticmethod\n    def sorted(d):\n        for i in range(1, len(d)):\n            if not TableTestCase.not_less_ex(d[i - 1], d[i]):\n                return False\n        return True\n\n    @staticmethod\n    def not_less_ex_ord(ex1, ex2, ord):\n        for a in ord:\n            if ex1[a] != ex2[a]:\n                return ex1[a] < ex2[a]\n        return True\n\n    @staticmethod\n    def sorted_ord(d, ord):\n        for i in range(1, len(d)):\n            if not TableTestCase.not_less_ex_ord(d[i - 1], d[i], ord):\n                return False\n        return True\n\n    def test_copy(self):\n        t = data.Table.from_numpy(\n            None, np.zeros((5, 3)), np.arange(5), np.zeros((5, 3)))\n\n        copy = t.copy()\n        self.assertTrue(np.all(t.X == copy.X))\n        self.assertTrue(np.all(t.Y == copy.Y))\n        self.assertTrue(np.all(t.metas == copy.metas))\n        with copy.unlocked():\n            copy[0] = [1, 1, 1, 1]\n        self.assertFalse(np.all(t.X == copy.X))\n        self.assertFalse(np.all(t.Y == copy.Y))\n        self.assertFalse(np.all(t.metas == copy.metas))\n\n    def test_copy_sparse(self):\n        t = data.Table('iris').to_sparse()\n        copy = t.copy()\n\n        self.assertEqual((t.X != copy.X).nnz, 0)      # sparse matrices match by content\n        np.testing.assert_equal(t.Y, copy.Y)\n        np.testing.assert_equal(t.metas, copy.metas)\n\n        self.assertNotEqual(id(t.X), id(copy.X))\n        self.assertNotEqual(id(t._Y), id(copy._Y))\n        self.assertNotEqual(id(t.metas), id(copy.metas))\n\n        # ensure that copied sparse arrays do not share data\n        with t.unlocked():\n            t.X[0, 0] = 42\n        self.assertEqual(copy.X[0, 0], 5.1)\n\n    def test_concatenate(self):\n        d1 = data.Domain(\n            [data.ContinuousVariable(n) for n in \"abc\"],\n            data.DiscreteVariable(\"y\", values=\"ABC\"),\n            [data.StringVariable(n) for n in [\"m1\", \"m2\"]],\n        )\n        x1 = np.arange(6).reshape(2, 3)\n        y1 = np.array([0, 1])\n        m1 = np.array([[\"foo\", \"bar\"], [\"baz\", \"qux\"]])\n        w1 = np.random.random((2,))\n        t1 = data.Table.from_numpy(d1, x1, y1, m1, w1)\n        t1.ids = ids1 = np.array([100, 101])\n        t1.attributes = {\"a\": 42, \"c\": 43}\n\n        x2 = np.arange(6, 15).reshape(3, 3)\n        y2 = np.array([1, 2, 0])\n        m2 = np.array([[\"a\", \"b\"], [\"c\", \"d\"], [\"e\", \"f\"]])\n        w2 = np.random.random((3,))\n        t2 = data.Table.from_numpy(d1, x2, y2, m2, w2)\n        t2.ids = ids2 = np.array([102, 103, 104])\n        t2.name = \"t2\"\n        t2.attributes = {\"a\": 44, \"b\": 45}\n\n        x3 = np.arange(15, 27).reshape(4, 3)\n        y3 = np.array([2, 1, 1, 0])\n        m3 = np.array([[\"g\", \"h\"], [\"i\", \"j\"], [\"k\", \"l\"], [\"m\", \"n\"]])\n        w3 = np.random.random((4,))\n        t3 = data.Table.from_numpy(d1, x3, y3, m3, w3)\n        t3.ids = ids3 = np.array([102, 103, 104, 105])\n        t3.name = \"t3\"\n\n        t1b = data.Table.concatenate((t1,))\n        self.assertEqual(t1b.domain, t1.domain)\n        np.testing.assert_almost_equal(t1b.X, x1)\n        np.testing.assert_almost_equal(t1b.Y, y1)\n        self.assertEqual(list(t1b.metas.flatten()),\n                         list(m1.flatten()))\n        np.testing.assert_almost_equal(t1b.W, w1)\n        np.testing.assert_almost_equal(t1b.ids, ids1)\n        self.assertEqual(t1b.name, t1.name)\n        self.assertEqual(t1b.attributes, {\"a\": 42, \"c\": 43})\n\n        t12 = data.Table.concatenate((t1, t2))\n        self.assertEqual(t12.domain, t1.domain)\n        np.testing.assert_almost_equal(t12.X, np.vstack((x1, x2)))\n        np.testing.assert_almost_equal(t12.Y, np.hstack((y1, y2)))\n        self.assertEqual(list(t12.metas.flatten()),\n                         list(np.vstack((m1, m2)).flatten()))\n        np.testing.assert_almost_equal(t12.W, np.hstack((w1, w2)))\n        np.testing.assert_almost_equal(t12.ids, np.hstack((ids1, ids2)))\n        self.assertEqual(t12.name, \"t2\")\n        self.assertEqual(t12.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n        t123 = data.Table.concatenate((t1, t2, t3))\n        self.assertEqual(t123.domain, t1.domain)\n        np.testing.assert_almost_equal(t123.X, np.vstack((x1, x2, x3)))\n        np.testing.assert_almost_equal(t123.Y, np.hstack((y1, y2, y3)))\n        self.assertEqual(list(t123.metas.flatten()),\n                         list(np.vstack((m1, m2, m3)).flatten()))\n        np.testing.assert_almost_equal(t123.W, np.hstack((w1, w2, w3)))\n        np.testing.assert_almost_equal(t123.ids, np.hstack((ids1, ids2, ids3)))\n        self.assertEqual(t123.name, \"t2\")\n        self.assertEqual(t123.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n        with t2.unlocked(t2.Y):\n            t2.Y = np.atleast_2d(t2.Y).T\n        t12 = data.Table.concatenate((t1, t2))\n        self.assertEqual(t12.domain, t1.domain)\n        np.testing.assert_almost_equal(t12.X, np.vstack((x1, x2)))\n        np.testing.assert_almost_equal(t12.Y, np.hstack((y1, y2)))\n        self.assertEqual(list(t12.metas.flatten()),\n                         list(np.vstack((m1, m2)).flatten()))\n        np.testing.assert_almost_equal(t12.W, np.hstack((w1, w2)))\n        np.testing.assert_almost_equal(t12.ids, np.hstack((ids1, ids2)))\n        self.assertEqual(t12.name, \"t2\")\n        self.assertEqual(t12.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n    def test_concatenate_exceptions(self):\n        zoo = data.Table(\"zoo\")\n        iris = data.Table(\"iris\")\n\n        self.assertRaises(ValueError, data.Table.concatenate, [])\n        self.assertRaises(ValueError, data.Table.concatenate, [zoo, iris])\n\n    def test_concatenate_sparse(self):\n        iris = Table(\"iris\")\n        with iris.unlocked():\n            iris.X = sp.csc_matrix(iris.X)\n        new = Table.concatenate([iris, iris])\n        self.assertEqual(len(new), 300)\n        self.assertTrue(sp.issparse(new.X), \"Concatenated X is not sparse.\")\n        self.assertFalse(sp.issparse(new.Y), \"Concatenated Y is not dense.\")\n        self.assertFalse(sp.issparse(new.metas), \"Concatenated metas is not dense.\")\n        self.assertEqual(len(new.ids), 300)\n\n    def test_pickle(self):\n        d = data.Table(\"zoo\")\n        s = pickle.dumps(d)\n        d2 = pickle.loads(s)\n        self.assertEqual(d[0], d2[0])\n\n        self.assertEqual(d.checksum(include_metas=False),\n                         d2.checksum(include_metas=False))\n\n        d = data.Table(\"iris\")\n        s = pickle.dumps(d)\n        d2 = pickle.loads(s)\n        self.assertEqual(d[0], d2[0])\n        self.assertEqual(d.checksum(include_metas=False),\n                         d2.checksum(include_metas=False))\n\n    def test_pickle_setstate(self):\n        d = data.Table(\"zoo\")\n        s = pickle.dumps(d)\n        with patch(\"Orange.data.Table.__setstate__\", Mock()) as mock:\n            pickle.loads(s)\n            state = mock.call_args[0][0]\n            for k in [\"X\", \"_Y\", \"metas\"]:\n                self.assertIn(k, state)\n                self.assertEqual(state[k].ndim, 2)\n            self.assertIn(\"W\", state)\n            for k in [\"_X\", \"Y\", \"_metas\", \"_W\"]:\n                self.assertNotIn(k, state)\n\n\n    def test_translate_through_slice(self):\n        d = data.Table(\"iris\")\n        dom = data.Domain([\"petal length\", \"sepal length\", \"iris\"],\n                          source=d.domain)\n        d_ref = d[:10, dom.variables]\n        self.assertEqual(d_ref.domain.class_var, d.domain.class_var)\n        self.assertEqual(d_ref[0, \"petal length\"], d[0, \"petal length\"])\n        self.assertEqual(d_ref[0, \"sepal length\"], d[0, \"sepal length\"])\n        self.assertEqual(d_ref.X.shape, (10, 2))\n        self.assertEqual(d_ref.Y.shape, (10,))\n\n    def test_saveTab(self):\n        d = data.Table(\"iris\")[:3]\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            for e1, e2 in zip(d, d2):\n                self.assertEqual(e1, e2)\n        finally:\n            os.remove(\"test-save.tab\")\n            os.remove(\"test-save.tab.metadata\")\n\n        dom = data.Domain([data.ContinuousVariable(\"a\")])\n        d = data.Table.from_list(dom, [[i] for i in range(3)])\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            self.assertEqual(len(d.domain.attributes), 1)\n            self.assertEqual(d.domain.class_var, None)\n            for i in range(3):\n                self.assertEqual(d2[i], [i])\n        finally:\n            os.remove(\"test-save.tab\")\n\n        dom = data.Domain([data.ContinuousVariable(\"a\")], None)\n        d = data.Table.from_list(dom, [[i] for i in range(3)])\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            self.assertEqual(len(d.domain.attributes), 1)\n            for i in range(3):\n                self.assertEqual(d2[i], [i])\n        finally:\n            os.remove(\"test-save.tab\")\n\n        d = data.Table(\"zoo\")\n        d.save(\"test-zoo.tab\")\n        dd = data.Table(\"test-zoo\")\n        try:\n            self.assertTupleEqual(d.domain.metas, dd.domain.metas,\n                                  msg=\"Meta attributes don't match.\")\n            self.assertTupleEqual(d.domain.variables, dd.domain.variables,\n                                  msg=\"Attributes don't match.\")\n\n            np.testing.assert_almost_equal(d.W, dd.W,\n                                           err_msg=\"Weights don't match.\")\n            for i in range(10):\n                for j in d.domain.variables:\n                    self.assertEqual(d[i][j], dd[i][j])\n        finally:\n            os.remove(\"test-zoo.tab\")\n            os.remove(\"test-zoo.tab.metadata\")\n\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d.set_weights(range(len(d)))\n        d.save(\"test-zoo-weights.tab\")\n        dd = data.Table(\"test-zoo-weights\")\n        try:\n            self.assertTupleEqual(d.domain.metas, dd.domain.metas,\n                                  msg=\"Meta attributes don't match.\")\n            self.assertTupleEqual(d.domain.variables, dd.domain.variables,\n                                  msg=\"Attributes don't match.\")\n\n            np.testing.assert_almost_equal(d.W, dd.W,\n                                           err_msg=\"Weights don't match.\")\n            for i in range(10):\n                for j in d.domain.variables:\n                    self.assertEqual(d[i][j], dd[i][j])\n        finally:\n            os.remove(\"test-zoo-weights.tab\")\n            os.remove(\"test-zoo-weights.tab.metadata\")\n\n    def test_save_pickle(self):\n        table = data.Table(\"iris\")\n        try:\n            table.save(\"iris.pickle\")\n            table2 = data.Table.from_file(\"iris.pickle\")\n            np.testing.assert_almost_equal(table.X, table2.X)\n            np.testing.assert_almost_equal(table.Y, table2.Y)\n            self.assertEqual(table.domain[0], table2.domain[0])\n        finally:\n            os.remove(\"iris.pickle\")\n\n    def test_from_numpy(self):\n        a = np.arange(20, dtype=\"d\").reshape((4, 5)).copy()\n        a[:, -1] = [0, 0, 0, 1]\n        dom = data.Domain([data.ContinuousVariable(x) for x in \"abcd\"],\n                          data.DiscreteVariable(\"e\", values=(\"no\", \"yes\")))\n        table = data.Table(dom, a)\n        with table.unlocked():\n            for i in range(4):\n                self.assertEqual(table[i].get_class(), \"no\" if i < 3 else \"yes\")\n                for j in range(5):\n                    self.assertEqual(a[i, j], table[i, j])\n\n        with table.unlocked(), self.assertRaises(IndexError):\n            table[0, -5] = 5\n\n    def test_filter_is_defined(self):\n        d = data.Table(\"iris\")\n        with d.unlocked():\n            d[1, 4] = Unknown\n        self.assertTrue(isnan(d[1, 4]))\n        with d.unlocked():\n            d[140, 0] = Unknown\n        e = filter.IsDefined()(d)\n        self.assertEqual(len(e), len(d) - 2)\n        self.assertEqual(e[0], d[0])\n        self.assertEqual(e[1], d[2])\n        self.assertEqual(e[147], d[149])\n        self.assertTrue(d.has_missing())\n        self.assertFalse(e.has_missing())\n\n    def test_filter_has_class(self):\n        d = data.Table(\"iris\")\n        with d.unlocked():\n            d[1, 4] = Unknown\n        self.assertTrue(isnan(d[1, 4]))\n        with d.unlocked():\n            d[140, 0] = Unknown\n        e = filter.HasClass()(d)\n        self.assertEqual(len(e), len(d) - 1)\n        self.assertEqual(e[0], d[0])\n        self.assertEqual(e[1], d[2])\n        self.assertEqual(e[148], d[149])\n        self.assertTrue(d.has_missing())\n        self.assertTrue(e.has_missing())\n        self.assertFalse(e.has_missing_class())\n\n    def test_filter_random(self):\n        d = data.Table(\"iris\")\n        e = filter.Random(50)(d)\n        self.assertEqual(len(e), 50)\n        e = filter.Random(50, negate=True)(d)\n        self.assertEqual(len(e), 100)\n        for _ in range(5):\n            e = filter.Random(0.2)(d)\n            self.assertEqual(len(e), 30)\n            bc = np.bincount(np.array(e.Y[:], dtype=int))\n            if min(bc) > 7:\n                break\n        else:\n            self.fail(\"Filter returns too uneven distributions\")\n\n    def test_filter_values_nested(self):\n        d = data.Table(\"iris\")\n        f1 = filter.FilterContinuous(d.columns.sepal_length,\n                                     filter.FilterContinuous.Between,\n                                     min=4.5, max=5.0)\n        f2 = filter.FilterContinuous(d.columns.sepal_width,\n                                     filter.FilterContinuous.Between,\n                                     min=3.1, max=3.4)\n        f3 = filter.FilterDiscrete(d.columns.iris, [0, 1])\n        f = filter.Values([filter.Values([f1, f2], conjunction=False), f3])\n        self.assertEqual(41, len(f(d)))\n\n    def test_filter_string_works_for_numeric_columns(self):\n        var = StringVariable(\"s\")\n        data = Table.from_list(Domain([], metas=[var]),\n                               [[x] for x in range(21)])\n        # 1, 2, 3, ..., 18, 19, 20\n\n        fs = filter.FilterString\n        filters = [\n            ((fs.Greater, \"5\"), dict(rows=4)),\n            # 6, 7, 8, 9\n            ((fs.Between, \"15\", \"2\"), dict(rows=6)),\n            # 15, 16, 17, 18, 19, 2\n            ((fs.Contains, \"2\"), dict(rows=3)),\n            # 2, 12, 20\n        ]\n\n        for args, expected in filters:\n            f = fs(var, *args)\n            filtered_data = filter.Values([f])(data)\n            self.assertEqual(len(filtered_data), expected[\"rows\"],\n                             \"{} returned wrong number of rows\".format(args))\n\n    def test_filter_value_continuous(self):\n        d = data.Table(\"iris\")\n        col = d.X[:, 2]\n\n        v = d.columns\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Between,\n                                    min=4.5, max=5.1)\n\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] >= 4.5))\n        self.assertTrue(np.all(x.X[:, 2] <= 5.1))\n        self.assertEqual(sum((col >= 4.5) * (col <= 5.1)), len(x))\n\n        f.ref = 5.1\n        f.oper = filter.FilterContinuous.Equal\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.NotEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] != 5.1))\n        self.assertEqual(sum(col != 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Less\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] < 5.1))\n        self.assertEqual(sum(col < 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.LessEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] <= 5.1))\n        self.assertEqual(sum(col <= 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Greater\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] > 5.1))\n        self.assertEqual(sum(col > 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] >= 5.1))\n        self.assertEqual(sum(col >= 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Outside\n        f.ref, f.max = 4.5, 5.1\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(e[2] < 4.5 or e[2] > 5.1)\n        self.assertEqual(sum((col < 4.5) + (col > 5.1)), len(x))\n\n        f.oper = filter.FilterContinuous.IsDefined\n        f.ref = f.max = None\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d))\n\n        with d.unlocked():\n            d[:30, v.petal_length] = Unknown\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 30)\n\n    def test_filter_value_continuous_args(self):\n        d = data.Table(\"iris\")\n        col = d.X[:, 2]\n        v = d.columns\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(2,\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"petal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"sepal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        f.column = 2\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"sepal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        f.column = v.petal_length\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=18)\n        f.ref = 5.1\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=18)\n        f.ref = 5.1\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n    def test_valueFilter_discrete(self):\n        d = data.Table(\"zoo\")\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, 3, 4])\n        for e in filter.Values([f])(d):\n            self.assertTrue(e.get_class() in [2, 3, 4])\n\n        f.values = [\"mammal\"]\n        for e in filter.Values([f])(d):\n            self.assertEqual(e.get_class(), \"mammal\")\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, \"mammal\"])\n        for e in filter.Values([f])(d):\n            self.assertTrue(e.get_class() in [2, \"mammal\"])\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, \"martian\"])\n        self.assertRaises(ValueError, d._filter_values, f)\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=(2, data.Table))\n        self.assertRaises(TypeError, d._filter_values, f)\n\n        v = d.columns\n        f = filter.FilterDiscrete(v.hair, values=None)\n        self.assertEqual(len(filter.Values([f])(d)), len(d))\n\n        with d.unlocked():\n            d[:5, v.hair] = Unknown\n        self.assertEqual(len(filter.Values([f])(d)), len(d) - 5)\n\n    def test_valueFilter_string_is_defined(self):\n        d = data.Table(\"datasets/test9.tab\")\n        f = filter.FilterString(-5, filter.FilterString.IsDefined)\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 7)\n\n    def test_valueFilter_discrete_meta_is_defined(self):\n        d = data.Table(\"datasets/test9.tab\")\n        f = filter.FilterDiscrete(-4, None)\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 8)\n\n    def test_valueFilter_string_case_sens(self):\n        d = data.Table(\"zoo\")\n        col = d[:, \"name\"].metas[:, 0]\n\n        f = filter.FilterString(\"name\",\n                                filter.FilterString.Equal, \"girl\")\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 1)\n        self.assertEqual(x[0, \"name\"], \"girl\")\n        self.assertTrue(np.all(x.metas == \"girl\"))\n\n        f.oper = f.NotEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 1)\n        self.assertTrue(np.all(x[:, \"name\"] != \"girl\"))\n\n        f.oper = f.Less\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"girl\"))\n        self.assertTrue(np.all(x.metas < \"girl\"))\n\n        f.oper = f.LessEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col <= \"girl\"))\n        self.assertTrue(np.all(x.metas <= \"girl\"))\n\n        f.oper = f.Greater\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col > \"girl\"))\n        self.assertTrue(np.all(x.metas > \"girl\"))\n\n        f.oper = f.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col >= \"girl\"))\n        self.assertTrue(np.all(x.metas >= \"girl\"))\n\n        f.oper = f.Between\n        f.max = \"lion\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum((col >= \"girl\") * (col <= \"lion\")))\n        self.assertTrue(np.all(x.metas >= \"girl\"))\n        self.assertTrue(np.all(x.metas <= \"lion\"))\n\n        f.oper = f.Outside\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"girl\") + sum(col > \"lion\"))\n        self.assertTrue(np.all((x.metas < \"girl\") + (x.metas > \"lion\")))\n\n        f.oper = f.Contains\n        f.ref = \"ea\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(\"ea\" in e[\"name\"])\n        self.assertEqual(len(x), len([e for e in col if \"ea\" in e]))\n\n        f.oper = f.StartsWith\n        f.ref = \"sea\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).startswith(\"sea\"))\n        self.assertEqual(len(x), len([e for e in col if e.startswith(\"sea\")]))\n\n        f.oper = f.EndsWith\n        f.ref = \"ion\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n        self.assertEqual(len(x), len([e for e in col if e.endswith(\"ion\")]))\n\n    def test_valueFilter_string_case_insens(self):\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d[d[:, \"name\"].metas[:, 0] == \"girl\", \"name\"] = \"GIrl\"\n\n        col = d[:, \"name\"].metas[:, 0]\n\n        f = filter.FilterString(\"name\",\n                                filter.FilterString.Equal, \"giRL\")\n        f.case_sensitive = False\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 1)\n        self.assertEqual(x[0, \"name\"], \"GIrl\")\n        self.assertTrue(np.all(x.metas == \"GIrl\"))\n\n        f.oper = f.NotEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 1)\n        self.assertTrue(np.all(x[:, \"name\"] != \"GIrl\"))\n\n        f.oper = f.Less\n        f.ref = \"CHiCKEN\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"chicken\") - 1)  # girl!\n        self.assertTrue(np.all(x.metas < \"chicken\"))\n\n        f.oper = f.LessEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col <= \"chicken\") - 1)\n        self.assertTrue(np.all(x.metas <= \"chicken\"))\n\n        f.oper = f.Greater\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col > \"chicken\") + 1)\n        for e in x:\n            self.assertGreater(str(e[\"name\"]).lower(), \"chicken\")\n\n        f.oper = f.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col >= \"chicken\") + 1)\n        for e in x:\n            self.assertGreaterEqual(str(e[\"name\"]).lower(), \"chicken\")\n\n        f.oper = f.Between\n        f.max = \"liOn\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum((col >= \"chicken\") * (col <= \"lion\")) + 1)\n        for e in x:\n            self.assertTrue(\"chicken\" <= str(e[\"name\"]).lower() <= \"lion\")\n\n        f.oper = f.Outside\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"chicken\") + sum(col > \"lion\") - 1)\n        self.assertTrue(np.all((x.metas < \"chicken\") + (x.metas > \"lion\")))\n\n        f.oper = f.Contains\n        f.ref = \"iR\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(\"ir\" in str(e[\"name\"]).lower())\n        self.assertEqual(len(x), len([e for e in col if \"ir\" in e]) + 1)\n\n        f.oper = f.StartsWith\n        f.ref = \"GI\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).lower().startswith(\"gi\"))\n        self.assertEqual(len(x),\n                         len([e for e in col if e.lower().startswith(\"gi\")]))\n\n        f.oper = f.EndsWith\n        f.ref = \"ion\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n        self.assertEqual(len(x), len([e for e in col if e.endswith(\"ion\")]))\n\n    def test_valueFilter_regex(self):\n        d = data.Table(\"zoo\")\n        f = filter.FilterRegex(d.domain['name'], '^c...$')\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 7)\n\n    def test_valueFilter_stringList(self):\n        data = Table(\"zoo\")\n        var = data.domain[\"name\"]\n\n        fs = filter.FilterStringList\n        filters = [\n            (([\"swan\", \"tuna\", \"wasp\"], True), dict(rows=3)),\n            (([\"swan\", \"tuna\", \"wasp\"], False), dict(rows=3)),\n            (([\"WoRm\", \"TOad\", \"vOLe\"], True), dict(rows=0)),\n            (([\"WoRm\", \"TOad\", \"vOLe\"], False), dict(rows=3)),\n        ]\n\n        for args, expected in filters:\n            f = fs(var, *args)\n            filtered_data = filter.Values([f])(data)\n            self.assertEqual(len(filtered_data), expected[\"rows\"],\n                             \"{} returned wrong number of rows\".format(args))\n\n    def test_table_dtypes(self):\n        table = data.Table(\"iris\")\n        metas = np.hstack((table.metas, table.Y.reshape(len(table), 1)))\n        attributes_metas = table.domain.metas + table.domain.class_vars\n        domain_metas = data.Domain(table.domain.attributes[:2],\n                                   table.domain.attributes[2:],\n                                   attributes_metas)\n        table_metas = data.Table(domain_metas, table.X[:, : 2], table.X[:, 2:],\n                                 metas)\n        new_table = data.Table.from_table(data.Domain(table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.X.dtype, np.float64)\n        new_table = data.Table.from_table(data.Domain((), table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.Y.dtype, np.float64)\n        new_table = data.Table.from_table(data.Domain((), (), table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.metas.dtype, np.float64)\n\n    def test_attributes(self):\n        table = data.Table(\"iris\")\n        table.attributes = {1: \"test\"}\n        table2 = table[:4]\n        self.assertEqual(table2.attributes[1], \"test\")\n        table2.attributes[1] = \"modified\"\n        self.assertEqual(table.attributes[1], \"modified\")\n\n    # TODO Test conjunctions and disjunctions of conditions\n\n    def test_is_sparse(self):\n        table = data.Table(\"iris\")\n        self.assertFalse(table.is_sparse())\n\n        with table.unlocked():\n            table.X = sp.csr_matrix(table.X)\n            self.assertTrue(table.is_sparse())\n\n    def test_repr_sparse_with_one_row(self):\n        table = data.Table(\"iris\")[:1]\n        with table.unlocked():\n            table.X = sp.csr_matrix(table.X)\n        repr(table)     # make sure repr does not crash\n\n    def test_inf(self):\n        a = np.array([[2, 0, 0, 0],\n                      [0, np.nan, np.nan, 1],\n                      [0, 0, np.inf, 0]])\n        with self.assertWarns(Warning):\n            tab = data.Table.from_numpy(None, a)\n        self.assertEqual(tab.get_nan_frequency_attribute(), 3/12)\n\n\ndef column_sizes(table):\n    return (len(table.domain.attributes),\n            len(table.domain.class_vars),\n            len(table.domain.metas))\n\n\nclass TableTests(unittest.TestCase):\n    attributes = [\"Feature %i\" % i for i in range(10)]\n    class_vars = [\"Class %i\" % i for i in range(1)]\n    metas = [\"Meta %i\" % i for i in range(5)]\n    nrows = 10\n    row_indices = (1, 5, 7, 9)\n\n    def setUp(self):\n        self.data = np.random.random((self.nrows, len(self.attributes)))\n        self.class_data = np.random.random((self.nrows, len(self.class_vars)))\n        if len(self.class_vars) == 1:\n            self.class_data = self.class_data.flatten()\n        self.meta_data = np.random.randint(0, 5, (self.nrows, len(self.metas))\n                                          ).astype(object)\n        self.weight_data = np.random.random((self.nrows, 1))\n\n    def mock_domain(self, with_classes=False, with_metas=False):\n        attributes = self.attributes\n        class_var = self.class_vars[0] if with_classes else None\n        class_vars = self.class_vars if with_classes else []\n        metas = self.metas if with_metas else []\n        variables = attributes + class_vars\n        return MagicMock(data.Domain,\n                         attributes=attributes,\n                         class_var=class_var,\n                         class_vars=class_vars,\n                         metas=metas,\n                         variables=variables)\n\n    def create_domain(self, attributes=(), classes=(), metas=()):\n        attr_vars = [data.ContinuousVariable(name=a) if isinstance(a, str)\n                     else a for a in attributes]\n        class_vars = [data.ContinuousVariable(name=c) if isinstance(c, str)\n                      else c for c in classes]\n        meta_vars = [data.DiscreteVariable(name=m, values=map(str, range(5)))\n                     if isinstance(m, str) else m for m in metas]\n\n        domain = data.Domain(attr_vars, class_vars, meta_vars)\n        return domain\n\n\nclass CreateEmptyTable(TableTests):\n    def test_calling_new_with_no_parameters_constructs_a_new_instance(self):\n        table = data.Table()\n        self.assertIsInstance(table, data.Table)\n\n    def test_table_has_file(self):\n        table = data.Table()\n        self.assertIsNone(table.__file__)\n\n\nclass CreateTableWithFilename(TableTests):\n    filename = \"data.tab\"\n\n    @patch(\"os.path.exists\", Mock(return_value=True))\n    def test_read_data_calls_reader(self):\n        table_mock = Mock(data.Table)\n        reader_instance = Mock(read=Mock(return_value=table_mock))\n        reader_mock = Mock(return_value=reader_instance)\n\n        with patch.dict(data.io.FileFormat.readers,\n                        {'.xlsx': reader_mock}):\n            table = data.Table.from_file(\"test.xlsx\")\n\n        reader_mock.assert_called_with(\"test.xlsx\")\n        reader_instance.read.assert_called_with()\n        self.assertEqual(table, table_mock)\n\n    @patch(\"os.path.exists\", Mock(return_value=False))\n    def test_raises_error_if_file_does_not_exist(self):\n        with self.assertRaises(IOError):\n            data.Table.from_file(self.filename)\n\n    @patch(\"os.path.exists\", Mock(return_value=True))\n    def test_raises_error_if_file_has_unknown_extension(self):\n        with self.assertRaises(IOError):\n            data.Table.from_file(\"file.invalid_extension\")\n\n    @patch(\"Orange.data.table.Table.from_file\")\n    def test_calling_new_with_string_argument_calls_read_data(self, read_data):\n        data.Table(self.filename)\n\n        read_data.assert_called_with(self.filename)\n\n    @patch(\"Orange.data.table.Table.from_file\")\n    def test_calling_new_with_keyword_argument_filename_calls_read_data(\n            self, read_data):\n        data.Table(self.filename)\n        read_data.assert_called_with(self.filename)\n\n\nclass CreateTableWithUrl(TableTests):\n    def test_url_no_scheme(self):\n\n        class SkipRest(Exception):\n            pass\n\n        mock_urlopen = Mock(side_effect=SkipRest())\n        url = 'www.foo.bar/xx.csv'\n\n        with patch('Orange.data.io.UrlReader.urlopen', mock_urlopen):\n            try:\n                Table.from_url(url)\n            except SkipRest:\n                pass\n\n        mock_urlopen.assert_called_once_with('http://' + url)\n\n    class _MockUrlOpen(MagicMock):\n        headers = {'content-disposition': 'attachment; filename=\"Something-FormResponses.tsv\"; '\n                                          'filename*=UTF-8''Something%20%28Responses%29.tsv'}\n        def __enter__(self):\n            return self\n\n        def __exit__(self, *args, **kwargs):\n            pass\n\n        def read(self):\n            return b'''\\\na\\tb\\tc\n1\\t2\\t3\n2\\t3\\t4'''\n\n    urlopen = _MockUrlOpen()\n\n    @patch('Orange.data.io.urlopen', urlopen)\n    def test_trimmed_urls(self):\n        for url in ('https://docs.google.com/spreadsheets/d/ABCD/edit',\n                    'https://www.dropbox.com/s/ABCD/filename.csv'):\n            self._MockUrlOpen.url = url\n            d = data.Table(url)\n            request = self.urlopen.call_args[0][0]\n            self.assertNotEqual(url, request.full_url)\n            self.assertIn('Mozilla/5.0', request.headers.get('User-agent', ''))\n            self.assertEqual(len(d), 2)\n            self.assertEqual(d.name, 'Something-FormResponses')\n\n\nclass CreateTableWithDomain(TableTests):\n    def test_creates_an_empty_table_with_given_domain(self):\n        domain = self.mock_domain()\n        table = data.Table.from_domain(domain)\n\n        self.assertEqual(table.domain, domain)\n\n    def test_creates_zero_filled_rows_in_X_if_domain_contains_attributes(self):\n        domain = self.mock_domain()\n        table = data.Table.from_domain(domain, self.nrows)\n\n        self.assertEqual(table.X.shape, (self.nrows, len(domain.attributes)))\n        self.assertFalse(table.X.any())\n\n    def test_creates_zero_filled_rows_in_Y_if_domain_contains_class_vars(self):\n        domain = self.mock_domain(with_classes=True)\n        table = data.Table.from_domain(domain, self.nrows)\n\n        if len(domain.class_vars) != 1:\n            self.assertEqual(table.Y.shape,\n                             (self.nrows, len(domain.class_vars)))\n        else:\n            self.assertEqual(table.Y.shape, (self.nrows,))\n        self.assertFalse(table.Y.any())\n\n    def test_creates_zero_filled_rows_in_metas_if_domain_contains_metas(self):\n        domain = self.mock_domain(with_metas=True)\n        table = data.Table.from_domain(domain, self.nrows)\n\n        self.assertEqual(table.metas.shape, (self.nrows, len(domain.metas)))\n        self.assertFalse(table.metas.any())\n\n    def test_creates_weights_if_weights_are_true(self):\n        domain = self.mock_domain()\n        table = data.Table.from_domain(domain, self.nrows, True)\n\n        self.assertEqual(table.W.shape, (self.nrows, ))\n\n    def test_does_not_create_weights_if_weights_are_false(self):\n        domain = self.mock_domain()\n        table = data.Table.from_domain(domain, self.nrows, False)\n\n        self.assertEqual(table.W.shape, (self.nrows, 0))\n\n    @patch(\"Orange.data.table.Table.from_domain\")\n    def test_calling_new_with_domain_calls_new_from_domain(\n            self, new_from_domain):\n        domain = self.mock_domain()\n        data.Table.from_domain(domain)\n\n        new_from_domain.assert_called_with(domain)\n\n\nclass CreateTableWithData(TableTests):\n    def test_creates_a_table_with_given_X(self):\n        # from numpy\n        table = data.Table.from_numpy(None, np.array(self.data))\n        self.assertIsInstance(table.domain, data.Domain)\n        np.testing.assert_almost_equal(table.X, self.data)\n\n        # from list\n        table = data.Table.from_numpy(None, list(self.data))\n        self.assertIsInstance(table.domain, data.Domain)\n        np.testing.assert_almost_equal(table.X, self.data)\n\n        # from tuple\n        table = data.Table.from_numpy(None, tuple(self.data))\n        self.assertIsInstance(table.domain, data.Domain)\n        np.testing.assert_almost_equal(table.X, self.data)\n\n    def test_creates_a_table_from_domain_and_list(self):\n        domain = data.Domain([data.DiscreteVariable(name=\"a\", values=\"mf\"),\n                              data.ContinuousVariable(name=\"b\")],\n                             data.DiscreteVariable(name=\"y\", values=\"abc\"))\n        table = data.Table.from_list(domain, [[0, 1, 2],\n                                              [1, 2, \"?\"],\n                                              [\"m\", 3, \"a\"],\n                                              [\"?\", \"?\", \"c\"]])\n        self.assertIs(table.domain, domain)\n        np.testing.assert_almost_equal(\n            table.X, np.array([[0, 1], [1, 2], [0, 3], [np.nan, np.nan]]))\n        np.testing.assert_almost_equal(table.Y, np.array([2, np.nan, 0, 2]))\n\n    def test_creates_a_table_from_domain_and_list_and_weights(self):\n        domain = data.Domain([data.DiscreteVariable(name=\"a\", values=\"mf\"),\n                              data.ContinuousVariable(name=\"b\")],\n                             data.DiscreteVariable(name=\"y\", values=\"abc\"))\n        table = data.Table.from_list(domain, [[0, 1, 2],\n                                              [1, 2, \"?\"],\n                                              [\"m\", 3, \"a\"],\n                                              [\"?\", \"?\", \"c\"]], [1, 2, 3, 4])\n        self.assertIs(table.domain, domain)\n        np.testing.assert_almost_equal(\n            table.X, np.array([[0, 1], [1, 2], [0, 3], [np.nan, np.nan]]))\n        np.testing.assert_almost_equal(table.Y, np.array([2, np.nan, 0, 2]))\n        np.testing.assert_almost_equal(table.W, np.array([1, 2, 3, 4]))\n\n    def test_creates_a_table_from_domain_and_list_and_metas(self):\n        metas = [data.DiscreteVariable(\"Meta 1\", values=\"XYZ\"),\n                 data.ContinuousVariable(\"Meta 2\"),\n                 data.StringVariable(\"Meta 3\")]\n        domain = data.Domain([data.DiscreteVariable(name=\"a\", values=\"mf\"),\n                              data.ContinuousVariable(name=\"b\")],\n                             data.DiscreteVariable(name=\"y\", values=\"abc\"),\n                             metas=metas)\n        table = data.Table.from_list(domain, [[0, 1, 2, \"X\", 2, \"bb\"],\n                                              [1, 2, \"?\", \"Y\", 1, \"aa\"],\n                                              [\"m\", 3, \"a\", \"Z\", 3, \"bb\"],\n                                              [\"?\", \"?\", \"c\", \"X\", 1, \"aa\"]])\n        self.assertIs(table.domain, domain)\n        np.testing.assert_almost_equal(\n            table.X, np.array([[0, 1], [1, 2], [0, 3], [np.nan, np.nan]]))\n        np.testing.assert_almost_equal(table.Y, np.array([2, np.nan, 0, 2]))\n        np.testing.assert_array_equal(table.metas,\n                                      np.array([[0, 2., \"bb\"],\n                                                [1, 1., \"aa\"],\n                                                [2, 3., \"bb\"],\n                                                [0, 1., \"aa\"]],\n                                               dtype=object))\n\n    def test_creates_a_table_from_list_of_instances(self):\n        table = data.Table('iris')\n        new_table = data.Table.from_list(table.domain, [d for d in table])\n        self.assertIs(table.domain, new_table.domain)\n        np.testing.assert_almost_equal(table.X, new_table.X)\n        np.testing.assert_almost_equal(table.Y, new_table.Y)\n        np.testing.assert_almost_equal(table.W, new_table.W)\n        self.assertEqual(table.domain, new_table.domain)\n        np.testing.assert_array_equal(table.metas, new_table.metas)\n\n    def test_creates_a_table_from_list_of_instances_with_metas(self):\n        table = data.Table('zoo')\n        new_table = data.Table.from_list(table.domain, [d for d in table])\n        self.assertIs(table.domain, new_table.domain)\n        np.testing.assert_almost_equal(table.X, new_table.X)\n        np.testing.assert_almost_equal(table.Y, new_table.Y)\n        np.testing.assert_almost_equal(table.W, new_table.W)\n        self.assertEqual(table.domain, new_table.domain)\n        np.testing.assert_array_equal(table.metas, new_table.metas)\n\n    def test_creates_a_table_with_domain_and_given_X(self):\n        domain = self.mock_domain()\n\n        table = data.Table(domain, self.data)\n        self.assertIsInstance(table.domain, data.Domain)\n        self.assertEqual(table.domain, domain)\n        np.testing.assert_almost_equal(table.X, self.data)\n\n    def test_creates_a_table_with_given_X_and_Y(self):\n        table = data.Table.from_numpy(None, self.data, self.class_data)\n\n        self.assertIsInstance(table.domain, data.Domain)\n        np.testing.assert_almost_equal(table.X, self.data)\n        np.testing.assert_almost_equal(table.Y, self.class_data)\n\n    def test_creates_a_table_with_given_X_Y_and_metas(self):\n        table = data.Table.from_numpy(\n            None, self.data, self.class_data, self.meta_data)\n\n        self.assertIsInstance(table.domain, data.Domain)\n        np.testing.assert_almost_equal(table.X, self.data)\n        np.testing.assert_almost_equal(table.Y, self.class_data)\n        np.testing.assert_almost_equal(table.metas, self.meta_data)\n\n    def test_creates_a_discrete_class_if_Y_has_few_distinct_values(self):\n        Y = np.array([float(np.random.randint(0, 2)) for i in self.data])\n        table = data.Table.from_numpy(None, self.data, Y, self.meta_data)\n\n        np.testing.assert_almost_equal(table.Y, Y)\n        self.assertIsInstance(table.domain.class_vars[0],\n                              data.DiscreteVariable)\n        self.assertEqual(table.domain.class_vars[0].values, (\"v1\", \"v2\"))\n\n    def test_creates_a_table_with_given_domain(self):\n        domain = self.mock_domain()\n        table = data.Table.from_numpy(domain, self.data)\n\n        self.assertEqual(table.domain, domain)\n\n    def test_sets_Y_if_given(self):\n        domain = self.mock_domain(with_classes=True)\n        table = data.Table.from_numpy(domain, self.data, self.class_data)\n\n        np.testing.assert_almost_equal(table.Y, self.class_data)\n\n    def test_sets_metas_if_given(self):\n        domain = self.mock_domain(with_metas=True)\n        table = data.Table.from_numpy(domain, self.data, metas=self.meta_data)\n\n        np.testing.assert_almost_equal(table.metas, self.meta_data)\n\n    def test_sets_weights_if_given(self):\n        domain = self.mock_domain()\n        table = data.Table.from_numpy(domain, self.data, W=self.weight_data)\n\n        np.testing.assert_equal(table.W.shape, (len(self.data), ))\n        np.testing.assert_almost_equal(table.W.flatten(),\n                                       self.weight_data.flatten())\n\n    def test_splits_X_and_Y_if_given_in_same_array(self):\n        joined_data = np.column_stack((self.data, self.class_data))\n        domain = self.mock_domain(with_classes=True)\n        table = data.Table.from_numpy(domain, joined_data)\n\n        np.testing.assert_almost_equal(table.X, self.data)\n        np.testing.assert_almost_equal(table.Y, self.class_data)\n\n    def test_initializes_Y_metas_and_W_if_not_given(self):\n        domain = self.mock_domain()\n        table = data.Table.from_numpy(domain, self.data)\n\n        self.assertEqual(table.Y.shape, (self.nrows, len(domain.class_vars)))\n        self.assertEqual(table.metas.shape, (self.nrows, len(domain.metas)))\n        self.assertEqual(table.W.shape, (self.nrows, 0))\n\n    def test_raises_error_if_columns_in_domain_and_data_do_not_match(self):\n        domain = self.mock_domain(with_classes=True, with_metas=True)\n        ones = np.zeros((self.nrows, 1))\n\n        with self.assertRaises(ValueError):\n            data_ = np.hstack((self.data, ones))\n            data.Table.from_numpy(domain, data_, self.class_data,\n                                  self.meta_data)\n\n        with self.assertRaises(ValueError):\n            classes_ = np.hstack((self.class_data, ones))\n            data.Table.from_numpy(domain, self.data, classes_,\n                                  self.meta_data)\n\n        with self.assertRaises(ValueError):\n            metas_ = np.hstack((self.meta_data, ones))\n            data.Table.from_numpy(domain, self.data, self.class_data,\n                                  metas_)\n\n    def test_raises_error_if_lengths_of_data_do_not_match(self):\n        domain = self.mock_domain(with_classes=True, with_metas=True)\n\n        with self.assertRaises(ValueError):\n            data_ = np.vstack((self.data, np.zeros((1, len(self.attributes)))))\n            data.Table(domain, data_, self.class_data, self.meta_data)\n\n        with self.assertRaises(ValueError):\n            class_data_ = np.vstack((self.class_data,\n                                     np.zeros((1, len(self.class_vars)))))\n            data.Table(domain, self.data, class_data_, self.meta_data)\n\n        with self.assertRaises(ValueError):\n            meta_data_ = np.vstack((self.meta_data,\n                                    np.zeros((1, len(self.metas)))))\n            data.Table(domain, self.data, self.class_data, meta_data_)\n\n    @patch(\"Orange.data.table.Table.from_numpy\")\n    def test_calling_new_with_domain_and_numpy_arrays_calls_new_from_numpy(\n            self, new_from_numpy):\n        domain = self.mock_domain()\n        data.Table(domain, self.data)\n        new_from_numpy.assert_called_with(domain, self.data)\n\n        domain = self.mock_domain(with_classes=True)\n        data.Table(domain, self.data, self.class_data)\n        new_from_numpy.assert_called_with(domain, self.data, self.class_data)\n\n        domain = self.mock_domain(with_classes=True, with_metas=True)\n        data.Table(domain, self.data, self.class_data, self.meta_data)\n        new_from_numpy.assert_called_with(\n            domain, self.data, self.class_data, self.meta_data)\n\n        data.Table(domain, self.data, self.class_data,\n                   self.meta_data, self.weight_data)\n        new_from_numpy.assert_called_with(domain, self.data, self.class_data,\n                                          self.meta_data, self.weight_data)\n\n    def test_from_numpy_reconstructable(self):\n        def assert_equal(t1, t2):\n            np.testing.assert_array_equal(t1.X, t2.X)\n            np.testing.assert_array_equal(t1.Y, t2.Y)\n            np.testing.assert_array_equal(t1.metas, t2.metas)\n            np.testing.assert_array_equal(t1.W, t2.W)\n\n        nullcol = np.empty((self.nrows, 0))\n        domain = self.create_domain(self.attributes)\n        table = data.Table(domain, self.data)\n\n        table_1 = data.Table.from_numpy(\n            domain, table.X, table.Y, table.metas, table.W)\n        assert_equal(table, table_1)\n\n        domain = self.create_domain(classes=self.class_vars)\n        table = data.Table(domain, nullcol, self.class_data)\n\n        table_1 = data.Table.from_numpy(\n            domain, table.X, table.Y, table.metas, table.W)\n        assert_equal(table, table_1)\n\n        domain = self.create_domain(metas=self.metas)\n        table = data.Table(domain, nullcol, nullcol, self.meta_data)\n\n        table_1 = data.Table.from_numpy(\n            domain, table.X, table.Y, table.metas, table.W)\n        assert_equal(table, table_1)\n\n\nclass CreateTableWithDomainAndTable(TableTests):\n    interesting_slices = [\n        slice(0, 0),  # [0:0] - empty slice\n        slice(1),  # [:1]  - only first element\n        slice(1, None),  # [1:]  - all but first\n        slice(-1, None),  # [-1:] - only last element\n        slice(-1),  # [:-1] - all but last\n        slice(None),  # [:]   - all elements\n        slice(None, None, 2),  # [::2] - even elements\n        slice(None, None, -1),  # [::-1]- all elements reversed\n        slice(9, 5, -10),  # slice a big negative stride and thus 1 element\n    ]\n\n    row_indices = [1, 5, 6, 7]\n\n    def setUp(self):\n        super().setUp()\n        self.domain = self.create_domain(\n            self.attributes, self.class_vars, self.metas)\n        self.table = data.Table(\n            self.domain, self.data, self.class_data, self.meta_data)\n\n    def test_creates_table_with_given_domain(self):\n        new_table = data.Table.from_table(self.table.domain, self.table)\n\n        self.assertIsInstance(new_table, data.Table)\n        self.assertIsNot(self.table, new_table)\n        self.assertEqual(new_table.domain, self.domain)\n\n    def test_transform(self):\n        class MyTableClass(data.Table):\n            pass\n\n        table = MyTableClass.from_table(self.table.domain, self.table)\n        domain = table.domain\n        attr = ContinuousVariable(\"x\")\n        new_domain = data.Domain(list(domain.attributes) + [attr], None)\n        new_table = table.transform(new_domain)\n\n        self.assertIsInstance(new_table, MyTableClass)\n        self.assertIsNot(table, new_table)\n        self.assertIs(new_table.domain, new_domain)\n\n    def test_transform_same_domain(self):\n        iris = data.Table(\"iris\")\n        new_domain = copy.copy(iris.domain)\n        new_data = iris.transform(new_domain)\n        self.assertIs(new_data.domain, new_domain)\n\n    def test_can_copy_table(self):\n        new_table = data.Table.from_table(self.domain, self.table)\n        self.assert_table_with_filter_matches(new_table, self.table)\n\n    def test_can_filter_rows_with_list(self):\n        for indices in ([0], [1, 5, 6, 7]):\n            new_table = data.Table.from_table(\n                self.domain, self.table, row_indices=indices)\n            self.assert_table_with_filter_matches(\n                new_table, self.table, rows=indices)\n\n    @patch.object(Table, \"from_table_rows\", wraps=Table.from_table_rows)\n    def test_can_filter_row_with_slice_from_table_rows(self, from_table_rows):\n        # calling from_table with the same domain will forward to from_table_rows\n        for slice_ in self.interesting_slices:\n            from_table_rows.reset_mock()\n            new_table = data.Table.from_table(\n                self.domain, self.table, row_indices=slice_)\n            self.assert_table_with_filter_matches(\n                new_table, self.table, rows=slice_)\n            from_table_rows.assert_called()\n\n    def test_can_filter_row_with_slice_from_table(self):\n        # calling from_table with a domain copy will use indexing in from_table\n        for slice_ in self.interesting_slices:\n            new_table = data.Table.from_table(\n                self.domain.copy(), self.table, row_indices=slice_)\n            self.assert_table_with_filter_matches(\n                new_table, self.table, rows=slice_)\n\n    def test_can_use_attributes_as_new_columns(self):\n        a, _, _ = column_sizes(self.table)\n        order = np.random.permutation(a)\n        new_attributes = [self.domain.attributes[i] for i in order]\n        new_domain = self.create_domain(\n            new_attributes[:2], new_attributes[2:4], new_attributes[4:])\n        new_table = data.Table.from_table(new_domain, self.table)\n\n        self.assert_table_with_filter_matches(\n            new_table, self.table, xcols=order[:2], ycols=order[2:4], mcols=order[4:])\n\n    def test_can_use_class_vars_as_new_columns(self):\n        a, _, _ = column_sizes(self.table)\n        order = np.random.permutation(range(a))\n        cvs = [self.domain.attributes[i] for i in order[:2]]\n        metas = [self.domain.attributes[i] for i in order[2:]]\n        new_domain = self.create_domain(self.domain.class_vars,\n                                        cvs,\n                                        metas)\n        new_table = data.Table.from_table(new_domain, self.table)\n\n        self.assert_table_with_filter_matches(\n            new_table, self.table, xcols=[a], ycols=order[:2], mcols=order[2:])\n\n    def test_can_use_metas_as_new_columns(self):\n        _, _, m = column_sizes(self.table)\n        order = np.random.permutation(range(-m, 0))\n        new_metas = [self.domain.metas[::-1][i] for i in order]\n        new_domain = self.create_domain(new_metas[0:2], [new_metas[2]], new_metas[3:5])\n        new_table = data.Table.from_table(new_domain, self.table)\n\n        self.assert_table_with_filter_matches(\n            new_table, self.table, xcols=order[0:2], ycols=order[2], mcols=order[3:5])\n\n    def test_can_use_combination_of_all_as_new_columns(self):\n        a, c, m = column_sizes(self.table)\n        order = (list(range(a+c)) + list(range(-m+1, 0)))\n        random. shuffle(order)\n        vars_ = list(self.domain.variables) + list(self.domain.metas[::-1])\n        atrs = [vars_[order[i]] for i in range(a)]\n        cv = [vars_[order[i]] for i in range(a, a+c)]\n        metas = [vars_[order[i]] for i in range(a+c, a+c+m-1)]\n\n        new_domain = self.create_domain(atrs, cv, metas)\n        new_table = data.Table.from_table(new_domain, self.table)\n        self.assert_table_with_filter_matches(\n            new_table, self.table, xcols=order[:a], ycols=order[a:a+c], mcols=order[a+c:])\n\n    def test_creates_table_with_given_domain_and_row_filter(self):\n        a, c, m = column_sizes(self.table)\n        order = (list(range(a+c)) + list(range(-m+1, 0)))\n        random.shuffle(order)\n        vars_ = list(self.domain.variables) + list(self.domain.metas[::-1])\n        atrs = [vars_[order[i]] for i in range(a)]\n        cv = [vars_[order[i]] for i in range(a, a+c)]\n        metas = [vars_[order[i]] for i in range(a+c, a+c+m-1)]\n\n        new_domain = self.create_domain(atrs, cv, metas)\n        new_table = data.Table.from_table(new_domain, self.table, [0])\n        self.assert_table_with_filter_matches(\n            new_table, self.table[:1], xcols=order[:a], ycols=order[a:a+c], mcols=order[a+c:])\n\n        new_table = data.Table.from_table(new_domain, self.table, [2, 1, 0])\n        self.assert_table_with_filter_matches(\n            new_table, self.table[2::-1], xcols=order[:a], ycols=order[a:a+c], mcols=order[a+c:])\n\n        new_table = data.Table.from_table(new_domain, self.table, [])\n        self.assert_table_with_filter_matches(\n            new_table, self.table[:0], xcols=order[:a], ycols=order[a:a+c], mcols=order[a+c:])\n\n    def test_from_table_sparse_move_some_to_empty_metas(self):\n        iris = data.Table(\"iris\").to_sparse()\n        new_domain = data.domain.Domain(\n            iris.domain.attributes[:2], iris.domain.class_vars,\n            iris.domain.attributes[2:], source=iris.domain)\n        new_iris = iris.transform(new_domain)\n\n        self.assertTrue(sp.issparse(new_iris.X))\n        self.assertTrue(sp.issparse(new_iris.metas))\n        self.assertEqual(new_iris.X.shape, (len(iris), 2))\n        self.assertEqual(new_iris.metas.shape, (len(iris), 2))\n\n        # move back\n        back_iris = new_iris.transform(iris.domain)\n        self.assertEqual(back_iris.domain, iris.domain)\n        self.assertTrue(sp.issparse(back_iris.X))\n        self.assertFalse(sp.issparse(back_iris.metas))\n        self.assertEqual(back_iris.X.shape, iris.X.shape)\n        self.assertEqual(back_iris.metas.shape, iris.metas.shape)\n\n    def test_from_table_sparse_move_all_to_empty_metas(self):\n        iris = data.Table(\"iris\").to_sparse()\n        new_domain = data.domain.Domain(\n            [], iris.domain.class_vars, iris.domain.attributes,\n            source=iris.domain)\n        new_iris = iris.transform(new_domain)\n\n        self.assertFalse(sp.issparse(new_iris.X))\n        self.assertTrue(sp.issparse(new_iris.metas))\n        self.assertEqual(new_iris.X.shape, (len(iris), 0))\n        self.assertEqual(new_iris.metas.shape, (len(iris), 4))\n\n        # move back\n        back_iris = new_iris.transform(iris.domain)\n        self.assertEqual(back_iris.domain, iris.domain)\n        self.assertTrue(sp.issparse(back_iris.X))\n        self.assertFalse(sp.issparse(back_iris.metas))\n        self.assertEqual(back_iris.X.shape, iris.X.shape)\n        self.assertEqual(back_iris.metas.shape, iris.metas.shape)\n\n    def test_from_table_sparse_move_to_nonempty_metas(self):\n        brown = data.Table(\"brown-selected\").to_sparse()\n        n_attr = len(brown.domain.attributes)\n        n_metas = len(brown.domain.metas)\n        new_domain = data.domain.Domain(\n            brown.domain.attributes[:-10],\n            brown.domain.class_vars,\n            brown.domain.attributes[-10:] + brown.domain.metas,\n            source=brown.domain)\n        new_brown = data.Table.from_table(new_domain, brown)\n\n        self.assertTrue(sp.issparse(new_brown.X))\n        self.assertFalse(sp.issparse(new_brown.metas))\n        self.assertEqual(new_brown.X.shape, (len(new_brown), n_attr-10))\n        self.assertEqual(new_brown.metas.shape, (len(new_brown), n_metas+10))\n\n        # move back\n        back_brown = data.Table.from_table(brown.domain, new_brown)\n        self.assertEqual(brown.domain, back_brown.domain)\n        self.assertTrue(sp.issparse(back_brown.X))\n        self.assertFalse(sp.issparse(back_brown.metas))\n        self.assertEqual(back_brown.X.shape, brown.X.shape)\n        self.assertEqual(back_brown.metas.shape, brown.metas.shape)\n\n    def test_from_table_shared_compute_value(self):\n        iris = data.Table(\"iris\").to_sparse()\n        d1 = Domain(\n            [\n                ContinuousVariable(\n                    name=at.name,\n                    compute_value=PreprocessSharedComputeValue(\n                        i, None, PreprocessShared(iris.domain, None)\n                    )\n                )\n                for i, at in enumerate(iris.domain.attributes)\n            ]\n        )\n\n        new_table = Table.from_table(d1, iris)\n        np.testing.assert_array_equal(new_table.X, iris.X.todense() * 2)\n\n        new_table = Table.from_table(d1, iris, row_indices=[0, 1, 2])\n        np.testing.assert_array_equal(new_table.X, iris.X.todense()[:3] * 2)\n\n    def assert_table_with_filter_matches(\n            self, new_table, old_table,\n            rows=..., xcols=..., ycols=..., mcols=...):\n        a, c, m = column_sizes(old_table)\n        xcols = slice(a) if xcols is Ellipsis else xcols\n        ycols = slice(a, a + c) if ycols is Ellipsis else ycols\n        mcols = slice(None, -m - 1, -1) if mcols is Ellipsis else mcols\n\n        # Indexing used by convert_domain uses positive indices for variables\n        # and classes (classes come after attributes) and negative indices for\n        # meta features. This is equivalent to ordinary indexing in a magic\n        # table below.\n        magic = np.hstack((old_table.X, old_table.Y[:, None],\n                           old_table.metas[:, ::-1]))\n        np.testing.assert_almost_equal(new_table.X, magic[rows, xcols])\n        Y = magic[rows, ycols]\n        if len(Y.shape) == 2 and Y.shape[1] == 1:\n            Y = Y.flatten()\n        np.testing.assert_almost_equal(new_table.Y, Y)\n        np.testing.assert_almost_equal(new_table.metas, magic[rows, mcols])\n        np.testing.assert_almost_equal(new_table.W, old_table.W[rows])\n\n\ndef isspecial(s):\n    return isinstance(s, slice) or s is Ellipsis\n\n\ndef split_columns(indices, t):\n    a, c, m = column_sizes(t)\n    if indices is ...:\n        return slice(a), slice(c), slice(m)\n    elif isinstance(indices, slice):\n        return indices, slice(0, 0), slice(0, 0)\n    elif not isinstance(indices, list) and not isinstance(indices, tuple):\n        indices = [indices]\n    return (\n        [t.domain.index(x)\n         for x in indices if 0 <= t.domain.index(x) < a] or slice(0, 0),\n        [t.domain.index(x) - a\n         for x in indices if t.domain.index(x) >= a] or slice(0, 0),\n        [-t.domain.index(x) - 1\n         for x in indices if t.domain.index(x) < 0] or slice(0, 0))\n\n\ndef getname(variable):\n    return variable.name\n\n\nclass TableIndexingTests(TableTests):\n    def setUp(self):\n        super().setUp()\n        d = self.domain = \\\n            self.create_domain(self.attributes, self.class_vars, self.metas)\n        t = self.table = \\\n            data.Table(self.domain, self.data, self.class_data, self.meta_data)\n        self.magic_table = \\\n            np.column_stack((self.table.X, self.table.Y,\n                             self.table.metas[:, ::-1]))\n\n        self.rows = [0, -1]\n        self.multiple_rows = [slice(0, 0), ..., slice(1, -1, -1)]\n        a, c, m = column_sizes(t)\n        columns = [0, a - 1, a, a + c - 1, -1, -m]\n        self.columns = chain(columns,\n                             map(lambda x: d[x], columns),\n                             map(lambda x: d[x].name, columns))\n        self.multiple_columns = chain(\n            self.multiple_rows,\n            [d.attributes, d.class_vars, d.metas, [0, a, -1]],\n            [self.attributes, self.class_vars, self.metas],\n            [self.attributes + self.class_vars + self.metas])\n\n        # TODO: indexing with [[0,1], [0,1]] produces weird results\n        # TODO: what should be the results of table[1, :]\n\n    def test_can_select_a_single_value(self):\n        for r in self.rows:\n            for c in self.columns:\n                value = self.table[r, c]\n                self.assertAlmostEqual(\n                    value, self.magic_table[r, self.domain.index(c)])\n\n                value = self.table[r][c]\n                self.assertAlmostEqual(\n                    value, self.magic_table[r, self.domain.index(c)])\n\n    def test_can_select_a_single_row(self):\n        for r in self.rows:\n            row = self.table[r]\n            new_row = np.hstack(\n                (self.data[r, :],\n                 self.class_data[r, None]))\n            np.testing.assert_almost_equal(\n                np.array(list(row)), new_row)\n\n\n    def test_can_select_a_subset_of_rows_and_columns(self):\n        for r in self.rows:\n            for c in self.multiple_columns:\n                table = self.table[r, c]\n\n                attr, cls, metas = split_columns(c, self.table)\n                X = self.table.X[[r], attr]\n                if X.ndim == 1:\n                    X = X.reshape(-1, len(table.domain.attributes))\n                np.testing.assert_almost_equal(table.X, X)\n                Y = self.table.Y[:, None][[r], cls]\n                if len(Y.shape) == 1 or Y.shape[1] == 1:\n                    Y = Y.flatten()\n                np.testing.assert_almost_equal(table.Y, Y)\n                metas_ = self.table.metas[[r], metas]\n                if metas_.ndim == 1:\n                    metas_ = metas_.reshape(-1, len(table.domain.metas))\n                np.testing.assert_almost_equal(table.metas, metas_)\n\n        for r in self.multiple_rows:\n            for c in chain(self.columns, self.multiple_rows):\n                table = self.table[r, c]\n\n                attr, cls, metas = split_columns(c, self.table)\n                np.testing.assert_almost_equal(table.X, self.table.X[r, attr])\n                Y = self.table.Y[:, None][r, cls]\n                if len(Y.shape) > 1 and Y.shape[1] == 1:\n                    Y = Y.flatten()\n                np.testing.assert_almost_equal(table.Y, Y)\n                np.testing.assert_almost_equal(table.metas,\n                                               self.table.metas[r, metas])\n\n\n    def test_optimize_indices(self):\n        # ordinary conversion\n        self.assertEqual(_optimize_indices([1, 2, 3], 4), slice(1, 4, 1))\n        self.assertEqual(_optimize_indices([], 1), [])\n        self.assertEqual(_optimize_indices([0, 2], 3), slice(0, 4, 2))\n\n        # not slices\n        np.testing.assert_equal(_optimize_indices([1, 2, 4], 5), [1, 2, 4])\n        np.testing.assert_equal(_optimize_indices((1, 2, 4), 5), [1, 2, 4])\n\n        # leave boolean arrays\n        np.testing.assert_equal(_optimize_indices([True, False, True], 3), [True, False, True])\n\n        # do not convert if step is negative\n        np.testing.assert_equal(_optimize_indices([4, 2, 0], 5), [4, 2, 0])\n\n        # try range\n        np.testing.assert_equal(_optimize_indices([3, 4, 5], 5), [3, 4, 5])  # out of range\n        self.assertEqual(_optimize_indices((3, 4, 5), 6), slice(3, 6, 1))\n\n        # negative elements\n        np.testing.assert_equal(_optimize_indices([-1, 0, 1], 5), [-1, 0, 1])\n\n        # single element\n        self.assertEqual(_optimize_indices([1], 2), slice(1, 2, 1))\n        self.assertEqual(_optimize_indices([-2], 5), slice(-2, -3, -1))\n\n\nclass TableElementAssignmentTest(TableTests):\n    def setUp(self):\n        super().setUp()\n        self.domain = \\\n            self.create_domain(self.attributes, self.class_vars, self.metas)\n        self.table = \\\n            data.Table(self.domain, self.data, self.class_data, self.meta_data)\n\n    def test_can_assign_values(self):\n        with self.table.unlocked():\n            self.table[0, 0] = 42.\n        self.assertAlmostEqual(self.table.X[0, 0], 42.)\n\n    def test_can_assign_values_to_classes(self):\n        a, _, _ = column_sizes(self.table)\n        with self.table.unlocked():\n            self.table[0, a] = 42.\n        self.assertAlmostEqual(self.table.Y[0], 42.)\n\n    def test_can_assign_values_to_metas(self):\n        with self.table.unlocked():\n            self.table[0, -1] = 42.\n        self.assertAlmostEqual(self.table.metas[0, 0], 42.)\n\n    def test_can_assign_rows_to_rows(self):\n        with self.table.unlocked():\n            self.table[0] = self.table[1]\n        np.testing.assert_almost_equal(\n            self.table.X[0], self.table.X[1])\n        np.testing.assert_almost_equal(\n            self.table.Y[0], self.table.Y[1])\n        np.testing.assert_almost_equal(\n            self.table.metas[0], self.table.metas[1])\n\n    def test_can_assign_lists(self):\n        a, _, _ = column_sizes(self.table)\n        new_example = [float(i)\n                       for i in range(len(self.attributes + self.class_vars))]\n        with self.table.unlocked():\n            self.table[0] = new_example\n        np.testing.assert_almost_equal(\n            self.table.X[0], np.array(new_example[:a]))\n        np.testing.assert_almost_equal(\n            self.table.Y[0], np.array(new_example[a:]))\n\n    def test_can_assign_np_array(self):\n        a, _, _ = column_sizes(self.table)\n        new_example = \\\n            np.array([float(i)\n                      for i in range(len(self.attributes + self.class_vars))])\n        with self.table.unlocked():\n            self.table[0] = new_example\n        np.testing.assert_almost_equal(self.table.X[0], new_example[:a])\n        np.testing.assert_almost_equal(self.table.Y[0], new_example[a:])\n\n\nclass InterfaceTest(unittest.TestCase):\n    \"\"\"Basic tests each implementation of Table should pass.\"\"\"\n\n    features = (\n        data.ContinuousVariable(name=\"Continuous Feature 1\"),\n        data.ContinuousVariable(name=\"Continuous Feature 2\"),\n        data.DiscreteVariable(name=\"Discrete Feature 1\", values=(\"0\", \"1\")),\n        data.DiscreteVariable(name=\"Discrete Feature 2\",\n                              values=(\"value1\", \"value2\")),\n    )\n\n    class_vars = (\n        data.ContinuousVariable(name=\"Continuous Class\"),\n        data.DiscreteVariable(name=\"Discrete Class\", values=(\"m\", \"f\"))\n    )\n\n    feature_data = (\n        (1, 0, 0, 0),\n        (0, 1, 0, 0),\n        (0, 0, 1, 0),\n        (0, 0, 0, 1),\n    )\n\n    class_data = (\n        (1, 0),\n        (0, 1),\n        (1, 0),\n        (0, 1)\n    )\n\n    data = tuple(a + c for a, c in zip(feature_data, class_data))\n\n    nrows = 4\n\n    def setUp(self):\n        self.domain = data.Domain(attributes=self.features,\n                                  class_vars=self.class_vars)\n        self.table = data.Table.from_numpy(\n            self.domain,\n            np.array(self.feature_data),\n            np.array(self.class_data),\n        )\n\n    def test_len(self):\n        self.assertEqual(len(self.table), self.nrows)\n\n    def test_row_len(self):\n        for i in range(self.nrows):\n            self.assertEqual(len(self.table[i]), len(self.data[i]))\n\n    def test_iteration(self):\n        for row, expected_data in zip(self.table, self.data):\n            self.assertEqual(tuple(row), expected_data)\n\n    def test_row_indexing(self):\n        for i in range(self.nrows):\n            self.assertEqual(tuple(self.table[i]), self.data[i])\n\n    def test_row_slicing(self):\n        t = self.table[1:]\n        self.assertEqual(len(t), self.nrows - 1)\n\n    def test_value_indexing(self):\n        for i in range(self.nrows):\n            for j in range(len(self.table[i])):\n                self.assertEqual(self.table[i, j], self.data[i][j])\n\n    def test_row_assignment(self):\n        new_value = 2.\n        with self.table.unlocked():\n            for i in range(self.nrows):\n                new_row = [new_value] * len(self.data[i])\n                self.table[i] = np.array(new_row)\n                self.assertEqual(list(self.table[i]), new_row)\n\n    def test_value_assignment(self):\n        new_value = 0.\n        with self.table.unlocked():\n            for i in range(self.nrows):\n                for j in range(len(self.table[i])):\n                    self.table[i, j] = new_value\n                    self.assertEqual(self.table[i, j], new_value)\n\n    def test_subclasses(self):\n        from pathlib import Path\n\n        class _ExtendedTable(data.Table):\n            pass\n\n        data_file = _ExtendedTable('iris')\n        data_url = _ExtendedTable.from_url(\n            Path(os.path.dirname(__file__), 'datasets/test1.tab').as_uri())\n\n        self.assertIsInstance(data_file, _ExtendedTable)\n        self.assertIsInstance(data_url, _ExtendedTable)\n\n\nclass TestTableStats(TableTests):\n    def test_get_nan_frequency(self):\n        domain = self.create_domain(self.attributes, self.class_vars)\n        table = data.Table(domain, self.data, self.class_data)\n        self.assertEqual(table.get_nan_frequency_attribute(), 0)\n        self.assertEqual(table.get_nan_frequency_class(), 0)\n\n        with table.unlocked():\n            table.X[1, 2] = table.X[4, 5] = np.nan\n        self.assertEqual(table.get_nan_frequency_attribute(), 2 / table.X.size)\n        self.assertEqual(table.get_nan_frequency_class(), 0)\n\n        with table.unlocked():\n            table.Y[3:6] = np.nan\n        self.assertEqual(table.get_nan_frequency_attribute(), 2 / table.X.size)\n        self.assertEqual(table.get_nan_frequency_class(), 3 / table.Y.size)\n\n        with table.unlocked():\n            table.X[1, 2] = table.X[4, 5] = 0\n        self.assertEqual(table.get_nan_frequency_attribute(), 0)\n        self.assertEqual(table.get_nan_frequency_class(), 3 / table.Y.size)\n\n    def test_get_nan_frequency_empty_table(self):\n        domain = self.create_domain(self.attributes, self.class_vars)\n        table = data.Table.from_domain(domain)\n        self.assertEqual(table.get_nan_frequency_attribute(), 0)\n        self.assertEqual(table.get_nan_frequency_class(), 0)\n\n\nclass TestRowInstance(unittest.TestCase):\n    def test_assignment(self):\n        table = data.Table(\"zoo\")\n        inst = table[2]\n        self.assertIsInstance(inst, data.RowInstance)\n\n        with table.unlocked():\n            inst[1] = 0\n        self.assertEqual(table[2, 1], 0)\n        with table.unlocked():\n            inst[1] = 1\n        self.assertEqual(table[2, 1], 1)\n\n        with table.unlocked():\n            inst.set_class(\"mammal\")\n        self.assertEqual(table[2, len(table.domain.attributes)], \"mammal\")\n        with table.unlocked():\n            inst.set_class(\"fish\")\n        self.assertEqual(table[2, len(table.domain.attributes)], \"fish\")\n\n        with table.unlocked():\n            inst[-1] = \"Foo\"\n        self.assertEqual(table[2, -1], \"Foo\")\n\n    def test_iteration_with_assignment(self):\n        table = data.Table(\"iris\")\n        with table.unlocked():\n            for i, row in enumerate(table):\n                row[0] = i\n        np.testing.assert_array_equal(table.X[:, 0], np.arange(len(table)))\n\n    def test_sparse_assignment(self):\n        X = np.eye(4)\n        Y = X[2].copy()\n        table = data.Table.from_numpy(None, X, Y)\n        row = table[1]\n        self.assertFalse(sp.issparse(row.sparse_x))\n        self.assertEqual(row[0], 0)\n        self.assertEqual(row[1], 1)\n\n        with table.unlocked():\n            table.X = sp.csr_matrix(table.X)\n            table.Y = sp.csr_matrix(table.Y)\n        sparse_row = table[1]\n        self.assertTrue(sp.issparse(sparse_row.sparse_x))\n        self.assertEqual(sparse_row[0], 0)\n        self.assertEqual(sparse_row[1], 1)\n\n        with table.unlocked():\n            sparse_row[1] = 0\n        self.assertEqual(sparse_row[1], 0)\n        self.assertEqual(table.X[1, 1], 0)\n        self.assertEqual(table[2][4], 1)\n\n        with table.unlocked():\n            table[2][4] = 0\n        self.assertEqual(table[2][4], 0)\n\n\nclass TestTableTranspose(unittest.TestCase):\n    def test_transpose_no_class(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        table = Table(Domain(attrs), np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose is original\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_discrete_class(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        domain = Domain(attrs, [DiscreteVariable(\"cls\", values=(\"a\", \"b\"))])\n        table = Table(domain, np.arange(8).reshape((4, 2)),\n                     np.array([1, 1, 0, 0]))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"cls\": \"b\"}\n        att[1].attributes = {\"cls\": \"b\"}\n        att[2].attributes = {\"cls\": \"a\"}\n        att[3].attributes = {\"cls\": \"a\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose is original\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_continuous_class(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")])\n        table = Table(domain, np.arange(8).reshape((4, 2)), np.arange(4, 0, -1))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"cls\": \"4\"}\n        att[1].attributes = {\"cls\": \"3\"}\n        att[2].attributes = {\"cls\": \"2\"}\n        att[3].attributes = {\"cls\": \"1\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_missing_class(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")])\n        table = Table(domain, np.arange(8).reshape((4, 2)),\n                     np.array([np.nan, 3, 2, 1]))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[1].attributes = {\"cls\": \"3\"}\n        att[2].attributes = {\"cls\": \"2\"}\n        att[3].attributes = {\"cls\": \"1\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_multiple_class(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        class_vars = [ContinuousVariable(\"cls1\"), ContinuousVariable(\"cls2\")]\n        domain = Domain(attrs, class_vars)\n        table = Table(domain, np.arange(8).reshape((4, 2)),\n                      np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"cls1\": \"0\", \"cls2\": \"1\"}\n        att[1].attributes = {\"cls1\": \"2\", \"cls2\": \"3\"}\n        att[2].attributes = {\"cls1\": \"4\", \"cls2\": \"5\"}\n        att[3].attributes = {\"cls1\": \"6\", \"cls2\": \"7\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_metas(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([\"aa\", \"bb\", \"cc\", \"dd\"])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"m1\": \"aa\"}\n        att[1].attributes = {\"m1\": \"bb\"}\n        att[2].attributes = {\"m1\": \"cc\"}\n        att[3].attributes = {\"m1\": \"dd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_discrete_metas(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [DiscreteVariable(\"m1\", values=(\"aa\", \"bb\"))]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([0, 1, 0, 1])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"m1\": \"aa\"}\n        att[1].attributes = {\"m1\": \"bb\"}\n        att[2].attributes = {\"m1\": \"aa\"}\n        att[3].attributes = {\"m1\": \"bb\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose is original\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_continuous_metas(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [ContinuousVariable(\"m1\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([0.0, 1.0, 0.0, 1.0])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"m1\": \"0\"}\n        att[1].attributes = {\"m1\": \"1\"}\n        att[2].attributes = {\"m1\": \"0\"}\n        att[3].attributes = {\"m1\": \"1\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose is original\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_missing_metas(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([\"aa\", \"bb\", \"\", \"dd\"])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"m1\": \"aa\"}\n        att[1].attributes = {\"m1\": \"bb\"}\n        att[3].attributes = {\"m1\": \"dd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_multiple_metas(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\"), StringVariable(\"m2\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([[\"aa\", \"aaa\"], [\"bb\", \"bbb\"],\n                      [\"cc\", \"ccc\"], [\"dd\", \"ddd\"]])\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"m1\": \"aa\", \"m2\": \"aaa\"}\n        att[1].attributes = {\"m1\": \"bb\", \"m2\": \"bbb\"}\n        att[2].attributes = {\"m1\": \"cc\", \"m2\": \"ccc\"}\n        att[3].attributes = {\"m1\": \"dd\", \"m2\": \"ddd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_class_and_metas(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\"), StringVariable(\"m2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")], metas)\n        M = np.array([[\"aa\", \"aaa\"], [\"bb\", \"bbb\"],\n                      [\"cc\", \"ccc\"], [\"dd\", \"ddd\"]])\n        table = Table(domain, np.arange(8).reshape((4, 2)), np.arange(1, 5), M)\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"cls\": \"1\", \"m1\": \"aa\", \"m2\": \"aaa\"}\n        att[1].attributes = {\"cls\": \"2\", \"m1\": \"bb\", \"m2\": \"bbb\"}\n        att[2].attributes = {\"cls\": \"3\", \"m1\": \"cc\", \"m2\": \"ccc\"}\n        att[3].attributes = {\"cls\": \"4\", \"m1\": \"dd\", \"m2\": \"ddd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_attributes_of_attributes_discrete(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"a\", \"attr2\": \"aa\"}\n        attrs[1].attributes = {\"attr1\": \"b\", \"attr2\": \"bb\"}\n        domain = Domain(attrs)\n        table = Table(domain, np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        metas = [StringVariable(\"Feature name\"),\n                 DiscreteVariable(\"attr1\", values=(\"a\", \"b\")),\n                 DiscreteVariable(\"attr2\", values=(\"aa\", \"bb\"))]\n        domain = Domain(att, metas=metas)\n        M = np.array([[\"c1\", 0.0, 0.0], [\"c2\", 1.0, 1.0]], dtype=object)\n        result = Table(domain, np.arange(8).reshape((4, 2)).T, metas=M)\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"a\", \"attr2\": \"aa\"})\n\n    def test_transpose_attributes_of_attributes_continuous(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"1.1\", \"attr2\": \"1.3\"}\n        attrs[1].attributes = {\"attr1\": \"2.2\", \"attr2\": \"2.3\"}\n        domain = Domain(attrs)\n        table = Table(domain, np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        metas = [StringVariable(\"Feature name\"), ContinuousVariable(\"attr1\"),\n                 ContinuousVariable(\"attr2\")]\n        domain = Domain(att, metas=metas)\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([[\"c1\", 1.1, 1.3],\n                                       [\"c2\", 2.2, 2.3]], dtype=object))\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"1.1\", \"attr2\": \"1.3\"})\n\n    def test_transpose_attributes_of_attributes_missings(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"a\", \"attr2\": \"aa\"}\n        attrs[1].attributes = {\"attr1\": \"b\"}\n        domain = Domain(attrs)\n        table = Table(domain, np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        metas = [StringVariable(\"Feature name\"),\n                 DiscreteVariable(\"attr1\", values=(\"a\", \"b\")),\n                 DiscreteVariable(\"attr2\", values=(\"aa\",))]\n        domain = Domain(att, metas=metas)\n        M = np.array([[\"c1\", 0.0, 0.0], [\"c2\", 1.0, np.nan]], dtype=object)\n        result = Table(domain, np.arange(8).reshape((4, 2)).T, metas=M)\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"a\", \"attr2\": \"aa\"})\n\n    def test_transpose_class_metas_attributes(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"a1\", \"attr2\": \"aa1\"}\n        attrs[1].attributes = {\"attr1\": \"b1\", \"attr2\": \"bb1\"}\n        metas = [StringVariable(\"m1\"), StringVariable(\"m2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")], metas)\n        M = np.array([[\"aa\", \"aaa\"], [\"bb\", \"bbb\"],\n                      [\"cc\", \"ccc\"], [\"dd\", \"ddd\"]])\n        table = Table(domain, np.arange(8).reshape((4, 2)), np.arange(1, 5), M)\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"cls\": \"1\", \"m1\": \"aa\", \"m2\": \"aaa\"}\n        att[1].attributes = {\"cls\": \"2\", \"m1\": \"bb\", \"m2\": \"bbb\"}\n        att[2].attributes = {\"cls\": \"3\", \"m1\": \"cc\", \"m2\": \"ccc\"}\n        att[3].attributes = {\"cls\": \"4\", \"m1\": \"dd\", \"m2\": \"ddd\"}\n        metas = [StringVariable(\"Feature name\"),\n                 DiscreteVariable(\"attr1\", values=(\"a1\", \"b1\")),\n                 DiscreteVariable(\"attr2\", values=(\"aa1\", \"bb1\"))]\n        domain = Domain(att, metas=metas)\n        M = np.array([[\"c1\", 0.0, 0.0], [\"c2\", 1.0, 1.0]], dtype=object)\n        result = Table(domain, np.arange(8).reshape((4, 2)).T, metas=M)\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"a1\", \"attr2\": \"aa1\"})\n\n    def test_transpose_duplicate_feature_names(self):\n        table = Table(\"iris\")\n        domain = table.domain\n        attrs, metas = domain.attributes[:3], domain.attributes[3:]\n        table = table.transform(Domain(attrs, domain.class_vars, metas))\n        transposed = Table.transpose(table, domain.attributes[3].name)\n        names = [f.name for f in transposed.domain.attributes]\n        self.assertEqual(len(names), len(set(names)))\n\n    def test_transpose(self):\n        zoo = Table(\"zoo\")\n        t1 = Table.transpose(zoo)\n        t2 = Table.transpose(t1, \"Feature name\")\n        t3 = Table.transpose(t2)\n        self._compare_tables(zoo, t2)\n        self._compare_tables(t1, t3)\n\n    def test_transpose_callback(self):\n        zoo = Table(\"zoo\")\n        cb = Mock()\n        Table.transpose(zoo, progress_callback=cb)\n        cb.assert_called()\n\n    def test_transpose_no_class_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        table = Table(Domain(attrs), np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_discrete_class_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        domain = Domain(attrs, [DiscreteVariable(\"cls\", values=(\"a\", \"b\"))])\n        table = Table(domain, np.arange(8).reshape((4, 2)),\n                     np.array([1, 1, 0, 0]))\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"cls\": \"b\"}\n        att[1].attributes = {\"cls\": \"b\"}\n        att[2].attributes = {\"cls\": \"a\"}\n        att[3].attributes = {\"cls\": \"a\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_continuous_class_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")])\n        table = Table(domain, np.arange(8).reshape((4, 2)), np.arange(4, 0, -1))\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"cls\": \"4\"}\n        att[1].attributes = {\"cls\": \"3\"}\n        att[2].attributes = {\"cls\": \"2\"}\n        att[3].attributes = {\"cls\": \"1\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_missing_class_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")])\n        table = Table(domain, np.arange(8).reshape((4, 2)),\n                     np.array([np.nan, 3, 2, 1]))\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[1].attributes = {\"cls\": \"3\"}\n        att[2].attributes = {\"cls\": \"2\"}\n        att[3].attributes = {\"cls\": \"1\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_multiple_class_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        class_vars = [ContinuousVariable(\"cls1\"), ContinuousVariable(\"cls2\")]\n        domain = Domain(attrs, class_vars)\n        table = Table(domain, np.arange(8).reshape((4, 2)),\n                     np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"cls1\": \"0\", \"cls2\": \"1\"}\n        att[1].attributes = {\"cls1\": \"2\", \"cls2\": \"3\"}\n        att[2].attributes = {\"cls1\": \"4\", \"cls2\": \"5\"}\n        att[3].attributes = {\"cls1\": \"6\", \"cls2\": \"7\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_metas_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([\"aa\", \"bb\", \"cc\", \"dd\"])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"m1\": \"aa\"}\n        att[1].attributes = {\"m1\": \"bb\"}\n        att[2].attributes = {\"m1\": \"cc\"}\n        att[3].attributes = {\"m1\": \"dd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_discrete_metas_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [DiscreteVariable(\"m1\", values=(\"aa\", \"bb\"))]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([0, 1, 0, 1])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"m1\": \"aa\"}\n        att[1].attributes = {\"m1\": \"bb\"}\n        att[2].attributes = {\"m1\": \"aa\"}\n        att[3].attributes = {\"m1\": \"bb\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_continuous_metas_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [ContinuousVariable(\"m1\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([0.0, 1.0, 0.0, 1.0])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"m1\": \"0\"}\n        att[1].attributes = {\"m1\": \"1\"}\n        att[2].attributes = {\"m1\": \"0\"}\n        att[3].attributes = {\"m1\": \"1\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_missing_metas_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([\"aa\", \"bb\", \"\", \"dd\"])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"m1\": \"aa\"}\n        att[1].attributes = {\"m1\": \"bb\"}\n        att[3].attributes = {\"m1\": \"dd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_multiple_metas_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\"), StringVariable(\"m2\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([[\"aa\", \"aaa\"], [\"bb\", \"bbb\"],\n                      [\"cc\", \"ccc\"], [\"dd\", \"ddd\"]])\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"m1\": \"aa\", \"m2\": \"aaa\"}\n        att[1].attributes = {\"m1\": \"bb\", \"m2\": \"bbb\"}\n        att[2].attributes = {\"m1\": \"cc\", \"m2\": \"ccc\"}\n        att[3].attributes = {\"m1\": \"dd\", \"m2\": \"ddd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_class_and_metas_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\"), StringVariable(\"m2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")], metas)\n        M = np.array([[\"aa\", \"aaa\"], [\"bb\", \"bbb\"],\n                      [\"cc\", \"ccc\"], [\"dd\", \"ddd\"]])\n        table = Table(domain, np.arange(8).reshape((4, 2)), np.arange(1, 5), M)\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"cls\": \"1\", \"m1\": \"aa\", \"m2\": \"aaa\"}\n        att[1].attributes = {\"cls\": \"2\", \"m1\": \"bb\", \"m2\": \"bbb\"}\n        att[2].attributes = {\"cls\": \"3\", \"m1\": \"cc\", \"m2\": \"ccc\"}\n        att[3].attributes = {\"cls\": \"4\", \"m1\": \"dd\", \"m2\": \"ddd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_attributes_of_attributes_discrete_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"a\", \"attr2\": \"aa\"}\n        attrs[1].attributes = {\"attr1\": \"b\", \"attr2\": \"bb\"}\n        domain = Domain(attrs)\n        table = Table(domain, np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        metas = [StringVariable(\"Feature name\"),\n                 DiscreteVariable(\"attr1\", values=(\"a\", \"b\")),\n                 DiscreteVariable(\"attr2\", values=(\"aa\", \"bb\"))]\n        domain = Domain(att, metas=metas)\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\", 0.0, 0.0]], dtype=object))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"a\", \"attr2\": \"aa\"})\n\n    def test_transpose_attributes_of_attributes_continuous_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"1.1\", \"attr2\": \"1.3\"}\n        attrs[1].attributes = {\"attr1\": \"2.2\", \"attr2\": \"2.3\"}\n        domain = Domain(attrs)\n        table = Table(domain, np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        metas = [StringVariable(\"Feature name\"), ContinuousVariable(\"attr1\"),\n                 ContinuousVariable(\"attr2\")]\n        domain = Domain(att, metas=metas)\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\", 1.1, 1.3]], dtype=object))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"1.1\", \"attr2\": \"1.3\"})\n\n    def test_transpose_attributes_of_attributes_missings_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"a\", \"attr2\": \"aa\"}\n        attrs[1].attributes = {\"attr1\": \"b\"}\n        domain = Domain(attrs)\n        table = Table(domain, np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"0\"), ContinuousVariable(\"2\"),\n               ContinuousVariable(\"4\"), ContinuousVariable(\"6\")]\n        metas = [StringVariable(\"Feature name\"),\n                 DiscreteVariable(\"attr1\", values=(\"b\",))]\n        domain = Domain(att, metas=metas)\n        result = Table(domain, np.array([[1, 3, 5, 7]]),\n                       metas=np.array([[\"c2\", 0.0]], dtype=object))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c1\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"2\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"a\", \"attr2\": \"aa\"})\n\n    def test_transpose_class_metas_attributes_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"a1\", \"attr2\": \"aa1\"}\n        attrs[1].attributes = {\"attr1\": \"b1\", \"attr2\": \"bb1\"}\n        metas = [StringVariable(\"m1\"), StringVariable(\"m2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")], metas)\n        M = np.array([[\"aa\", \"aaa\"], [\"bb\", \"bbb\"],\n                      [\"cc\", \"ccc\"], [\"dd\", \"ddd\"]])\n        table = Table(domain, np.arange(8).reshape((4, 2)), np.arange(1, 5), M)\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"cls\": \"1\", \"m1\": \"aa\", \"m2\": \"aaa\"}\n        att[1].attributes = {\"cls\": \"2\", \"m1\": \"bb\", \"m2\": \"bbb\"}\n        att[2].attributes = {\"cls\": \"3\", \"m1\": \"cc\", \"m2\": \"ccc\"}\n        att[3].attributes = {\"cls\": \"4\", \"m1\": \"dd\", \"m2\": \"ddd\"}\n        metas = [StringVariable(\"Feature name\"),\n                 DiscreteVariable(\"attr1\", values=(\"a1\", \"b1\")),\n                 DiscreteVariable(\"attr2\", values=(\"aa1\", \"bb1\"))]\n        domain = Domain(att, metas=metas)\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\", 0.0, 0.0]], dtype=object))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"a1\", \"attr2\": \"aa1\"})\n\n    def _compare_tables(self, table1, table2):\n        self.assertEqual(table1.n_rows, table2.n_rows)\n        np.testing.assert_array_equal(table1.X, table2.X)\n        np.testing.assert_array_equal(table1.Y, table2.Y)\n        np.testing.assert_array_equal(table1.metas.astype(str),\n                                      table2.metas.astype(str))\n        np.testing.assert_array_equal(table1.W, table2.W)\n\n        self.assertEqual([(type(x), x.name, x.attributes)\n                          for x in table1.domain.attributes],\n                         [(type(x), x.name, x.attributes)\n                          for x in table2.domain.attributes])\n        self.assertEqual([(type(x), x.name, x.attributes)\n                          for x in table1.domain.class_vars],\n                         [(type(x), x.name, x.attributes)\n                          for x in table2.domain.class_vars])\n        self.assertEqual([(type(x), x.name, x.attributes)\n                          for x in table1.domain.metas],\n                         [(type(x), x.name, x.attributes)\n                          for x in table2.domain.metas])\n\n\nclass SparseCV:\n    def __call__(self, data):\n        return sp.csr_matrix((len(data), 1))\n\n\nclass TestTableSparseDense(unittest.TestCase):\n    def setUp(self):\n        self.iris = Table('iris')\n\n    def test_sparse_dense_transformation(self):\n        iris = Table('iris')\n        iris_sparse = iris.to_sparse(sparse_attributes=True)\n        self.assertTrue(sp.issparse(iris_sparse.X))\n        self.assertFalse(sp.issparse(iris_sparse.Y))\n        self.assertFalse(sp.issparse(iris_sparse.metas))\n\n        iris_sparse = iris.to_sparse(sparse_attributes=True, sparse_class=True)\n        self.assertTrue(sp.issparse(iris_sparse.X))\n        self.assertFalse(sp.issparse(iris_sparse.Y))\n        self.assertFalse(sp.issparse(iris_sparse.metas))\n\n        dense_iris = iris_sparse.to_dense()\n        self.assertFalse(sp.issparse(dense_iris.X))\n        self.assertFalse(sp.issparse(dense_iris.Y))\n        self.assertFalse(sp.issparse(dense_iris.metas))\n\n    def test_from_table_add_one_sparse_column(self):\n        # add one sparse feature, should remain dense\n        domain = self.iris.domain.copy()\n        domain.attributes += (\n            ContinuousVariable('S1', compute_value=SparseCV(), sparse=True),\n        )\n        d = self.iris.transform(domain)\n        self.assertFalse(sp.issparse(d.X))\n\n        # try with indices that are not Ellipsis\n        d = Table.from_table(domain, self.iris, row_indices=[0, 1, 2])\n        np.testing.assert_array_equal(\n            d.X,\n            [[5.1, 3.5, 1.4, 0.2, 0],\n             [4.9, 3.0, 1.4, 0.2, 0],\n             [4.7, 3.2, 1.3, 0.2, 0]]\n        )\n        self.assertFalse(sp.issparse(d.X))\n\n    def test_from_table_add_lots_of_sparse_columns(self):\n        n_attrs = len(self.iris.domain.attributes)\n\n        # add 2*n_attrs+1 sparse feature, should became sparse\n        domain = self.iris.domain.copy()\n        domain.attributes += tuple(\n            ContinuousVariable('S' + str(i), compute_value=SparseCV(), sparse=True)\n            for i in range(2*n_attrs + 1)\n        )\n        d = self.iris.transform(domain)\n        self.assertTrue(sp.issparse(d.X))\n\n    def test_from_table_replace_attrs_with_sparse(self):\n        # replace attrs with a sparse feature, should became sparse\n        domain = self.iris.domain.copy()\n        domain.attributes = (\n            ContinuousVariable('S1', compute_value=SparseCV(), sparse=True),\n        )\n        d = self.iris.transform(domain)\n        self.assertTrue(sp.issparse(d.X))\n\n    def test_from_table_sparse_metas(self):\n        # replace metas with a sparse feature, should became sparse\n        domain = self.iris.domain.copy()\n        domain._metas = (\n            ContinuousVariable('S1', compute_value=SparseCV(), sparse=True),\n        )\n        d = self.iris.transform(domain)\n        self.assertTrue(sp.issparse(d.metas))\n\n    def test_from_table_sparse_metas_with_strings(self):\n        # replace metas with text and 100 sparse features, should be dense\n        domain = self.iris.domain.copy()\n        domain._metas = (StringVariable('text'),) + tuple(\n            ContinuousVariable('S' + str(i), compute_value=SparseCV(), sparse=True)\n            for i in range(100)\n        )\n        d = self.iris.transform(domain)\n        self.assertFalse(sp.issparse(d.metas))\n\n\nclass ConcurrencyTests(unittest.TestCase):\n\n    def test_from_table_non_blocking(self):\n        iris = Table(\"iris\")[:10]\n\n        def slow_compute_value(d):\n            sleep(0.1)\n            return d.X[:, 0]\n\n        ndom = Domain([ContinuousVariable(\"a\", compute_value=slow_compute_value)])\n\n        def run_from_table():\n            Table.from_table(ndom, iris)\n\n        start = time()\n\n        threads = []\n        for _ in range(10):\n            thread = Thread(target=run_from_table)\n            thread.start()\n            threads.append(thread)\n        for t in threads:\n            t.join()\n\n        # if from_table was blocking these threads would need at least 0.1*10s\n        duration = time() - start\n        self.assertLess(duration, 0.5)\n\n\nclass PreprocessComputeValue:\n\n    def __init__(self, domain, callback):\n        self.domain = domain\n        self.callback = callback\n\n    def __call__(self, data_):\n        if self.callback:\n            self.callback(data_)\n        transformed = data_.transform(self.domain)\n        return transformed.X[:, 0] * 2\n\n\nclass PreprocessShared:\n\n    def __init__(self, domain, callback):\n        self.domain = domain\n        self.callback = callback\n\n    def __call__(self, data_):\n        if self.callback:\n            self.callback(data_)\n        transformed = data_.transform(self.domain)\n        return transformed.X * 2\n\n\nclass PreprocessSharedComputeValue(SharedComputeValue):\n\n    def __init__(self, col, callback, shared):\n        super().__init__(compute_shared=shared)\n        self.col = col\n        self.callback = callback\n\n    # pylint: disable=arguments-differ\n    def compute(self, data_, shared_data):\n        if self.callback:\n            self.callback(data_)\n        return shared_data[:, self.col]\n\n\ndef preprocess_domain_single(domain, callback):\n    \"\"\" Preprocess domain with single-source compute values.\n    \"\"\"\n    return Domain([\n        ContinuousVariable(name=at.name,\n                           compute_value=PreprocessComputeValue(Domain([at]), callback))\n        for at in domain.attributes])\n\n\ndef preprocess_domain_shared(domain, callback, callback_shared):\n    \"\"\" Preprocess domain with shared compute values.\n    \"\"\"\n    shared = PreprocessShared(domain, callback_shared)\n    return Domain([\n        ContinuousVariable(name=at.name,\n                           compute_value=PreprocessSharedComputeValue(i, callback, shared))\n        for i, at in enumerate(domain.attributes)])\n\n\ndef preprocess_domain_single_stupid(domain, callback):\n    \"\"\" Preprocess domain with single-source compute values with stupid\n    implementation: before applying it, instead of transforming just one column\n    into the input domain, do a needless transform of the whole domain.\n    \"\"\"\n    return Domain([\n        ContinuousVariable(name=at.name,\n                           compute_value=PreprocessComputeValue(domain, callback))\n        for at in domain.attributes])\n\n\nclass EfficientTransformTests(unittest.TestCase):\n\n    def setUp(self):\n        self.iris = Table(\"iris\")[:10]\n\n    def test_simple(self):\n        call_cv = Mock()\n        d1 = preprocess_domain_single(self.iris.domain, call_cv)\n        t = self.iris.transform(d1)\n        self.assertEqual(4, call_cv.call_count)\n        np.testing.assert_equal(t.X, self.iris.X * 2)\n\n    def test_shared(self):\n        call_cv = Mock()\n        call_shared = Mock()\n        d1 = preprocess_domain_shared(self.iris.domain, call_cv, call_shared)\n        t = self.iris.transform(d1)\n        self.assertEqual(4, call_cv.call_count)\n        self.assertEqual(1, call_shared.call_count)\n        np.testing.assert_equal(t.X, self.iris.X * 2)\n\n    def test_simple_simple_shared(self):\n        call_cv = Mock()\n        d1 = preprocess_domain_single(self.iris.domain, call_cv)\n        d2 = preprocess_domain_single(d1, call_cv)\n        call_shared = Mock()\n        d3 = preprocess_domain_shared(d2, call_cv, call_shared)\n        t = self.iris.transform(d3)\n        self.assertEqual(1, call_shared.call_count)\n        self.assertEqual(12, call_cv.call_count)\n        np.testing.assert_equal(t.X, self.iris.X * 2**3)\n\n    def test_simple_simple_shared_simple(self):\n        call_cv = Mock()\n        d1 = preprocess_domain_single(self.iris.domain, call_cv)\n        d2 = preprocess_domain_single(d1, call_cv)\n        call_shared = Mock()\n        d3 = preprocess_domain_shared(d2, call_cv, call_shared)\n        d4 = preprocess_domain_single(d3, call_cv)\n        t = self.iris.transform(d4)\n        self.assertEqual(1, call_shared.call_count)\n        self.assertEqual(16, call_cv.call_count)\n        np.testing.assert_equal(t.X, self.iris.X * 2**4)\n\n    def test_simple_simple_shared_simple_shared_simple(self):\n        call_cv = Mock()\n        d1 = preprocess_domain_single(self.iris.domain, call_cv)\n        d2 = preprocess_domain_single(d1, call_cv)\n        call_shared = Mock()\n        d3 = preprocess_domain_shared(d2, call_cv, call_shared)\n        d4 = preprocess_domain_single(d3, call_cv)\n        d5 = preprocess_domain_shared(d4, call_cv, call_shared)\n        d6 = preprocess_domain_single(d5, call_cv)\n        t = self.iris.transform(d6)\n        self.assertEqual(2, call_shared.call_count)\n        self.assertEqual(24, call_cv.call_count)\n        np.testing.assert_equal(t.X, self.iris.X * 2**6)\n\n    def test_simple_simple_stupid(self):\n        call_cv = Mock()\n        d1 = preprocess_domain_single_stupid(self.iris.domain, call_cv)\n        d2 = preprocess_domain_single_stupid(d1, call_cv)\n        t = self.iris.transform(d2)\n        self.assertEqual(8, call_cv.call_count)\n        np.testing.assert_equal(t.X[:, 0], self.iris.X[:, 0] * 4)\n\n\nif __name__ == \"__main__\":\n    unittest.main()\n",
            "header": {
                "file": {
                    "path": "Orange/tests/test_table.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "ddfa7ea3a",
                "new_commit_hash": "3a0975c8a",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/Orange/tests/test_table.py"
            },
            "plus_file": {
                "path": "b/Orange/tests/test_table.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 3,
                            "length": 6
                        },
                        "new_range": {
                            "start": 3,
                            "length": 7
                        },
                        "section": ""
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "import copy",
                                "type": "context"
                            },
                            {
                                "content": "import os",
                                "type": "context"
                            },
                            {
                                "content": "import pickle",
                                "type": "added"
                            },
                            {
                                "content": "import random",
                                "type": "context"
                            },
                            {
                                "content": "import unittest",
                                "type": "context"
                            },
                            {
                                "content": "import warnings",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [],
                    "added_entities": [
                        {
                            "file_name": "Orange/tests/test_table.py",
                            "type": "import",
                            "name": "pickle",
                            "content": "import pickle",
                            "ast_type_str": "Import",
                            "start_lineno": 6,
                            "end_lineno": 6,
                            "parent": null
                        }
                    ],
                    "deleted_entities": []
                },
                {
                    "descriptor": {
                        "old_range": {
                            "start": 591,
                            "length": 8
                        },
                        "new_range": {
                            "start": 592,
                            "length": 6
                        },
                        "section": "class TableTestCase(unittest.TestCase):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "        self.assertEqual(len(new.ids), 300)",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "    def test_pickle(self):",
                                "type": "context"
                            },
                            {
                                "content": "        import pickle",
                                "type": "deleted"
                            },
                            {
                                "content": "",
                                "type": "deleted"
                            },
                            {
                                "content": "        d = data.Table(\"zoo\")",
                                "type": "context"
                            },
                            {
                                "content": "        s = pickle.dumps(d)",
                                "type": "context"
                            },
                            {
                                "content": "        d2 = pickle.loads(s)",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "Orange/tests/test_table.py",
                            "type": "method",
                            "name": "TableTestCase.test_pickle",
                            "content": "class TableTestCase(unittest.TestCase):\n    def setUp(self):\n        data.table.dataset_dirs.append(test_dirname())\n\n    def tearDown(self):\n        data.table.dataset_dirs.remove(test_dirname())\n\n    def test_indexing_class(self):\n        d = data.Table(\"datasets/test1\")\n        self.assertEqual([e.get_class() for e in d], [\"t\", \"t\", \"f\"])\n        cind = len(d.domain.variables) - 1\n        self.assertEqual([e[cind] for e in d], [\"t\", \"t\", \"f\"])\n        self.assertEqual([e[\"d\"] for e in d], [\"t\", \"t\", \"f\"])\n        cvar = d.domain.class_var\n        self.assertEqual([e[cvar] for e in d], [\"t\", \"t\", \"f\"])\n\n    def test_filename(self):\n        dir = data.table.get_sample_datasets_dir()\n        d = data.Table(\"iris\")\n        self.assertEqual(d.__file__, os.path.join(dir, \"iris.tab\"))\n\n        d = data.Table(\"datasets/test2.tab\")\n        self.assertTrue(d.__file__.endswith(\"test2.tab\"))  # platform dependent\n\n    def test_indexing(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            # regular, discrete\n            varc = d.domain[\"c\"]\n            self.assertEqual(d[0, 1], \"0\")\n            self.assertEqual(d[0, varc], \"0\")\n            self.assertEqual(d[0, \"c\"], \"0\")\n            self.assertEqual(d[0][1], \"0\")\n            self.assertEqual(d[0][varc], \"0\")\n            self.assertEqual(d[0][\"c\"], \"0\")\n            self.assertEqual(d[np.int_(0), np.int_(1)], \"0\")\n            self.assertEqual(d[np.int_(0)][np.int_(1)], \"0\")\n\n            # regular, continuous\n            varb = d.domain[\"b\"]\n            self.assertEqual(d[0, 0], 0)\n            self.assertEqual(d[0, varb], 0)\n            self.assertEqual(d[0, \"b\"], 0)\n            self.assertEqual(d[0][0], 0)\n            self.assertEqual(d[0][varb], 0)\n            self.assertEqual(d[0][\"b\"], 0)\n            self.assertEqual(d[np.int_(0), np.int_(0)], 0)\n            self.assertEqual(d[np.int_(0)][np.int_(0)], 0)\n\n            # negative\n            varb = d.domain[\"b\"]\n            self.assertEqual(d[-2, 0], 3.333)\n            self.assertEqual(d[-2, varb], 3.333)\n            self.assertEqual(d[-2, \"b\"], 3.333)\n            self.assertEqual(d[-2][0], 3.333)\n            self.assertEqual(d[-2][varb], 3.333)\n            self.assertEqual(d[-2][\"b\"], 3.333)\n            self.assertEqual(d[np.int_(-2), np.int_(0)], 3.333)\n            self.assertEqual(d[np.int_(-2)][np.int_(0)], 3.333)\n\n            # meta, discrete\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n            self.assertEqual(d[0, metaa], \"A\")\n            self.assertEqual(d[0, vara], \"A\")\n            self.assertEqual(d[0, \"a\"], \"A\")\n            self.assertEqual(d[0][metaa], \"A\")\n            self.assertEqual(d[0][vara], \"A\")\n            self.assertEqual(d[0][\"a\"], \"A\")\n            self.assertEqual(d[np.int_(0), np.int_(metaa)], \"A\")\n            self.assertEqual(d[np.int_(0)][np.int_(metaa)], \"A\")\n\n            # meta, string\n            vare = d.domain[\"e\"]\n            metae = d.domain.index(\"e\")\n            self.assertEqual(d[0, metae], \"i\")\n            self.assertEqual(d[0, vare], \"i\")\n            self.assertEqual(d[0, \"e\"], \"i\")\n            self.assertEqual(d[0][metae], \"i\")\n            self.assertEqual(d[0][vare], \"i\")\n            self.assertEqual(d[0][\"e\"], \"i\")\n            self.assertEqual(d[np.int_(0), np.int_(metae)], \"i\")\n            self.assertEqual(d[np.int_(0)][np.int_(metae)], \"i\")\n\n    def test_indexing_example(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            e = d[0]\n\n            # regular, discrete\n            varc = d.domain[\"c\"]\n            self.assertEqual(e[1], \"0\")\n            self.assertEqual(e[varc], \"0\")\n            self.assertEqual(e[\"c\"], \"0\")\n            self.assertEqual(e[np.int_(1)], \"0\")\n\n            # regular, continuous\n            varb = d.domain[\"b\"]\n            self.assertEqual(e[0], 0)\n            self.assertEqual(e[varb], 0)\n            self.assertEqual(e[\"b\"], 0)\n            self.assertEqual(e[np.int_(0)], 0)\n\n            # meta, discrete\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n            self.assertEqual(e[metaa], \"A\")\n            self.assertEqual(e[vara], \"A\")\n            self.assertEqual(e[\"a\"], \"A\")\n            self.assertEqual(e[np.int_(metaa)], \"A\")\n\n            # meta, string\n            vare = d.domain[\"e\"]\n            metae = d.domain.index(\"e\")\n            self.assertEqual(e[metae], \"i\")\n            self.assertEqual(e[vare], \"i\")\n            self.assertEqual(e[\"e\"], \"i\")\n            self.assertEqual(e[np.int_(metae)], \"i\")\n\n    def test_indexing_assign_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            # meta\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, \"a\"] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][\"a\"] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, vara] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][vara] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, metaa] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][metaa] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, np.int_(metaa)] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][np.int_(metaa)] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            # regular\n            varb = d.domain[\"b\"]\n\n            self.assertEqual(d[0, \"b\"], 0)\n            with d.unlocked():\n                d[0, \"b\"] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][\"b\"] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, varb] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][varb] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, 0] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][0] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, np.int_(0)] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][np.int_(0)] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n    def test_indexing_assign_example(self):\n        def almost_equal_list(s, t):\n            for e, f in zip(s, t):\n                self.assertAlmostEqual(e, f)\n\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            self.assertFalse(isnan(d[0, \"a\"]))\n            with d.unlocked():\n                d[0] = [\"3.14\", \"1\", \"f\"]\n            almost_equal_list(d[0].values(), [3.14, \"1\", \"f\"])\n            self.assertTrue(isnan(d[0, \"a\"]))\n\n            with d.unlocked():\n                d[0] = [3.15, 1, \"t\"]\n            almost_equal_list(d[0].values(), [3.15, \"0\", \"t\"])\n\n            with d.unlocked():\n                d[np.int_(0)] = [3.15, 2, \"f\"]\n            almost_equal_list(d[0].values(), [3.15, 2, \"f\"])\n\n            with d.unlocked(), self.assertRaises(ValueError):\n                d[0] = [\"3.14\", \"1\"]\n\n            with d.unlocked(), self.assertRaises(ValueError):\n                d[np.int_(0)] = [\"3.14\", \"1\"]\n\n            ex = data.Instance(d.domain, [\"3.16\", \"1\", \"f\"])\n            with d.unlocked():\n                d[0] = ex\n            almost_equal_list(d[0].values(), [3.16, \"1\", \"f\"])\n\n            ex = data.Instance(d.domain, [\"3.16\", 2, \"t\"])\n            with d.unlocked():\n                d[np.int_(0)] = ex\n            almost_equal_list(d[0].values(), [3.16, 2, \"t\"])\n\n            ex = data.Instance(d.domain, [\"3.16\", \"1\", \"f\"])\n            ex[\"e\"] = \"mmmapp\"\n            with d.unlocked():\n                d[0] = ex\n            almost_equal_list(d[0].values(), [3.16, \"1\", \"f\"])\n            self.assertEqual(d[0, \"e\"], \"mmmapp\")\n\n    def test_slice(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            x = d[:3]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [0, 1.1, 2.22])\n\n            x = d[2:5]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.22, 2.23, 2.24])\n\n            x = d[4:1:-1]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.24, 2.23, 2.22])\n\n            x = d[-3:]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.26, 3.333, Unknown])\n\n    def test_assign_slice_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            with d.unlocked():\n                d[2:5, 0] = 42\n            self.assertEqual([e[0] for e in d],\n                             [0, 1.1, 42, 42, 42, 2.25, 2.26, 3.333, Unknown])\n            with d.unlocked():\n                d[:3, \"b\"] = 43\n            self.assertEqual([e[0] for e in d],\n                             [43, 43, 43, 42, 42, 2.25, 2.26, 3.333, None])\n            with d.unlocked():\n                d[-2:, d.domain[0]] = 44\n            self.assertEqual([e[0] for e in d],\n                             [43, 43, 43, 42, 42, 2.25, 2.26, 44, 44])\n\n            with d.unlocked():\n                d[2:5, \"a\"] = \"A\"\n            self.assertEqual([e[\"a\"] for e in d], list(\"ABAAACCDE\"))\n\n    def test_multiple_indices(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            with self.assertRaises(IndexError):\n                x = d[2, 5, 1]\n\n            with self.assertRaises(IndexError):\n                x = d[(2, 5, 1)]\n\n            x = d[[2, 5, 1]]\n            self.assertEqual([e[0] for e in x], [2.22, 2.25, 1.1])\n\n    def test_assign_multiple_indices_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            with d.unlocked():\n                d[1:4, \"b\"] = 42\n            self.assertEqual([e[0] for e in d],\n                             [0, 42, 42, 42, 2.24, 2.25, 2.26, 3.333, None])\n\n            with d.unlocked():\n                d[range(5, 2, -1), \"b\"] = None\n            self.assertEqual([e[d.domain[0]] for e in d],\n                             [0, 42, 42, None, \"?\", \"\", 2.26, 3.333, None])\n\n    def test_set_multiple_indices_example(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            vals = [e[0] for e in d]\n            with d.unlocked():\n                d[[1, 2, 5]] = [42, None, None]\n            vals[1] = vals[2] = vals[5] = 42\n            self.assertEqual([e[0] for e in d], vals)\n\n    def test_bool(self):\n        d = data.Table(\"iris\")\n        self.assertTrue(d)\n\n        d = data.Table(\"datasets/test3\")\n        self.assertFalse(d)\n\n        d = data.Table(\"iris\")\n        self.assertTrue(d)\n\n    def test_checksum(self):\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d[42, 3] = 0\n        crc1 = d.checksum(False)\n\n        with d.unlocked():\n            d[42, 3] = 1\n        crc2 = d.checksum(False)\n        self.assertNotEqual(crc1, crc2)\n\n        with d.unlocked():\n            d[42, 3] = 0\n        crc3 = d.checksum(False)\n        self.assertEqual(crc1, crc3)\n\n        _ = d[42, \"name\"]\n        with d.unlocked():\n            d[42, \"name\"] = \"non-animal\"\n        crc4 = d.checksum(False)\n        self.assertEqual(crc1, crc4)\n        crc4 = d.checksum(True)\n        crc5 = d.checksum(1)\n        crc6 = d.checksum(False)\n        self.assertNotEqual(crc1, crc4)\n        self.assertNotEqual(crc1, crc5)\n        self.assertEqual(crc1, crc6)\n\n    def test_total_weight(self):\n        d = data.Table(\"zoo\")\n        self.assertEqual(d.total_weight(), len(d))\n\n        with d.unlocked():\n            d.set_weights(0)\n            d[0].weight = 0.1\n            d[10].weight = 0.2\n            d[-1].weight = 0.3\n        self.assertAlmostEqual(d.total_weight(), 0.6)\n\n    def test_has_missing(self):\n        d = data.Table(\"zoo\")\n        self.assertFalse(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n        with d.unlocked():\n            d[10, 3] = \"?\"\n        self.assertTrue(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n        with d.unlocked():\n            d[10].set_class(\"?\")\n        self.assertTrue(d.has_missing())\n        self.assertTrue(d.has_missing_class())\n\n        with d.unlocked():\n            d = data.Table(\"datasets/test3\")\n        self.assertFalse(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n    def test_shuffle(self):\n        d = data.Table(\"zoo\")\n        crc = d.checksum()\n        names = set(str(x[\"name\"]) for x in d)\n\n        with d.unlocked():\n            d.shuffle()\n        self.assertNotEqual(crc, d.checksum())\n        self.assertSetEqual(names, set(str(x[\"name\"]) for x in d))\n        crc2 = d.checksum()\n\n        x = d[2:10]\n        crcx = x.checksum()\n        with d.unlocked():\n            d.shuffle()\n        self.assertNotEqual(crc2, d.checksum())\n        self.assertEqual(crcx, x.checksum())\n\n        crc2 = d.checksum()\n        with x.unlocked():\n            x.shuffle()\n        self.assertNotEqual(crcx, x.checksum())\n        self.assertEqual(crc2, d.checksum())\n\n    @staticmethod\n    def not_less_ex(ex1, ex2):\n        for v1, v2 in zip(ex1, ex2):\n            if v1 != v2:\n                return v1 < v2\n        return True\n\n    @staticmethod\n    def sorted(d):\n        for i in range(1, len(d)):\n            if not TableTestCase.not_less_ex(d[i - 1], d[i]):\n                return False\n        return True\n\n    @staticmethod\n    def not_less_ex_ord(ex1, ex2, ord):\n        for a in ord:\n            if ex1[a] != ex2[a]:\n                return ex1[a] < ex2[a]\n        return True\n\n    @staticmethod\n    def sorted_ord(d, ord):\n        for i in range(1, len(d)):\n            if not TableTestCase.not_less_ex_ord(d[i - 1], d[i], ord):\n                return False\n        return True\n\n    def test_copy(self):\n        t = data.Table.from_numpy(\n            None, np.zeros((5, 3)), np.arange(5), np.zeros((5, 3)))\n\n        copy = t.copy()\n        self.assertTrue(np.all(t.X == copy.X))\n        self.assertTrue(np.all(t.Y == copy.Y))\n        self.assertTrue(np.all(t.metas == copy.metas))\n        with copy.unlocked():\n            copy[0] = [1, 1, 1, 1]\n        self.assertFalse(np.all(t.X == copy.X))\n        self.assertFalse(np.all(t.Y == copy.Y))\n        self.assertFalse(np.all(t.metas == copy.metas))\n\n    def test_copy_sparse(self):\n        t = data.Table('iris').to_sparse()\n        copy = t.copy()\n\n        self.assertEqual((t.X != copy.X).nnz, 0)      # sparse matrices match by content\n        np.testing.assert_equal(t.Y, copy.Y)\n        np.testing.assert_equal(t.metas, copy.metas)\n\n        self.assertNotEqual(id(t.X), id(copy.X))\n        self.assertNotEqual(id(t._Y), id(copy._Y))\n        self.assertNotEqual(id(t.metas), id(copy.metas))\n\n        # ensure that copied sparse arrays do not share data\n        with t.unlocked():\n            t.X[0, 0] = 42\n        self.assertEqual(copy.X[0, 0], 5.1)\n\n    def test_concatenate(self):\n        d1 = data.Domain(\n            [data.ContinuousVariable(n) for n in \"abc\"],\n            data.DiscreteVariable(\"y\", values=\"ABC\"),\n            [data.StringVariable(n) for n in [\"m1\", \"m2\"]],\n        )\n        x1 = np.arange(6).reshape(2, 3)\n        y1 = np.array([0, 1])\n        m1 = np.array([[\"foo\", \"bar\"], [\"baz\", \"qux\"]])\n        w1 = np.random.random((2,))\n        t1 = data.Table.from_numpy(d1, x1, y1, m1, w1)\n        t1.ids = ids1 = np.array([100, 101])\n        t1.attributes = {\"a\": 42, \"c\": 43}\n\n        x2 = np.arange(6, 15).reshape(3, 3)\n        y2 = np.array([1, 2, 0])\n        m2 = np.array([[\"a\", \"b\"], [\"c\", \"d\"], [\"e\", \"f\"]])\n        w2 = np.random.random((3,))\n        t2 = data.Table.from_numpy(d1, x2, y2, m2, w2)\n        t2.ids = ids2 = np.array([102, 103, 104])\n        t2.name = \"t2\"\n        t2.attributes = {\"a\": 44, \"b\": 45}\n\n        x3 = np.arange(15, 27).reshape(4, 3)\n        y3 = np.array([2, 1, 1, 0])\n        m3 = np.array([[\"g\", \"h\"], [\"i\", \"j\"], [\"k\", \"l\"], [\"m\", \"n\"]])\n        w3 = np.random.random((4,))\n        t3 = data.Table.from_numpy(d1, x3, y3, m3, w3)\n        t3.ids = ids3 = np.array([102, 103, 104, 105])\n        t3.name = \"t3\"\n\n        t1b = data.Table.concatenate((t1,))\n        self.assertEqual(t1b.domain, t1.domain)\n        np.testing.assert_almost_equal(t1b.X, x1)\n        np.testing.assert_almost_equal(t1b.Y, y1)\n        self.assertEqual(list(t1b.metas.flatten()),\n                         list(m1.flatten()))\n        np.testing.assert_almost_equal(t1b.W, w1)\n        np.testing.assert_almost_equal(t1b.ids, ids1)\n        self.assertEqual(t1b.name, t1.name)\n        self.assertEqual(t1b.attributes, {\"a\": 42, \"c\": 43})\n\n        t12 = data.Table.concatenate((t1, t2))\n        self.assertEqual(t12.domain, t1.domain)\n        np.testing.assert_almost_equal(t12.X, np.vstack((x1, x2)))\n        np.testing.assert_almost_equal(t12.Y, np.hstack((y1, y2)))\n        self.assertEqual(list(t12.metas.flatten()),\n                         list(np.vstack((m1, m2)).flatten()))\n        np.testing.assert_almost_equal(t12.W, np.hstack((w1, w2)))\n        np.testing.assert_almost_equal(t12.ids, np.hstack((ids1, ids2)))\n        self.assertEqual(t12.name, \"t2\")\n        self.assertEqual(t12.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n        t123 = data.Table.concatenate((t1, t2, t3))\n        self.assertEqual(t123.domain, t1.domain)\n        np.testing.assert_almost_equal(t123.X, np.vstack((x1, x2, x3)))\n        np.testing.assert_almost_equal(t123.Y, np.hstack((y1, y2, y3)))\n        self.assertEqual(list(t123.metas.flatten()),\n                         list(np.vstack((m1, m2, m3)).flatten()))\n        np.testing.assert_almost_equal(t123.W, np.hstack((w1, w2, w3)))\n        np.testing.assert_almost_equal(t123.ids, np.hstack((ids1, ids2, ids3)))\n        self.assertEqual(t123.name, \"t2\")\n        self.assertEqual(t123.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n        with t2.unlocked(t2.Y):\n            t2.Y = np.atleast_2d(t2.Y).T\n        t12 = data.Table.concatenate((t1, t2))\n        self.assertEqual(t12.domain, t1.domain)\n        np.testing.assert_almost_equal(t12.X, np.vstack((x1, x2)))\n        np.testing.assert_almost_equal(t12.Y, np.hstack((y1, y2)))\n        self.assertEqual(list(t12.metas.flatten()),\n                         list(np.vstack((m1, m2)).flatten()))\n        np.testing.assert_almost_equal(t12.W, np.hstack((w1, w2)))\n        np.testing.assert_almost_equal(t12.ids, np.hstack((ids1, ids2)))\n        self.assertEqual(t12.name, \"t2\")\n        self.assertEqual(t12.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n    def test_concatenate_exceptions(self):\n        zoo = data.Table(\"zoo\")\n        iris = data.Table(\"iris\")\n\n        self.assertRaises(ValueError, data.Table.concatenate, [])\n        self.assertRaises(ValueError, data.Table.concatenate, [zoo, iris])\n\n    def test_concatenate_sparse(self):\n        iris = Table(\"iris\")\n        with iris.unlocked():\n            iris.X = sp.csc_matrix(iris.X)\n        new = Table.concatenate([iris, iris])\n        self.assertEqual(len(new), 300)\n        self.assertTrue(sp.issparse(new.X), \"Concatenated X is not sparse.\")\n        self.assertFalse(sp.issparse(new.Y), \"Concatenated Y is not dense.\")\n        self.assertFalse(sp.issparse(new.metas), \"Concatenated metas is not dense.\")\n        self.assertEqual(len(new.ids), 300)\n\n    def test_pickle(self):\n        import pickle\n\n        d = data.Table(\"zoo\")\n        s = pickle.dumps(d)\n        d2 = pickle.loads(s)\n        self.assertEqual(d[0], d2[0])\n\n        self.assertEqual(d.checksum(include_metas=False),\n                         d2.checksum(include_metas=False))\n\n        d = data.Table(\"iris\")\n        s = pickle.dumps(d)\n        d2 = pickle.loads(s)\n        self.assertEqual(d[0], d2[0])\n        self.assertEqual(d.checksum(include_metas=False),\n                         d2.checksum(include_metas=False))\n\n    def test_translate_through_slice(self):\n        d = data.Table(\"iris\")\n        dom = data.Domain([\"petal length\", \"sepal length\", \"iris\"],\n                          source=d.domain)\n        d_ref = d[:10, dom.variables]\n        self.assertEqual(d_ref.domain.class_var, d.domain.class_var)\n        self.assertEqual(d_ref[0, \"petal length\"], d[0, \"petal length\"])\n        self.assertEqual(d_ref[0, \"sepal length\"], d[0, \"sepal length\"])\n        self.assertEqual(d_ref.X.shape, (10, 2))\n        self.assertEqual(d_ref.Y.shape, (10,))\n\n    def test_saveTab(self):\n        d = data.Table(\"iris\")[:3]\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            for e1, e2 in zip(d, d2):\n                self.assertEqual(e1, e2)\n        finally:\n            os.remove(\"test-save.tab\")\n            os.remove(\"test-save.tab.metadata\")\n\n        dom = data.Domain([data.ContinuousVariable(\"a\")])\n        d = data.Table.from_list(dom, [[i] for i in range(3)])\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            self.assertEqual(len(d.domain.attributes), 1)\n            self.assertEqual(d.domain.class_var, None)\n            for i in range(3):\n                self.assertEqual(d2[i], [i])\n        finally:\n            os.remove(\"test-save.tab\")\n\n        dom = data.Domain([data.ContinuousVariable(\"a\")], None)\n        d = data.Table.from_list(dom, [[i] for i in range(3)])\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            self.assertEqual(len(d.domain.attributes), 1)\n            for i in range(3):\n                self.assertEqual(d2[i], [i])\n        finally:\n            os.remove(\"test-save.tab\")\n\n        d = data.Table(\"zoo\")\n        d.save(\"test-zoo.tab\")\n        dd = data.Table(\"test-zoo\")\n        try:\n            self.assertTupleEqual(d.domain.metas, dd.domain.metas,\n                                  msg=\"Meta attributes don't match.\")\n            self.assertTupleEqual(d.domain.variables, dd.domain.variables,\n                                  msg=\"Attributes don't match.\")\n\n            np.testing.assert_almost_equal(d.W, dd.W,\n                                           err_msg=\"Weights don't match.\")\n            for i in range(10):\n                for j in d.domain.variables:\n                    self.assertEqual(d[i][j], dd[i][j])\n        finally:\n            os.remove(\"test-zoo.tab\")\n            os.remove(\"test-zoo.tab.metadata\")\n\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d.set_weights(range(len(d)))\n        d.save(\"test-zoo-weights.tab\")\n        dd = data.Table(\"test-zoo-weights\")\n        try:\n            self.assertTupleEqual(d.domain.metas, dd.domain.metas,\n                                  msg=\"Meta attributes don't match.\")\n            self.assertTupleEqual(d.domain.variables, dd.domain.variables,\n                                  msg=\"Attributes don't match.\")\n\n            np.testing.assert_almost_equal(d.W, dd.W,\n                                           err_msg=\"Weights don't match.\")\n            for i in range(10):\n                for j in d.domain.variables:\n                    self.assertEqual(d[i][j], dd[i][j])\n        finally:\n            os.remove(\"test-zoo-weights.tab\")\n            os.remove(\"test-zoo-weights.tab.metadata\")\n\n    def test_save_pickle(self):\n        table = data.Table(\"iris\")\n        try:\n            table.save(\"iris.pickle\")\n            table2 = data.Table.from_file(\"iris.pickle\")\n            np.testing.assert_almost_equal(table.X, table2.X)\n            np.testing.assert_almost_equal(table.Y, table2.Y)\n            self.assertEqual(table.domain[0], table2.domain[0])\n        finally:\n            os.remove(\"iris.pickle\")\n\n    def test_from_numpy(self):\n        a = np.arange(20, dtype=\"d\").reshape((4, 5)).copy()\n        a[:, -1] = [0, 0, 0, 1]\n        dom = data.Domain([data.ContinuousVariable(x) for x in \"abcd\"],\n                          data.DiscreteVariable(\"e\", values=(\"no\", \"yes\")))\n        table = data.Table(dom, a)\n        with table.unlocked():\n            for i in range(4):\n                self.assertEqual(table[i].get_class(), \"no\" if i < 3 else \"yes\")\n                for j in range(5):\n                    self.assertEqual(a[i, j], table[i, j])\n\n        with table.unlocked(), self.assertRaises(IndexError):\n            table[0, -5] = 5\n\n    def test_filter_is_defined(self):\n        d = data.Table(\"iris\")\n        with d.unlocked():\n            d[1, 4] = Unknown\n        self.assertTrue(isnan(d[1, 4]))\n        with d.unlocked():\n            d[140, 0] = Unknown\n        e = filter.IsDefined()(d)\n        self.assertEqual(len(e), len(d) - 2)\n        self.assertEqual(e[0], d[0])\n        self.assertEqual(e[1], d[2])\n        self.assertEqual(e[147], d[149])\n        self.assertTrue(d.has_missing())\n        self.assertFalse(e.has_missing())\n\n    def test_filter_has_class(self):\n        d = data.Table(\"iris\")\n        with d.unlocked():\n            d[1, 4] = Unknown\n        self.assertTrue(isnan(d[1, 4]))\n        with d.unlocked():\n            d[140, 0] = Unknown\n        e = filter.HasClass()(d)\n        self.assertEqual(len(e), len(d) - 1)\n        self.assertEqual(e[0], d[0])\n        self.assertEqual(e[1], d[2])\n        self.assertEqual(e[148], d[149])\n        self.assertTrue(d.has_missing())\n        self.assertTrue(e.has_missing())\n        self.assertFalse(e.has_missing_class())\n\n    def test_filter_random(self):\n        d = data.Table(\"iris\")\n        e = filter.Random(50)(d)\n        self.assertEqual(len(e), 50)\n        e = filter.Random(50, negate=True)(d)\n        self.assertEqual(len(e), 100)\n        for _ in range(5):\n            e = filter.Random(0.2)(d)\n            self.assertEqual(len(e), 30)\n            bc = np.bincount(np.array(e.Y[:], dtype=int))\n            if min(bc) > 7:\n                break\n        else:\n            self.fail(\"Filter returns too uneven distributions\")\n\n    def test_filter_values_nested(self):\n        d = data.Table(\"iris\")\n        f1 = filter.FilterContinuous(d.columns.sepal_length,\n                                     filter.FilterContinuous.Between,\n                                     min=4.5, max=5.0)\n        f2 = filter.FilterContinuous(d.columns.sepal_width,\n                                     filter.FilterContinuous.Between,\n                                     min=3.1, max=3.4)\n        f3 = filter.FilterDiscrete(d.columns.iris, [0, 1])\n        f = filter.Values([filter.Values([f1, f2], conjunction=False), f3])\n        self.assertEqual(41, len(f(d)))\n\n    def test_filter_string_works_for_numeric_columns(self):\n        var = StringVariable(\"s\")\n        data = Table.from_list(Domain([], metas=[var]),\n                               [[x] for x in range(21)])\n        # 1, 2, 3, ..., 18, 19, 20\n\n        fs = filter.FilterString\n        filters = [\n            ((fs.Greater, \"5\"), dict(rows=4)),\n            # 6, 7, 8, 9\n            ((fs.Between, \"15\", \"2\"), dict(rows=6)),\n            # 15, 16, 17, 18, 19, 2\n            ((fs.Contains, \"2\"), dict(rows=3)),\n            # 2, 12, 20\n        ]\n\n        for args, expected in filters:\n            f = fs(var, *args)\n            filtered_data = filter.Values([f])(data)\n            self.assertEqual(len(filtered_data), expected[\"rows\"],\n                             \"{} returned wrong number of rows\".format(args))\n\n    def test_filter_value_continuous(self):\n        d = data.Table(\"iris\")\n        col = d.X[:, 2]\n\n        v = d.columns\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Between,\n                                    min=4.5, max=5.1)\n\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] >= 4.5))\n        self.assertTrue(np.all(x.X[:, 2] <= 5.1))\n        self.assertEqual(sum((col >= 4.5) * (col <= 5.1)), len(x))\n\n        f.ref = 5.1\n        f.oper = filter.FilterContinuous.Equal\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.NotEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] != 5.1))\n        self.assertEqual(sum(col != 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Less\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] < 5.1))\n        self.assertEqual(sum(col < 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.LessEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] <= 5.1))\n        self.assertEqual(sum(col <= 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Greater\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] > 5.1))\n        self.assertEqual(sum(col > 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] >= 5.1))\n        self.assertEqual(sum(col >= 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Outside\n        f.ref, f.max = 4.5, 5.1\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(e[2] < 4.5 or e[2] > 5.1)\n        self.assertEqual(sum((col < 4.5) + (col > 5.1)), len(x))\n\n        f.oper = filter.FilterContinuous.IsDefined\n        f.ref = f.max = None\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d))\n\n        with d.unlocked():\n            d[:30, v.petal_length] = Unknown\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 30)\n\n    def test_filter_value_continuous_args(self):\n        d = data.Table(\"iris\")\n        col = d.X[:, 2]\n        v = d.columns\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(2,\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"petal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"sepal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        f.column = 2\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"sepal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        f.column = v.petal_length\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=18)\n        f.ref = 5.1\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=18)\n        f.ref = 5.1\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n    def test_valueFilter_discrete(self):\n        d = data.Table(\"zoo\")\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, 3, 4])\n        for e in filter.Values([f])(d):\n            self.assertTrue(e.get_class() in [2, 3, 4])\n\n        f.values = [\"mammal\"]\n        for e in filter.Values([f])(d):\n            self.assertEqual(e.get_class(), \"mammal\")\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, \"mammal\"])\n        for e in filter.Values([f])(d):\n            self.assertTrue(e.get_class() in [2, \"mammal\"])\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, \"martian\"])\n        self.assertRaises(ValueError, d._filter_values, f)\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=(2, data.Table))\n        self.assertRaises(TypeError, d._filter_values, f)\n\n        v = d.columns\n        f = filter.FilterDiscrete(v.hair, values=None)\n        self.assertEqual(len(filter.Values([f])(d)), len(d))\n\n        with d.unlocked():\n            d[:5, v.hair] = Unknown\n        self.assertEqual(len(filter.Values([f])(d)), len(d) - 5)\n\n    def test_valueFilter_string_is_defined(self):\n        d = data.Table(\"datasets/test9.tab\")\n        f = filter.FilterString(-5, filter.FilterString.IsDefined)\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 7)\n\n    def test_valueFilter_discrete_meta_is_defined(self):\n        d = data.Table(\"datasets/test9.tab\")\n        f = filter.FilterDiscrete(-4, None)\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 8)\n\n    def test_valueFilter_string_case_sens(self):\n        d = data.Table(\"zoo\")\n        col = d[:, \"name\"].metas[:, 0]\n\n        f = filter.FilterString(\"name\",\n                                filter.FilterString.Equal, \"girl\")\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 1)\n        self.assertEqual(x[0, \"name\"], \"girl\")\n        self.assertTrue(np.all(x.metas == \"girl\"))\n\n        f.oper = f.NotEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 1)\n        self.assertTrue(np.all(x[:, \"name\"] != \"girl\"))\n\n        f.oper = f.Less\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"girl\"))\n        self.assertTrue(np.all(x.metas < \"girl\"))\n\n        f.oper = f.LessEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col <= \"girl\"))\n        self.assertTrue(np.all(x.metas <= \"girl\"))\n\n        f.oper = f.Greater\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col > \"girl\"))\n        self.assertTrue(np.all(x.metas > \"girl\"))\n\n        f.oper = f.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col >= \"girl\"))\n        self.assertTrue(np.all(x.metas >= \"girl\"))\n\n        f.oper = f.Between\n        f.max = \"lion\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum((col >= \"girl\") * (col <= \"lion\")))\n        self.assertTrue(np.all(x.metas >= \"girl\"))\n        self.assertTrue(np.all(x.metas <= \"lion\"))\n\n        f.oper = f.Outside\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"girl\") + sum(col > \"lion\"))\n        self.assertTrue(np.all((x.metas < \"girl\") + (x.metas > \"lion\")))\n\n        f.oper = f.Contains\n        f.ref = \"ea\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(\"ea\" in e[\"name\"])\n        self.assertEqual(len(x), len([e for e in col if \"ea\" in e]))\n\n        f.oper = f.StartsWith\n        f.ref = \"sea\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).startswith(\"sea\"))\n        self.assertEqual(len(x), len([e for e in col if e.startswith(\"sea\")]))\n\n        f.oper = f.EndsWith\n        f.ref = \"ion\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n        self.assertEqual(len(x), len([e for e in col if e.endswith(\"ion\")]))\n\n    def test_valueFilter_string_case_insens(self):\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d[d[:, \"name\"].metas[:, 0] == \"girl\", \"name\"] = \"GIrl\"\n\n        col = d[:, \"name\"].metas[:, 0]\n\n        f = filter.FilterString(\"name\",\n                                filter.FilterString.Equal, \"giRL\")\n        f.case_sensitive = False\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 1)\n        self.assertEqual(x[0, \"name\"], \"GIrl\")\n        self.assertTrue(np.all(x.metas == \"GIrl\"))\n\n        f.oper = f.NotEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 1)\n        self.assertTrue(np.all(x[:, \"name\"] != \"GIrl\"))\n\n        f.oper = f.Less\n        f.ref = \"CHiCKEN\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"chicken\") - 1)  # girl!\n        self.assertTrue(np.all(x.metas < \"chicken\"))\n\n        f.oper = f.LessEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col <= \"chicken\") - 1)\n        self.assertTrue(np.all(x.metas <= \"chicken\"))\n\n        f.oper = f.Greater\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col > \"chicken\") + 1)\n        for e in x:\n            self.assertGreater(str(e[\"name\"]).lower(), \"chicken\")\n\n        f.oper = f.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col >= \"chicken\") + 1)\n        for e in x:\n            self.assertGreaterEqual(str(e[\"name\"]).lower(), \"chicken\")\n\n        f.oper = f.Between\n        f.max = \"liOn\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum((col >= \"chicken\") * (col <= \"lion\")) + 1)\n        for e in x:\n            self.assertTrue(\"chicken\" <= str(e[\"name\"]).lower() <= \"lion\")\n\n        f.oper = f.Outside\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"chicken\") + sum(col > \"lion\") - 1)\n        self.assertTrue(np.all((x.metas < \"chicken\") + (x.metas > \"lion\")))\n\n        f.oper = f.Contains\n        f.ref = \"iR\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(\"ir\" in str(e[\"name\"]).lower())\n        self.assertEqual(len(x), len([e for e in col if \"ir\" in e]) + 1)\n\n        f.oper = f.StartsWith\n        f.ref = \"GI\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).lower().startswith(\"gi\"))\n        self.assertEqual(len(x),\n                         len([e for e in col if e.lower().startswith(\"gi\")]))\n\n        f.oper = f.EndsWith\n        f.ref = \"ion\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n        self.assertEqual(len(x), len([e for e in col if e.endswith(\"ion\")]))\n\n    def test_valueFilter_regex(self):\n        d = data.Table(\"zoo\")\n        f = filter.FilterRegex(d.domain['name'], '^c...$')\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 7)\n\n    def test_valueFilter_stringList(self):\n        data = Table(\"zoo\")\n        var = data.domain[\"name\"]\n\n        fs = filter.FilterStringList\n        filters = [\n            (([\"swan\", \"tuna\", \"wasp\"], True), dict(rows=3)),\n            (([\"swan\", \"tuna\", \"wasp\"], False), dict(rows=3)),\n            (([\"WoRm\", \"TOad\", \"vOLe\"], True), dict(rows=0)),\n            (([\"WoRm\", \"TOad\", \"vOLe\"], False), dict(rows=3)),\n        ]\n\n        for args, expected in filters:\n            f = fs(var, *args)\n            filtered_data = filter.Values([f])(data)\n            self.assertEqual(len(filtered_data), expected[\"rows\"],\n                             \"{} returned wrong number of rows\".format(args))\n\n    def test_table_dtypes(self):\n        table = data.Table(\"iris\")\n        metas = np.hstack((table.metas, table.Y.reshape(len(table), 1)))\n        attributes_metas = table.domain.metas + table.domain.class_vars\n        domain_metas = data.Domain(table.domain.attributes[:2],\n                                   table.domain.attributes[2:],\n                                   attributes_metas)\n        table_metas = data.Table(domain_metas, table.X[:, : 2], table.X[:, 2:],\n                                 metas)\n        new_table = data.Table.from_table(data.Domain(table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.X.dtype, np.float64)\n        new_table = data.Table.from_table(data.Domain((), table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.Y.dtype, np.float64)\n        new_table = data.Table.from_table(data.Domain((), (), table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.metas.dtype, np.float64)\n\n    def test_attributes(self):\n        table = data.Table(\"iris\")\n        table.attributes = {1: \"test\"}\n        table2 = table[:4]\n        self.assertEqual(table2.attributes[1], \"test\")\n        table2.attributes[1] = \"modified\"\n        self.assertEqual(table.attributes[1], \"modified\")\n\n    # TODO Test conjunctions and disjunctions of conditions\n\n    def test_is_sparse(self):\n        table = data.Table(\"iris\")\n        self.assertFalse(table.is_sparse())\n\n        with table.unlocked():\n            table.X = sp.csr_matrix(table.X)\n            self.assertTrue(table.is_sparse())\n\n    def test_repr_sparse_with_one_row(self):\n        table = data.Table(\"iris\")[:1]\n        with table.unlocked():\n            table.X = sp.csr_matrix(table.X)\n        repr(table)     # make sure repr does not crash\n\n    def test_inf(self):\n        a = np.array([[2, 0, 0, 0],\n                      [0, np.nan, np.nan, 1],\n                      [0, 0, np.inf, 0]])\n        with self.assertWarns(Warning):\n            tab = data.Table.from_numpy(None, a)\n        self.assertEqual(tab.get_nan_frequency_attribute(), 3/12)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 593,
                            "end_lineno": 609,
                            "parent": {
                                "file_name": "Orange/tests/test_table.py",
                                "type": "class",
                                "name": "TableTestCase",
                                "content": "class TableTestCase(unittest.TestCase):\n    def setUp(self):\n        data.table.dataset_dirs.append(test_dirname())\n\n    def tearDown(self):\n        data.table.dataset_dirs.remove(test_dirname())\n\n    def test_indexing_class(self):\n        d = data.Table(\"datasets/test1\")\n        self.assertEqual([e.get_class() for e in d], [\"t\", \"t\", \"f\"])\n        cind = len(d.domain.variables) - 1\n        self.assertEqual([e[cind] for e in d], [\"t\", \"t\", \"f\"])\n        self.assertEqual([e[\"d\"] for e in d], [\"t\", \"t\", \"f\"])\n        cvar = d.domain.class_var\n        self.assertEqual([e[cvar] for e in d], [\"t\", \"t\", \"f\"])\n\n    def test_filename(self):\n        dir = data.table.get_sample_datasets_dir()\n        d = data.Table(\"iris\")\n        self.assertEqual(d.__file__, os.path.join(dir, \"iris.tab\"))\n\n        d = data.Table(\"datasets/test2.tab\")\n        self.assertTrue(d.__file__.endswith(\"test2.tab\"))  # platform dependent\n\n    def test_indexing(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            # regular, discrete\n            varc = d.domain[\"c\"]\n            self.assertEqual(d[0, 1], \"0\")\n            self.assertEqual(d[0, varc], \"0\")\n            self.assertEqual(d[0, \"c\"], \"0\")\n            self.assertEqual(d[0][1], \"0\")\n            self.assertEqual(d[0][varc], \"0\")\n            self.assertEqual(d[0][\"c\"], \"0\")\n            self.assertEqual(d[np.int_(0), np.int_(1)], \"0\")\n            self.assertEqual(d[np.int_(0)][np.int_(1)], \"0\")\n\n            # regular, continuous\n            varb = d.domain[\"b\"]\n            self.assertEqual(d[0, 0], 0)\n            self.assertEqual(d[0, varb], 0)\n            self.assertEqual(d[0, \"b\"], 0)\n            self.assertEqual(d[0][0], 0)\n            self.assertEqual(d[0][varb], 0)\n            self.assertEqual(d[0][\"b\"], 0)\n            self.assertEqual(d[np.int_(0), np.int_(0)], 0)\n            self.assertEqual(d[np.int_(0)][np.int_(0)], 0)\n\n            # negative\n            varb = d.domain[\"b\"]\n            self.assertEqual(d[-2, 0], 3.333)\n            self.assertEqual(d[-2, varb], 3.333)\n            self.assertEqual(d[-2, \"b\"], 3.333)\n            self.assertEqual(d[-2][0], 3.333)\n            self.assertEqual(d[-2][varb], 3.333)\n            self.assertEqual(d[-2][\"b\"], 3.333)\n            self.assertEqual(d[np.int_(-2), np.int_(0)], 3.333)\n            self.assertEqual(d[np.int_(-2)][np.int_(0)], 3.333)\n\n            # meta, discrete\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n            self.assertEqual(d[0, metaa], \"A\")\n            self.assertEqual(d[0, vara], \"A\")\n            self.assertEqual(d[0, \"a\"], \"A\")\n            self.assertEqual(d[0][metaa], \"A\")\n            self.assertEqual(d[0][vara], \"A\")\n            self.assertEqual(d[0][\"a\"], \"A\")\n            self.assertEqual(d[np.int_(0), np.int_(metaa)], \"A\")\n            self.assertEqual(d[np.int_(0)][np.int_(metaa)], \"A\")\n\n            # meta, string\n            vare = d.domain[\"e\"]\n            metae = d.domain.index(\"e\")\n            self.assertEqual(d[0, metae], \"i\")\n            self.assertEqual(d[0, vare], \"i\")\n            self.assertEqual(d[0, \"e\"], \"i\")\n            self.assertEqual(d[0][metae], \"i\")\n            self.assertEqual(d[0][vare], \"i\")\n            self.assertEqual(d[0][\"e\"], \"i\")\n            self.assertEqual(d[np.int_(0), np.int_(metae)], \"i\")\n            self.assertEqual(d[np.int_(0)][np.int_(metae)], \"i\")\n\n    def test_indexing_example(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            e = d[0]\n\n            # regular, discrete\n            varc = d.domain[\"c\"]\n            self.assertEqual(e[1], \"0\")\n            self.assertEqual(e[varc], \"0\")\n            self.assertEqual(e[\"c\"], \"0\")\n            self.assertEqual(e[np.int_(1)], \"0\")\n\n            # regular, continuous\n            varb = d.domain[\"b\"]\n            self.assertEqual(e[0], 0)\n            self.assertEqual(e[varb], 0)\n            self.assertEqual(e[\"b\"], 0)\n            self.assertEqual(e[np.int_(0)], 0)\n\n            # meta, discrete\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n            self.assertEqual(e[metaa], \"A\")\n            self.assertEqual(e[vara], \"A\")\n            self.assertEqual(e[\"a\"], \"A\")\n            self.assertEqual(e[np.int_(metaa)], \"A\")\n\n            # meta, string\n            vare = d.domain[\"e\"]\n            metae = d.domain.index(\"e\")\n            self.assertEqual(e[metae], \"i\")\n            self.assertEqual(e[vare], \"i\")\n            self.assertEqual(e[\"e\"], \"i\")\n            self.assertEqual(e[np.int_(metae)], \"i\")\n\n    def test_indexing_assign_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            # meta\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, \"a\"] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][\"a\"] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, vara] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][vara] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, metaa] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][metaa] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, np.int_(metaa)] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][np.int_(metaa)] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            # regular\n            varb = d.domain[\"b\"]\n\n            self.assertEqual(d[0, \"b\"], 0)\n            with d.unlocked():\n                d[0, \"b\"] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][\"b\"] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, varb] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][varb] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, 0] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][0] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, np.int_(0)] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][np.int_(0)] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n    def test_indexing_assign_example(self):\n        def almost_equal_list(s, t):\n            for e, f in zip(s, t):\n                self.assertAlmostEqual(e, f)\n\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            self.assertFalse(isnan(d[0, \"a\"]))\n            with d.unlocked():\n                d[0] = [\"3.14\", \"1\", \"f\"]\n            almost_equal_list(d[0].values(), [3.14, \"1\", \"f\"])\n            self.assertTrue(isnan(d[0, \"a\"]))\n\n            with d.unlocked():\n                d[0] = [3.15, 1, \"t\"]\n            almost_equal_list(d[0].values(), [3.15, \"0\", \"t\"])\n\n            with d.unlocked():\n                d[np.int_(0)] = [3.15, 2, \"f\"]\n            almost_equal_list(d[0].values(), [3.15, 2, \"f\"])\n\n            with d.unlocked(), self.assertRaises(ValueError):\n                d[0] = [\"3.14\", \"1\"]\n\n            with d.unlocked(), self.assertRaises(ValueError):\n                d[np.int_(0)] = [\"3.14\", \"1\"]\n\n            ex = data.Instance(d.domain, [\"3.16\", \"1\", \"f\"])\n            with d.unlocked():\n                d[0] = ex\n            almost_equal_list(d[0].values(), [3.16, \"1\", \"f\"])\n\n            ex = data.Instance(d.domain, [\"3.16\", 2, \"t\"])\n            with d.unlocked():\n                d[np.int_(0)] = ex\n            almost_equal_list(d[0].values(), [3.16, 2, \"t\"])\n\n            ex = data.Instance(d.domain, [\"3.16\", \"1\", \"f\"])\n            ex[\"e\"] = \"mmmapp\"\n            with d.unlocked():\n                d[0] = ex\n            almost_equal_list(d[0].values(), [3.16, \"1\", \"f\"])\n            self.assertEqual(d[0, \"e\"], \"mmmapp\")\n\n    def test_slice(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            x = d[:3]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [0, 1.1, 2.22])\n\n            x = d[2:5]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.22, 2.23, 2.24])\n\n            x = d[4:1:-1]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.24, 2.23, 2.22])\n\n            x = d[-3:]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.26, 3.333, Unknown])\n\n    def test_assign_slice_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            with d.unlocked():\n                d[2:5, 0] = 42\n            self.assertEqual([e[0] for e in d],\n                             [0, 1.1, 42, 42, 42, 2.25, 2.26, 3.333, Unknown])\n            with d.unlocked():\n                d[:3, \"b\"] = 43\n            self.assertEqual([e[0] for e in d],\n                             [43, 43, 43, 42, 42, 2.25, 2.26, 3.333, None])\n            with d.unlocked():\n                d[-2:, d.domain[0]] = 44\n            self.assertEqual([e[0] for e in d],\n                             [43, 43, 43, 42, 42, 2.25, 2.26, 44, 44])\n\n            with d.unlocked():\n                d[2:5, \"a\"] = \"A\"\n            self.assertEqual([e[\"a\"] for e in d], list(\"ABAAACCDE\"))\n\n    def test_multiple_indices(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            with self.assertRaises(IndexError):\n                x = d[2, 5, 1]\n\n            with self.assertRaises(IndexError):\n                x = d[(2, 5, 1)]\n\n            x = d[[2, 5, 1]]\n            self.assertEqual([e[0] for e in x], [2.22, 2.25, 1.1])\n\n    def test_assign_multiple_indices_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            with d.unlocked():\n                d[1:4, \"b\"] = 42\n            self.assertEqual([e[0] for e in d],\n                             [0, 42, 42, 42, 2.24, 2.25, 2.26, 3.333, None])\n\n            with d.unlocked():\n                d[range(5, 2, -1), \"b\"] = None\n            self.assertEqual([e[d.domain[0]] for e in d],\n                             [0, 42, 42, None, \"?\", \"\", 2.26, 3.333, None])\n\n    def test_set_multiple_indices_example(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            vals = [e[0] for e in d]\n            with d.unlocked():\n                d[[1, 2, 5]] = [42, None, None]\n            vals[1] = vals[2] = vals[5] = 42\n            self.assertEqual([e[0] for e in d], vals)\n\n    def test_bool(self):\n        d = data.Table(\"iris\")\n        self.assertTrue(d)\n\n        d = data.Table(\"datasets/test3\")\n        self.assertFalse(d)\n\n        d = data.Table(\"iris\")\n        self.assertTrue(d)\n\n    def test_checksum(self):\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d[42, 3] = 0\n        crc1 = d.checksum(False)\n\n        with d.unlocked():\n            d[42, 3] = 1\n        crc2 = d.checksum(False)\n        self.assertNotEqual(crc1, crc2)\n\n        with d.unlocked():\n            d[42, 3] = 0\n        crc3 = d.checksum(False)\n        self.assertEqual(crc1, crc3)\n\n        _ = d[42, \"name\"]\n        with d.unlocked():\n            d[42, \"name\"] = \"non-animal\"\n        crc4 = d.checksum(False)\n        self.assertEqual(crc1, crc4)\n        crc4 = d.checksum(True)\n        crc5 = d.checksum(1)\n        crc6 = d.checksum(False)\n        self.assertNotEqual(crc1, crc4)\n        self.assertNotEqual(crc1, crc5)\n        self.assertEqual(crc1, crc6)\n\n    def test_total_weight(self):\n        d = data.Table(\"zoo\")\n        self.assertEqual(d.total_weight(), len(d))\n\n        with d.unlocked():\n            d.set_weights(0)\n            d[0].weight = 0.1\n            d[10].weight = 0.2\n            d[-1].weight = 0.3\n        self.assertAlmostEqual(d.total_weight(), 0.6)\n\n    def test_has_missing(self):\n        d = data.Table(\"zoo\")\n        self.assertFalse(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n        with d.unlocked():\n            d[10, 3] = \"?\"\n        self.assertTrue(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n        with d.unlocked():\n            d[10].set_class(\"?\")\n        self.assertTrue(d.has_missing())\n        self.assertTrue(d.has_missing_class())\n\n        with d.unlocked():\n            d = data.Table(\"datasets/test3\")\n        self.assertFalse(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n    def test_shuffle(self):\n        d = data.Table(\"zoo\")\n        crc = d.checksum()\n        names = set(str(x[\"name\"]) for x in d)\n\n        with d.unlocked():\n            d.shuffle()\n        self.assertNotEqual(crc, d.checksum())\n        self.assertSetEqual(names, set(str(x[\"name\"]) for x in d))\n        crc2 = d.checksum()\n\n        x = d[2:10]\n        crcx = x.checksum()\n        with d.unlocked():\n            d.shuffle()\n        self.assertNotEqual(crc2, d.checksum())\n        self.assertEqual(crcx, x.checksum())\n\n        crc2 = d.checksum()\n        with x.unlocked():\n            x.shuffle()\n        self.assertNotEqual(crcx, x.checksum())\n        self.assertEqual(crc2, d.checksum())\n\n    @staticmethod\n    def not_less_ex(ex1, ex2):\n        for v1, v2 in zip(ex1, ex2):\n            if v1 != v2:\n                return v1 < v2\n        return True\n\n    @staticmethod\n    def sorted(d):\n        for i in range(1, len(d)):\n            if not TableTestCase.not_less_ex(d[i - 1], d[i]):\n                return False\n        return True\n\n    @staticmethod\n    def not_less_ex_ord(ex1, ex2, ord):\n        for a in ord:\n            if ex1[a] != ex2[a]:\n                return ex1[a] < ex2[a]\n        return True\n\n    @staticmethod\n    def sorted_ord(d, ord):\n        for i in range(1, len(d)):\n            if not TableTestCase.not_less_ex_ord(d[i - 1], d[i], ord):\n                return False\n        return True\n\n    def test_copy(self):\n        t = data.Table.from_numpy(\n            None, np.zeros((5, 3)), np.arange(5), np.zeros((5, 3)))\n\n        copy = t.copy()\n        self.assertTrue(np.all(t.X == copy.X))\n        self.assertTrue(np.all(t.Y == copy.Y))\n        self.assertTrue(np.all(t.metas == copy.metas))\n        with copy.unlocked():\n            copy[0] = [1, 1, 1, 1]\n        self.assertFalse(np.all(t.X == copy.X))\n        self.assertFalse(np.all(t.Y == copy.Y))\n        self.assertFalse(np.all(t.metas == copy.metas))\n\n    def test_copy_sparse(self):\n        t = data.Table('iris').to_sparse()\n        copy = t.copy()\n\n        self.assertEqual((t.X != copy.X).nnz, 0)      # sparse matrices match by content\n        np.testing.assert_equal(t.Y, copy.Y)\n        np.testing.assert_equal(t.metas, copy.metas)\n\n        self.assertNotEqual(id(t.X), id(copy.X))\n        self.assertNotEqual(id(t._Y), id(copy._Y))\n        self.assertNotEqual(id(t.metas), id(copy.metas))\n\n        # ensure that copied sparse arrays do not share data\n        with t.unlocked():\n            t.X[0, 0] = 42\n        self.assertEqual(copy.X[0, 0], 5.1)\n\n    def test_concatenate(self):\n        d1 = data.Domain(\n            [data.ContinuousVariable(n) for n in \"abc\"],\n            data.DiscreteVariable(\"y\", values=\"ABC\"),\n            [data.StringVariable(n) for n in [\"m1\", \"m2\"]],\n        )\n        x1 = np.arange(6).reshape(2, 3)\n        y1 = np.array([0, 1])\n        m1 = np.array([[\"foo\", \"bar\"], [\"baz\", \"qux\"]])\n        w1 = np.random.random((2,))\n        t1 = data.Table.from_numpy(d1, x1, y1, m1, w1)\n        t1.ids = ids1 = np.array([100, 101])\n        t1.attributes = {\"a\": 42, \"c\": 43}\n\n        x2 = np.arange(6, 15).reshape(3, 3)\n        y2 = np.array([1, 2, 0])\n        m2 = np.array([[\"a\", \"b\"], [\"c\", \"d\"], [\"e\", \"f\"]])\n        w2 = np.random.random((3,))\n        t2 = data.Table.from_numpy(d1, x2, y2, m2, w2)\n        t2.ids = ids2 = np.array([102, 103, 104])\n        t2.name = \"t2\"\n        t2.attributes = {\"a\": 44, \"b\": 45}\n\n        x3 = np.arange(15, 27).reshape(4, 3)\n        y3 = np.array([2, 1, 1, 0])\n        m3 = np.array([[\"g\", \"h\"], [\"i\", \"j\"], [\"k\", \"l\"], [\"m\", \"n\"]])\n        w3 = np.random.random((4,))\n        t3 = data.Table.from_numpy(d1, x3, y3, m3, w3)\n        t3.ids = ids3 = np.array([102, 103, 104, 105])\n        t3.name = \"t3\"\n\n        t1b = data.Table.concatenate((t1,))\n        self.assertEqual(t1b.domain, t1.domain)\n        np.testing.assert_almost_equal(t1b.X, x1)\n        np.testing.assert_almost_equal(t1b.Y, y1)\n        self.assertEqual(list(t1b.metas.flatten()),\n                         list(m1.flatten()))\n        np.testing.assert_almost_equal(t1b.W, w1)\n        np.testing.assert_almost_equal(t1b.ids, ids1)\n        self.assertEqual(t1b.name, t1.name)\n        self.assertEqual(t1b.attributes, {\"a\": 42, \"c\": 43})\n\n        t12 = data.Table.concatenate((t1, t2))\n        self.assertEqual(t12.domain, t1.domain)\n        np.testing.assert_almost_equal(t12.X, np.vstack((x1, x2)))\n        np.testing.assert_almost_equal(t12.Y, np.hstack((y1, y2)))\n        self.assertEqual(list(t12.metas.flatten()),\n                         list(np.vstack((m1, m2)).flatten()))\n        np.testing.assert_almost_equal(t12.W, np.hstack((w1, w2)))\n        np.testing.assert_almost_equal(t12.ids, np.hstack((ids1, ids2)))\n        self.assertEqual(t12.name, \"t2\")\n        self.assertEqual(t12.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n        t123 = data.Table.concatenate((t1, t2, t3))\n        self.assertEqual(t123.domain, t1.domain)\n        np.testing.assert_almost_equal(t123.X, np.vstack((x1, x2, x3)))\n        np.testing.assert_almost_equal(t123.Y, np.hstack((y1, y2, y3)))\n        self.assertEqual(list(t123.metas.flatten()),\n                         list(np.vstack((m1, m2, m3)).flatten()))\n        np.testing.assert_almost_equal(t123.W, np.hstack((w1, w2, w3)))\n        np.testing.assert_almost_equal(t123.ids, np.hstack((ids1, ids2, ids3)))\n        self.assertEqual(t123.name, \"t2\")\n        self.assertEqual(t123.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n        with t2.unlocked(t2.Y):\n            t2.Y = np.atleast_2d(t2.Y).T\n        t12 = data.Table.concatenate((t1, t2))\n        self.assertEqual(t12.domain, t1.domain)\n        np.testing.assert_almost_equal(t12.X, np.vstack((x1, x2)))\n        np.testing.assert_almost_equal(t12.Y, np.hstack((y1, y2)))\n        self.assertEqual(list(t12.metas.flatten()),\n                         list(np.vstack((m1, m2)).flatten()))\n        np.testing.assert_almost_equal(t12.W, np.hstack((w1, w2)))\n        np.testing.assert_almost_equal(t12.ids, np.hstack((ids1, ids2)))\n        self.assertEqual(t12.name, \"t2\")\n        self.assertEqual(t12.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n    def test_concatenate_exceptions(self):\n        zoo = data.Table(\"zoo\")\n        iris = data.Table(\"iris\")\n\n        self.assertRaises(ValueError, data.Table.concatenate, [])\n        self.assertRaises(ValueError, data.Table.concatenate, [zoo, iris])\n\n    def test_concatenate_sparse(self):\n        iris = Table(\"iris\")\n        with iris.unlocked():\n            iris.X = sp.csc_matrix(iris.X)\n        new = Table.concatenate([iris, iris])\n        self.assertEqual(len(new), 300)\n        self.assertTrue(sp.issparse(new.X), \"Concatenated X is not sparse.\")\n        self.assertFalse(sp.issparse(new.Y), \"Concatenated Y is not dense.\")\n        self.assertFalse(sp.issparse(new.metas), \"Concatenated metas is not dense.\")\n        self.assertEqual(len(new.ids), 300)\n\n    def test_pickle(self):\n        import pickle\n\n        d = data.Table(\"zoo\")\n        s = pickle.dumps(d)\n        d2 = pickle.loads(s)\n        self.assertEqual(d[0], d2[0])\n\n        self.assertEqual(d.checksum(include_metas=False),\n                         d2.checksum(include_metas=False))\n\n        d = data.Table(\"iris\")\n        s = pickle.dumps(d)\n        d2 = pickle.loads(s)\n        self.assertEqual(d[0], d2[0])\n        self.assertEqual(d.checksum(include_metas=False),\n                         d2.checksum(include_metas=False))\n\n    def test_translate_through_slice(self):\n        d = data.Table(\"iris\")\n        dom = data.Domain([\"petal length\", \"sepal length\", \"iris\"],\n                          source=d.domain)\n        d_ref = d[:10, dom.variables]\n        self.assertEqual(d_ref.domain.class_var, d.domain.class_var)\n        self.assertEqual(d_ref[0, \"petal length\"], d[0, \"petal length\"])\n        self.assertEqual(d_ref[0, \"sepal length\"], d[0, \"sepal length\"])\n        self.assertEqual(d_ref.X.shape, (10, 2))\n        self.assertEqual(d_ref.Y.shape, (10,))\n\n    def test_saveTab(self):\n        d = data.Table(\"iris\")[:3]\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            for e1, e2 in zip(d, d2):\n                self.assertEqual(e1, e2)\n        finally:\n            os.remove(\"test-save.tab\")\n            os.remove(\"test-save.tab.metadata\")\n\n        dom = data.Domain([data.ContinuousVariable(\"a\")])\n        d = data.Table.from_list(dom, [[i] for i in range(3)])\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            self.assertEqual(len(d.domain.attributes), 1)\n            self.assertEqual(d.domain.class_var, None)\n            for i in range(3):\n                self.assertEqual(d2[i], [i])\n        finally:\n            os.remove(\"test-save.tab\")\n\n        dom = data.Domain([data.ContinuousVariable(\"a\")], None)\n        d = data.Table.from_list(dom, [[i] for i in range(3)])\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            self.assertEqual(len(d.domain.attributes), 1)\n            for i in range(3):\n                self.assertEqual(d2[i], [i])\n        finally:\n            os.remove(\"test-save.tab\")\n\n        d = data.Table(\"zoo\")\n        d.save(\"test-zoo.tab\")\n        dd = data.Table(\"test-zoo\")\n        try:\n            self.assertTupleEqual(d.domain.metas, dd.domain.metas,\n                                  msg=\"Meta attributes don't match.\")\n            self.assertTupleEqual(d.domain.variables, dd.domain.variables,\n                                  msg=\"Attributes don't match.\")\n\n            np.testing.assert_almost_equal(d.W, dd.W,\n                                           err_msg=\"Weights don't match.\")\n            for i in range(10):\n                for j in d.domain.variables:\n                    self.assertEqual(d[i][j], dd[i][j])\n        finally:\n            os.remove(\"test-zoo.tab\")\n            os.remove(\"test-zoo.tab.metadata\")\n\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d.set_weights(range(len(d)))\n        d.save(\"test-zoo-weights.tab\")\n        dd = data.Table(\"test-zoo-weights\")\n        try:\n            self.assertTupleEqual(d.domain.metas, dd.domain.metas,\n                                  msg=\"Meta attributes don't match.\")\n            self.assertTupleEqual(d.domain.variables, dd.domain.variables,\n                                  msg=\"Attributes don't match.\")\n\n            np.testing.assert_almost_equal(d.W, dd.W,\n                                           err_msg=\"Weights don't match.\")\n            for i in range(10):\n                for j in d.domain.variables:\n                    self.assertEqual(d[i][j], dd[i][j])\n        finally:\n            os.remove(\"test-zoo-weights.tab\")\n            os.remove(\"test-zoo-weights.tab.metadata\")\n\n    def test_save_pickle(self):\n        table = data.Table(\"iris\")\n        try:\n            table.save(\"iris.pickle\")\n            table2 = data.Table.from_file(\"iris.pickle\")\n            np.testing.assert_almost_equal(table.X, table2.X)\n            np.testing.assert_almost_equal(table.Y, table2.Y)\n            self.assertEqual(table.domain[0], table2.domain[0])\n        finally:\n            os.remove(\"iris.pickle\")\n\n    def test_from_numpy(self):\n        a = np.arange(20, dtype=\"d\").reshape((4, 5)).copy()\n        a[:, -1] = [0, 0, 0, 1]\n        dom = data.Domain([data.ContinuousVariable(x) for x in \"abcd\"],\n                          data.DiscreteVariable(\"e\", values=(\"no\", \"yes\")))\n        table = data.Table(dom, a)\n        with table.unlocked():\n            for i in range(4):\n                self.assertEqual(table[i].get_class(), \"no\" if i < 3 else \"yes\")\n                for j in range(5):\n                    self.assertEqual(a[i, j], table[i, j])\n\n        with table.unlocked(), self.assertRaises(IndexError):\n            table[0, -5] = 5\n\n    def test_filter_is_defined(self):\n        d = data.Table(\"iris\")\n        with d.unlocked():\n            d[1, 4] = Unknown\n        self.assertTrue(isnan(d[1, 4]))\n        with d.unlocked():\n            d[140, 0] = Unknown\n        e = filter.IsDefined()(d)\n        self.assertEqual(len(e), len(d) - 2)\n        self.assertEqual(e[0], d[0])\n        self.assertEqual(e[1], d[2])\n        self.assertEqual(e[147], d[149])\n        self.assertTrue(d.has_missing())\n        self.assertFalse(e.has_missing())\n\n    def test_filter_has_class(self):\n        d = data.Table(\"iris\")\n        with d.unlocked():\n            d[1, 4] = Unknown\n        self.assertTrue(isnan(d[1, 4]))\n        with d.unlocked():\n            d[140, 0] = Unknown\n        e = filter.HasClass()(d)\n        self.assertEqual(len(e), len(d) - 1)\n        self.assertEqual(e[0], d[0])\n        self.assertEqual(e[1], d[2])\n        self.assertEqual(e[148], d[149])\n        self.assertTrue(d.has_missing())\n        self.assertTrue(e.has_missing())\n        self.assertFalse(e.has_missing_class())\n\n    def test_filter_random(self):\n        d = data.Table(\"iris\")\n        e = filter.Random(50)(d)\n        self.assertEqual(len(e), 50)\n        e = filter.Random(50, negate=True)(d)\n        self.assertEqual(len(e), 100)\n        for _ in range(5):\n            e = filter.Random(0.2)(d)\n            self.assertEqual(len(e), 30)\n            bc = np.bincount(np.array(e.Y[:], dtype=int))\n            if min(bc) > 7:\n                break\n        else:\n            self.fail(\"Filter returns too uneven distributions\")\n\n    def test_filter_values_nested(self):\n        d = data.Table(\"iris\")\n        f1 = filter.FilterContinuous(d.columns.sepal_length,\n                                     filter.FilterContinuous.Between,\n                                     min=4.5, max=5.0)\n        f2 = filter.FilterContinuous(d.columns.sepal_width,\n                                     filter.FilterContinuous.Between,\n                                     min=3.1, max=3.4)\n        f3 = filter.FilterDiscrete(d.columns.iris, [0, 1])\n        f = filter.Values([filter.Values([f1, f2], conjunction=False), f3])\n        self.assertEqual(41, len(f(d)))\n\n    def test_filter_string_works_for_numeric_columns(self):\n        var = StringVariable(\"s\")\n        data = Table.from_list(Domain([], metas=[var]),\n                               [[x] for x in range(21)])\n        # 1, 2, 3, ..., 18, 19, 20\n\n        fs = filter.FilterString\n        filters = [\n            ((fs.Greater, \"5\"), dict(rows=4)),\n            # 6, 7, 8, 9\n            ((fs.Between, \"15\", \"2\"), dict(rows=6)),\n            # 15, 16, 17, 18, 19, 2\n            ((fs.Contains, \"2\"), dict(rows=3)),\n            # 2, 12, 20\n        ]\n\n        for args, expected in filters:\n            f = fs(var, *args)\n            filtered_data = filter.Values([f])(data)\n            self.assertEqual(len(filtered_data), expected[\"rows\"],\n                             \"{} returned wrong number of rows\".format(args))\n\n    def test_filter_value_continuous(self):\n        d = data.Table(\"iris\")\n        col = d.X[:, 2]\n\n        v = d.columns\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Between,\n                                    min=4.5, max=5.1)\n\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] >= 4.5))\n        self.assertTrue(np.all(x.X[:, 2] <= 5.1))\n        self.assertEqual(sum((col >= 4.5) * (col <= 5.1)), len(x))\n\n        f.ref = 5.1\n        f.oper = filter.FilterContinuous.Equal\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.NotEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] != 5.1))\n        self.assertEqual(sum(col != 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Less\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] < 5.1))\n        self.assertEqual(sum(col < 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.LessEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] <= 5.1))\n        self.assertEqual(sum(col <= 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Greater\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] > 5.1))\n        self.assertEqual(sum(col > 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] >= 5.1))\n        self.assertEqual(sum(col >= 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Outside\n        f.ref, f.max = 4.5, 5.1\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(e[2] < 4.5 or e[2] > 5.1)\n        self.assertEqual(sum((col < 4.5) + (col > 5.1)), len(x))\n\n        f.oper = filter.FilterContinuous.IsDefined\n        f.ref = f.max = None\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d))\n\n        with d.unlocked():\n            d[:30, v.petal_length] = Unknown\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 30)\n\n    def test_filter_value_continuous_args(self):\n        d = data.Table(\"iris\")\n        col = d.X[:, 2]\n        v = d.columns\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(2,\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"petal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"sepal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        f.column = 2\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"sepal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        f.column = v.petal_length\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=18)\n        f.ref = 5.1\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=18)\n        f.ref = 5.1\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n    def test_valueFilter_discrete(self):\n        d = data.Table(\"zoo\")\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, 3, 4])\n        for e in filter.Values([f])(d):\n            self.assertTrue(e.get_class() in [2, 3, 4])\n\n        f.values = [\"mammal\"]\n        for e in filter.Values([f])(d):\n            self.assertEqual(e.get_class(), \"mammal\")\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, \"mammal\"])\n        for e in filter.Values([f])(d):\n            self.assertTrue(e.get_class() in [2, \"mammal\"])\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, \"martian\"])\n        self.assertRaises(ValueError, d._filter_values, f)\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=(2, data.Table))\n        self.assertRaises(TypeError, d._filter_values, f)\n\n        v = d.columns\n        f = filter.FilterDiscrete(v.hair, values=None)\n        self.assertEqual(len(filter.Values([f])(d)), len(d))\n\n        with d.unlocked():\n            d[:5, v.hair] = Unknown\n        self.assertEqual(len(filter.Values([f])(d)), len(d) - 5)\n\n    def test_valueFilter_string_is_defined(self):\n        d = data.Table(\"datasets/test9.tab\")\n        f = filter.FilterString(-5, filter.FilterString.IsDefined)\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 7)\n\n    def test_valueFilter_discrete_meta_is_defined(self):\n        d = data.Table(\"datasets/test9.tab\")\n        f = filter.FilterDiscrete(-4, None)\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 8)\n\n    def test_valueFilter_string_case_sens(self):\n        d = data.Table(\"zoo\")\n        col = d[:, \"name\"].metas[:, 0]\n\n        f = filter.FilterString(\"name\",\n                                filter.FilterString.Equal, \"girl\")\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 1)\n        self.assertEqual(x[0, \"name\"], \"girl\")\n        self.assertTrue(np.all(x.metas == \"girl\"))\n\n        f.oper = f.NotEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 1)\n        self.assertTrue(np.all(x[:, \"name\"] != \"girl\"))\n\n        f.oper = f.Less\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"girl\"))\n        self.assertTrue(np.all(x.metas < \"girl\"))\n\n        f.oper = f.LessEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col <= \"girl\"))\n        self.assertTrue(np.all(x.metas <= \"girl\"))\n\n        f.oper = f.Greater\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col > \"girl\"))\n        self.assertTrue(np.all(x.metas > \"girl\"))\n\n        f.oper = f.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col >= \"girl\"))\n        self.assertTrue(np.all(x.metas >= \"girl\"))\n\n        f.oper = f.Between\n        f.max = \"lion\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum((col >= \"girl\") * (col <= \"lion\")))\n        self.assertTrue(np.all(x.metas >= \"girl\"))\n        self.assertTrue(np.all(x.metas <= \"lion\"))\n\n        f.oper = f.Outside\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"girl\") + sum(col > \"lion\"))\n        self.assertTrue(np.all((x.metas < \"girl\") + (x.metas > \"lion\")))\n\n        f.oper = f.Contains\n        f.ref = \"ea\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(\"ea\" in e[\"name\"])\n        self.assertEqual(len(x), len([e for e in col if \"ea\" in e]))\n\n        f.oper = f.StartsWith\n        f.ref = \"sea\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).startswith(\"sea\"))\n        self.assertEqual(len(x), len([e for e in col if e.startswith(\"sea\")]))\n\n        f.oper = f.EndsWith\n        f.ref = \"ion\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n        self.assertEqual(len(x), len([e for e in col if e.endswith(\"ion\")]))\n\n    def test_valueFilter_string_case_insens(self):\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d[d[:, \"name\"].metas[:, 0] == \"girl\", \"name\"] = \"GIrl\"\n\n        col = d[:, \"name\"].metas[:, 0]\n\n        f = filter.FilterString(\"name\",\n                                filter.FilterString.Equal, \"giRL\")\n        f.case_sensitive = False\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 1)\n        self.assertEqual(x[0, \"name\"], \"GIrl\")\n        self.assertTrue(np.all(x.metas == \"GIrl\"))\n\n        f.oper = f.NotEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 1)\n        self.assertTrue(np.all(x[:, \"name\"] != \"GIrl\"))\n\n        f.oper = f.Less\n        f.ref = \"CHiCKEN\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"chicken\") - 1)  # girl!\n        self.assertTrue(np.all(x.metas < \"chicken\"))\n\n        f.oper = f.LessEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col <= \"chicken\") - 1)\n        self.assertTrue(np.all(x.metas <= \"chicken\"))\n\n        f.oper = f.Greater\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col > \"chicken\") + 1)\n        for e in x:\n            self.assertGreater(str(e[\"name\"]).lower(), \"chicken\")\n\n        f.oper = f.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col >= \"chicken\") + 1)\n        for e in x:\n            self.assertGreaterEqual(str(e[\"name\"]).lower(), \"chicken\")\n\n        f.oper = f.Between\n        f.max = \"liOn\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum((col >= \"chicken\") * (col <= \"lion\")) + 1)\n        for e in x:\n            self.assertTrue(\"chicken\" <= str(e[\"name\"]).lower() <= \"lion\")\n\n        f.oper = f.Outside\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"chicken\") + sum(col > \"lion\") - 1)\n        self.assertTrue(np.all((x.metas < \"chicken\") + (x.metas > \"lion\")))\n\n        f.oper = f.Contains\n        f.ref = \"iR\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(\"ir\" in str(e[\"name\"]).lower())\n        self.assertEqual(len(x), len([e for e in col if \"ir\" in e]) + 1)\n\n        f.oper = f.StartsWith\n        f.ref = \"GI\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).lower().startswith(\"gi\"))\n        self.assertEqual(len(x),\n                         len([e for e in col if e.lower().startswith(\"gi\")]))\n\n        f.oper = f.EndsWith\n        f.ref = \"ion\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n        self.assertEqual(len(x), len([e for e in col if e.endswith(\"ion\")]))\n\n    def test_valueFilter_regex(self):\n        d = data.Table(\"zoo\")\n        f = filter.FilterRegex(d.domain['name'], '^c...$')\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 7)\n\n    def test_valueFilter_stringList(self):\n        data = Table(\"zoo\")\n        var = data.domain[\"name\"]\n\n        fs = filter.FilterStringList\n        filters = [\n            (([\"swan\", \"tuna\", \"wasp\"], True), dict(rows=3)),\n            (([\"swan\", \"tuna\", \"wasp\"], False), dict(rows=3)),\n            (([\"WoRm\", \"TOad\", \"vOLe\"], True), dict(rows=0)),\n            (([\"WoRm\", \"TOad\", \"vOLe\"], False), dict(rows=3)),\n        ]\n\n        for args, expected in filters:\n            f = fs(var, *args)\n            filtered_data = filter.Values([f])(data)\n            self.assertEqual(len(filtered_data), expected[\"rows\"],\n                             \"{} returned wrong number of rows\".format(args))\n\n    def test_table_dtypes(self):\n        table = data.Table(\"iris\")\n        metas = np.hstack((table.metas, table.Y.reshape(len(table), 1)))\n        attributes_metas = table.domain.metas + table.domain.class_vars\n        domain_metas = data.Domain(table.domain.attributes[:2],\n                                   table.domain.attributes[2:],\n                                   attributes_metas)\n        table_metas = data.Table(domain_metas, table.X[:, : 2], table.X[:, 2:],\n                                 metas)\n        new_table = data.Table.from_table(data.Domain(table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.X.dtype, np.float64)\n        new_table = data.Table.from_table(data.Domain((), table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.Y.dtype, np.float64)\n        new_table = data.Table.from_table(data.Domain((), (), table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.metas.dtype, np.float64)\n\n    def test_attributes(self):\n        table = data.Table(\"iris\")\n        table.attributes = {1: \"test\"}\n        table2 = table[:4]\n        self.assertEqual(table2.attributes[1], \"test\")\n        table2.attributes[1] = \"modified\"\n        self.assertEqual(table.attributes[1], \"modified\")\n\n    # TODO Test conjunctions and disjunctions of conditions\n\n    def test_is_sparse(self):\n        table = data.Table(\"iris\")\n        self.assertFalse(table.is_sparse())\n\n        with table.unlocked():\n            table.X = sp.csr_matrix(table.X)\n            self.assertTrue(table.is_sparse())\n\n    def test_repr_sparse_with_one_row(self):\n        table = data.Table(\"iris\")[:1]\n        with table.unlocked():\n            table.X = sp.csr_matrix(table.X)\n        repr(table)     # make sure repr does not crash\n\n    def test_inf(self):\n        a = np.array([[2, 0, 0, 0],\n                      [0, np.nan, np.nan, 1],\n                      [0, 0, np.inf, 0]])\n        with self.assertWarns(Warning):\n            tab = data.Table.from_numpy(None, a)\n        self.assertEqual(tab.get_nan_frequency_attribute(), 3/12)",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 26,
                                "end_lineno": 1170,
                                "parent": null
                            }
                        },
                        {
                            "file_name": "Orange/tests/test_table.py",
                            "type": "class",
                            "name": "TableTestCase",
                            "content": "class TableTestCase(unittest.TestCase):\n    def setUp(self):\n        data.table.dataset_dirs.append(test_dirname())\n\n    def tearDown(self):\n        data.table.dataset_dirs.remove(test_dirname())\n\n    def test_indexing_class(self):\n        d = data.Table(\"datasets/test1\")\n        self.assertEqual([e.get_class() for e in d], [\"t\", \"t\", \"f\"])\n        cind = len(d.domain.variables) - 1\n        self.assertEqual([e[cind] for e in d], [\"t\", \"t\", \"f\"])\n        self.assertEqual([e[\"d\"] for e in d], [\"t\", \"t\", \"f\"])\n        cvar = d.domain.class_var\n        self.assertEqual([e[cvar] for e in d], [\"t\", \"t\", \"f\"])\n\n    def test_filename(self):\n        dir = data.table.get_sample_datasets_dir()\n        d = data.Table(\"iris\")\n        self.assertEqual(d.__file__, os.path.join(dir, \"iris.tab\"))\n\n        d = data.Table(\"datasets/test2.tab\")\n        self.assertTrue(d.__file__.endswith(\"test2.tab\"))  # platform dependent\n\n    def test_indexing(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            # regular, discrete\n            varc = d.domain[\"c\"]\n            self.assertEqual(d[0, 1], \"0\")\n            self.assertEqual(d[0, varc], \"0\")\n            self.assertEqual(d[0, \"c\"], \"0\")\n            self.assertEqual(d[0][1], \"0\")\n            self.assertEqual(d[0][varc], \"0\")\n            self.assertEqual(d[0][\"c\"], \"0\")\n            self.assertEqual(d[np.int_(0), np.int_(1)], \"0\")\n            self.assertEqual(d[np.int_(0)][np.int_(1)], \"0\")\n\n            # regular, continuous\n            varb = d.domain[\"b\"]\n            self.assertEqual(d[0, 0], 0)\n            self.assertEqual(d[0, varb], 0)\n            self.assertEqual(d[0, \"b\"], 0)\n            self.assertEqual(d[0][0], 0)\n            self.assertEqual(d[0][varb], 0)\n            self.assertEqual(d[0][\"b\"], 0)\n            self.assertEqual(d[np.int_(0), np.int_(0)], 0)\n            self.assertEqual(d[np.int_(0)][np.int_(0)], 0)\n\n            # negative\n            varb = d.domain[\"b\"]\n            self.assertEqual(d[-2, 0], 3.333)\n            self.assertEqual(d[-2, varb], 3.333)\n            self.assertEqual(d[-2, \"b\"], 3.333)\n            self.assertEqual(d[-2][0], 3.333)\n            self.assertEqual(d[-2][varb], 3.333)\n            self.assertEqual(d[-2][\"b\"], 3.333)\n            self.assertEqual(d[np.int_(-2), np.int_(0)], 3.333)\n            self.assertEqual(d[np.int_(-2)][np.int_(0)], 3.333)\n\n            # meta, discrete\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n            self.assertEqual(d[0, metaa], \"A\")\n            self.assertEqual(d[0, vara], \"A\")\n            self.assertEqual(d[0, \"a\"], \"A\")\n            self.assertEqual(d[0][metaa], \"A\")\n            self.assertEqual(d[0][vara], \"A\")\n            self.assertEqual(d[0][\"a\"], \"A\")\n            self.assertEqual(d[np.int_(0), np.int_(metaa)], \"A\")\n            self.assertEqual(d[np.int_(0)][np.int_(metaa)], \"A\")\n\n            # meta, string\n            vare = d.domain[\"e\"]\n            metae = d.domain.index(\"e\")\n            self.assertEqual(d[0, metae], \"i\")\n            self.assertEqual(d[0, vare], \"i\")\n            self.assertEqual(d[0, \"e\"], \"i\")\n            self.assertEqual(d[0][metae], \"i\")\n            self.assertEqual(d[0][vare], \"i\")\n            self.assertEqual(d[0][\"e\"], \"i\")\n            self.assertEqual(d[np.int_(0), np.int_(metae)], \"i\")\n            self.assertEqual(d[np.int_(0)][np.int_(metae)], \"i\")\n\n    def test_indexing_example(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            e = d[0]\n\n            # regular, discrete\n            varc = d.domain[\"c\"]\n            self.assertEqual(e[1], \"0\")\n            self.assertEqual(e[varc], \"0\")\n            self.assertEqual(e[\"c\"], \"0\")\n            self.assertEqual(e[np.int_(1)], \"0\")\n\n            # regular, continuous\n            varb = d.domain[\"b\"]\n            self.assertEqual(e[0], 0)\n            self.assertEqual(e[varb], 0)\n            self.assertEqual(e[\"b\"], 0)\n            self.assertEqual(e[np.int_(0)], 0)\n\n            # meta, discrete\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n            self.assertEqual(e[metaa], \"A\")\n            self.assertEqual(e[vara], \"A\")\n            self.assertEqual(e[\"a\"], \"A\")\n            self.assertEqual(e[np.int_(metaa)], \"A\")\n\n            # meta, string\n            vare = d.domain[\"e\"]\n            metae = d.domain.index(\"e\")\n            self.assertEqual(e[metae], \"i\")\n            self.assertEqual(e[vare], \"i\")\n            self.assertEqual(e[\"e\"], \"i\")\n            self.assertEqual(e[np.int_(metae)], \"i\")\n\n    def test_indexing_assign_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            # meta\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, \"a\"] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][\"a\"] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, vara] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][vara] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, metaa] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][metaa] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, np.int_(metaa)] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][np.int_(metaa)] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            # regular\n            varb = d.domain[\"b\"]\n\n            self.assertEqual(d[0, \"b\"], 0)\n            with d.unlocked():\n                d[0, \"b\"] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][\"b\"] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, varb] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][varb] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, 0] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][0] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, np.int_(0)] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][np.int_(0)] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n    def test_indexing_assign_example(self):\n        def almost_equal_list(s, t):\n            for e, f in zip(s, t):\n                self.assertAlmostEqual(e, f)\n\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            self.assertFalse(isnan(d[0, \"a\"]))\n            with d.unlocked():\n                d[0] = [\"3.14\", \"1\", \"f\"]\n            almost_equal_list(d[0].values(), [3.14, \"1\", \"f\"])\n            self.assertTrue(isnan(d[0, \"a\"]))\n\n            with d.unlocked():\n                d[0] = [3.15, 1, \"t\"]\n            almost_equal_list(d[0].values(), [3.15, \"0\", \"t\"])\n\n            with d.unlocked():\n                d[np.int_(0)] = [3.15, 2, \"f\"]\n            almost_equal_list(d[0].values(), [3.15, 2, \"f\"])\n\n            with d.unlocked(), self.assertRaises(ValueError):\n                d[0] = [\"3.14\", \"1\"]\n\n            with d.unlocked(), self.assertRaises(ValueError):\n                d[np.int_(0)] = [\"3.14\", \"1\"]\n\n            ex = data.Instance(d.domain, [\"3.16\", \"1\", \"f\"])\n            with d.unlocked():\n                d[0] = ex\n            almost_equal_list(d[0].values(), [3.16, \"1\", \"f\"])\n\n            ex = data.Instance(d.domain, [\"3.16\", 2, \"t\"])\n            with d.unlocked():\n                d[np.int_(0)] = ex\n            almost_equal_list(d[0].values(), [3.16, 2, \"t\"])\n\n            ex = data.Instance(d.domain, [\"3.16\", \"1\", \"f\"])\n            ex[\"e\"] = \"mmmapp\"\n            with d.unlocked():\n                d[0] = ex\n            almost_equal_list(d[0].values(), [3.16, \"1\", \"f\"])\n            self.assertEqual(d[0, \"e\"], \"mmmapp\")\n\n    def test_slice(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            x = d[:3]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [0, 1.1, 2.22])\n\n            x = d[2:5]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.22, 2.23, 2.24])\n\n            x = d[4:1:-1]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.24, 2.23, 2.22])\n\n            x = d[-3:]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.26, 3.333, Unknown])\n\n    def test_assign_slice_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            with d.unlocked():\n                d[2:5, 0] = 42\n            self.assertEqual([e[0] for e in d],\n                             [0, 1.1, 42, 42, 42, 2.25, 2.26, 3.333, Unknown])\n            with d.unlocked():\n                d[:3, \"b\"] = 43\n            self.assertEqual([e[0] for e in d],\n                             [43, 43, 43, 42, 42, 2.25, 2.26, 3.333, None])\n            with d.unlocked():\n                d[-2:, d.domain[0]] = 44\n            self.assertEqual([e[0] for e in d],\n                             [43, 43, 43, 42, 42, 2.25, 2.26, 44, 44])\n\n            with d.unlocked():\n                d[2:5, \"a\"] = \"A\"\n            self.assertEqual([e[\"a\"] for e in d], list(\"ABAAACCDE\"))\n\n    def test_multiple_indices(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            with self.assertRaises(IndexError):\n                x = d[2, 5, 1]\n\n            with self.assertRaises(IndexError):\n                x = d[(2, 5, 1)]\n\n            x = d[[2, 5, 1]]\n            self.assertEqual([e[0] for e in x], [2.22, 2.25, 1.1])\n\n    def test_assign_multiple_indices_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            with d.unlocked():\n                d[1:4, \"b\"] = 42\n            self.assertEqual([e[0] for e in d],\n                             [0, 42, 42, 42, 2.24, 2.25, 2.26, 3.333, None])\n\n            with d.unlocked():\n                d[range(5, 2, -1), \"b\"] = None\n            self.assertEqual([e[d.domain[0]] for e in d],\n                             [0, 42, 42, None, \"?\", \"\", 2.26, 3.333, None])\n\n    def test_set_multiple_indices_example(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            vals = [e[0] for e in d]\n            with d.unlocked():\n                d[[1, 2, 5]] = [42, None, None]\n            vals[1] = vals[2] = vals[5] = 42\n            self.assertEqual([e[0] for e in d], vals)\n\n    def test_bool(self):\n        d = data.Table(\"iris\")\n        self.assertTrue(d)\n\n        d = data.Table(\"datasets/test3\")\n        self.assertFalse(d)\n\n        d = data.Table(\"iris\")\n        self.assertTrue(d)\n\n    def test_checksum(self):\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d[42, 3] = 0\n        crc1 = d.checksum(False)\n\n        with d.unlocked():\n            d[42, 3] = 1\n        crc2 = d.checksum(False)\n        self.assertNotEqual(crc1, crc2)\n\n        with d.unlocked():\n            d[42, 3] = 0\n        crc3 = d.checksum(False)\n        self.assertEqual(crc1, crc3)\n\n        _ = d[42, \"name\"]\n        with d.unlocked():\n            d[42, \"name\"] = \"non-animal\"\n        crc4 = d.checksum(False)\n        self.assertEqual(crc1, crc4)\n        crc4 = d.checksum(True)\n        crc5 = d.checksum(1)\n        crc6 = d.checksum(False)\n        self.assertNotEqual(crc1, crc4)\n        self.assertNotEqual(crc1, crc5)\n        self.assertEqual(crc1, crc6)\n\n    def test_total_weight(self):\n        d = data.Table(\"zoo\")\n        self.assertEqual(d.total_weight(), len(d))\n\n        with d.unlocked():\n            d.set_weights(0)\n            d[0].weight = 0.1\n            d[10].weight = 0.2\n            d[-1].weight = 0.3\n        self.assertAlmostEqual(d.total_weight(), 0.6)\n\n    def test_has_missing(self):\n        d = data.Table(\"zoo\")\n        self.assertFalse(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n        with d.unlocked():\n            d[10, 3] = \"?\"\n        self.assertTrue(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n        with d.unlocked():\n            d[10].set_class(\"?\")\n        self.assertTrue(d.has_missing())\n        self.assertTrue(d.has_missing_class())\n\n        with d.unlocked():\n            d = data.Table(\"datasets/test3\")\n        self.assertFalse(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n    def test_shuffle(self):\n        d = data.Table(\"zoo\")\n        crc = d.checksum()\n        names = set(str(x[\"name\"]) for x in d)\n\n        with d.unlocked():\n            d.shuffle()\n        self.assertNotEqual(crc, d.checksum())\n        self.assertSetEqual(names, set(str(x[\"name\"]) for x in d))\n        crc2 = d.checksum()\n\n        x = d[2:10]\n        crcx = x.checksum()\n        with d.unlocked():\n            d.shuffle()\n        self.assertNotEqual(crc2, d.checksum())\n        self.assertEqual(crcx, x.checksum())\n\n        crc2 = d.checksum()\n        with x.unlocked():\n            x.shuffle()\n        self.assertNotEqual(crcx, x.checksum())\n        self.assertEqual(crc2, d.checksum())\n\n    @staticmethod\n    def not_less_ex(ex1, ex2):\n        for v1, v2 in zip(ex1, ex2):\n            if v1 != v2:\n                return v1 < v2\n        return True\n\n    @staticmethod\n    def sorted(d):\n        for i in range(1, len(d)):\n            if not TableTestCase.not_less_ex(d[i - 1], d[i]):\n                return False\n        return True\n\n    @staticmethod\n    def not_less_ex_ord(ex1, ex2, ord):\n        for a in ord:\n            if ex1[a] != ex2[a]:\n                return ex1[a] < ex2[a]\n        return True\n\n    @staticmethod\n    def sorted_ord(d, ord):\n        for i in range(1, len(d)):\n            if not TableTestCase.not_less_ex_ord(d[i - 1], d[i], ord):\n                return False\n        return True\n\n    def test_copy(self):\n        t = data.Table.from_numpy(\n            None, np.zeros((5, 3)), np.arange(5), np.zeros((5, 3)))\n\n        copy = t.copy()\n        self.assertTrue(np.all(t.X == copy.X))\n        self.assertTrue(np.all(t.Y == copy.Y))\n        self.assertTrue(np.all(t.metas == copy.metas))\n        with copy.unlocked():\n            copy[0] = [1, 1, 1, 1]\n        self.assertFalse(np.all(t.X == copy.X))\n        self.assertFalse(np.all(t.Y == copy.Y))\n        self.assertFalse(np.all(t.metas == copy.metas))\n\n    def test_copy_sparse(self):\n        t = data.Table('iris').to_sparse()\n        copy = t.copy()\n\n        self.assertEqual((t.X != copy.X).nnz, 0)      # sparse matrices match by content\n        np.testing.assert_equal(t.Y, copy.Y)\n        np.testing.assert_equal(t.metas, copy.metas)\n\n        self.assertNotEqual(id(t.X), id(copy.X))\n        self.assertNotEqual(id(t._Y), id(copy._Y))\n        self.assertNotEqual(id(t.metas), id(copy.metas))\n\n        # ensure that copied sparse arrays do not share data\n        with t.unlocked():\n            t.X[0, 0] = 42\n        self.assertEqual(copy.X[0, 0], 5.1)\n\n    def test_concatenate(self):\n        d1 = data.Domain(\n            [data.ContinuousVariable(n) for n in \"abc\"],\n            data.DiscreteVariable(\"y\", values=\"ABC\"),\n            [data.StringVariable(n) for n in [\"m1\", \"m2\"]],\n        )\n        x1 = np.arange(6).reshape(2, 3)\n        y1 = np.array([0, 1])\n        m1 = np.array([[\"foo\", \"bar\"], [\"baz\", \"qux\"]])\n        w1 = np.random.random((2,))\n        t1 = data.Table.from_numpy(d1, x1, y1, m1, w1)\n        t1.ids = ids1 = np.array([100, 101])\n        t1.attributes = {\"a\": 42, \"c\": 43}\n\n        x2 = np.arange(6, 15).reshape(3, 3)\n        y2 = np.array([1, 2, 0])\n        m2 = np.array([[\"a\", \"b\"], [\"c\", \"d\"], [\"e\", \"f\"]])\n        w2 = np.random.random((3,))\n        t2 = data.Table.from_numpy(d1, x2, y2, m2, w2)\n        t2.ids = ids2 = np.array([102, 103, 104])\n        t2.name = \"t2\"\n        t2.attributes = {\"a\": 44, \"b\": 45}\n\n        x3 = np.arange(15, 27).reshape(4, 3)\n        y3 = np.array([2, 1, 1, 0])\n        m3 = np.array([[\"g\", \"h\"], [\"i\", \"j\"], [\"k\", \"l\"], [\"m\", \"n\"]])\n        w3 = np.random.random((4,))\n        t3 = data.Table.from_numpy(d1, x3, y3, m3, w3)\n        t3.ids = ids3 = np.array([102, 103, 104, 105])\n        t3.name = \"t3\"\n\n        t1b = data.Table.concatenate((t1,))\n        self.assertEqual(t1b.domain, t1.domain)\n        np.testing.assert_almost_equal(t1b.X, x1)\n        np.testing.assert_almost_equal(t1b.Y, y1)\n        self.assertEqual(list(t1b.metas.flatten()),\n                         list(m1.flatten()))\n        np.testing.assert_almost_equal(t1b.W, w1)\n        np.testing.assert_almost_equal(t1b.ids, ids1)\n        self.assertEqual(t1b.name, t1.name)\n        self.assertEqual(t1b.attributes, {\"a\": 42, \"c\": 43})\n\n        t12 = data.Table.concatenate((t1, t2))\n        self.assertEqual(t12.domain, t1.domain)\n        np.testing.assert_almost_equal(t12.X, np.vstack((x1, x2)))\n        np.testing.assert_almost_equal(t12.Y, np.hstack((y1, y2)))\n        self.assertEqual(list(t12.metas.flatten()),\n                         list(np.vstack((m1, m2)).flatten()))\n        np.testing.assert_almost_equal(t12.W, np.hstack((w1, w2)))\n        np.testing.assert_almost_equal(t12.ids, np.hstack((ids1, ids2)))\n        self.assertEqual(t12.name, \"t2\")\n        self.assertEqual(t12.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n        t123 = data.Table.concatenate((t1, t2, t3))\n        self.assertEqual(t123.domain, t1.domain)\n        np.testing.assert_almost_equal(t123.X, np.vstack((x1, x2, x3)))\n        np.testing.assert_almost_equal(t123.Y, np.hstack((y1, y2, y3)))\n        self.assertEqual(list(t123.metas.flatten()),\n                         list(np.vstack((m1, m2, m3)).flatten()))\n        np.testing.assert_almost_equal(t123.W, np.hstack((w1, w2, w3)))\n        np.testing.assert_almost_equal(t123.ids, np.hstack((ids1, ids2, ids3)))\n        self.assertEqual(t123.name, \"t2\")\n        self.assertEqual(t123.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n        with t2.unlocked(t2.Y):\n            t2.Y = np.atleast_2d(t2.Y).T\n        t12 = data.Table.concatenate((t1, t2))\n        self.assertEqual(t12.domain, t1.domain)\n        np.testing.assert_almost_equal(t12.X, np.vstack((x1, x2)))\n        np.testing.assert_almost_equal(t12.Y, np.hstack((y1, y2)))\n        self.assertEqual(list(t12.metas.flatten()),\n                         list(np.vstack((m1, m2)).flatten()))\n        np.testing.assert_almost_equal(t12.W, np.hstack((w1, w2)))\n        np.testing.assert_almost_equal(t12.ids, np.hstack((ids1, ids2)))\n        self.assertEqual(t12.name, \"t2\")\n        self.assertEqual(t12.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n    def test_concatenate_exceptions(self):\n        zoo = data.Table(\"zoo\")\n        iris = data.Table(\"iris\")\n\n        self.assertRaises(ValueError, data.Table.concatenate, [])\n        self.assertRaises(ValueError, data.Table.concatenate, [zoo, iris])\n\n    def test_concatenate_sparse(self):\n        iris = Table(\"iris\")\n        with iris.unlocked():\n            iris.X = sp.csc_matrix(iris.X)\n        new = Table.concatenate([iris, iris])\n        self.assertEqual(len(new), 300)\n        self.assertTrue(sp.issparse(new.X), \"Concatenated X is not sparse.\")\n        self.assertFalse(sp.issparse(new.Y), \"Concatenated Y is not dense.\")\n        self.assertFalse(sp.issparse(new.metas), \"Concatenated metas is not dense.\")\n        self.assertEqual(len(new.ids), 300)\n\n    def test_pickle(self):\n        import pickle\n\n        d = data.Table(\"zoo\")\n        s = pickle.dumps(d)\n        d2 = pickle.loads(s)\n        self.assertEqual(d[0], d2[0])\n\n        self.assertEqual(d.checksum(include_metas=False),\n                         d2.checksum(include_metas=False))\n\n        d = data.Table(\"iris\")\n        s = pickle.dumps(d)\n        d2 = pickle.loads(s)\n        self.assertEqual(d[0], d2[0])\n        self.assertEqual(d.checksum(include_metas=False),\n                         d2.checksum(include_metas=False))\n\n    def test_translate_through_slice(self):\n        d = data.Table(\"iris\")\n        dom = data.Domain([\"petal length\", \"sepal length\", \"iris\"],\n                          source=d.domain)\n        d_ref = d[:10, dom.variables]\n        self.assertEqual(d_ref.domain.class_var, d.domain.class_var)\n        self.assertEqual(d_ref[0, \"petal length\"], d[0, \"petal length\"])\n        self.assertEqual(d_ref[0, \"sepal length\"], d[0, \"sepal length\"])\n        self.assertEqual(d_ref.X.shape, (10, 2))\n        self.assertEqual(d_ref.Y.shape, (10,))\n\n    def test_saveTab(self):\n        d = data.Table(\"iris\")[:3]\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            for e1, e2 in zip(d, d2):\n                self.assertEqual(e1, e2)\n        finally:\n            os.remove(\"test-save.tab\")\n            os.remove(\"test-save.tab.metadata\")\n\n        dom = data.Domain([data.ContinuousVariable(\"a\")])\n        d = data.Table.from_list(dom, [[i] for i in range(3)])\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            self.assertEqual(len(d.domain.attributes), 1)\n            self.assertEqual(d.domain.class_var, None)\n            for i in range(3):\n                self.assertEqual(d2[i], [i])\n        finally:\n            os.remove(\"test-save.tab\")\n\n        dom = data.Domain([data.ContinuousVariable(\"a\")], None)\n        d = data.Table.from_list(dom, [[i] for i in range(3)])\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            self.assertEqual(len(d.domain.attributes), 1)\n            for i in range(3):\n                self.assertEqual(d2[i], [i])\n        finally:\n            os.remove(\"test-save.tab\")\n\n        d = data.Table(\"zoo\")\n        d.save(\"test-zoo.tab\")\n        dd = data.Table(\"test-zoo\")\n        try:\n            self.assertTupleEqual(d.domain.metas, dd.domain.metas,\n                                  msg=\"Meta attributes don't match.\")\n            self.assertTupleEqual(d.domain.variables, dd.domain.variables,\n                                  msg=\"Attributes don't match.\")\n\n            np.testing.assert_almost_equal(d.W, dd.W,\n                                           err_msg=\"Weights don't match.\")\n            for i in range(10):\n                for j in d.domain.variables:\n                    self.assertEqual(d[i][j], dd[i][j])\n        finally:\n            os.remove(\"test-zoo.tab\")\n            os.remove(\"test-zoo.tab.metadata\")\n\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d.set_weights(range(len(d)))\n        d.save(\"test-zoo-weights.tab\")\n        dd = data.Table(\"test-zoo-weights\")\n        try:\n            self.assertTupleEqual(d.domain.metas, dd.domain.metas,\n                                  msg=\"Meta attributes don't match.\")\n            self.assertTupleEqual(d.domain.variables, dd.domain.variables,\n                                  msg=\"Attributes don't match.\")\n\n            np.testing.assert_almost_equal(d.W, dd.W,\n                                           err_msg=\"Weights don't match.\")\n            for i in range(10):\n                for j in d.domain.variables:\n                    self.assertEqual(d[i][j], dd[i][j])\n        finally:\n            os.remove(\"test-zoo-weights.tab\")\n            os.remove(\"test-zoo-weights.tab.metadata\")\n\n    def test_save_pickle(self):\n        table = data.Table(\"iris\")\n        try:\n            table.save(\"iris.pickle\")\n            table2 = data.Table.from_file(\"iris.pickle\")\n            np.testing.assert_almost_equal(table.X, table2.X)\n            np.testing.assert_almost_equal(table.Y, table2.Y)\n            self.assertEqual(table.domain[0], table2.domain[0])\n        finally:\n            os.remove(\"iris.pickle\")\n\n    def test_from_numpy(self):\n        a = np.arange(20, dtype=\"d\").reshape((4, 5)).copy()\n        a[:, -1] = [0, 0, 0, 1]\n        dom = data.Domain([data.ContinuousVariable(x) for x in \"abcd\"],\n                          data.DiscreteVariable(\"e\", values=(\"no\", \"yes\")))\n        table = data.Table(dom, a)\n        with table.unlocked():\n            for i in range(4):\n                self.assertEqual(table[i].get_class(), \"no\" if i < 3 else \"yes\")\n                for j in range(5):\n                    self.assertEqual(a[i, j], table[i, j])\n\n        with table.unlocked(), self.assertRaises(IndexError):\n            table[0, -5] = 5\n\n    def test_filter_is_defined(self):\n        d = data.Table(\"iris\")\n        with d.unlocked():\n            d[1, 4] = Unknown\n        self.assertTrue(isnan(d[1, 4]))\n        with d.unlocked():\n            d[140, 0] = Unknown\n        e = filter.IsDefined()(d)\n        self.assertEqual(len(e), len(d) - 2)\n        self.assertEqual(e[0], d[0])\n        self.assertEqual(e[1], d[2])\n        self.assertEqual(e[147], d[149])\n        self.assertTrue(d.has_missing())\n        self.assertFalse(e.has_missing())\n\n    def test_filter_has_class(self):\n        d = data.Table(\"iris\")\n        with d.unlocked():\n            d[1, 4] = Unknown\n        self.assertTrue(isnan(d[1, 4]))\n        with d.unlocked():\n            d[140, 0] = Unknown\n        e = filter.HasClass()(d)\n        self.assertEqual(len(e), len(d) - 1)\n        self.assertEqual(e[0], d[0])\n        self.assertEqual(e[1], d[2])\n        self.assertEqual(e[148], d[149])\n        self.assertTrue(d.has_missing())\n        self.assertTrue(e.has_missing())\n        self.assertFalse(e.has_missing_class())\n\n    def test_filter_random(self):\n        d = data.Table(\"iris\")\n        e = filter.Random(50)(d)\n        self.assertEqual(len(e), 50)\n        e = filter.Random(50, negate=True)(d)\n        self.assertEqual(len(e), 100)\n        for _ in range(5):\n            e = filter.Random(0.2)(d)\n            self.assertEqual(len(e), 30)\n            bc = np.bincount(np.array(e.Y[:], dtype=int))\n            if min(bc) > 7:\n                break\n        else:\n            self.fail(\"Filter returns too uneven distributions\")\n\n    def test_filter_values_nested(self):\n        d = data.Table(\"iris\")\n        f1 = filter.FilterContinuous(d.columns.sepal_length,\n                                     filter.FilterContinuous.Between,\n                                     min=4.5, max=5.0)\n        f2 = filter.FilterContinuous(d.columns.sepal_width,\n                                     filter.FilterContinuous.Between,\n                                     min=3.1, max=3.4)\n        f3 = filter.FilterDiscrete(d.columns.iris, [0, 1])\n        f = filter.Values([filter.Values([f1, f2], conjunction=False), f3])\n        self.assertEqual(41, len(f(d)))\n\n    def test_filter_string_works_for_numeric_columns(self):\n        var = StringVariable(\"s\")\n        data = Table.from_list(Domain([], metas=[var]),\n                               [[x] for x in range(21)])\n        # 1, 2, 3, ..., 18, 19, 20\n\n        fs = filter.FilterString\n        filters = [\n            ((fs.Greater, \"5\"), dict(rows=4)),\n            # 6, 7, 8, 9\n            ((fs.Between, \"15\", \"2\"), dict(rows=6)),\n            # 15, 16, 17, 18, 19, 2\n            ((fs.Contains, \"2\"), dict(rows=3)),\n            # 2, 12, 20\n        ]\n\n        for args, expected in filters:\n            f = fs(var, *args)\n            filtered_data = filter.Values([f])(data)\n            self.assertEqual(len(filtered_data), expected[\"rows\"],\n                             \"{} returned wrong number of rows\".format(args))\n\n    def test_filter_value_continuous(self):\n        d = data.Table(\"iris\")\n        col = d.X[:, 2]\n\n        v = d.columns\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Between,\n                                    min=4.5, max=5.1)\n\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] >= 4.5))\n        self.assertTrue(np.all(x.X[:, 2] <= 5.1))\n        self.assertEqual(sum((col >= 4.5) * (col <= 5.1)), len(x))\n\n        f.ref = 5.1\n        f.oper = filter.FilterContinuous.Equal\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.NotEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] != 5.1))\n        self.assertEqual(sum(col != 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Less\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] < 5.1))\n        self.assertEqual(sum(col < 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.LessEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] <= 5.1))\n        self.assertEqual(sum(col <= 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Greater\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] > 5.1))\n        self.assertEqual(sum(col > 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] >= 5.1))\n        self.assertEqual(sum(col >= 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Outside\n        f.ref, f.max = 4.5, 5.1\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(e[2] < 4.5 or e[2] > 5.1)\n        self.assertEqual(sum((col < 4.5) + (col > 5.1)), len(x))\n\n        f.oper = filter.FilterContinuous.IsDefined\n        f.ref = f.max = None\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d))\n\n        with d.unlocked():\n            d[:30, v.petal_length] = Unknown\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 30)\n\n    def test_filter_value_continuous_args(self):\n        d = data.Table(\"iris\")\n        col = d.X[:, 2]\n        v = d.columns\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(2,\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"petal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"sepal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        f.column = 2\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"sepal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        f.column = v.petal_length\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=18)\n        f.ref = 5.1\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=18)\n        f.ref = 5.1\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n    def test_valueFilter_discrete(self):\n        d = data.Table(\"zoo\")\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, 3, 4])\n        for e in filter.Values([f])(d):\n            self.assertTrue(e.get_class() in [2, 3, 4])\n\n        f.values = [\"mammal\"]\n        for e in filter.Values([f])(d):\n            self.assertEqual(e.get_class(), \"mammal\")\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, \"mammal\"])\n        for e in filter.Values([f])(d):\n            self.assertTrue(e.get_class() in [2, \"mammal\"])\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, \"martian\"])\n        self.assertRaises(ValueError, d._filter_values, f)\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=(2, data.Table))\n        self.assertRaises(TypeError, d._filter_values, f)\n\n        v = d.columns\n        f = filter.FilterDiscrete(v.hair, values=None)\n        self.assertEqual(len(filter.Values([f])(d)), len(d))\n\n        with d.unlocked():\n            d[:5, v.hair] = Unknown\n        self.assertEqual(len(filter.Values([f])(d)), len(d) - 5)\n\n    def test_valueFilter_string_is_defined(self):\n        d = data.Table(\"datasets/test9.tab\")\n        f = filter.FilterString(-5, filter.FilterString.IsDefined)\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 7)\n\n    def test_valueFilter_discrete_meta_is_defined(self):\n        d = data.Table(\"datasets/test9.tab\")\n        f = filter.FilterDiscrete(-4, None)\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 8)\n\n    def test_valueFilter_string_case_sens(self):\n        d = data.Table(\"zoo\")\n        col = d[:, \"name\"].metas[:, 0]\n\n        f = filter.FilterString(\"name\",\n                                filter.FilterString.Equal, \"girl\")\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 1)\n        self.assertEqual(x[0, \"name\"], \"girl\")\n        self.assertTrue(np.all(x.metas == \"girl\"))\n\n        f.oper = f.NotEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 1)\n        self.assertTrue(np.all(x[:, \"name\"] != \"girl\"))\n\n        f.oper = f.Less\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"girl\"))\n        self.assertTrue(np.all(x.metas < \"girl\"))\n\n        f.oper = f.LessEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col <= \"girl\"))\n        self.assertTrue(np.all(x.metas <= \"girl\"))\n\n        f.oper = f.Greater\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col > \"girl\"))\n        self.assertTrue(np.all(x.metas > \"girl\"))\n\n        f.oper = f.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col >= \"girl\"))\n        self.assertTrue(np.all(x.metas >= \"girl\"))\n\n        f.oper = f.Between\n        f.max = \"lion\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum((col >= \"girl\") * (col <= \"lion\")))\n        self.assertTrue(np.all(x.metas >= \"girl\"))\n        self.assertTrue(np.all(x.metas <= \"lion\"))\n\n        f.oper = f.Outside\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"girl\") + sum(col > \"lion\"))\n        self.assertTrue(np.all((x.metas < \"girl\") + (x.metas > \"lion\")))\n\n        f.oper = f.Contains\n        f.ref = \"ea\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(\"ea\" in e[\"name\"])\n        self.assertEqual(len(x), len([e for e in col if \"ea\" in e]))\n\n        f.oper = f.StartsWith\n        f.ref = \"sea\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).startswith(\"sea\"))\n        self.assertEqual(len(x), len([e for e in col if e.startswith(\"sea\")]))\n\n        f.oper = f.EndsWith\n        f.ref = \"ion\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n        self.assertEqual(len(x), len([e for e in col if e.endswith(\"ion\")]))\n\n    def test_valueFilter_string_case_insens(self):\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d[d[:, \"name\"].metas[:, 0] == \"girl\", \"name\"] = \"GIrl\"\n\n        col = d[:, \"name\"].metas[:, 0]\n\n        f = filter.FilterString(\"name\",\n                                filter.FilterString.Equal, \"giRL\")\n        f.case_sensitive = False\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 1)\n        self.assertEqual(x[0, \"name\"], \"GIrl\")\n        self.assertTrue(np.all(x.metas == \"GIrl\"))\n\n        f.oper = f.NotEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 1)\n        self.assertTrue(np.all(x[:, \"name\"] != \"GIrl\"))\n\n        f.oper = f.Less\n        f.ref = \"CHiCKEN\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"chicken\") - 1)  # girl!\n        self.assertTrue(np.all(x.metas < \"chicken\"))\n\n        f.oper = f.LessEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col <= \"chicken\") - 1)\n        self.assertTrue(np.all(x.metas <= \"chicken\"))\n\n        f.oper = f.Greater\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col > \"chicken\") + 1)\n        for e in x:\n            self.assertGreater(str(e[\"name\"]).lower(), \"chicken\")\n\n        f.oper = f.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col >= \"chicken\") + 1)\n        for e in x:\n            self.assertGreaterEqual(str(e[\"name\"]).lower(), \"chicken\")\n\n        f.oper = f.Between\n        f.max = \"liOn\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum((col >= \"chicken\") * (col <= \"lion\")) + 1)\n        for e in x:\n            self.assertTrue(\"chicken\" <= str(e[\"name\"]).lower() <= \"lion\")\n\n        f.oper = f.Outside\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"chicken\") + sum(col > \"lion\") - 1)\n        self.assertTrue(np.all((x.metas < \"chicken\") + (x.metas > \"lion\")))\n\n        f.oper = f.Contains\n        f.ref = \"iR\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(\"ir\" in str(e[\"name\"]).lower())\n        self.assertEqual(len(x), len([e for e in col if \"ir\" in e]) + 1)\n\n        f.oper = f.StartsWith\n        f.ref = \"GI\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).lower().startswith(\"gi\"))\n        self.assertEqual(len(x),\n                         len([e for e in col if e.lower().startswith(\"gi\")]))\n\n        f.oper = f.EndsWith\n        f.ref = \"ion\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n        self.assertEqual(len(x), len([e for e in col if e.endswith(\"ion\")]))\n\n    def test_valueFilter_regex(self):\n        d = data.Table(\"zoo\")\n        f = filter.FilterRegex(d.domain['name'], '^c...$')\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 7)\n\n    def test_valueFilter_stringList(self):\n        data = Table(\"zoo\")\n        var = data.domain[\"name\"]\n\n        fs = filter.FilterStringList\n        filters = [\n            (([\"swan\", \"tuna\", \"wasp\"], True), dict(rows=3)),\n            (([\"swan\", \"tuna\", \"wasp\"], False), dict(rows=3)),\n            (([\"WoRm\", \"TOad\", \"vOLe\"], True), dict(rows=0)),\n            (([\"WoRm\", \"TOad\", \"vOLe\"], False), dict(rows=3)),\n        ]\n\n        for args, expected in filters:\n            f = fs(var, *args)\n            filtered_data = filter.Values([f])(data)\n            self.assertEqual(len(filtered_data), expected[\"rows\"],\n                             \"{} returned wrong number of rows\".format(args))\n\n    def test_table_dtypes(self):\n        table = data.Table(\"iris\")\n        metas = np.hstack((table.metas, table.Y.reshape(len(table), 1)))\n        attributes_metas = table.domain.metas + table.domain.class_vars\n        domain_metas = data.Domain(table.domain.attributes[:2],\n                                   table.domain.attributes[2:],\n                                   attributes_metas)\n        table_metas = data.Table(domain_metas, table.X[:, : 2], table.X[:, 2:],\n                                 metas)\n        new_table = data.Table.from_table(data.Domain(table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.X.dtype, np.float64)\n        new_table = data.Table.from_table(data.Domain((), table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.Y.dtype, np.float64)\n        new_table = data.Table.from_table(data.Domain((), (), table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.metas.dtype, np.float64)\n\n    def test_attributes(self):\n        table = data.Table(\"iris\")\n        table.attributes = {1: \"test\"}\n        table2 = table[:4]\n        self.assertEqual(table2.attributes[1], \"test\")\n        table2.attributes[1] = \"modified\"\n        self.assertEqual(table.attributes[1], \"modified\")\n\n    # TODO Test conjunctions and disjunctions of conditions\n\n    def test_is_sparse(self):\n        table = data.Table(\"iris\")\n        self.assertFalse(table.is_sparse())\n\n        with table.unlocked():\n            table.X = sp.csr_matrix(table.X)\n            self.assertTrue(table.is_sparse())\n\n    def test_repr_sparse_with_one_row(self):\n        table = data.Table(\"iris\")[:1]\n        with table.unlocked():\n            table.X = sp.csr_matrix(table.X)\n        repr(table)     # make sure repr does not crash\n\n    def test_inf(self):\n        a = np.array([[2, 0, 0, 0],\n                      [0, np.nan, np.nan, 1],\n                      [0, 0, np.inf, 0]])\n        with self.assertWarns(Warning):\n            tab = data.Table.from_numpy(None, a)\n        self.assertEqual(tab.get_nan_frequency_attribute(), 3/12)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 26,
                            "end_lineno": 1170,
                            "parent": null
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                },
                {
                    "descriptor": {
                        "old_range": {
                            "start": 608,
                            "length": 6
                        },
                        "new_range": {
                            "start": 607,
                            "length": 20
                        },
                        "section": "class TableTestCase(unittest.TestCase):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "        self.assertEqual(d.checksum(include_metas=False),",
                                "type": "context"
                            },
                            {
                                "content": "                         d2.checksum(include_metas=False))",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "    def test_pickle_setstate(self):",
                                "type": "added"
                            },
                            {
                                "content": "        d = data.Table(\"zoo\")",
                                "type": "added"
                            },
                            {
                                "content": "        s = pickle.dumps(d)",
                                "type": "added"
                            },
                            {
                                "content": "        with patch(\"Orange.data.Table.__setstate__\", Mock()) as mock:",
                                "type": "added"
                            },
                            {
                                "content": "            pickle.loads(s)",
                                "type": "added"
                            },
                            {
                                "content": "            state = mock.call_args[0][0]",
                                "type": "added"
                            },
                            {
                                "content": "            for k in [\"X\", \"_Y\", \"metas\"]:",
                                "type": "added"
                            },
                            {
                                "content": "                self.assertIn(k, state)",
                                "type": "added"
                            },
                            {
                                "content": "                self.assertEqual(state[k].ndim, 2)",
                                "type": "added"
                            },
                            {
                                "content": "            self.assertIn(\"W\", state)",
                                "type": "added"
                            },
                            {
                                "content": "            for k in [\"_X\", \"Y\", \"_metas\", \"_W\"]:",
                                "type": "added"
                            },
                            {
                                "content": "                self.assertNotIn(k, state)",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "    def test_translate_through_slice(self):",
                                "type": "context"
                            },
                            {
                                "content": "        d = data.Table(\"iris\")",
                                "type": "context"
                            },
                            {
                                "content": "        dom = data.Domain([\"petal length\", \"sepal length\", \"iris\"],",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "Orange/tests/test_table.py",
                            "type": "class",
                            "name": "TableTestCase",
                            "content": "class TableTestCase(unittest.TestCase):\n    def setUp(self):\n        data.table.dataset_dirs.append(test_dirname())\n\n    def tearDown(self):\n        data.table.dataset_dirs.remove(test_dirname())\n\n    def test_indexing_class(self):\n        d = data.Table(\"datasets/test1\")\n        self.assertEqual([e.get_class() for e in d], [\"t\", \"t\", \"f\"])\n        cind = len(d.domain.variables) - 1\n        self.assertEqual([e[cind] for e in d], [\"t\", \"t\", \"f\"])\n        self.assertEqual([e[\"d\"] for e in d], [\"t\", \"t\", \"f\"])\n        cvar = d.domain.class_var\n        self.assertEqual([e[cvar] for e in d], [\"t\", \"t\", \"f\"])\n\n    def test_filename(self):\n        dir = data.table.get_sample_datasets_dir()\n        d = data.Table(\"iris\")\n        self.assertEqual(d.__file__, os.path.join(dir, \"iris.tab\"))\n\n        d = data.Table(\"datasets/test2.tab\")\n        self.assertTrue(d.__file__.endswith(\"test2.tab\"))  # platform dependent\n\n    def test_indexing(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            # regular, discrete\n            varc = d.domain[\"c\"]\n            self.assertEqual(d[0, 1], \"0\")\n            self.assertEqual(d[0, varc], \"0\")\n            self.assertEqual(d[0, \"c\"], \"0\")\n            self.assertEqual(d[0][1], \"0\")\n            self.assertEqual(d[0][varc], \"0\")\n            self.assertEqual(d[0][\"c\"], \"0\")\n            self.assertEqual(d[np.int_(0), np.int_(1)], \"0\")\n            self.assertEqual(d[np.int_(0)][np.int_(1)], \"0\")\n\n            # regular, continuous\n            varb = d.domain[\"b\"]\n            self.assertEqual(d[0, 0], 0)\n            self.assertEqual(d[0, varb], 0)\n            self.assertEqual(d[0, \"b\"], 0)\n            self.assertEqual(d[0][0], 0)\n            self.assertEqual(d[0][varb], 0)\n            self.assertEqual(d[0][\"b\"], 0)\n            self.assertEqual(d[np.int_(0), np.int_(0)], 0)\n            self.assertEqual(d[np.int_(0)][np.int_(0)], 0)\n\n            # negative\n            varb = d.domain[\"b\"]\n            self.assertEqual(d[-2, 0], 3.333)\n            self.assertEqual(d[-2, varb], 3.333)\n            self.assertEqual(d[-2, \"b\"], 3.333)\n            self.assertEqual(d[-2][0], 3.333)\n            self.assertEqual(d[-2][varb], 3.333)\n            self.assertEqual(d[-2][\"b\"], 3.333)\n            self.assertEqual(d[np.int_(-2), np.int_(0)], 3.333)\n            self.assertEqual(d[np.int_(-2)][np.int_(0)], 3.333)\n\n            # meta, discrete\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n            self.assertEqual(d[0, metaa], \"A\")\n            self.assertEqual(d[0, vara], \"A\")\n            self.assertEqual(d[0, \"a\"], \"A\")\n            self.assertEqual(d[0][metaa], \"A\")\n            self.assertEqual(d[0][vara], \"A\")\n            self.assertEqual(d[0][\"a\"], \"A\")\n            self.assertEqual(d[np.int_(0), np.int_(metaa)], \"A\")\n            self.assertEqual(d[np.int_(0)][np.int_(metaa)], \"A\")\n\n            # meta, string\n            vare = d.domain[\"e\"]\n            metae = d.domain.index(\"e\")\n            self.assertEqual(d[0, metae], \"i\")\n            self.assertEqual(d[0, vare], \"i\")\n            self.assertEqual(d[0, \"e\"], \"i\")\n            self.assertEqual(d[0][metae], \"i\")\n            self.assertEqual(d[0][vare], \"i\")\n            self.assertEqual(d[0][\"e\"], \"i\")\n            self.assertEqual(d[np.int_(0), np.int_(metae)], \"i\")\n            self.assertEqual(d[np.int_(0)][np.int_(metae)], \"i\")\n\n    def test_indexing_example(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            e = d[0]\n\n            # regular, discrete\n            varc = d.domain[\"c\"]\n            self.assertEqual(e[1], \"0\")\n            self.assertEqual(e[varc], \"0\")\n            self.assertEqual(e[\"c\"], \"0\")\n            self.assertEqual(e[np.int_(1)], \"0\")\n\n            # regular, continuous\n            varb = d.domain[\"b\"]\n            self.assertEqual(e[0], 0)\n            self.assertEqual(e[varb], 0)\n            self.assertEqual(e[\"b\"], 0)\n            self.assertEqual(e[np.int_(0)], 0)\n\n            # meta, discrete\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n            self.assertEqual(e[metaa], \"A\")\n            self.assertEqual(e[vara], \"A\")\n            self.assertEqual(e[\"a\"], \"A\")\n            self.assertEqual(e[np.int_(metaa)], \"A\")\n\n            # meta, string\n            vare = d.domain[\"e\"]\n            metae = d.domain.index(\"e\")\n            self.assertEqual(e[metae], \"i\")\n            self.assertEqual(e[vare], \"i\")\n            self.assertEqual(e[\"e\"], \"i\")\n            self.assertEqual(e[np.int_(metae)], \"i\")\n\n    def test_indexing_assign_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            # meta\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, \"a\"] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][\"a\"] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, vara] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][vara] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, metaa] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][metaa] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, np.int_(metaa)] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][np.int_(metaa)] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            # regular\n            varb = d.domain[\"b\"]\n\n            self.assertEqual(d[0, \"b\"], 0)\n            with d.unlocked():\n                d[0, \"b\"] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][\"b\"] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, varb] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][varb] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, 0] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][0] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, np.int_(0)] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][np.int_(0)] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n    def test_indexing_assign_example(self):\n        def almost_equal_list(s, t):\n            for e, f in zip(s, t):\n                self.assertAlmostEqual(e, f)\n\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            self.assertFalse(isnan(d[0, \"a\"]))\n            with d.unlocked():\n                d[0] = [\"3.14\", \"1\", \"f\"]\n            almost_equal_list(d[0].values(), [3.14, \"1\", \"f\"])\n            self.assertTrue(isnan(d[0, \"a\"]))\n\n            with d.unlocked():\n                d[0] = [3.15, 1, \"t\"]\n            almost_equal_list(d[0].values(), [3.15, \"0\", \"t\"])\n\n            with d.unlocked():\n                d[np.int_(0)] = [3.15, 2, \"f\"]\n            almost_equal_list(d[0].values(), [3.15, 2, \"f\"])\n\n            with d.unlocked(), self.assertRaises(ValueError):\n                d[0] = [\"3.14\", \"1\"]\n\n            with d.unlocked(), self.assertRaises(ValueError):\n                d[np.int_(0)] = [\"3.14\", \"1\"]\n\n            ex = data.Instance(d.domain, [\"3.16\", \"1\", \"f\"])\n            with d.unlocked():\n                d[0] = ex\n            almost_equal_list(d[0].values(), [3.16, \"1\", \"f\"])\n\n            ex = data.Instance(d.domain, [\"3.16\", 2, \"t\"])\n            with d.unlocked():\n                d[np.int_(0)] = ex\n            almost_equal_list(d[0].values(), [3.16, 2, \"t\"])\n\n            ex = data.Instance(d.domain, [\"3.16\", \"1\", \"f\"])\n            ex[\"e\"] = \"mmmapp\"\n            with d.unlocked():\n                d[0] = ex\n            almost_equal_list(d[0].values(), [3.16, \"1\", \"f\"])\n            self.assertEqual(d[0, \"e\"], \"mmmapp\")\n\n    def test_slice(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            x = d[:3]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [0, 1.1, 2.22])\n\n            x = d[2:5]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.22, 2.23, 2.24])\n\n            x = d[4:1:-1]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.24, 2.23, 2.22])\n\n            x = d[-3:]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.26, 3.333, Unknown])\n\n    def test_assign_slice_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            with d.unlocked():\n                d[2:5, 0] = 42\n            self.assertEqual([e[0] for e in d],\n                             [0, 1.1, 42, 42, 42, 2.25, 2.26, 3.333, Unknown])\n            with d.unlocked():\n                d[:3, \"b\"] = 43\n            self.assertEqual([e[0] for e in d],\n                             [43, 43, 43, 42, 42, 2.25, 2.26, 3.333, None])\n            with d.unlocked():\n                d[-2:, d.domain[0]] = 44\n            self.assertEqual([e[0] for e in d],\n                             [43, 43, 43, 42, 42, 2.25, 2.26, 44, 44])\n\n            with d.unlocked():\n                d[2:5, \"a\"] = \"A\"\n            self.assertEqual([e[\"a\"] for e in d], list(\"ABAAACCDE\"))\n\n    def test_multiple_indices(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            with self.assertRaises(IndexError):\n                x = d[2, 5, 1]\n\n            with self.assertRaises(IndexError):\n                x = d[(2, 5, 1)]\n\n            x = d[[2, 5, 1]]\n            self.assertEqual([e[0] for e in x], [2.22, 2.25, 1.1])\n\n    def test_assign_multiple_indices_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            with d.unlocked():\n                d[1:4, \"b\"] = 42\n            self.assertEqual([e[0] for e in d],\n                             [0, 42, 42, 42, 2.24, 2.25, 2.26, 3.333, None])\n\n            with d.unlocked():\n                d[range(5, 2, -1), \"b\"] = None\n            self.assertEqual([e[d.domain[0]] for e in d],\n                             [0, 42, 42, None, \"?\", \"\", 2.26, 3.333, None])\n\n    def test_set_multiple_indices_example(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            vals = [e[0] for e in d]\n            with d.unlocked():\n                d[[1, 2, 5]] = [42, None, None]\n            vals[1] = vals[2] = vals[5] = 42\n            self.assertEqual([e[0] for e in d], vals)\n\n    def test_bool(self):\n        d = data.Table(\"iris\")\n        self.assertTrue(d)\n\n        d = data.Table(\"datasets/test3\")\n        self.assertFalse(d)\n\n        d = data.Table(\"iris\")\n        self.assertTrue(d)\n\n    def test_checksum(self):\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d[42, 3] = 0\n        crc1 = d.checksum(False)\n\n        with d.unlocked():\n            d[42, 3] = 1\n        crc2 = d.checksum(False)\n        self.assertNotEqual(crc1, crc2)\n\n        with d.unlocked():\n            d[42, 3] = 0\n        crc3 = d.checksum(False)\n        self.assertEqual(crc1, crc3)\n\n        _ = d[42, \"name\"]\n        with d.unlocked():\n            d[42, \"name\"] = \"non-animal\"\n        crc4 = d.checksum(False)\n        self.assertEqual(crc1, crc4)\n        crc4 = d.checksum(True)\n        crc5 = d.checksum(1)\n        crc6 = d.checksum(False)\n        self.assertNotEqual(crc1, crc4)\n        self.assertNotEqual(crc1, crc5)\n        self.assertEqual(crc1, crc6)\n\n    def test_total_weight(self):\n        d = data.Table(\"zoo\")\n        self.assertEqual(d.total_weight(), len(d))\n\n        with d.unlocked():\n            d.set_weights(0)\n            d[0].weight = 0.1\n            d[10].weight = 0.2\n            d[-1].weight = 0.3\n        self.assertAlmostEqual(d.total_weight(), 0.6)\n\n    def test_has_missing(self):\n        d = data.Table(\"zoo\")\n        self.assertFalse(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n        with d.unlocked():\n            d[10, 3] = \"?\"\n        self.assertTrue(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n        with d.unlocked():\n            d[10].set_class(\"?\")\n        self.assertTrue(d.has_missing())\n        self.assertTrue(d.has_missing_class())\n\n        with d.unlocked():\n            d = data.Table(\"datasets/test3\")\n        self.assertFalse(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n    def test_shuffle(self):\n        d = data.Table(\"zoo\")\n        crc = d.checksum()\n        names = set(str(x[\"name\"]) for x in d)\n\n        with d.unlocked():\n            d.shuffle()\n        self.assertNotEqual(crc, d.checksum())\n        self.assertSetEqual(names, set(str(x[\"name\"]) for x in d))\n        crc2 = d.checksum()\n\n        x = d[2:10]\n        crcx = x.checksum()\n        with d.unlocked():\n            d.shuffle()\n        self.assertNotEqual(crc2, d.checksum())\n        self.assertEqual(crcx, x.checksum())\n\n        crc2 = d.checksum()\n        with x.unlocked():\n            x.shuffle()\n        self.assertNotEqual(crcx, x.checksum())\n        self.assertEqual(crc2, d.checksum())\n\n    @staticmethod\n    def not_less_ex(ex1, ex2):\n        for v1, v2 in zip(ex1, ex2):\n            if v1 != v2:\n                return v1 < v2\n        return True\n\n    @staticmethod\n    def sorted(d):\n        for i in range(1, len(d)):\n            if not TableTestCase.not_less_ex(d[i - 1], d[i]):\n                return False\n        return True\n\n    @staticmethod\n    def not_less_ex_ord(ex1, ex2, ord):\n        for a in ord:\n            if ex1[a] != ex2[a]:\n                return ex1[a] < ex2[a]\n        return True\n\n    @staticmethod\n    def sorted_ord(d, ord):\n        for i in range(1, len(d)):\n            if not TableTestCase.not_less_ex_ord(d[i - 1], d[i], ord):\n                return False\n        return True\n\n    def test_copy(self):\n        t = data.Table.from_numpy(\n            None, np.zeros((5, 3)), np.arange(5), np.zeros((5, 3)))\n\n        copy = t.copy()\n        self.assertTrue(np.all(t.X == copy.X))\n        self.assertTrue(np.all(t.Y == copy.Y))\n        self.assertTrue(np.all(t.metas == copy.metas))\n        with copy.unlocked():\n            copy[0] = [1, 1, 1, 1]\n        self.assertFalse(np.all(t.X == copy.X))\n        self.assertFalse(np.all(t.Y == copy.Y))\n        self.assertFalse(np.all(t.metas == copy.metas))\n\n    def test_copy_sparse(self):\n        t = data.Table('iris').to_sparse()\n        copy = t.copy()\n\n        self.assertEqual((t.X != copy.X).nnz, 0)      # sparse matrices match by content\n        np.testing.assert_equal(t.Y, copy.Y)\n        np.testing.assert_equal(t.metas, copy.metas)\n\n        self.assertNotEqual(id(t.X), id(copy.X))\n        self.assertNotEqual(id(t._Y), id(copy._Y))\n        self.assertNotEqual(id(t.metas), id(copy.metas))\n\n        # ensure that copied sparse arrays do not share data\n        with t.unlocked():\n            t.X[0, 0] = 42\n        self.assertEqual(copy.X[0, 0], 5.1)\n\n    def test_concatenate(self):\n        d1 = data.Domain(\n            [data.ContinuousVariable(n) for n in \"abc\"],\n            data.DiscreteVariable(\"y\", values=\"ABC\"),\n            [data.StringVariable(n) for n in [\"m1\", \"m2\"]],\n        )\n        x1 = np.arange(6).reshape(2, 3)\n        y1 = np.array([0, 1])\n        m1 = np.array([[\"foo\", \"bar\"], [\"baz\", \"qux\"]])\n        w1 = np.random.random((2,))\n        t1 = data.Table.from_numpy(d1, x1, y1, m1, w1)\n        t1.ids = ids1 = np.array([100, 101])\n        t1.attributes = {\"a\": 42, \"c\": 43}\n\n        x2 = np.arange(6, 15).reshape(3, 3)\n        y2 = np.array([1, 2, 0])\n        m2 = np.array([[\"a\", \"b\"], [\"c\", \"d\"], [\"e\", \"f\"]])\n        w2 = np.random.random((3,))\n        t2 = data.Table.from_numpy(d1, x2, y2, m2, w2)\n        t2.ids = ids2 = np.array([102, 103, 104])\n        t2.name = \"t2\"\n        t2.attributes = {\"a\": 44, \"b\": 45}\n\n        x3 = np.arange(15, 27).reshape(4, 3)\n        y3 = np.array([2, 1, 1, 0])\n        m3 = np.array([[\"g\", \"h\"], [\"i\", \"j\"], [\"k\", \"l\"], [\"m\", \"n\"]])\n        w3 = np.random.random((4,))\n        t3 = data.Table.from_numpy(d1, x3, y3, m3, w3)\n        t3.ids = ids3 = np.array([102, 103, 104, 105])\n        t3.name = \"t3\"\n\n        t1b = data.Table.concatenate((t1,))\n        self.assertEqual(t1b.domain, t1.domain)\n        np.testing.assert_almost_equal(t1b.X, x1)\n        np.testing.assert_almost_equal(t1b.Y, y1)\n        self.assertEqual(list(t1b.metas.flatten()),\n                         list(m1.flatten()))\n        np.testing.assert_almost_equal(t1b.W, w1)\n        np.testing.assert_almost_equal(t1b.ids, ids1)\n        self.assertEqual(t1b.name, t1.name)\n        self.assertEqual(t1b.attributes, {\"a\": 42, \"c\": 43})\n\n        t12 = data.Table.concatenate((t1, t2))\n        self.assertEqual(t12.domain, t1.domain)\n        np.testing.assert_almost_equal(t12.X, np.vstack((x1, x2)))\n        np.testing.assert_almost_equal(t12.Y, np.hstack((y1, y2)))\n        self.assertEqual(list(t12.metas.flatten()),\n                         list(np.vstack((m1, m2)).flatten()))\n        np.testing.assert_almost_equal(t12.W, np.hstack((w1, w2)))\n        np.testing.assert_almost_equal(t12.ids, np.hstack((ids1, ids2)))\n        self.assertEqual(t12.name, \"t2\")\n        self.assertEqual(t12.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n        t123 = data.Table.concatenate((t1, t2, t3))\n        self.assertEqual(t123.domain, t1.domain)\n        np.testing.assert_almost_equal(t123.X, np.vstack((x1, x2, x3)))\n        np.testing.assert_almost_equal(t123.Y, np.hstack((y1, y2, y3)))\n        self.assertEqual(list(t123.metas.flatten()),\n                         list(np.vstack((m1, m2, m3)).flatten()))\n        np.testing.assert_almost_equal(t123.W, np.hstack((w1, w2, w3)))\n        np.testing.assert_almost_equal(t123.ids, np.hstack((ids1, ids2, ids3)))\n        self.assertEqual(t123.name, \"t2\")\n        self.assertEqual(t123.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n        with t2.unlocked(t2.Y):\n            t2.Y = np.atleast_2d(t2.Y).T\n        t12 = data.Table.concatenate((t1, t2))\n        self.assertEqual(t12.domain, t1.domain)\n        np.testing.assert_almost_equal(t12.X, np.vstack((x1, x2)))\n        np.testing.assert_almost_equal(t12.Y, np.hstack((y1, y2)))\n        self.assertEqual(list(t12.metas.flatten()),\n                         list(np.vstack((m1, m2)).flatten()))\n        np.testing.assert_almost_equal(t12.W, np.hstack((w1, w2)))\n        np.testing.assert_almost_equal(t12.ids, np.hstack((ids1, ids2)))\n        self.assertEqual(t12.name, \"t2\")\n        self.assertEqual(t12.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n    def test_concatenate_exceptions(self):\n        zoo = data.Table(\"zoo\")\n        iris = data.Table(\"iris\")\n\n        self.assertRaises(ValueError, data.Table.concatenate, [])\n        self.assertRaises(ValueError, data.Table.concatenate, [zoo, iris])\n\n    def test_concatenate_sparse(self):\n        iris = Table(\"iris\")\n        with iris.unlocked():\n            iris.X = sp.csc_matrix(iris.X)\n        new = Table.concatenate([iris, iris])\n        self.assertEqual(len(new), 300)\n        self.assertTrue(sp.issparse(new.X), \"Concatenated X is not sparse.\")\n        self.assertFalse(sp.issparse(new.Y), \"Concatenated Y is not dense.\")\n        self.assertFalse(sp.issparse(new.metas), \"Concatenated metas is not dense.\")\n        self.assertEqual(len(new.ids), 300)\n\n    def test_pickle(self):\n        d = data.Table(\"zoo\")\n        s = pickle.dumps(d)\n        d2 = pickle.loads(s)\n        self.assertEqual(d[0], d2[0])\n\n        self.assertEqual(d.checksum(include_metas=False),\n                         d2.checksum(include_metas=False))\n\n        d = data.Table(\"iris\")\n        s = pickle.dumps(d)\n        d2 = pickle.loads(s)\n        self.assertEqual(d[0], d2[0])\n        self.assertEqual(d.checksum(include_metas=False),\n                         d2.checksum(include_metas=False))\n\n    def test_pickle_setstate(self):\n        d = data.Table(\"zoo\")\n        s = pickle.dumps(d)\n        with patch(\"Orange.data.Table.__setstate__\", Mock()) as mock:\n            pickle.loads(s)\n            state = mock.call_args[0][0]\n            for k in [\"X\", \"_Y\", \"metas\"]:\n                self.assertIn(k, state)\n                self.assertEqual(state[k].ndim, 2)\n            self.assertIn(\"W\", state)\n            for k in [\"_X\", \"Y\", \"_metas\", \"_W\"]:\n                self.assertNotIn(k, state)\n\n\n    def test_translate_through_slice(self):\n        d = data.Table(\"iris\")\n        dom = data.Domain([\"petal length\", \"sepal length\", \"iris\"],\n                          source=d.domain)\n        d_ref = d[:10, dom.variables]\n        self.assertEqual(d_ref.domain.class_var, d.domain.class_var)\n        self.assertEqual(d_ref[0, \"petal length\"], d[0, \"petal length\"])\n        self.assertEqual(d_ref[0, \"sepal length\"], d[0, \"sepal length\"])\n        self.assertEqual(d_ref.X.shape, (10, 2))\n        self.assertEqual(d_ref.Y.shape, (10,))\n\n    def test_saveTab(self):\n        d = data.Table(\"iris\")[:3]\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            for e1, e2 in zip(d, d2):\n                self.assertEqual(e1, e2)\n        finally:\n            os.remove(\"test-save.tab\")\n            os.remove(\"test-save.tab.metadata\")\n\n        dom = data.Domain([data.ContinuousVariable(\"a\")])\n        d = data.Table.from_list(dom, [[i] for i in range(3)])\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            self.assertEqual(len(d.domain.attributes), 1)\n            self.assertEqual(d.domain.class_var, None)\n            for i in range(3):\n                self.assertEqual(d2[i], [i])\n        finally:\n            os.remove(\"test-save.tab\")\n\n        dom = data.Domain([data.ContinuousVariable(\"a\")], None)\n        d = data.Table.from_list(dom, [[i] for i in range(3)])\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            self.assertEqual(len(d.domain.attributes), 1)\n            for i in range(3):\n                self.assertEqual(d2[i], [i])\n        finally:\n            os.remove(\"test-save.tab\")\n\n        d = data.Table(\"zoo\")\n        d.save(\"test-zoo.tab\")\n        dd = data.Table(\"test-zoo\")\n        try:\n            self.assertTupleEqual(d.domain.metas, dd.domain.metas,\n                                  msg=\"Meta attributes don't match.\")\n            self.assertTupleEqual(d.domain.variables, dd.domain.variables,\n                                  msg=\"Attributes don't match.\")\n\n            np.testing.assert_almost_equal(d.W, dd.W,\n                                           err_msg=\"Weights don't match.\")\n            for i in range(10):\n                for j in d.domain.variables:\n                    self.assertEqual(d[i][j], dd[i][j])\n        finally:\n            os.remove(\"test-zoo.tab\")\n            os.remove(\"test-zoo.tab.metadata\")\n\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d.set_weights(range(len(d)))\n        d.save(\"test-zoo-weights.tab\")\n        dd = data.Table(\"test-zoo-weights\")\n        try:\n            self.assertTupleEqual(d.domain.metas, dd.domain.metas,\n                                  msg=\"Meta attributes don't match.\")\n            self.assertTupleEqual(d.domain.variables, dd.domain.variables,\n                                  msg=\"Attributes don't match.\")\n\n            np.testing.assert_almost_equal(d.W, dd.W,\n                                           err_msg=\"Weights don't match.\")\n            for i in range(10):\n                for j in d.domain.variables:\n                    self.assertEqual(d[i][j], dd[i][j])\n        finally:\n            os.remove(\"test-zoo-weights.tab\")\n            os.remove(\"test-zoo-weights.tab.metadata\")\n\n    def test_save_pickle(self):\n        table = data.Table(\"iris\")\n        try:\n            table.save(\"iris.pickle\")\n            table2 = data.Table.from_file(\"iris.pickle\")\n            np.testing.assert_almost_equal(table.X, table2.X)\n            np.testing.assert_almost_equal(table.Y, table2.Y)\n            self.assertEqual(table.domain[0], table2.domain[0])\n        finally:\n            os.remove(\"iris.pickle\")\n\n    def test_from_numpy(self):\n        a = np.arange(20, dtype=\"d\").reshape((4, 5)).copy()\n        a[:, -1] = [0, 0, 0, 1]\n        dom = data.Domain([data.ContinuousVariable(x) for x in \"abcd\"],\n                          data.DiscreteVariable(\"e\", values=(\"no\", \"yes\")))\n        table = data.Table(dom, a)\n        with table.unlocked():\n            for i in range(4):\n                self.assertEqual(table[i].get_class(), \"no\" if i < 3 else \"yes\")\n                for j in range(5):\n                    self.assertEqual(a[i, j], table[i, j])\n\n        with table.unlocked(), self.assertRaises(IndexError):\n            table[0, -5] = 5\n\n    def test_filter_is_defined(self):\n        d = data.Table(\"iris\")\n        with d.unlocked():\n            d[1, 4] = Unknown\n        self.assertTrue(isnan(d[1, 4]))\n        with d.unlocked():\n            d[140, 0] = Unknown\n        e = filter.IsDefined()(d)\n        self.assertEqual(len(e), len(d) - 2)\n        self.assertEqual(e[0], d[0])\n        self.assertEqual(e[1], d[2])\n        self.assertEqual(e[147], d[149])\n        self.assertTrue(d.has_missing())\n        self.assertFalse(e.has_missing())\n\n    def test_filter_has_class(self):\n        d = data.Table(\"iris\")\n        with d.unlocked():\n            d[1, 4] = Unknown\n        self.assertTrue(isnan(d[1, 4]))\n        with d.unlocked():\n            d[140, 0] = Unknown\n        e = filter.HasClass()(d)\n        self.assertEqual(len(e), len(d) - 1)\n        self.assertEqual(e[0], d[0])\n        self.assertEqual(e[1], d[2])\n        self.assertEqual(e[148], d[149])\n        self.assertTrue(d.has_missing())\n        self.assertTrue(e.has_missing())\n        self.assertFalse(e.has_missing_class())\n\n    def test_filter_random(self):\n        d = data.Table(\"iris\")\n        e = filter.Random(50)(d)\n        self.assertEqual(len(e), 50)\n        e = filter.Random(50, negate=True)(d)\n        self.assertEqual(len(e), 100)\n        for _ in range(5):\n            e = filter.Random(0.2)(d)\n            self.assertEqual(len(e), 30)\n            bc = np.bincount(np.array(e.Y[:], dtype=int))\n            if min(bc) > 7:\n                break\n        else:\n            self.fail(\"Filter returns too uneven distributions\")\n\n    def test_filter_values_nested(self):\n        d = data.Table(\"iris\")\n        f1 = filter.FilterContinuous(d.columns.sepal_length,\n                                     filter.FilterContinuous.Between,\n                                     min=4.5, max=5.0)\n        f2 = filter.FilterContinuous(d.columns.sepal_width,\n                                     filter.FilterContinuous.Between,\n                                     min=3.1, max=3.4)\n        f3 = filter.FilterDiscrete(d.columns.iris, [0, 1])\n        f = filter.Values([filter.Values([f1, f2], conjunction=False), f3])\n        self.assertEqual(41, len(f(d)))\n\n    def test_filter_string_works_for_numeric_columns(self):\n        var = StringVariable(\"s\")\n        data = Table.from_list(Domain([], metas=[var]),\n                               [[x] for x in range(21)])\n        # 1, 2, 3, ..., 18, 19, 20\n\n        fs = filter.FilterString\n        filters = [\n            ((fs.Greater, \"5\"), dict(rows=4)),\n            # 6, 7, 8, 9\n            ((fs.Between, \"15\", \"2\"), dict(rows=6)),\n            # 15, 16, 17, 18, 19, 2\n            ((fs.Contains, \"2\"), dict(rows=3)),\n            # 2, 12, 20\n        ]\n\n        for args, expected in filters:\n            f = fs(var, *args)\n            filtered_data = filter.Values([f])(data)\n            self.assertEqual(len(filtered_data), expected[\"rows\"],\n                             \"{} returned wrong number of rows\".format(args))\n\n    def test_filter_value_continuous(self):\n        d = data.Table(\"iris\")\n        col = d.X[:, 2]\n\n        v = d.columns\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Between,\n                                    min=4.5, max=5.1)\n\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] >= 4.5))\n        self.assertTrue(np.all(x.X[:, 2] <= 5.1))\n        self.assertEqual(sum((col >= 4.5) * (col <= 5.1)), len(x))\n\n        f.ref = 5.1\n        f.oper = filter.FilterContinuous.Equal\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.NotEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] != 5.1))\n        self.assertEqual(sum(col != 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Less\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] < 5.1))\n        self.assertEqual(sum(col < 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.LessEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] <= 5.1))\n        self.assertEqual(sum(col <= 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Greater\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] > 5.1))\n        self.assertEqual(sum(col > 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] >= 5.1))\n        self.assertEqual(sum(col >= 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Outside\n        f.ref, f.max = 4.5, 5.1\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(e[2] < 4.5 or e[2] > 5.1)\n        self.assertEqual(sum((col < 4.5) + (col > 5.1)), len(x))\n\n        f.oper = filter.FilterContinuous.IsDefined\n        f.ref = f.max = None\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d))\n\n        with d.unlocked():\n            d[:30, v.petal_length] = Unknown\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 30)\n\n    def test_filter_value_continuous_args(self):\n        d = data.Table(\"iris\")\n        col = d.X[:, 2]\n        v = d.columns\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(2,\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"petal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"sepal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        f.column = 2\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"sepal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        f.column = v.petal_length\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=18)\n        f.ref = 5.1\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=18)\n        f.ref = 5.1\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n    def test_valueFilter_discrete(self):\n        d = data.Table(\"zoo\")\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, 3, 4])\n        for e in filter.Values([f])(d):\n            self.assertTrue(e.get_class() in [2, 3, 4])\n\n        f.values = [\"mammal\"]\n        for e in filter.Values([f])(d):\n            self.assertEqual(e.get_class(), \"mammal\")\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, \"mammal\"])\n        for e in filter.Values([f])(d):\n            self.assertTrue(e.get_class() in [2, \"mammal\"])\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, \"martian\"])\n        self.assertRaises(ValueError, d._filter_values, f)\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=(2, data.Table))\n        self.assertRaises(TypeError, d._filter_values, f)\n\n        v = d.columns\n        f = filter.FilterDiscrete(v.hair, values=None)\n        self.assertEqual(len(filter.Values([f])(d)), len(d))\n\n        with d.unlocked():\n            d[:5, v.hair] = Unknown\n        self.assertEqual(len(filter.Values([f])(d)), len(d) - 5)\n\n    def test_valueFilter_string_is_defined(self):\n        d = data.Table(\"datasets/test9.tab\")\n        f = filter.FilterString(-5, filter.FilterString.IsDefined)\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 7)\n\n    def test_valueFilter_discrete_meta_is_defined(self):\n        d = data.Table(\"datasets/test9.tab\")\n        f = filter.FilterDiscrete(-4, None)\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 8)\n\n    def test_valueFilter_string_case_sens(self):\n        d = data.Table(\"zoo\")\n        col = d[:, \"name\"].metas[:, 0]\n\n        f = filter.FilterString(\"name\",\n                                filter.FilterString.Equal, \"girl\")\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 1)\n        self.assertEqual(x[0, \"name\"], \"girl\")\n        self.assertTrue(np.all(x.metas == \"girl\"))\n\n        f.oper = f.NotEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 1)\n        self.assertTrue(np.all(x[:, \"name\"] != \"girl\"))\n\n        f.oper = f.Less\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"girl\"))\n        self.assertTrue(np.all(x.metas < \"girl\"))\n\n        f.oper = f.LessEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col <= \"girl\"))\n        self.assertTrue(np.all(x.metas <= \"girl\"))\n\n        f.oper = f.Greater\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col > \"girl\"))\n        self.assertTrue(np.all(x.metas > \"girl\"))\n\n        f.oper = f.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col >= \"girl\"))\n        self.assertTrue(np.all(x.metas >= \"girl\"))\n\n        f.oper = f.Between\n        f.max = \"lion\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum((col >= \"girl\") * (col <= \"lion\")))\n        self.assertTrue(np.all(x.metas >= \"girl\"))\n        self.assertTrue(np.all(x.metas <= \"lion\"))\n\n        f.oper = f.Outside\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"girl\") + sum(col > \"lion\"))\n        self.assertTrue(np.all((x.metas < \"girl\") + (x.metas > \"lion\")))\n\n        f.oper = f.Contains\n        f.ref = \"ea\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(\"ea\" in e[\"name\"])\n        self.assertEqual(len(x), len([e for e in col if \"ea\" in e]))\n\n        f.oper = f.StartsWith\n        f.ref = \"sea\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).startswith(\"sea\"))\n        self.assertEqual(len(x), len([e for e in col if e.startswith(\"sea\")]))\n\n        f.oper = f.EndsWith\n        f.ref = \"ion\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n        self.assertEqual(len(x), len([e for e in col if e.endswith(\"ion\")]))\n\n    def test_valueFilter_string_case_insens(self):\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d[d[:, \"name\"].metas[:, 0] == \"girl\", \"name\"] = \"GIrl\"\n\n        col = d[:, \"name\"].metas[:, 0]\n\n        f = filter.FilterString(\"name\",\n                                filter.FilterString.Equal, \"giRL\")\n        f.case_sensitive = False\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 1)\n        self.assertEqual(x[0, \"name\"], \"GIrl\")\n        self.assertTrue(np.all(x.metas == \"GIrl\"))\n\n        f.oper = f.NotEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 1)\n        self.assertTrue(np.all(x[:, \"name\"] != \"GIrl\"))\n\n        f.oper = f.Less\n        f.ref = \"CHiCKEN\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"chicken\") - 1)  # girl!\n        self.assertTrue(np.all(x.metas < \"chicken\"))\n\n        f.oper = f.LessEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col <= \"chicken\") - 1)\n        self.assertTrue(np.all(x.metas <= \"chicken\"))\n\n        f.oper = f.Greater\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col > \"chicken\") + 1)\n        for e in x:\n            self.assertGreater(str(e[\"name\"]).lower(), \"chicken\")\n\n        f.oper = f.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col >= \"chicken\") + 1)\n        for e in x:\n            self.assertGreaterEqual(str(e[\"name\"]).lower(), \"chicken\")\n\n        f.oper = f.Between\n        f.max = \"liOn\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum((col >= \"chicken\") * (col <= \"lion\")) + 1)\n        for e in x:\n            self.assertTrue(\"chicken\" <= str(e[\"name\"]).lower() <= \"lion\")\n\n        f.oper = f.Outside\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"chicken\") + sum(col > \"lion\") - 1)\n        self.assertTrue(np.all((x.metas < \"chicken\") + (x.metas > \"lion\")))\n\n        f.oper = f.Contains\n        f.ref = \"iR\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(\"ir\" in str(e[\"name\"]).lower())\n        self.assertEqual(len(x), len([e for e in col if \"ir\" in e]) + 1)\n\n        f.oper = f.StartsWith\n        f.ref = \"GI\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).lower().startswith(\"gi\"))\n        self.assertEqual(len(x),\n                         len([e for e in col if e.lower().startswith(\"gi\")]))\n\n        f.oper = f.EndsWith\n        f.ref = \"ion\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n        self.assertEqual(len(x), len([e for e in col if e.endswith(\"ion\")]))\n\n    def test_valueFilter_regex(self):\n        d = data.Table(\"zoo\")\n        f = filter.FilterRegex(d.domain['name'], '^c...$')\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 7)\n\n    def test_valueFilter_stringList(self):\n        data = Table(\"zoo\")\n        var = data.domain[\"name\"]\n\n        fs = filter.FilterStringList\n        filters = [\n            (([\"swan\", \"tuna\", \"wasp\"], True), dict(rows=3)),\n            (([\"swan\", \"tuna\", \"wasp\"], False), dict(rows=3)),\n            (([\"WoRm\", \"TOad\", \"vOLe\"], True), dict(rows=0)),\n            (([\"WoRm\", \"TOad\", \"vOLe\"], False), dict(rows=3)),\n        ]\n\n        for args, expected in filters:\n            f = fs(var, *args)\n            filtered_data = filter.Values([f])(data)\n            self.assertEqual(len(filtered_data), expected[\"rows\"],\n                             \"{} returned wrong number of rows\".format(args))\n\n    def test_table_dtypes(self):\n        table = data.Table(\"iris\")\n        metas = np.hstack((table.metas, table.Y.reshape(len(table), 1)))\n        attributes_metas = table.domain.metas + table.domain.class_vars\n        domain_metas = data.Domain(table.domain.attributes[:2],\n                                   table.domain.attributes[2:],\n                                   attributes_metas)\n        table_metas = data.Table(domain_metas, table.X[:, : 2], table.X[:, 2:],\n                                 metas)\n        new_table = data.Table.from_table(data.Domain(table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.X.dtype, np.float64)\n        new_table = data.Table.from_table(data.Domain((), table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.Y.dtype, np.float64)\n        new_table = data.Table.from_table(data.Domain((), (), table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.metas.dtype, np.float64)\n\n    def test_attributes(self):\n        table = data.Table(\"iris\")\n        table.attributes = {1: \"test\"}\n        table2 = table[:4]\n        self.assertEqual(table2.attributes[1], \"test\")\n        table2.attributes[1] = \"modified\"\n        self.assertEqual(table.attributes[1], \"modified\")\n\n    # TODO Test conjunctions and disjunctions of conditions\n\n    def test_is_sparse(self):\n        table = data.Table(\"iris\")\n        self.assertFalse(table.is_sparse())\n\n        with table.unlocked():\n            table.X = sp.csr_matrix(table.X)\n            self.assertTrue(table.is_sparse())\n\n    def test_repr_sparse_with_one_row(self):\n        table = data.Table(\"iris\")[:1]\n        with table.unlocked():\n            table.X = sp.csr_matrix(table.X)\n        repr(table)     # make sure repr does not crash\n\n    def test_inf(self):\n        a = np.array([[2, 0, 0, 0],\n                      [0, np.nan, np.nan, 1],\n                      [0, 0, np.inf, 0]])\n        with self.assertWarns(Warning):\n            tab = data.Table.from_numpy(None, a)\n        self.assertEqual(tab.get_nan_frequency_attribute(), 3/12)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 27,
                            "end_lineno": 1183,
                            "parent": null
                        }
                    ],
                    "added_entities": [
                        {
                            "file_name": "Orange/tests/test_table.py",
                            "type": "method",
                            "name": "TableTestCase.test_pickle_setstate",
                            "content": "class TableTestCase(unittest.TestCase):\n    def setUp(self):\n        data.table.dataset_dirs.append(test_dirname())\n\n    def tearDown(self):\n        data.table.dataset_dirs.remove(test_dirname())\n\n    def test_indexing_class(self):\n        d = data.Table(\"datasets/test1\")\n        self.assertEqual([e.get_class() for e in d], [\"t\", \"t\", \"f\"])\n        cind = len(d.domain.variables) - 1\n        self.assertEqual([e[cind] for e in d], [\"t\", \"t\", \"f\"])\n        self.assertEqual([e[\"d\"] for e in d], [\"t\", \"t\", \"f\"])\n        cvar = d.domain.class_var\n        self.assertEqual([e[cvar] for e in d], [\"t\", \"t\", \"f\"])\n\n    def test_filename(self):\n        dir = data.table.get_sample_datasets_dir()\n        d = data.Table(\"iris\")\n        self.assertEqual(d.__file__, os.path.join(dir, \"iris.tab\"))\n\n        d = data.Table(\"datasets/test2.tab\")\n        self.assertTrue(d.__file__.endswith(\"test2.tab\"))  # platform dependent\n\n    def test_indexing(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            # regular, discrete\n            varc = d.domain[\"c\"]\n            self.assertEqual(d[0, 1], \"0\")\n            self.assertEqual(d[0, varc], \"0\")\n            self.assertEqual(d[0, \"c\"], \"0\")\n            self.assertEqual(d[0][1], \"0\")\n            self.assertEqual(d[0][varc], \"0\")\n            self.assertEqual(d[0][\"c\"], \"0\")\n            self.assertEqual(d[np.int_(0), np.int_(1)], \"0\")\n            self.assertEqual(d[np.int_(0)][np.int_(1)], \"0\")\n\n            # regular, continuous\n            varb = d.domain[\"b\"]\n            self.assertEqual(d[0, 0], 0)\n            self.assertEqual(d[0, varb], 0)\n            self.assertEqual(d[0, \"b\"], 0)\n            self.assertEqual(d[0][0], 0)\n            self.assertEqual(d[0][varb], 0)\n            self.assertEqual(d[0][\"b\"], 0)\n            self.assertEqual(d[np.int_(0), np.int_(0)], 0)\n            self.assertEqual(d[np.int_(0)][np.int_(0)], 0)\n\n            # negative\n            varb = d.domain[\"b\"]\n            self.assertEqual(d[-2, 0], 3.333)\n            self.assertEqual(d[-2, varb], 3.333)\n            self.assertEqual(d[-2, \"b\"], 3.333)\n            self.assertEqual(d[-2][0], 3.333)\n            self.assertEqual(d[-2][varb], 3.333)\n            self.assertEqual(d[-2][\"b\"], 3.333)\n            self.assertEqual(d[np.int_(-2), np.int_(0)], 3.333)\n            self.assertEqual(d[np.int_(-2)][np.int_(0)], 3.333)\n\n            # meta, discrete\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n            self.assertEqual(d[0, metaa], \"A\")\n            self.assertEqual(d[0, vara], \"A\")\n            self.assertEqual(d[0, \"a\"], \"A\")\n            self.assertEqual(d[0][metaa], \"A\")\n            self.assertEqual(d[0][vara], \"A\")\n            self.assertEqual(d[0][\"a\"], \"A\")\n            self.assertEqual(d[np.int_(0), np.int_(metaa)], \"A\")\n            self.assertEqual(d[np.int_(0)][np.int_(metaa)], \"A\")\n\n            # meta, string\n            vare = d.domain[\"e\"]\n            metae = d.domain.index(\"e\")\n            self.assertEqual(d[0, metae], \"i\")\n            self.assertEqual(d[0, vare], \"i\")\n            self.assertEqual(d[0, \"e\"], \"i\")\n            self.assertEqual(d[0][metae], \"i\")\n            self.assertEqual(d[0][vare], \"i\")\n            self.assertEqual(d[0][\"e\"], \"i\")\n            self.assertEqual(d[np.int_(0), np.int_(metae)], \"i\")\n            self.assertEqual(d[np.int_(0)][np.int_(metae)], \"i\")\n\n    def test_indexing_example(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            e = d[0]\n\n            # regular, discrete\n            varc = d.domain[\"c\"]\n            self.assertEqual(e[1], \"0\")\n            self.assertEqual(e[varc], \"0\")\n            self.assertEqual(e[\"c\"], \"0\")\n            self.assertEqual(e[np.int_(1)], \"0\")\n\n            # regular, continuous\n            varb = d.domain[\"b\"]\n            self.assertEqual(e[0], 0)\n            self.assertEqual(e[varb], 0)\n            self.assertEqual(e[\"b\"], 0)\n            self.assertEqual(e[np.int_(0)], 0)\n\n            # meta, discrete\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n            self.assertEqual(e[metaa], \"A\")\n            self.assertEqual(e[vara], \"A\")\n            self.assertEqual(e[\"a\"], \"A\")\n            self.assertEqual(e[np.int_(metaa)], \"A\")\n\n            # meta, string\n            vare = d.domain[\"e\"]\n            metae = d.domain.index(\"e\")\n            self.assertEqual(e[metae], \"i\")\n            self.assertEqual(e[vare], \"i\")\n            self.assertEqual(e[\"e\"], \"i\")\n            self.assertEqual(e[np.int_(metae)], \"i\")\n\n    def test_indexing_assign_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            # meta\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, \"a\"] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][\"a\"] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, vara] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][vara] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, metaa] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][metaa] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, np.int_(metaa)] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][np.int_(metaa)] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            # regular\n            varb = d.domain[\"b\"]\n\n            self.assertEqual(d[0, \"b\"], 0)\n            with d.unlocked():\n                d[0, \"b\"] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][\"b\"] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, varb] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][varb] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, 0] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][0] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, np.int_(0)] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][np.int_(0)] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n    def test_indexing_assign_example(self):\n        def almost_equal_list(s, t):\n            for e, f in zip(s, t):\n                self.assertAlmostEqual(e, f)\n\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            self.assertFalse(isnan(d[0, \"a\"]))\n            with d.unlocked():\n                d[0] = [\"3.14\", \"1\", \"f\"]\n            almost_equal_list(d[0].values(), [3.14, \"1\", \"f\"])\n            self.assertTrue(isnan(d[0, \"a\"]))\n\n            with d.unlocked():\n                d[0] = [3.15, 1, \"t\"]\n            almost_equal_list(d[0].values(), [3.15, \"0\", \"t\"])\n\n            with d.unlocked():\n                d[np.int_(0)] = [3.15, 2, \"f\"]\n            almost_equal_list(d[0].values(), [3.15, 2, \"f\"])\n\n            with d.unlocked(), self.assertRaises(ValueError):\n                d[0] = [\"3.14\", \"1\"]\n\n            with d.unlocked(), self.assertRaises(ValueError):\n                d[np.int_(0)] = [\"3.14\", \"1\"]\n\n            ex = data.Instance(d.domain, [\"3.16\", \"1\", \"f\"])\n            with d.unlocked():\n                d[0] = ex\n            almost_equal_list(d[0].values(), [3.16, \"1\", \"f\"])\n\n            ex = data.Instance(d.domain, [\"3.16\", 2, \"t\"])\n            with d.unlocked():\n                d[np.int_(0)] = ex\n            almost_equal_list(d[0].values(), [3.16, 2, \"t\"])\n\n            ex = data.Instance(d.domain, [\"3.16\", \"1\", \"f\"])\n            ex[\"e\"] = \"mmmapp\"\n            with d.unlocked():\n                d[0] = ex\n            almost_equal_list(d[0].values(), [3.16, \"1\", \"f\"])\n            self.assertEqual(d[0, \"e\"], \"mmmapp\")\n\n    def test_slice(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            x = d[:3]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [0, 1.1, 2.22])\n\n            x = d[2:5]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.22, 2.23, 2.24])\n\n            x = d[4:1:-1]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.24, 2.23, 2.22])\n\n            x = d[-3:]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.26, 3.333, Unknown])\n\n    def test_assign_slice_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            with d.unlocked():\n                d[2:5, 0] = 42\n            self.assertEqual([e[0] for e in d],\n                             [0, 1.1, 42, 42, 42, 2.25, 2.26, 3.333, Unknown])\n            with d.unlocked():\n                d[:3, \"b\"] = 43\n            self.assertEqual([e[0] for e in d],\n                             [43, 43, 43, 42, 42, 2.25, 2.26, 3.333, None])\n            with d.unlocked():\n                d[-2:, d.domain[0]] = 44\n            self.assertEqual([e[0] for e in d],\n                             [43, 43, 43, 42, 42, 2.25, 2.26, 44, 44])\n\n            with d.unlocked():\n                d[2:5, \"a\"] = \"A\"\n            self.assertEqual([e[\"a\"] for e in d], list(\"ABAAACCDE\"))\n\n    def test_multiple_indices(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            with self.assertRaises(IndexError):\n                x = d[2, 5, 1]\n\n            with self.assertRaises(IndexError):\n                x = d[(2, 5, 1)]\n\n            x = d[[2, 5, 1]]\n            self.assertEqual([e[0] for e in x], [2.22, 2.25, 1.1])\n\n    def test_assign_multiple_indices_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            with d.unlocked():\n                d[1:4, \"b\"] = 42\n            self.assertEqual([e[0] for e in d],\n                             [0, 42, 42, 42, 2.24, 2.25, 2.26, 3.333, None])\n\n            with d.unlocked():\n                d[range(5, 2, -1), \"b\"] = None\n            self.assertEqual([e[d.domain[0]] for e in d],\n                             [0, 42, 42, None, \"?\", \"\", 2.26, 3.333, None])\n\n    def test_set_multiple_indices_example(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            vals = [e[0] for e in d]\n            with d.unlocked():\n                d[[1, 2, 5]] = [42, None, None]\n            vals[1] = vals[2] = vals[5] = 42\n            self.assertEqual([e[0] for e in d], vals)\n\n    def test_bool(self):\n        d = data.Table(\"iris\")\n        self.assertTrue(d)\n\n        d = data.Table(\"datasets/test3\")\n        self.assertFalse(d)\n\n        d = data.Table(\"iris\")\n        self.assertTrue(d)\n\n    def test_checksum(self):\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d[42, 3] = 0\n        crc1 = d.checksum(False)\n\n        with d.unlocked():\n            d[42, 3] = 1\n        crc2 = d.checksum(False)\n        self.assertNotEqual(crc1, crc2)\n\n        with d.unlocked():\n            d[42, 3] = 0\n        crc3 = d.checksum(False)\n        self.assertEqual(crc1, crc3)\n\n        _ = d[42, \"name\"]\n        with d.unlocked():\n            d[42, \"name\"] = \"non-animal\"\n        crc4 = d.checksum(False)\n        self.assertEqual(crc1, crc4)\n        crc4 = d.checksum(True)\n        crc5 = d.checksum(1)\n        crc6 = d.checksum(False)\n        self.assertNotEqual(crc1, crc4)\n        self.assertNotEqual(crc1, crc5)\n        self.assertEqual(crc1, crc6)\n\n    def test_total_weight(self):\n        d = data.Table(\"zoo\")\n        self.assertEqual(d.total_weight(), len(d))\n\n        with d.unlocked():\n            d.set_weights(0)\n            d[0].weight = 0.1\n            d[10].weight = 0.2\n            d[-1].weight = 0.3\n        self.assertAlmostEqual(d.total_weight(), 0.6)\n\n    def test_has_missing(self):\n        d = data.Table(\"zoo\")\n        self.assertFalse(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n        with d.unlocked():\n            d[10, 3] = \"?\"\n        self.assertTrue(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n        with d.unlocked():\n            d[10].set_class(\"?\")\n        self.assertTrue(d.has_missing())\n        self.assertTrue(d.has_missing_class())\n\n        with d.unlocked():\n            d = data.Table(\"datasets/test3\")\n        self.assertFalse(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n    def test_shuffle(self):\n        d = data.Table(\"zoo\")\n        crc = d.checksum()\n        names = set(str(x[\"name\"]) for x in d)\n\n        with d.unlocked():\n            d.shuffle()\n        self.assertNotEqual(crc, d.checksum())\n        self.assertSetEqual(names, set(str(x[\"name\"]) for x in d))\n        crc2 = d.checksum()\n\n        x = d[2:10]\n        crcx = x.checksum()\n        with d.unlocked():\n            d.shuffle()\n        self.assertNotEqual(crc2, d.checksum())\n        self.assertEqual(crcx, x.checksum())\n\n        crc2 = d.checksum()\n        with x.unlocked():\n            x.shuffle()\n        self.assertNotEqual(crcx, x.checksum())\n        self.assertEqual(crc2, d.checksum())\n\n    @staticmethod\n    def not_less_ex(ex1, ex2):\n        for v1, v2 in zip(ex1, ex2):\n            if v1 != v2:\n                return v1 < v2\n        return True\n\n    @staticmethod\n    def sorted(d):\n        for i in range(1, len(d)):\n            if not TableTestCase.not_less_ex(d[i - 1], d[i]):\n                return False\n        return True\n\n    @staticmethod\n    def not_less_ex_ord(ex1, ex2, ord):\n        for a in ord:\n            if ex1[a] != ex2[a]:\n                return ex1[a] < ex2[a]\n        return True\n\n    @staticmethod\n    def sorted_ord(d, ord):\n        for i in range(1, len(d)):\n            if not TableTestCase.not_less_ex_ord(d[i - 1], d[i], ord):\n                return False\n        return True\n\n    def test_copy(self):\n        t = data.Table.from_numpy(\n            None, np.zeros((5, 3)), np.arange(5), np.zeros((5, 3)))\n\n        copy = t.copy()\n        self.assertTrue(np.all(t.X == copy.X))\n        self.assertTrue(np.all(t.Y == copy.Y))\n        self.assertTrue(np.all(t.metas == copy.metas))\n        with copy.unlocked():\n            copy[0] = [1, 1, 1, 1]\n        self.assertFalse(np.all(t.X == copy.X))\n        self.assertFalse(np.all(t.Y == copy.Y))\n        self.assertFalse(np.all(t.metas == copy.metas))\n\n    def test_copy_sparse(self):\n        t = data.Table('iris').to_sparse()\n        copy = t.copy()\n\n        self.assertEqual((t.X != copy.X).nnz, 0)      # sparse matrices match by content\n        np.testing.assert_equal(t.Y, copy.Y)\n        np.testing.assert_equal(t.metas, copy.metas)\n\n        self.assertNotEqual(id(t.X), id(copy.X))\n        self.assertNotEqual(id(t._Y), id(copy._Y))\n        self.assertNotEqual(id(t.metas), id(copy.metas))\n\n        # ensure that copied sparse arrays do not share data\n        with t.unlocked():\n            t.X[0, 0] = 42\n        self.assertEqual(copy.X[0, 0], 5.1)\n\n    def test_concatenate(self):\n        d1 = data.Domain(\n            [data.ContinuousVariable(n) for n in \"abc\"],\n            data.DiscreteVariable(\"y\", values=\"ABC\"),\n            [data.StringVariable(n) for n in [\"m1\", \"m2\"]],\n        )\n        x1 = np.arange(6).reshape(2, 3)\n        y1 = np.array([0, 1])\n        m1 = np.array([[\"foo\", \"bar\"], [\"baz\", \"qux\"]])\n        w1 = np.random.random((2,))\n        t1 = data.Table.from_numpy(d1, x1, y1, m1, w1)\n        t1.ids = ids1 = np.array([100, 101])\n        t1.attributes = {\"a\": 42, \"c\": 43}\n\n        x2 = np.arange(6, 15).reshape(3, 3)\n        y2 = np.array([1, 2, 0])\n        m2 = np.array([[\"a\", \"b\"], [\"c\", \"d\"], [\"e\", \"f\"]])\n        w2 = np.random.random((3,))\n        t2 = data.Table.from_numpy(d1, x2, y2, m2, w2)\n        t2.ids = ids2 = np.array([102, 103, 104])\n        t2.name = \"t2\"\n        t2.attributes = {\"a\": 44, \"b\": 45}\n\n        x3 = np.arange(15, 27).reshape(4, 3)\n        y3 = np.array([2, 1, 1, 0])\n        m3 = np.array([[\"g\", \"h\"], [\"i\", \"j\"], [\"k\", \"l\"], [\"m\", \"n\"]])\n        w3 = np.random.random((4,))\n        t3 = data.Table.from_numpy(d1, x3, y3, m3, w3)\n        t3.ids = ids3 = np.array([102, 103, 104, 105])\n        t3.name = \"t3\"\n\n        t1b = data.Table.concatenate((t1,))\n        self.assertEqual(t1b.domain, t1.domain)\n        np.testing.assert_almost_equal(t1b.X, x1)\n        np.testing.assert_almost_equal(t1b.Y, y1)\n        self.assertEqual(list(t1b.metas.flatten()),\n                         list(m1.flatten()))\n        np.testing.assert_almost_equal(t1b.W, w1)\n        np.testing.assert_almost_equal(t1b.ids, ids1)\n        self.assertEqual(t1b.name, t1.name)\n        self.assertEqual(t1b.attributes, {\"a\": 42, \"c\": 43})\n\n        t12 = data.Table.concatenate((t1, t2))\n        self.assertEqual(t12.domain, t1.domain)\n        np.testing.assert_almost_equal(t12.X, np.vstack((x1, x2)))\n        np.testing.assert_almost_equal(t12.Y, np.hstack((y1, y2)))\n        self.assertEqual(list(t12.metas.flatten()),\n                         list(np.vstack((m1, m2)).flatten()))\n        np.testing.assert_almost_equal(t12.W, np.hstack((w1, w2)))\n        np.testing.assert_almost_equal(t12.ids, np.hstack((ids1, ids2)))\n        self.assertEqual(t12.name, \"t2\")\n        self.assertEqual(t12.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n        t123 = data.Table.concatenate((t1, t2, t3))\n        self.assertEqual(t123.domain, t1.domain)\n        np.testing.assert_almost_equal(t123.X, np.vstack((x1, x2, x3)))\n        np.testing.assert_almost_equal(t123.Y, np.hstack((y1, y2, y3)))\n        self.assertEqual(list(t123.metas.flatten()),\n                         list(np.vstack((m1, m2, m3)).flatten()))\n        np.testing.assert_almost_equal(t123.W, np.hstack((w1, w2, w3)))\n        np.testing.assert_almost_equal(t123.ids, np.hstack((ids1, ids2, ids3)))\n        self.assertEqual(t123.name, \"t2\")\n        self.assertEqual(t123.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n        with t2.unlocked(t2.Y):\n            t2.Y = np.atleast_2d(t2.Y).T\n        t12 = data.Table.concatenate((t1, t2))\n        self.assertEqual(t12.domain, t1.domain)\n        np.testing.assert_almost_equal(t12.X, np.vstack((x1, x2)))\n        np.testing.assert_almost_equal(t12.Y, np.hstack((y1, y2)))\n        self.assertEqual(list(t12.metas.flatten()),\n                         list(np.vstack((m1, m2)).flatten()))\n        np.testing.assert_almost_equal(t12.W, np.hstack((w1, w2)))\n        np.testing.assert_almost_equal(t12.ids, np.hstack((ids1, ids2)))\n        self.assertEqual(t12.name, \"t2\")\n        self.assertEqual(t12.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n    def test_concatenate_exceptions(self):\n        zoo = data.Table(\"zoo\")\n        iris = data.Table(\"iris\")\n\n        self.assertRaises(ValueError, data.Table.concatenate, [])\n        self.assertRaises(ValueError, data.Table.concatenate, [zoo, iris])\n\n    def test_concatenate_sparse(self):\n        iris = Table(\"iris\")\n        with iris.unlocked():\n            iris.X = sp.csc_matrix(iris.X)\n        new = Table.concatenate([iris, iris])\n        self.assertEqual(len(new), 300)\n        self.assertTrue(sp.issparse(new.X), \"Concatenated X is not sparse.\")\n        self.assertFalse(sp.issparse(new.Y), \"Concatenated Y is not dense.\")\n        self.assertFalse(sp.issparse(new.metas), \"Concatenated metas is not dense.\")\n        self.assertEqual(len(new.ids), 300)\n\n    def test_pickle(self):\n        d = data.Table(\"zoo\")\n        s = pickle.dumps(d)\n        d2 = pickle.loads(s)\n        self.assertEqual(d[0], d2[0])\n\n        self.assertEqual(d.checksum(include_metas=False),\n                         d2.checksum(include_metas=False))\n\n        d = data.Table(\"iris\")\n        s = pickle.dumps(d)\n        d2 = pickle.loads(s)\n        self.assertEqual(d[0], d2[0])\n        self.assertEqual(d.checksum(include_metas=False),\n                         d2.checksum(include_metas=False))\n\n    def test_pickle_setstate(self):\n        d = data.Table(\"zoo\")\n        s = pickle.dumps(d)\n        with patch(\"Orange.data.Table.__setstate__\", Mock()) as mock:\n            pickle.loads(s)\n            state = mock.call_args[0][0]\n            for k in [\"X\", \"_Y\", \"metas\"]:\n                self.assertIn(k, state)\n                self.assertEqual(state[k].ndim, 2)\n            self.assertIn(\"W\", state)\n            for k in [\"_X\", \"Y\", \"_metas\", \"_W\"]:\n                self.assertNotIn(k, state)\n\n\n    def test_translate_through_slice(self):\n        d = data.Table(\"iris\")\n        dom = data.Domain([\"petal length\", \"sepal length\", \"iris\"],\n                          source=d.domain)\n        d_ref = d[:10, dom.variables]\n        self.assertEqual(d_ref.domain.class_var, d.domain.class_var)\n        self.assertEqual(d_ref[0, \"petal length\"], d[0, \"petal length\"])\n        self.assertEqual(d_ref[0, \"sepal length\"], d[0, \"sepal length\"])\n        self.assertEqual(d_ref.X.shape, (10, 2))\n        self.assertEqual(d_ref.Y.shape, (10,))\n\n    def test_saveTab(self):\n        d = data.Table(\"iris\")[:3]\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            for e1, e2 in zip(d, d2):\n                self.assertEqual(e1, e2)\n        finally:\n            os.remove(\"test-save.tab\")\n            os.remove(\"test-save.tab.metadata\")\n\n        dom = data.Domain([data.ContinuousVariable(\"a\")])\n        d = data.Table.from_list(dom, [[i] for i in range(3)])\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            self.assertEqual(len(d.domain.attributes), 1)\n            self.assertEqual(d.domain.class_var, None)\n            for i in range(3):\n                self.assertEqual(d2[i], [i])\n        finally:\n            os.remove(\"test-save.tab\")\n\n        dom = data.Domain([data.ContinuousVariable(\"a\")], None)\n        d = data.Table.from_list(dom, [[i] for i in range(3)])\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            self.assertEqual(len(d.domain.attributes), 1)\n            for i in range(3):\n                self.assertEqual(d2[i], [i])\n        finally:\n            os.remove(\"test-save.tab\")\n\n        d = data.Table(\"zoo\")\n        d.save(\"test-zoo.tab\")\n        dd = data.Table(\"test-zoo\")\n        try:\n            self.assertTupleEqual(d.domain.metas, dd.domain.metas,\n                                  msg=\"Meta attributes don't match.\")\n            self.assertTupleEqual(d.domain.variables, dd.domain.variables,\n                                  msg=\"Attributes don't match.\")\n\n            np.testing.assert_almost_equal(d.W, dd.W,\n                                           err_msg=\"Weights don't match.\")\n            for i in range(10):\n                for j in d.domain.variables:\n                    self.assertEqual(d[i][j], dd[i][j])\n        finally:\n            os.remove(\"test-zoo.tab\")\n            os.remove(\"test-zoo.tab.metadata\")\n\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d.set_weights(range(len(d)))\n        d.save(\"test-zoo-weights.tab\")\n        dd = data.Table(\"test-zoo-weights\")\n        try:\n            self.assertTupleEqual(d.domain.metas, dd.domain.metas,\n                                  msg=\"Meta attributes don't match.\")\n            self.assertTupleEqual(d.domain.variables, dd.domain.variables,\n                                  msg=\"Attributes don't match.\")\n\n            np.testing.assert_almost_equal(d.W, dd.W,\n                                           err_msg=\"Weights don't match.\")\n            for i in range(10):\n                for j in d.domain.variables:\n                    self.assertEqual(d[i][j], dd[i][j])\n        finally:\n            os.remove(\"test-zoo-weights.tab\")\n            os.remove(\"test-zoo-weights.tab.metadata\")\n\n    def test_save_pickle(self):\n        table = data.Table(\"iris\")\n        try:\n            table.save(\"iris.pickle\")\n            table2 = data.Table.from_file(\"iris.pickle\")\n            np.testing.assert_almost_equal(table.X, table2.X)\n            np.testing.assert_almost_equal(table.Y, table2.Y)\n            self.assertEqual(table.domain[0], table2.domain[0])\n        finally:\n            os.remove(\"iris.pickle\")\n\n    def test_from_numpy(self):\n        a = np.arange(20, dtype=\"d\").reshape((4, 5)).copy()\n        a[:, -1] = [0, 0, 0, 1]\n        dom = data.Domain([data.ContinuousVariable(x) for x in \"abcd\"],\n                          data.DiscreteVariable(\"e\", values=(\"no\", \"yes\")))\n        table = data.Table(dom, a)\n        with table.unlocked():\n            for i in range(4):\n                self.assertEqual(table[i].get_class(), \"no\" if i < 3 else \"yes\")\n                for j in range(5):\n                    self.assertEqual(a[i, j], table[i, j])\n\n        with table.unlocked(), self.assertRaises(IndexError):\n            table[0, -5] = 5\n\n    def test_filter_is_defined(self):\n        d = data.Table(\"iris\")\n        with d.unlocked():\n            d[1, 4] = Unknown\n        self.assertTrue(isnan(d[1, 4]))\n        with d.unlocked():\n            d[140, 0] = Unknown\n        e = filter.IsDefined()(d)\n        self.assertEqual(len(e), len(d) - 2)\n        self.assertEqual(e[0], d[0])\n        self.assertEqual(e[1], d[2])\n        self.assertEqual(e[147], d[149])\n        self.assertTrue(d.has_missing())\n        self.assertFalse(e.has_missing())\n\n    def test_filter_has_class(self):\n        d = data.Table(\"iris\")\n        with d.unlocked():\n            d[1, 4] = Unknown\n        self.assertTrue(isnan(d[1, 4]))\n        with d.unlocked():\n            d[140, 0] = Unknown\n        e = filter.HasClass()(d)\n        self.assertEqual(len(e), len(d) - 1)\n        self.assertEqual(e[0], d[0])\n        self.assertEqual(e[1], d[2])\n        self.assertEqual(e[148], d[149])\n        self.assertTrue(d.has_missing())\n        self.assertTrue(e.has_missing())\n        self.assertFalse(e.has_missing_class())\n\n    def test_filter_random(self):\n        d = data.Table(\"iris\")\n        e = filter.Random(50)(d)\n        self.assertEqual(len(e), 50)\n        e = filter.Random(50, negate=True)(d)\n        self.assertEqual(len(e), 100)\n        for _ in range(5):\n            e = filter.Random(0.2)(d)\n            self.assertEqual(len(e), 30)\n            bc = np.bincount(np.array(e.Y[:], dtype=int))\n            if min(bc) > 7:\n                break\n        else:\n            self.fail(\"Filter returns too uneven distributions\")\n\n    def test_filter_values_nested(self):\n        d = data.Table(\"iris\")\n        f1 = filter.FilterContinuous(d.columns.sepal_length,\n                                     filter.FilterContinuous.Between,\n                                     min=4.5, max=5.0)\n        f2 = filter.FilterContinuous(d.columns.sepal_width,\n                                     filter.FilterContinuous.Between,\n                                     min=3.1, max=3.4)\n        f3 = filter.FilterDiscrete(d.columns.iris, [0, 1])\n        f = filter.Values([filter.Values([f1, f2], conjunction=False), f3])\n        self.assertEqual(41, len(f(d)))\n\n    def test_filter_string_works_for_numeric_columns(self):\n        var = StringVariable(\"s\")\n        data = Table.from_list(Domain([], metas=[var]),\n                               [[x] for x in range(21)])\n        # 1, 2, 3, ..., 18, 19, 20\n\n        fs = filter.FilterString\n        filters = [\n            ((fs.Greater, \"5\"), dict(rows=4)),\n            # 6, 7, 8, 9\n            ((fs.Between, \"15\", \"2\"), dict(rows=6)),\n            # 15, 16, 17, 18, 19, 2\n            ((fs.Contains, \"2\"), dict(rows=3)),\n            # 2, 12, 20\n        ]\n\n        for args, expected in filters:\n            f = fs(var, *args)\n            filtered_data = filter.Values([f])(data)\n            self.assertEqual(len(filtered_data), expected[\"rows\"],\n                             \"{} returned wrong number of rows\".format(args))\n\n    def test_filter_value_continuous(self):\n        d = data.Table(\"iris\")\n        col = d.X[:, 2]\n\n        v = d.columns\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Between,\n                                    min=4.5, max=5.1)\n\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] >= 4.5))\n        self.assertTrue(np.all(x.X[:, 2] <= 5.1))\n        self.assertEqual(sum((col >= 4.5) * (col <= 5.1)), len(x))\n\n        f.ref = 5.1\n        f.oper = filter.FilterContinuous.Equal\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.NotEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] != 5.1))\n        self.assertEqual(sum(col != 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Less\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] < 5.1))\n        self.assertEqual(sum(col < 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.LessEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] <= 5.1))\n        self.assertEqual(sum(col <= 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Greater\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] > 5.1))\n        self.assertEqual(sum(col > 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] >= 5.1))\n        self.assertEqual(sum(col >= 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Outside\n        f.ref, f.max = 4.5, 5.1\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(e[2] < 4.5 or e[2] > 5.1)\n        self.assertEqual(sum((col < 4.5) + (col > 5.1)), len(x))\n\n        f.oper = filter.FilterContinuous.IsDefined\n        f.ref = f.max = None\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d))\n\n        with d.unlocked():\n            d[:30, v.petal_length] = Unknown\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 30)\n\n    def test_filter_value_continuous_args(self):\n        d = data.Table(\"iris\")\n        col = d.X[:, 2]\n        v = d.columns\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(2,\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"petal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"sepal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        f.column = 2\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"sepal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        f.column = v.petal_length\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=18)\n        f.ref = 5.1\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=18)\n        f.ref = 5.1\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n    def test_valueFilter_discrete(self):\n        d = data.Table(\"zoo\")\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, 3, 4])\n        for e in filter.Values([f])(d):\n            self.assertTrue(e.get_class() in [2, 3, 4])\n\n        f.values = [\"mammal\"]\n        for e in filter.Values([f])(d):\n            self.assertEqual(e.get_class(), \"mammal\")\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, \"mammal\"])\n        for e in filter.Values([f])(d):\n            self.assertTrue(e.get_class() in [2, \"mammal\"])\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, \"martian\"])\n        self.assertRaises(ValueError, d._filter_values, f)\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=(2, data.Table))\n        self.assertRaises(TypeError, d._filter_values, f)\n\n        v = d.columns\n        f = filter.FilterDiscrete(v.hair, values=None)\n        self.assertEqual(len(filter.Values([f])(d)), len(d))\n\n        with d.unlocked():\n            d[:5, v.hair] = Unknown\n        self.assertEqual(len(filter.Values([f])(d)), len(d) - 5)\n\n    def test_valueFilter_string_is_defined(self):\n        d = data.Table(\"datasets/test9.tab\")\n        f = filter.FilterString(-5, filter.FilterString.IsDefined)\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 7)\n\n    def test_valueFilter_discrete_meta_is_defined(self):\n        d = data.Table(\"datasets/test9.tab\")\n        f = filter.FilterDiscrete(-4, None)\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 8)\n\n    def test_valueFilter_string_case_sens(self):\n        d = data.Table(\"zoo\")\n        col = d[:, \"name\"].metas[:, 0]\n\n        f = filter.FilterString(\"name\",\n                                filter.FilterString.Equal, \"girl\")\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 1)\n        self.assertEqual(x[0, \"name\"], \"girl\")\n        self.assertTrue(np.all(x.metas == \"girl\"))\n\n        f.oper = f.NotEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 1)\n        self.assertTrue(np.all(x[:, \"name\"] != \"girl\"))\n\n        f.oper = f.Less\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"girl\"))\n        self.assertTrue(np.all(x.metas < \"girl\"))\n\n        f.oper = f.LessEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col <= \"girl\"))\n        self.assertTrue(np.all(x.metas <= \"girl\"))\n\n        f.oper = f.Greater\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col > \"girl\"))\n        self.assertTrue(np.all(x.metas > \"girl\"))\n\n        f.oper = f.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col >= \"girl\"))\n        self.assertTrue(np.all(x.metas >= \"girl\"))\n\n        f.oper = f.Between\n        f.max = \"lion\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum((col >= \"girl\") * (col <= \"lion\")))\n        self.assertTrue(np.all(x.metas >= \"girl\"))\n        self.assertTrue(np.all(x.metas <= \"lion\"))\n\n        f.oper = f.Outside\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"girl\") + sum(col > \"lion\"))\n        self.assertTrue(np.all((x.metas < \"girl\") + (x.metas > \"lion\")))\n\n        f.oper = f.Contains\n        f.ref = \"ea\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(\"ea\" in e[\"name\"])\n        self.assertEqual(len(x), len([e for e in col if \"ea\" in e]))\n\n        f.oper = f.StartsWith\n        f.ref = \"sea\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).startswith(\"sea\"))\n        self.assertEqual(len(x), len([e for e in col if e.startswith(\"sea\")]))\n\n        f.oper = f.EndsWith\n        f.ref = \"ion\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n        self.assertEqual(len(x), len([e for e in col if e.endswith(\"ion\")]))\n\n    def test_valueFilter_string_case_insens(self):\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d[d[:, \"name\"].metas[:, 0] == \"girl\", \"name\"] = \"GIrl\"\n\n        col = d[:, \"name\"].metas[:, 0]\n\n        f = filter.FilterString(\"name\",\n                                filter.FilterString.Equal, \"giRL\")\n        f.case_sensitive = False\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 1)\n        self.assertEqual(x[0, \"name\"], \"GIrl\")\n        self.assertTrue(np.all(x.metas == \"GIrl\"))\n\n        f.oper = f.NotEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 1)\n        self.assertTrue(np.all(x[:, \"name\"] != \"GIrl\"))\n\n        f.oper = f.Less\n        f.ref = \"CHiCKEN\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"chicken\") - 1)  # girl!\n        self.assertTrue(np.all(x.metas < \"chicken\"))\n\n        f.oper = f.LessEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col <= \"chicken\") - 1)\n        self.assertTrue(np.all(x.metas <= \"chicken\"))\n\n        f.oper = f.Greater\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col > \"chicken\") + 1)\n        for e in x:\n            self.assertGreater(str(e[\"name\"]).lower(), \"chicken\")\n\n        f.oper = f.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col >= \"chicken\") + 1)\n        for e in x:\n            self.assertGreaterEqual(str(e[\"name\"]).lower(), \"chicken\")\n\n        f.oper = f.Between\n        f.max = \"liOn\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum((col >= \"chicken\") * (col <= \"lion\")) + 1)\n        for e in x:\n            self.assertTrue(\"chicken\" <= str(e[\"name\"]).lower() <= \"lion\")\n\n        f.oper = f.Outside\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"chicken\") + sum(col > \"lion\") - 1)\n        self.assertTrue(np.all((x.metas < \"chicken\") + (x.metas > \"lion\")))\n\n        f.oper = f.Contains\n        f.ref = \"iR\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(\"ir\" in str(e[\"name\"]).lower())\n        self.assertEqual(len(x), len([e for e in col if \"ir\" in e]) + 1)\n\n        f.oper = f.StartsWith\n        f.ref = \"GI\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).lower().startswith(\"gi\"))\n        self.assertEqual(len(x),\n                         len([e for e in col if e.lower().startswith(\"gi\")]))\n\n        f.oper = f.EndsWith\n        f.ref = \"ion\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n        self.assertEqual(len(x), len([e for e in col if e.endswith(\"ion\")]))\n\n    def test_valueFilter_regex(self):\n        d = data.Table(\"zoo\")\n        f = filter.FilterRegex(d.domain['name'], '^c...$')\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 7)\n\n    def test_valueFilter_stringList(self):\n        data = Table(\"zoo\")\n        var = data.domain[\"name\"]\n\n        fs = filter.FilterStringList\n        filters = [\n            (([\"swan\", \"tuna\", \"wasp\"], True), dict(rows=3)),\n            (([\"swan\", \"tuna\", \"wasp\"], False), dict(rows=3)),\n            (([\"WoRm\", \"TOad\", \"vOLe\"], True), dict(rows=0)),\n            (([\"WoRm\", \"TOad\", \"vOLe\"], False), dict(rows=3)),\n        ]\n\n        for args, expected in filters:\n            f = fs(var, *args)\n            filtered_data = filter.Values([f])(data)\n            self.assertEqual(len(filtered_data), expected[\"rows\"],\n                             \"{} returned wrong number of rows\".format(args))\n\n    def test_table_dtypes(self):\n        table = data.Table(\"iris\")\n        metas = np.hstack((table.metas, table.Y.reshape(len(table), 1)))\n        attributes_metas = table.domain.metas + table.domain.class_vars\n        domain_metas = data.Domain(table.domain.attributes[:2],\n                                   table.domain.attributes[2:],\n                                   attributes_metas)\n        table_metas = data.Table(domain_metas, table.X[:, : 2], table.X[:, 2:],\n                                 metas)\n        new_table = data.Table.from_table(data.Domain(table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.X.dtype, np.float64)\n        new_table = data.Table.from_table(data.Domain((), table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.Y.dtype, np.float64)\n        new_table = data.Table.from_table(data.Domain((), (), table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.metas.dtype, np.float64)\n\n    def test_attributes(self):\n        table = data.Table(\"iris\")\n        table.attributes = {1: \"test\"}\n        table2 = table[:4]\n        self.assertEqual(table2.attributes[1], \"test\")\n        table2.attributes[1] = \"modified\"\n        self.assertEqual(table.attributes[1], \"modified\")\n\n    # TODO Test conjunctions and disjunctions of conditions\n\n    def test_is_sparse(self):\n        table = data.Table(\"iris\")\n        self.assertFalse(table.is_sparse())\n\n        with table.unlocked():\n            table.X = sp.csr_matrix(table.X)\n            self.assertTrue(table.is_sparse())\n\n    def test_repr_sparse_with_one_row(self):\n        table = data.Table(\"iris\")[:1]\n        with table.unlocked():\n            table.X = sp.csr_matrix(table.X)\n        repr(table)     # make sure repr does not crash\n\n    def test_inf(self):\n        a = np.array([[2, 0, 0, 0],\n                      [0, np.nan, np.nan, 1],\n                      [0, 0, np.inf, 0]])\n        with self.assertWarns(Warning):\n            tab = data.Table.from_numpy(None, a)\n        self.assertEqual(tab.get_nan_frequency_attribute(), 3/12)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 610,
                            "end_lineno": 621,
                            "parent": {
                                "file_name": "Orange/tests/test_table.py",
                                "type": "class",
                                "name": "TableTestCase",
                                "content": "class TableTestCase(unittest.TestCase):\n    def setUp(self):\n        data.table.dataset_dirs.append(test_dirname())\n\n    def tearDown(self):\n        data.table.dataset_dirs.remove(test_dirname())\n\n    def test_indexing_class(self):\n        d = data.Table(\"datasets/test1\")\n        self.assertEqual([e.get_class() for e in d], [\"t\", \"t\", \"f\"])\n        cind = len(d.domain.variables) - 1\n        self.assertEqual([e[cind] for e in d], [\"t\", \"t\", \"f\"])\n        self.assertEqual([e[\"d\"] for e in d], [\"t\", \"t\", \"f\"])\n        cvar = d.domain.class_var\n        self.assertEqual([e[cvar] for e in d], [\"t\", \"t\", \"f\"])\n\n    def test_filename(self):\n        dir = data.table.get_sample_datasets_dir()\n        d = data.Table(\"iris\")\n        self.assertEqual(d.__file__, os.path.join(dir, \"iris.tab\"))\n\n        d = data.Table(\"datasets/test2.tab\")\n        self.assertTrue(d.__file__.endswith(\"test2.tab\"))  # platform dependent\n\n    def test_indexing(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            # regular, discrete\n            varc = d.domain[\"c\"]\n            self.assertEqual(d[0, 1], \"0\")\n            self.assertEqual(d[0, varc], \"0\")\n            self.assertEqual(d[0, \"c\"], \"0\")\n            self.assertEqual(d[0][1], \"0\")\n            self.assertEqual(d[0][varc], \"0\")\n            self.assertEqual(d[0][\"c\"], \"0\")\n            self.assertEqual(d[np.int_(0), np.int_(1)], \"0\")\n            self.assertEqual(d[np.int_(0)][np.int_(1)], \"0\")\n\n            # regular, continuous\n            varb = d.domain[\"b\"]\n            self.assertEqual(d[0, 0], 0)\n            self.assertEqual(d[0, varb], 0)\n            self.assertEqual(d[0, \"b\"], 0)\n            self.assertEqual(d[0][0], 0)\n            self.assertEqual(d[0][varb], 0)\n            self.assertEqual(d[0][\"b\"], 0)\n            self.assertEqual(d[np.int_(0), np.int_(0)], 0)\n            self.assertEqual(d[np.int_(0)][np.int_(0)], 0)\n\n            # negative\n            varb = d.domain[\"b\"]\n            self.assertEqual(d[-2, 0], 3.333)\n            self.assertEqual(d[-2, varb], 3.333)\n            self.assertEqual(d[-2, \"b\"], 3.333)\n            self.assertEqual(d[-2][0], 3.333)\n            self.assertEqual(d[-2][varb], 3.333)\n            self.assertEqual(d[-2][\"b\"], 3.333)\n            self.assertEqual(d[np.int_(-2), np.int_(0)], 3.333)\n            self.assertEqual(d[np.int_(-2)][np.int_(0)], 3.333)\n\n            # meta, discrete\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n            self.assertEqual(d[0, metaa], \"A\")\n            self.assertEqual(d[0, vara], \"A\")\n            self.assertEqual(d[0, \"a\"], \"A\")\n            self.assertEqual(d[0][metaa], \"A\")\n            self.assertEqual(d[0][vara], \"A\")\n            self.assertEqual(d[0][\"a\"], \"A\")\n            self.assertEqual(d[np.int_(0), np.int_(metaa)], \"A\")\n            self.assertEqual(d[np.int_(0)][np.int_(metaa)], \"A\")\n\n            # meta, string\n            vare = d.domain[\"e\"]\n            metae = d.domain.index(\"e\")\n            self.assertEqual(d[0, metae], \"i\")\n            self.assertEqual(d[0, vare], \"i\")\n            self.assertEqual(d[0, \"e\"], \"i\")\n            self.assertEqual(d[0][metae], \"i\")\n            self.assertEqual(d[0][vare], \"i\")\n            self.assertEqual(d[0][\"e\"], \"i\")\n            self.assertEqual(d[np.int_(0), np.int_(metae)], \"i\")\n            self.assertEqual(d[np.int_(0)][np.int_(metae)], \"i\")\n\n    def test_indexing_example(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            e = d[0]\n\n            # regular, discrete\n            varc = d.domain[\"c\"]\n            self.assertEqual(e[1], \"0\")\n            self.assertEqual(e[varc], \"0\")\n            self.assertEqual(e[\"c\"], \"0\")\n            self.assertEqual(e[np.int_(1)], \"0\")\n\n            # regular, continuous\n            varb = d.domain[\"b\"]\n            self.assertEqual(e[0], 0)\n            self.assertEqual(e[varb], 0)\n            self.assertEqual(e[\"b\"], 0)\n            self.assertEqual(e[np.int_(0)], 0)\n\n            # meta, discrete\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n            self.assertEqual(e[metaa], \"A\")\n            self.assertEqual(e[vara], \"A\")\n            self.assertEqual(e[\"a\"], \"A\")\n            self.assertEqual(e[np.int_(metaa)], \"A\")\n\n            # meta, string\n            vare = d.domain[\"e\"]\n            metae = d.domain.index(\"e\")\n            self.assertEqual(e[metae], \"i\")\n            self.assertEqual(e[vare], \"i\")\n            self.assertEqual(e[\"e\"], \"i\")\n            self.assertEqual(e[np.int_(metae)], \"i\")\n\n    def test_indexing_assign_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            # meta\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, \"a\"] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][\"a\"] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, vara] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][vara] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, metaa] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][metaa] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, np.int_(metaa)] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][np.int_(metaa)] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            # regular\n            varb = d.domain[\"b\"]\n\n            self.assertEqual(d[0, \"b\"], 0)\n            with d.unlocked():\n                d[0, \"b\"] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][\"b\"] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, varb] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][varb] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, 0] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][0] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, np.int_(0)] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][np.int_(0)] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n    def test_indexing_assign_example(self):\n        def almost_equal_list(s, t):\n            for e, f in zip(s, t):\n                self.assertAlmostEqual(e, f)\n\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            self.assertFalse(isnan(d[0, \"a\"]))\n            with d.unlocked():\n                d[0] = [\"3.14\", \"1\", \"f\"]\n            almost_equal_list(d[0].values(), [3.14, \"1\", \"f\"])\n            self.assertTrue(isnan(d[0, \"a\"]))\n\n            with d.unlocked():\n                d[0] = [3.15, 1, \"t\"]\n            almost_equal_list(d[0].values(), [3.15, \"0\", \"t\"])\n\n            with d.unlocked():\n                d[np.int_(0)] = [3.15, 2, \"f\"]\n            almost_equal_list(d[0].values(), [3.15, 2, \"f\"])\n\n            with d.unlocked(), self.assertRaises(ValueError):\n                d[0] = [\"3.14\", \"1\"]\n\n            with d.unlocked(), self.assertRaises(ValueError):\n                d[np.int_(0)] = [\"3.14\", \"1\"]\n\n            ex = data.Instance(d.domain, [\"3.16\", \"1\", \"f\"])\n            with d.unlocked():\n                d[0] = ex\n            almost_equal_list(d[0].values(), [3.16, \"1\", \"f\"])\n\n            ex = data.Instance(d.domain, [\"3.16\", 2, \"t\"])\n            with d.unlocked():\n                d[np.int_(0)] = ex\n            almost_equal_list(d[0].values(), [3.16, 2, \"t\"])\n\n            ex = data.Instance(d.domain, [\"3.16\", \"1\", \"f\"])\n            ex[\"e\"] = \"mmmapp\"\n            with d.unlocked():\n                d[0] = ex\n            almost_equal_list(d[0].values(), [3.16, \"1\", \"f\"])\n            self.assertEqual(d[0, \"e\"], \"mmmapp\")\n\n    def test_slice(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            x = d[:3]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [0, 1.1, 2.22])\n\n            x = d[2:5]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.22, 2.23, 2.24])\n\n            x = d[4:1:-1]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.24, 2.23, 2.22])\n\n            x = d[-3:]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.26, 3.333, Unknown])\n\n    def test_assign_slice_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            with d.unlocked():\n                d[2:5, 0] = 42\n            self.assertEqual([e[0] for e in d],\n                             [0, 1.1, 42, 42, 42, 2.25, 2.26, 3.333, Unknown])\n            with d.unlocked():\n                d[:3, \"b\"] = 43\n            self.assertEqual([e[0] for e in d],\n                             [43, 43, 43, 42, 42, 2.25, 2.26, 3.333, None])\n            with d.unlocked():\n                d[-2:, d.domain[0]] = 44\n            self.assertEqual([e[0] for e in d],\n                             [43, 43, 43, 42, 42, 2.25, 2.26, 44, 44])\n\n            with d.unlocked():\n                d[2:5, \"a\"] = \"A\"\n            self.assertEqual([e[\"a\"] for e in d], list(\"ABAAACCDE\"))\n\n    def test_multiple_indices(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            with self.assertRaises(IndexError):\n                x = d[2, 5, 1]\n\n            with self.assertRaises(IndexError):\n                x = d[(2, 5, 1)]\n\n            x = d[[2, 5, 1]]\n            self.assertEqual([e[0] for e in x], [2.22, 2.25, 1.1])\n\n    def test_assign_multiple_indices_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            with d.unlocked():\n                d[1:4, \"b\"] = 42\n            self.assertEqual([e[0] for e in d],\n                             [0, 42, 42, 42, 2.24, 2.25, 2.26, 3.333, None])\n\n            with d.unlocked():\n                d[range(5, 2, -1), \"b\"] = None\n            self.assertEqual([e[d.domain[0]] for e in d],\n                             [0, 42, 42, None, \"?\", \"\", 2.26, 3.333, None])\n\n    def test_set_multiple_indices_example(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            vals = [e[0] for e in d]\n            with d.unlocked():\n                d[[1, 2, 5]] = [42, None, None]\n            vals[1] = vals[2] = vals[5] = 42\n            self.assertEqual([e[0] for e in d], vals)\n\n    def test_bool(self):\n        d = data.Table(\"iris\")\n        self.assertTrue(d)\n\n        d = data.Table(\"datasets/test3\")\n        self.assertFalse(d)\n\n        d = data.Table(\"iris\")\n        self.assertTrue(d)\n\n    def test_checksum(self):\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d[42, 3] = 0\n        crc1 = d.checksum(False)\n\n        with d.unlocked():\n            d[42, 3] = 1\n        crc2 = d.checksum(False)\n        self.assertNotEqual(crc1, crc2)\n\n        with d.unlocked():\n            d[42, 3] = 0\n        crc3 = d.checksum(False)\n        self.assertEqual(crc1, crc3)\n\n        _ = d[42, \"name\"]\n        with d.unlocked():\n            d[42, \"name\"] = \"non-animal\"\n        crc4 = d.checksum(False)\n        self.assertEqual(crc1, crc4)\n        crc4 = d.checksum(True)\n        crc5 = d.checksum(1)\n        crc6 = d.checksum(False)\n        self.assertNotEqual(crc1, crc4)\n        self.assertNotEqual(crc1, crc5)\n        self.assertEqual(crc1, crc6)\n\n    def test_total_weight(self):\n        d = data.Table(\"zoo\")\n        self.assertEqual(d.total_weight(), len(d))\n\n        with d.unlocked():\n            d.set_weights(0)\n            d[0].weight = 0.1\n            d[10].weight = 0.2\n            d[-1].weight = 0.3\n        self.assertAlmostEqual(d.total_weight(), 0.6)\n\n    def test_has_missing(self):\n        d = data.Table(\"zoo\")\n        self.assertFalse(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n        with d.unlocked():\n            d[10, 3] = \"?\"\n        self.assertTrue(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n        with d.unlocked():\n            d[10].set_class(\"?\")\n        self.assertTrue(d.has_missing())\n        self.assertTrue(d.has_missing_class())\n\n        with d.unlocked():\n            d = data.Table(\"datasets/test3\")\n        self.assertFalse(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n    def test_shuffle(self):\n        d = data.Table(\"zoo\")\n        crc = d.checksum()\n        names = set(str(x[\"name\"]) for x in d)\n\n        with d.unlocked():\n            d.shuffle()\n        self.assertNotEqual(crc, d.checksum())\n        self.assertSetEqual(names, set(str(x[\"name\"]) for x in d))\n        crc2 = d.checksum()\n\n        x = d[2:10]\n        crcx = x.checksum()\n        with d.unlocked():\n            d.shuffle()\n        self.assertNotEqual(crc2, d.checksum())\n        self.assertEqual(crcx, x.checksum())\n\n        crc2 = d.checksum()\n        with x.unlocked():\n            x.shuffle()\n        self.assertNotEqual(crcx, x.checksum())\n        self.assertEqual(crc2, d.checksum())\n\n    @staticmethod\n    def not_less_ex(ex1, ex2):\n        for v1, v2 in zip(ex1, ex2):\n            if v1 != v2:\n                return v1 < v2\n        return True\n\n    @staticmethod\n    def sorted(d):\n        for i in range(1, len(d)):\n            if not TableTestCase.not_less_ex(d[i - 1], d[i]):\n                return False\n        return True\n\n    @staticmethod\n    def not_less_ex_ord(ex1, ex2, ord):\n        for a in ord:\n            if ex1[a] != ex2[a]:\n                return ex1[a] < ex2[a]\n        return True\n\n    @staticmethod\n    def sorted_ord(d, ord):\n        for i in range(1, len(d)):\n            if not TableTestCase.not_less_ex_ord(d[i - 1], d[i], ord):\n                return False\n        return True\n\n    def test_copy(self):\n        t = data.Table.from_numpy(\n            None, np.zeros((5, 3)), np.arange(5), np.zeros((5, 3)))\n\n        copy = t.copy()\n        self.assertTrue(np.all(t.X == copy.X))\n        self.assertTrue(np.all(t.Y == copy.Y))\n        self.assertTrue(np.all(t.metas == copy.metas))\n        with copy.unlocked():\n            copy[0] = [1, 1, 1, 1]\n        self.assertFalse(np.all(t.X == copy.X))\n        self.assertFalse(np.all(t.Y == copy.Y))\n        self.assertFalse(np.all(t.metas == copy.metas))\n\n    def test_copy_sparse(self):\n        t = data.Table('iris').to_sparse()\n        copy = t.copy()\n\n        self.assertEqual((t.X != copy.X).nnz, 0)      # sparse matrices match by content\n        np.testing.assert_equal(t.Y, copy.Y)\n        np.testing.assert_equal(t.metas, copy.metas)\n\n        self.assertNotEqual(id(t.X), id(copy.X))\n        self.assertNotEqual(id(t._Y), id(copy._Y))\n        self.assertNotEqual(id(t.metas), id(copy.metas))\n\n        # ensure that copied sparse arrays do not share data\n        with t.unlocked():\n            t.X[0, 0] = 42\n        self.assertEqual(copy.X[0, 0], 5.1)\n\n    def test_concatenate(self):\n        d1 = data.Domain(\n            [data.ContinuousVariable(n) for n in \"abc\"],\n            data.DiscreteVariable(\"y\", values=\"ABC\"),\n            [data.StringVariable(n) for n in [\"m1\", \"m2\"]],\n        )\n        x1 = np.arange(6).reshape(2, 3)\n        y1 = np.array([0, 1])\n        m1 = np.array([[\"foo\", \"bar\"], [\"baz\", \"qux\"]])\n        w1 = np.random.random((2,))\n        t1 = data.Table.from_numpy(d1, x1, y1, m1, w1)\n        t1.ids = ids1 = np.array([100, 101])\n        t1.attributes = {\"a\": 42, \"c\": 43}\n\n        x2 = np.arange(6, 15).reshape(3, 3)\n        y2 = np.array([1, 2, 0])\n        m2 = np.array([[\"a\", \"b\"], [\"c\", \"d\"], [\"e\", \"f\"]])\n        w2 = np.random.random((3,))\n        t2 = data.Table.from_numpy(d1, x2, y2, m2, w2)\n        t2.ids = ids2 = np.array([102, 103, 104])\n        t2.name = \"t2\"\n        t2.attributes = {\"a\": 44, \"b\": 45}\n\n        x3 = np.arange(15, 27).reshape(4, 3)\n        y3 = np.array([2, 1, 1, 0])\n        m3 = np.array([[\"g\", \"h\"], [\"i\", \"j\"], [\"k\", \"l\"], [\"m\", \"n\"]])\n        w3 = np.random.random((4,))\n        t3 = data.Table.from_numpy(d1, x3, y3, m3, w3)\n        t3.ids = ids3 = np.array([102, 103, 104, 105])\n        t3.name = \"t3\"\n\n        t1b = data.Table.concatenate((t1,))\n        self.assertEqual(t1b.domain, t1.domain)\n        np.testing.assert_almost_equal(t1b.X, x1)\n        np.testing.assert_almost_equal(t1b.Y, y1)\n        self.assertEqual(list(t1b.metas.flatten()),\n                         list(m1.flatten()))\n        np.testing.assert_almost_equal(t1b.W, w1)\n        np.testing.assert_almost_equal(t1b.ids, ids1)\n        self.assertEqual(t1b.name, t1.name)\n        self.assertEqual(t1b.attributes, {\"a\": 42, \"c\": 43})\n\n        t12 = data.Table.concatenate((t1, t2))\n        self.assertEqual(t12.domain, t1.domain)\n        np.testing.assert_almost_equal(t12.X, np.vstack((x1, x2)))\n        np.testing.assert_almost_equal(t12.Y, np.hstack((y1, y2)))\n        self.assertEqual(list(t12.metas.flatten()),\n                         list(np.vstack((m1, m2)).flatten()))\n        np.testing.assert_almost_equal(t12.W, np.hstack((w1, w2)))\n        np.testing.assert_almost_equal(t12.ids, np.hstack((ids1, ids2)))\n        self.assertEqual(t12.name, \"t2\")\n        self.assertEqual(t12.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n        t123 = data.Table.concatenate((t1, t2, t3))\n        self.assertEqual(t123.domain, t1.domain)\n        np.testing.assert_almost_equal(t123.X, np.vstack((x1, x2, x3)))\n        np.testing.assert_almost_equal(t123.Y, np.hstack((y1, y2, y3)))\n        self.assertEqual(list(t123.metas.flatten()),\n                         list(np.vstack((m1, m2, m3)).flatten()))\n        np.testing.assert_almost_equal(t123.W, np.hstack((w1, w2, w3)))\n        np.testing.assert_almost_equal(t123.ids, np.hstack((ids1, ids2, ids3)))\n        self.assertEqual(t123.name, \"t2\")\n        self.assertEqual(t123.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n        with t2.unlocked(t2.Y):\n            t2.Y = np.atleast_2d(t2.Y).T\n        t12 = data.Table.concatenate((t1, t2))\n        self.assertEqual(t12.domain, t1.domain)\n        np.testing.assert_almost_equal(t12.X, np.vstack((x1, x2)))\n        np.testing.assert_almost_equal(t12.Y, np.hstack((y1, y2)))\n        self.assertEqual(list(t12.metas.flatten()),\n                         list(np.vstack((m1, m2)).flatten()))\n        np.testing.assert_almost_equal(t12.W, np.hstack((w1, w2)))\n        np.testing.assert_almost_equal(t12.ids, np.hstack((ids1, ids2)))\n        self.assertEqual(t12.name, \"t2\")\n        self.assertEqual(t12.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n    def test_concatenate_exceptions(self):\n        zoo = data.Table(\"zoo\")\n        iris = data.Table(\"iris\")\n\n        self.assertRaises(ValueError, data.Table.concatenate, [])\n        self.assertRaises(ValueError, data.Table.concatenate, [zoo, iris])\n\n    def test_concatenate_sparse(self):\n        iris = Table(\"iris\")\n        with iris.unlocked():\n            iris.X = sp.csc_matrix(iris.X)\n        new = Table.concatenate([iris, iris])\n        self.assertEqual(len(new), 300)\n        self.assertTrue(sp.issparse(new.X), \"Concatenated X is not sparse.\")\n        self.assertFalse(sp.issparse(new.Y), \"Concatenated Y is not dense.\")\n        self.assertFalse(sp.issparse(new.metas), \"Concatenated metas is not dense.\")\n        self.assertEqual(len(new.ids), 300)\n\n    def test_pickle(self):\n        d = data.Table(\"zoo\")\n        s = pickle.dumps(d)\n        d2 = pickle.loads(s)\n        self.assertEqual(d[0], d2[0])\n\n        self.assertEqual(d.checksum(include_metas=False),\n                         d2.checksum(include_metas=False))\n\n        d = data.Table(\"iris\")\n        s = pickle.dumps(d)\n        d2 = pickle.loads(s)\n        self.assertEqual(d[0], d2[0])\n        self.assertEqual(d.checksum(include_metas=False),\n                         d2.checksum(include_metas=False))\n\n    def test_pickle_setstate(self):\n        d = data.Table(\"zoo\")\n        s = pickle.dumps(d)\n        with patch(\"Orange.data.Table.__setstate__\", Mock()) as mock:\n            pickle.loads(s)\n            state = mock.call_args[0][0]\n            for k in [\"X\", \"_Y\", \"metas\"]:\n                self.assertIn(k, state)\n                self.assertEqual(state[k].ndim, 2)\n            self.assertIn(\"W\", state)\n            for k in [\"_X\", \"Y\", \"_metas\", \"_W\"]:\n                self.assertNotIn(k, state)\n\n\n    def test_translate_through_slice(self):\n        d = data.Table(\"iris\")\n        dom = data.Domain([\"petal length\", \"sepal length\", \"iris\"],\n                          source=d.domain)\n        d_ref = d[:10, dom.variables]\n        self.assertEqual(d_ref.domain.class_var, d.domain.class_var)\n        self.assertEqual(d_ref[0, \"petal length\"], d[0, \"petal length\"])\n        self.assertEqual(d_ref[0, \"sepal length\"], d[0, \"sepal length\"])\n        self.assertEqual(d_ref.X.shape, (10, 2))\n        self.assertEqual(d_ref.Y.shape, (10,))\n\n    def test_saveTab(self):\n        d = data.Table(\"iris\")[:3]\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            for e1, e2 in zip(d, d2):\n                self.assertEqual(e1, e2)\n        finally:\n            os.remove(\"test-save.tab\")\n            os.remove(\"test-save.tab.metadata\")\n\n        dom = data.Domain([data.ContinuousVariable(\"a\")])\n        d = data.Table.from_list(dom, [[i] for i in range(3)])\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            self.assertEqual(len(d.domain.attributes), 1)\n            self.assertEqual(d.domain.class_var, None)\n            for i in range(3):\n                self.assertEqual(d2[i], [i])\n        finally:\n            os.remove(\"test-save.tab\")\n\n        dom = data.Domain([data.ContinuousVariable(\"a\")], None)\n        d = data.Table.from_list(dom, [[i] for i in range(3)])\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            self.assertEqual(len(d.domain.attributes), 1)\n            for i in range(3):\n                self.assertEqual(d2[i], [i])\n        finally:\n            os.remove(\"test-save.tab\")\n\n        d = data.Table(\"zoo\")\n        d.save(\"test-zoo.tab\")\n        dd = data.Table(\"test-zoo\")\n        try:\n            self.assertTupleEqual(d.domain.metas, dd.domain.metas,\n                                  msg=\"Meta attributes don't match.\")\n            self.assertTupleEqual(d.domain.variables, dd.domain.variables,\n                                  msg=\"Attributes don't match.\")\n\n            np.testing.assert_almost_equal(d.W, dd.W,\n                                           err_msg=\"Weights don't match.\")\n            for i in range(10):\n                for j in d.domain.variables:\n                    self.assertEqual(d[i][j], dd[i][j])\n        finally:\n            os.remove(\"test-zoo.tab\")\n            os.remove(\"test-zoo.tab.metadata\")\n\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d.set_weights(range(len(d)))\n        d.save(\"test-zoo-weights.tab\")\n        dd = data.Table(\"test-zoo-weights\")\n        try:\n            self.assertTupleEqual(d.domain.metas, dd.domain.metas,\n                                  msg=\"Meta attributes don't match.\")\n            self.assertTupleEqual(d.domain.variables, dd.domain.variables,\n                                  msg=\"Attributes don't match.\")\n\n            np.testing.assert_almost_equal(d.W, dd.W,\n                                           err_msg=\"Weights don't match.\")\n            for i in range(10):\n                for j in d.domain.variables:\n                    self.assertEqual(d[i][j], dd[i][j])\n        finally:\n            os.remove(\"test-zoo-weights.tab\")\n            os.remove(\"test-zoo-weights.tab.metadata\")\n\n    def test_save_pickle(self):\n        table = data.Table(\"iris\")\n        try:\n            table.save(\"iris.pickle\")\n            table2 = data.Table.from_file(\"iris.pickle\")\n            np.testing.assert_almost_equal(table.X, table2.X)\n            np.testing.assert_almost_equal(table.Y, table2.Y)\n            self.assertEqual(table.domain[0], table2.domain[0])\n        finally:\n            os.remove(\"iris.pickle\")\n\n    def test_from_numpy(self):\n        a = np.arange(20, dtype=\"d\").reshape((4, 5)).copy()\n        a[:, -1] = [0, 0, 0, 1]\n        dom = data.Domain([data.ContinuousVariable(x) for x in \"abcd\"],\n                          data.DiscreteVariable(\"e\", values=(\"no\", \"yes\")))\n        table = data.Table(dom, a)\n        with table.unlocked():\n            for i in range(4):\n                self.assertEqual(table[i].get_class(), \"no\" if i < 3 else \"yes\")\n                for j in range(5):\n                    self.assertEqual(a[i, j], table[i, j])\n\n        with table.unlocked(), self.assertRaises(IndexError):\n            table[0, -5] = 5\n\n    def test_filter_is_defined(self):\n        d = data.Table(\"iris\")\n        with d.unlocked():\n            d[1, 4] = Unknown\n        self.assertTrue(isnan(d[1, 4]))\n        with d.unlocked():\n            d[140, 0] = Unknown\n        e = filter.IsDefined()(d)\n        self.assertEqual(len(e), len(d) - 2)\n        self.assertEqual(e[0], d[0])\n        self.assertEqual(e[1], d[2])\n        self.assertEqual(e[147], d[149])\n        self.assertTrue(d.has_missing())\n        self.assertFalse(e.has_missing())\n\n    def test_filter_has_class(self):\n        d = data.Table(\"iris\")\n        with d.unlocked():\n            d[1, 4] = Unknown\n        self.assertTrue(isnan(d[1, 4]))\n        with d.unlocked():\n            d[140, 0] = Unknown\n        e = filter.HasClass()(d)\n        self.assertEqual(len(e), len(d) - 1)\n        self.assertEqual(e[0], d[0])\n        self.assertEqual(e[1], d[2])\n        self.assertEqual(e[148], d[149])\n        self.assertTrue(d.has_missing())\n        self.assertTrue(e.has_missing())\n        self.assertFalse(e.has_missing_class())\n\n    def test_filter_random(self):\n        d = data.Table(\"iris\")\n        e = filter.Random(50)(d)\n        self.assertEqual(len(e), 50)\n        e = filter.Random(50, negate=True)(d)\n        self.assertEqual(len(e), 100)\n        for _ in range(5):\n            e = filter.Random(0.2)(d)\n            self.assertEqual(len(e), 30)\n            bc = np.bincount(np.array(e.Y[:], dtype=int))\n            if min(bc) > 7:\n                break\n        else:\n            self.fail(\"Filter returns too uneven distributions\")\n\n    def test_filter_values_nested(self):\n        d = data.Table(\"iris\")\n        f1 = filter.FilterContinuous(d.columns.sepal_length,\n                                     filter.FilterContinuous.Between,\n                                     min=4.5, max=5.0)\n        f2 = filter.FilterContinuous(d.columns.sepal_width,\n                                     filter.FilterContinuous.Between,\n                                     min=3.1, max=3.4)\n        f3 = filter.FilterDiscrete(d.columns.iris, [0, 1])\n        f = filter.Values([filter.Values([f1, f2], conjunction=False), f3])\n        self.assertEqual(41, len(f(d)))\n\n    def test_filter_string_works_for_numeric_columns(self):\n        var = StringVariable(\"s\")\n        data = Table.from_list(Domain([], metas=[var]),\n                               [[x] for x in range(21)])\n        # 1, 2, 3, ..., 18, 19, 20\n\n        fs = filter.FilterString\n        filters = [\n            ((fs.Greater, \"5\"), dict(rows=4)),\n            # 6, 7, 8, 9\n            ((fs.Between, \"15\", \"2\"), dict(rows=6)),\n            # 15, 16, 17, 18, 19, 2\n            ((fs.Contains, \"2\"), dict(rows=3)),\n            # 2, 12, 20\n        ]\n\n        for args, expected in filters:\n            f = fs(var, *args)\n            filtered_data = filter.Values([f])(data)\n            self.assertEqual(len(filtered_data), expected[\"rows\"],\n                             \"{} returned wrong number of rows\".format(args))\n\n    def test_filter_value_continuous(self):\n        d = data.Table(\"iris\")\n        col = d.X[:, 2]\n\n        v = d.columns\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Between,\n                                    min=4.5, max=5.1)\n\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] >= 4.5))\n        self.assertTrue(np.all(x.X[:, 2] <= 5.1))\n        self.assertEqual(sum((col >= 4.5) * (col <= 5.1)), len(x))\n\n        f.ref = 5.1\n        f.oper = filter.FilterContinuous.Equal\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.NotEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] != 5.1))\n        self.assertEqual(sum(col != 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Less\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] < 5.1))\n        self.assertEqual(sum(col < 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.LessEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] <= 5.1))\n        self.assertEqual(sum(col <= 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Greater\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] > 5.1))\n        self.assertEqual(sum(col > 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] >= 5.1))\n        self.assertEqual(sum(col >= 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Outside\n        f.ref, f.max = 4.5, 5.1\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(e[2] < 4.5 or e[2] > 5.1)\n        self.assertEqual(sum((col < 4.5) + (col > 5.1)), len(x))\n\n        f.oper = filter.FilterContinuous.IsDefined\n        f.ref = f.max = None\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d))\n\n        with d.unlocked():\n            d[:30, v.petal_length] = Unknown\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 30)\n\n    def test_filter_value_continuous_args(self):\n        d = data.Table(\"iris\")\n        col = d.X[:, 2]\n        v = d.columns\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(2,\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"petal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"sepal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        f.column = 2\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"sepal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        f.column = v.petal_length\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=18)\n        f.ref = 5.1\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=18)\n        f.ref = 5.1\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n    def test_valueFilter_discrete(self):\n        d = data.Table(\"zoo\")\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, 3, 4])\n        for e in filter.Values([f])(d):\n            self.assertTrue(e.get_class() in [2, 3, 4])\n\n        f.values = [\"mammal\"]\n        for e in filter.Values([f])(d):\n            self.assertEqual(e.get_class(), \"mammal\")\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, \"mammal\"])\n        for e in filter.Values([f])(d):\n            self.assertTrue(e.get_class() in [2, \"mammal\"])\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, \"martian\"])\n        self.assertRaises(ValueError, d._filter_values, f)\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=(2, data.Table))\n        self.assertRaises(TypeError, d._filter_values, f)\n\n        v = d.columns\n        f = filter.FilterDiscrete(v.hair, values=None)\n        self.assertEqual(len(filter.Values([f])(d)), len(d))\n\n        with d.unlocked():\n            d[:5, v.hair] = Unknown\n        self.assertEqual(len(filter.Values([f])(d)), len(d) - 5)\n\n    def test_valueFilter_string_is_defined(self):\n        d = data.Table(\"datasets/test9.tab\")\n        f = filter.FilterString(-5, filter.FilterString.IsDefined)\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 7)\n\n    def test_valueFilter_discrete_meta_is_defined(self):\n        d = data.Table(\"datasets/test9.tab\")\n        f = filter.FilterDiscrete(-4, None)\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 8)\n\n    def test_valueFilter_string_case_sens(self):\n        d = data.Table(\"zoo\")\n        col = d[:, \"name\"].metas[:, 0]\n\n        f = filter.FilterString(\"name\",\n                                filter.FilterString.Equal, \"girl\")\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 1)\n        self.assertEqual(x[0, \"name\"], \"girl\")\n        self.assertTrue(np.all(x.metas == \"girl\"))\n\n        f.oper = f.NotEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 1)\n        self.assertTrue(np.all(x[:, \"name\"] != \"girl\"))\n\n        f.oper = f.Less\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"girl\"))\n        self.assertTrue(np.all(x.metas < \"girl\"))\n\n        f.oper = f.LessEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col <= \"girl\"))\n        self.assertTrue(np.all(x.metas <= \"girl\"))\n\n        f.oper = f.Greater\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col > \"girl\"))\n        self.assertTrue(np.all(x.metas > \"girl\"))\n\n        f.oper = f.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col >= \"girl\"))\n        self.assertTrue(np.all(x.metas >= \"girl\"))\n\n        f.oper = f.Between\n        f.max = \"lion\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum((col >= \"girl\") * (col <= \"lion\")))\n        self.assertTrue(np.all(x.metas >= \"girl\"))\n        self.assertTrue(np.all(x.metas <= \"lion\"))\n\n        f.oper = f.Outside\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"girl\") + sum(col > \"lion\"))\n        self.assertTrue(np.all((x.metas < \"girl\") + (x.metas > \"lion\")))\n\n        f.oper = f.Contains\n        f.ref = \"ea\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(\"ea\" in e[\"name\"])\n        self.assertEqual(len(x), len([e for e in col if \"ea\" in e]))\n\n        f.oper = f.StartsWith\n        f.ref = \"sea\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).startswith(\"sea\"))\n        self.assertEqual(len(x), len([e for e in col if e.startswith(\"sea\")]))\n\n        f.oper = f.EndsWith\n        f.ref = \"ion\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n        self.assertEqual(len(x), len([e for e in col if e.endswith(\"ion\")]))\n\n    def test_valueFilter_string_case_insens(self):\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d[d[:, \"name\"].metas[:, 0] == \"girl\", \"name\"] = \"GIrl\"\n\n        col = d[:, \"name\"].metas[:, 0]\n\n        f = filter.FilterString(\"name\",\n                                filter.FilterString.Equal, \"giRL\")\n        f.case_sensitive = False\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 1)\n        self.assertEqual(x[0, \"name\"], \"GIrl\")\n        self.assertTrue(np.all(x.metas == \"GIrl\"))\n\n        f.oper = f.NotEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 1)\n        self.assertTrue(np.all(x[:, \"name\"] != \"GIrl\"))\n\n        f.oper = f.Less\n        f.ref = \"CHiCKEN\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"chicken\") - 1)  # girl!\n        self.assertTrue(np.all(x.metas < \"chicken\"))\n\n        f.oper = f.LessEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col <= \"chicken\") - 1)\n        self.assertTrue(np.all(x.metas <= \"chicken\"))\n\n        f.oper = f.Greater\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col > \"chicken\") + 1)\n        for e in x:\n            self.assertGreater(str(e[\"name\"]).lower(), \"chicken\")\n\n        f.oper = f.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col >= \"chicken\") + 1)\n        for e in x:\n            self.assertGreaterEqual(str(e[\"name\"]).lower(), \"chicken\")\n\n        f.oper = f.Between\n        f.max = \"liOn\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum((col >= \"chicken\") * (col <= \"lion\")) + 1)\n        for e in x:\n            self.assertTrue(\"chicken\" <= str(e[\"name\"]).lower() <= \"lion\")\n\n        f.oper = f.Outside\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"chicken\") + sum(col > \"lion\") - 1)\n        self.assertTrue(np.all((x.metas < \"chicken\") + (x.metas > \"lion\")))\n\n        f.oper = f.Contains\n        f.ref = \"iR\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(\"ir\" in str(e[\"name\"]).lower())\n        self.assertEqual(len(x), len([e for e in col if \"ir\" in e]) + 1)\n\n        f.oper = f.StartsWith\n        f.ref = \"GI\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).lower().startswith(\"gi\"))\n        self.assertEqual(len(x),\n                         len([e for e in col if e.lower().startswith(\"gi\")]))\n\n        f.oper = f.EndsWith\n        f.ref = \"ion\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n        self.assertEqual(len(x), len([e for e in col if e.endswith(\"ion\")]))\n\n    def test_valueFilter_regex(self):\n        d = data.Table(\"zoo\")\n        f = filter.FilterRegex(d.domain['name'], '^c...$')\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 7)\n\n    def test_valueFilter_stringList(self):\n        data = Table(\"zoo\")\n        var = data.domain[\"name\"]\n\n        fs = filter.FilterStringList\n        filters = [\n            (([\"swan\", \"tuna\", \"wasp\"], True), dict(rows=3)),\n            (([\"swan\", \"tuna\", \"wasp\"], False), dict(rows=3)),\n            (([\"WoRm\", \"TOad\", \"vOLe\"], True), dict(rows=0)),\n            (([\"WoRm\", \"TOad\", \"vOLe\"], False), dict(rows=3)),\n        ]\n\n        for args, expected in filters:\n            f = fs(var, *args)\n            filtered_data = filter.Values([f])(data)\n            self.assertEqual(len(filtered_data), expected[\"rows\"],\n                             \"{} returned wrong number of rows\".format(args))\n\n    def test_table_dtypes(self):\n        table = data.Table(\"iris\")\n        metas = np.hstack((table.metas, table.Y.reshape(len(table), 1)))\n        attributes_metas = table.domain.metas + table.domain.class_vars\n        domain_metas = data.Domain(table.domain.attributes[:2],\n                                   table.domain.attributes[2:],\n                                   attributes_metas)\n        table_metas = data.Table(domain_metas, table.X[:, : 2], table.X[:, 2:],\n                                 metas)\n        new_table = data.Table.from_table(data.Domain(table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.X.dtype, np.float64)\n        new_table = data.Table.from_table(data.Domain((), table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.Y.dtype, np.float64)\n        new_table = data.Table.from_table(data.Domain((), (), table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.metas.dtype, np.float64)\n\n    def test_attributes(self):\n        table = data.Table(\"iris\")\n        table.attributes = {1: \"test\"}\n        table2 = table[:4]\n        self.assertEqual(table2.attributes[1], \"test\")\n        table2.attributes[1] = \"modified\"\n        self.assertEqual(table.attributes[1], \"modified\")\n\n    # TODO Test conjunctions and disjunctions of conditions\n\n    def test_is_sparse(self):\n        table = data.Table(\"iris\")\n        self.assertFalse(table.is_sparse())\n\n        with table.unlocked():\n            table.X = sp.csr_matrix(table.X)\n            self.assertTrue(table.is_sparse())\n\n    def test_repr_sparse_with_one_row(self):\n        table = data.Table(\"iris\")[:1]\n        with table.unlocked():\n            table.X = sp.csr_matrix(table.X)\n        repr(table)     # make sure repr does not crash\n\n    def test_inf(self):\n        a = np.array([[2, 0, 0, 0],\n                      [0, np.nan, np.nan, 1],\n                      [0, 0, np.inf, 0]])\n        with self.assertWarns(Warning):\n            tab = data.Table.from_numpy(None, a)\n        self.assertEqual(tab.get_nan_frequency_attribute(), 3/12)",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 27,
                                "end_lineno": 1183,
                                "parent": null
                            }
                        }
                    ],
                    "deleted_entities": []
                }
            ]
        }
    ],
    "old_commit_hash": "c86388cdfa52cb5be7ea27e2713cc4e38e115dda^",
    "new_commit_hash": "c86388cdfa52cb5be7ea27e2713cc4e38e115dda",
    "commit_message": "Table-lock: a compatible pickle format",
    "commit_date": "2021-10-18T19:22:01+02:00",
    "metadata": {}
}
{
    "repo_name": "orange3",
    "new_commit_hash": "c86388cdfa52cb5be7ea27e2713cc4e38e115dda",
    "test_file_codes": [
        "# Test methods with long descriptive names can omit docstrings\n# pylint: disable=missing-docstring\n\nimport copy\nimport os\nimport pickle\nimport random\nimport unittest\nimport warnings\nfrom unittest.mock import Mock, MagicMock, patch\nfrom itertools import chain\nfrom math import isnan\nfrom threading import Thread\nfrom time import sleep, time\n\nimport numpy as np\nimport scipy.sparse as sp\n\nfrom Orange import data\nfrom Orange.data import (filter, Unknown, Variable, Table, DiscreteVariable,\n                         ContinuousVariable, Domain, StringVariable)\nfrom Orange.data.util import SharedComputeValue\nfrom Orange.tests import test_dirname\nfrom Orange.data.table import _optimize_indices\n\n\nclass TableTestCase(unittest.TestCase):\n    def setUp(self):\n        data.table.dataset_dirs.append(test_dirname())\n\n    def tearDown(self):\n        data.table.dataset_dirs.remove(test_dirname())\n\n    def test_indexing_class(self):\n        d = data.Table(\"datasets/test1\")\n        self.assertEqual([e.get_class() for e in d], [\"t\", \"t\", \"f\"])\n        cind = len(d.domain.variables) - 1\n        self.assertEqual([e[cind] for e in d], [\"t\", \"t\", \"f\"])\n        self.assertEqual([e[\"d\"] for e in d], [\"t\", \"t\", \"f\"])\n        cvar = d.domain.class_var\n        self.assertEqual([e[cvar] for e in d], [\"t\", \"t\", \"f\"])\n\n    def test_filename(self):\n        dir = data.table.get_sample_datasets_dir()\n        d = data.Table(\"iris\")\n        self.assertEqual(d.__file__, os.path.join(dir, \"iris.tab\"))\n\n        d = data.Table(\"datasets/test2.tab\")\n        self.assertTrue(d.__file__.endswith(\"test2.tab\"))  # platform dependent\n\n    def test_indexing(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            # regular, discrete\n            varc = d.domain[\"c\"]\n            self.assertEqual(d[0, 1], \"0\")\n            self.assertEqual(d[0, varc], \"0\")\n            self.assertEqual(d[0, \"c\"], \"0\")\n            self.assertEqual(d[0][1], \"0\")\n            self.assertEqual(d[0][varc], \"0\")\n            self.assertEqual(d[0][\"c\"], \"0\")\n            self.assertEqual(d[np.int_(0), np.int_(1)], \"0\")\n            self.assertEqual(d[np.int_(0)][np.int_(1)], \"0\")\n\n            # regular, continuous\n            varb = d.domain[\"b\"]\n            self.assertEqual(d[0, 0], 0)\n            self.assertEqual(d[0, varb], 0)\n            self.assertEqual(d[0, \"b\"], 0)\n            self.assertEqual(d[0][0], 0)\n            self.assertEqual(d[0][varb], 0)\n            self.assertEqual(d[0][\"b\"], 0)\n            self.assertEqual(d[np.int_(0), np.int_(0)], 0)\n            self.assertEqual(d[np.int_(0)][np.int_(0)], 0)\n\n            # negative\n            varb = d.domain[\"b\"]\n            self.assertEqual(d[-2, 0], 3.333)\n            self.assertEqual(d[-2, varb], 3.333)\n            self.assertEqual(d[-2, \"b\"], 3.333)\n            self.assertEqual(d[-2][0], 3.333)\n            self.assertEqual(d[-2][varb], 3.333)\n            self.assertEqual(d[-2][\"b\"], 3.333)\n            self.assertEqual(d[np.int_(-2), np.int_(0)], 3.333)\n            self.assertEqual(d[np.int_(-2)][np.int_(0)], 3.333)\n\n            # meta, discrete\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n            self.assertEqual(d[0, metaa], \"A\")\n            self.assertEqual(d[0, vara], \"A\")\n            self.assertEqual(d[0, \"a\"], \"A\")\n            self.assertEqual(d[0][metaa], \"A\")\n            self.assertEqual(d[0][vara], \"A\")\n            self.assertEqual(d[0][\"a\"], \"A\")\n            self.assertEqual(d[np.int_(0), np.int_(metaa)], \"A\")\n            self.assertEqual(d[np.int_(0)][np.int_(metaa)], \"A\")\n\n            # meta, string\n            vare = d.domain[\"e\"]\n            metae = d.domain.index(\"e\")\n            self.assertEqual(d[0, metae], \"i\")\n            self.assertEqual(d[0, vare], \"i\")\n            self.assertEqual(d[0, \"e\"], \"i\")\n            self.assertEqual(d[0][metae], \"i\")\n            self.assertEqual(d[0][vare], \"i\")\n            self.assertEqual(d[0][\"e\"], \"i\")\n            self.assertEqual(d[np.int_(0), np.int_(metae)], \"i\")\n            self.assertEqual(d[np.int_(0)][np.int_(metae)], \"i\")\n\n    def test_indexing_example(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            e = d[0]\n\n            # regular, discrete\n            varc = d.domain[\"c\"]\n            self.assertEqual(e[1], \"0\")\n            self.assertEqual(e[varc], \"0\")\n            self.assertEqual(e[\"c\"], \"0\")\n            self.assertEqual(e[np.int_(1)], \"0\")\n\n            # regular, continuous\n            varb = d.domain[\"b\"]\n            self.assertEqual(e[0], 0)\n            self.assertEqual(e[varb], 0)\n            self.assertEqual(e[\"b\"], 0)\n            self.assertEqual(e[np.int_(0)], 0)\n\n            # meta, discrete\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n            self.assertEqual(e[metaa], \"A\")\n            self.assertEqual(e[vara], \"A\")\n            self.assertEqual(e[\"a\"], \"A\")\n            self.assertEqual(e[np.int_(metaa)], \"A\")\n\n            # meta, string\n            vare = d.domain[\"e\"]\n            metae = d.domain.index(\"e\")\n            self.assertEqual(e[metae], \"i\")\n            self.assertEqual(e[vare], \"i\")\n            self.assertEqual(e[\"e\"], \"i\")\n            self.assertEqual(e[np.int_(metae)], \"i\")\n\n    def test_indexing_assign_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            # meta\n            vara = d.domain[\"a\"]\n            metaa = d.domain.index(\"a\")\n\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, \"a\"] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][\"a\"] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, vara] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][vara] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, metaa] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][metaa] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            with d.unlocked():\n                d[0, np.int_(metaa)] = \"B\"\n            self.assertEqual(d[0, \"a\"], \"B\")\n            with d.unlocked():\n                d[0][np.int_(metaa)] = \"A\"\n            self.assertEqual(d[0, \"a\"], \"A\")\n\n            # regular\n            varb = d.domain[\"b\"]\n\n            self.assertEqual(d[0, \"b\"], 0)\n            with d.unlocked():\n                d[0, \"b\"] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][\"b\"] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, varb] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][varb] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, 0] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][0] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n            with d.unlocked():\n                d[0, np.int_(0)] = 42\n            self.assertEqual(d[0, \"b\"], 42)\n            with d.unlocked():\n                d[0][np.int_(0)] = 0\n            self.assertEqual(d[0, \"b\"], 0)\n\n    def test_indexing_assign_example(self):\n        def almost_equal_list(s, t):\n            for e, f in zip(s, t):\n                self.assertAlmostEqual(e, f)\n\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            self.assertFalse(isnan(d[0, \"a\"]))\n            with d.unlocked():\n                d[0] = [\"3.14\", \"1\", \"f\"]\n            almost_equal_list(d[0].values(), [3.14, \"1\", \"f\"])\n            self.assertTrue(isnan(d[0, \"a\"]))\n\n            with d.unlocked():\n                d[0] = [3.15, 1, \"t\"]\n            almost_equal_list(d[0].values(), [3.15, \"0\", \"t\"])\n\n            with d.unlocked():\n                d[np.int_(0)] = [3.15, 2, \"f\"]\n            almost_equal_list(d[0].values(), [3.15, 2, \"f\"])\n\n            with d.unlocked(), self.assertRaises(ValueError):\n                d[0] = [\"3.14\", \"1\"]\n\n            with d.unlocked(), self.assertRaises(ValueError):\n                d[np.int_(0)] = [\"3.14\", \"1\"]\n\n            ex = data.Instance(d.domain, [\"3.16\", \"1\", \"f\"])\n            with d.unlocked():\n                d[0] = ex\n            almost_equal_list(d[0].values(), [3.16, \"1\", \"f\"])\n\n            ex = data.Instance(d.domain, [\"3.16\", 2, \"t\"])\n            with d.unlocked():\n                d[np.int_(0)] = ex\n            almost_equal_list(d[0].values(), [3.16, 2, \"t\"])\n\n            ex = data.Instance(d.domain, [\"3.16\", \"1\", \"f\"])\n            ex[\"e\"] = \"mmmapp\"\n            with d.unlocked():\n                d[0] = ex\n            almost_equal_list(d[0].values(), [3.16, \"1\", \"f\"])\n            self.assertEqual(d[0, \"e\"], \"mmmapp\")\n\n    def test_slice(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            x = d[:3]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [0, 1.1, 2.22])\n\n            x = d[2:5]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.22, 2.23, 2.24])\n\n            x = d[4:1:-1]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.24, 2.23, 2.22])\n\n            x = d[-3:]\n            self.assertEqual(len(x), 3)\n            self.assertEqual([e[0] for e in x], [2.26, 3.333, Unknown])\n\n    def test_assign_slice_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n            with d.unlocked():\n                d[2:5, 0] = 42\n            self.assertEqual([e[0] for e in d],\n                             [0, 1.1, 42, 42, 42, 2.25, 2.26, 3.333, Unknown])\n            with d.unlocked():\n                d[:3, \"b\"] = 43\n            self.assertEqual([e[0] for e in d],\n                             [43, 43, 43, 42, 42, 2.25, 2.26, 3.333, None])\n            with d.unlocked():\n                d[-2:, d.domain[0]] = 44\n            self.assertEqual([e[0] for e in d],\n                             [43, 43, 43, 42, 42, 2.25, 2.26, 44, 44])\n\n            with d.unlocked():\n                d[2:5, \"a\"] = \"A\"\n            self.assertEqual([e[\"a\"] for e in d], list(\"ABAAACCDE\"))\n\n    def test_multiple_indices(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            with self.assertRaises(IndexError):\n                x = d[2, 5, 1]\n\n            with self.assertRaises(IndexError):\n                x = d[(2, 5, 1)]\n\n            x = d[[2, 5, 1]]\n            self.assertEqual([e[0] for e in x], [2.22, 2.25, 1.1])\n\n    def test_assign_multiple_indices_value(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            with d.unlocked():\n                d[1:4, \"b\"] = 42\n            self.assertEqual([e[0] for e in d],\n                             [0, 42, 42, 42, 2.24, 2.25, 2.26, 3.333, None])\n\n            with d.unlocked():\n                d[range(5, 2, -1), \"b\"] = None\n            self.assertEqual([e[d.domain[0]] for e in d],\n                             [0, 42, 42, None, \"?\", \"\", 2.26, 3.333, None])\n\n    def test_set_multiple_indices_example(self):\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            d = data.Table(\"datasets/test2\")\n\n            vals = [e[0] for e in d]\n            with d.unlocked():\n                d[[1, 2, 5]] = [42, None, None]\n            vals[1] = vals[2] = vals[5] = 42\n            self.assertEqual([e[0] for e in d], vals)\n\n    def test_bool(self):\n        d = data.Table(\"iris\")\n        self.assertTrue(d)\n\n        d = data.Table(\"datasets/test3\")\n        self.assertFalse(d)\n\n        d = data.Table(\"iris\")\n        self.assertTrue(d)\n\n    def test_checksum(self):\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d[42, 3] = 0\n        crc1 = d.checksum(False)\n\n        with d.unlocked():\n            d[42, 3] = 1\n        crc2 = d.checksum(False)\n        self.assertNotEqual(crc1, crc2)\n\n        with d.unlocked():\n            d[42, 3] = 0\n        crc3 = d.checksum(False)\n        self.assertEqual(crc1, crc3)\n\n        _ = d[42, \"name\"]\n        with d.unlocked():\n            d[42, \"name\"] = \"non-animal\"\n        crc4 = d.checksum(False)\n        self.assertEqual(crc1, crc4)\n        crc4 = d.checksum(True)\n        crc5 = d.checksum(1)\n        crc6 = d.checksum(False)\n        self.assertNotEqual(crc1, crc4)\n        self.assertNotEqual(crc1, crc5)\n        self.assertEqual(crc1, crc6)\n\n    def test_total_weight(self):\n        d = data.Table(\"zoo\")\n        self.assertEqual(d.total_weight(), len(d))\n\n        with d.unlocked():\n            d.set_weights(0)\n            d[0].weight = 0.1\n            d[10].weight = 0.2\n            d[-1].weight = 0.3\n        self.assertAlmostEqual(d.total_weight(), 0.6)\n\n    def test_has_missing(self):\n        d = data.Table(\"zoo\")\n        self.assertFalse(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n        with d.unlocked():\n            d[10, 3] = \"?\"\n        self.assertTrue(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n        with d.unlocked():\n            d[10].set_class(\"?\")\n        self.assertTrue(d.has_missing())\n        self.assertTrue(d.has_missing_class())\n\n        with d.unlocked():\n            d = data.Table(\"datasets/test3\")\n        self.assertFalse(d.has_missing())\n        self.assertFalse(d.has_missing_class())\n\n    def test_shuffle(self):\n        d = data.Table(\"zoo\")\n        crc = d.checksum()\n        names = set(str(x[\"name\"]) for x in d)\n\n        with d.unlocked():\n            d.shuffle()\n        self.assertNotEqual(crc, d.checksum())\n        self.assertSetEqual(names, set(str(x[\"name\"]) for x in d))\n        crc2 = d.checksum()\n\n        x = d[2:10]\n        crcx = x.checksum()\n        with d.unlocked():\n            d.shuffle()\n        self.assertNotEqual(crc2, d.checksum())\n        self.assertEqual(crcx, x.checksum())\n\n        crc2 = d.checksum()\n        with x.unlocked():\n            x.shuffle()\n        self.assertNotEqual(crcx, x.checksum())\n        self.assertEqual(crc2, d.checksum())\n\n    @staticmethod\n    def not_less_ex(ex1, ex2):\n        for v1, v2 in zip(ex1, ex2):\n            if v1 != v2:\n                return v1 < v2\n        return True\n\n    @staticmethod\n    def sorted(d):\n        for i in range(1, len(d)):\n            if not TableTestCase.not_less_ex(d[i - 1], d[i]):\n                return False\n        return True\n\n    @staticmethod\n    def not_less_ex_ord(ex1, ex2, ord):\n        for a in ord:\n            if ex1[a] != ex2[a]:\n                return ex1[a] < ex2[a]\n        return True\n\n    @staticmethod\n    def sorted_ord(d, ord):\n        for i in range(1, len(d)):\n            if not TableTestCase.not_less_ex_ord(d[i - 1], d[i], ord):\n                return False\n        return True\n\n    def test_copy(self):\n        t = data.Table.from_numpy(\n            None, np.zeros((5, 3)), np.arange(5), np.zeros((5, 3)))\n\n        copy = t.copy()\n        self.assertTrue(np.all(t.X == copy.X))\n        self.assertTrue(np.all(t.Y == copy.Y))\n        self.assertTrue(np.all(t.metas == copy.metas))\n        with copy.unlocked():\n            copy[0] = [1, 1, 1, 1]\n        self.assertFalse(np.all(t.X == copy.X))\n        self.assertFalse(np.all(t.Y == copy.Y))\n        self.assertFalse(np.all(t.metas == copy.metas))\n\n    def test_copy_sparse(self):\n        t = data.Table('iris').to_sparse()\n        copy = t.copy()\n\n        self.assertEqual((t.X != copy.X).nnz, 0)      # sparse matrices match by content\n        np.testing.assert_equal(t.Y, copy.Y)\n        np.testing.assert_equal(t.metas, copy.metas)\n\n        self.assertNotEqual(id(t.X), id(copy.X))\n        self.assertNotEqual(id(t._Y), id(copy._Y))\n        self.assertNotEqual(id(t.metas), id(copy.metas))\n\n        # ensure that copied sparse arrays do not share data\n        with t.unlocked():\n            t.X[0, 0] = 42\n        self.assertEqual(copy.X[0, 0], 5.1)\n\n    def test_concatenate(self):\n        d1 = data.Domain(\n            [data.ContinuousVariable(n) for n in \"abc\"],\n            data.DiscreteVariable(\"y\", values=\"ABC\"),\n            [data.StringVariable(n) for n in [\"m1\", \"m2\"]],\n        )\n        x1 = np.arange(6).reshape(2, 3)\n        y1 = np.array([0, 1])\n        m1 = np.array([[\"foo\", \"bar\"], [\"baz\", \"qux\"]])\n        w1 = np.random.random((2,))\n        t1 = data.Table.from_numpy(d1, x1, y1, m1, w1)\n        t1.ids = ids1 = np.array([100, 101])\n        t1.attributes = {\"a\": 42, \"c\": 43}\n\n        x2 = np.arange(6, 15).reshape(3, 3)\n        y2 = np.array([1, 2, 0])\n        m2 = np.array([[\"a\", \"b\"], [\"c\", \"d\"], [\"e\", \"f\"]])\n        w2 = np.random.random((3,))\n        t2 = data.Table.from_numpy(d1, x2, y2, m2, w2)\n        t2.ids = ids2 = np.array([102, 103, 104])\n        t2.name = \"t2\"\n        t2.attributes = {\"a\": 44, \"b\": 45}\n\n        x3 = np.arange(15, 27).reshape(4, 3)\n        y3 = np.array([2, 1, 1, 0])\n        m3 = np.array([[\"g\", \"h\"], [\"i\", \"j\"], [\"k\", \"l\"], [\"m\", \"n\"]])\n        w3 = np.random.random((4,))\n        t3 = data.Table.from_numpy(d1, x3, y3, m3, w3)\n        t3.ids = ids3 = np.array([102, 103, 104, 105])\n        t3.name = \"t3\"\n\n        t1b = data.Table.concatenate((t1,))\n        self.assertEqual(t1b.domain, t1.domain)\n        np.testing.assert_almost_equal(t1b.X, x1)\n        np.testing.assert_almost_equal(t1b.Y, y1)\n        self.assertEqual(list(t1b.metas.flatten()),\n                         list(m1.flatten()))\n        np.testing.assert_almost_equal(t1b.W, w1)\n        np.testing.assert_almost_equal(t1b.ids, ids1)\n        self.assertEqual(t1b.name, t1.name)\n        self.assertEqual(t1b.attributes, {\"a\": 42, \"c\": 43})\n\n        t12 = data.Table.concatenate((t1, t2))\n        self.assertEqual(t12.domain, t1.domain)\n        np.testing.assert_almost_equal(t12.X, np.vstack((x1, x2)))\n        np.testing.assert_almost_equal(t12.Y, np.hstack((y1, y2)))\n        self.assertEqual(list(t12.metas.flatten()),\n                         list(np.vstack((m1, m2)).flatten()))\n        np.testing.assert_almost_equal(t12.W, np.hstack((w1, w2)))\n        np.testing.assert_almost_equal(t12.ids, np.hstack((ids1, ids2)))\n        self.assertEqual(t12.name, \"t2\")\n        self.assertEqual(t12.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n        t123 = data.Table.concatenate((t1, t2, t3))\n        self.assertEqual(t123.domain, t1.domain)\n        np.testing.assert_almost_equal(t123.X, np.vstack((x1, x2, x3)))\n        np.testing.assert_almost_equal(t123.Y, np.hstack((y1, y2, y3)))\n        self.assertEqual(list(t123.metas.flatten()),\n                         list(np.vstack((m1, m2, m3)).flatten()))\n        np.testing.assert_almost_equal(t123.W, np.hstack((w1, w2, w3)))\n        np.testing.assert_almost_equal(t123.ids, np.hstack((ids1, ids2, ids3)))\n        self.assertEqual(t123.name, \"t2\")\n        self.assertEqual(t123.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n        with t2.unlocked(t2.Y):\n            t2.Y = np.atleast_2d(t2.Y).T\n        t12 = data.Table.concatenate((t1, t2))\n        self.assertEqual(t12.domain, t1.domain)\n        np.testing.assert_almost_equal(t12.X, np.vstack((x1, x2)))\n        np.testing.assert_almost_equal(t12.Y, np.hstack((y1, y2)))\n        self.assertEqual(list(t12.metas.flatten()),\n                         list(np.vstack((m1, m2)).flatten()))\n        np.testing.assert_almost_equal(t12.W, np.hstack((w1, w2)))\n        np.testing.assert_almost_equal(t12.ids, np.hstack((ids1, ids2)))\n        self.assertEqual(t12.name, \"t2\")\n        self.assertEqual(t12.attributes, {\"a\": 42, \"c\": 43, \"b\": 45})\n\n    def test_concatenate_exceptions(self):\n        zoo = data.Table(\"zoo\")\n        iris = data.Table(\"iris\")\n\n        self.assertRaises(ValueError, data.Table.concatenate, [])\n        self.assertRaises(ValueError, data.Table.concatenate, [zoo, iris])\n\n    def test_concatenate_sparse(self):\n        iris = Table(\"iris\")\n        with iris.unlocked():\n            iris.X = sp.csc_matrix(iris.X)\n        new = Table.concatenate([iris, iris])\n        self.assertEqual(len(new), 300)\n        self.assertTrue(sp.issparse(new.X), \"Concatenated X is not sparse.\")\n        self.assertFalse(sp.issparse(new.Y), \"Concatenated Y is not dense.\")\n        self.assertFalse(sp.issparse(new.metas), \"Concatenated metas is not dense.\")\n        self.assertEqual(len(new.ids), 300)\n\n    def test_pickle(self):\n        d = data.Table(\"zoo\")\n        s = pickle.dumps(d)\n        d2 = pickle.loads(s)\n        self.assertEqual(d[0], d2[0])\n\n        self.assertEqual(d.checksum(include_metas=False),\n                         d2.checksum(include_metas=False))\n\n        d = data.Table(\"iris\")\n        s = pickle.dumps(d)\n        d2 = pickle.loads(s)\n        self.assertEqual(d[0], d2[0])\n        self.assertEqual(d.checksum(include_metas=False),\n                         d2.checksum(include_metas=False))\n\n    def test_pickle_setstate(self):\n        d = data.Table(\"zoo\")\n        s = pickle.dumps(d)\n        with patch(\"Orange.data.Table.__setstate__\", Mock()) as mock:\n            pickle.loads(s)\n            state = mock.call_args[0][0]\n            for k in [\"X\", \"_Y\", \"metas\"]:\n                self.assertIn(k, state)\n                self.assertEqual(state[k].ndim, 2)\n            self.assertIn(\"W\", state)\n            for k in [\"_X\", \"Y\", \"_metas\", \"_W\"]:\n                self.assertNotIn(k, state)\n\n\n    def test_translate_through_slice(self):\n        d = data.Table(\"iris\")\n        dom = data.Domain([\"petal length\", \"sepal length\", \"iris\"],\n                          source=d.domain)\n        d_ref = d[:10, dom.variables]\n        self.assertEqual(d_ref.domain.class_var, d.domain.class_var)\n        self.assertEqual(d_ref[0, \"petal length\"], d[0, \"petal length\"])\n        self.assertEqual(d_ref[0, \"sepal length\"], d[0, \"sepal length\"])\n        self.assertEqual(d_ref.X.shape, (10, 2))\n        self.assertEqual(d_ref.Y.shape, (10,))\n\n    def test_saveTab(self):\n        d = data.Table(\"iris\")[:3]\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            for e1, e2 in zip(d, d2):\n                self.assertEqual(e1, e2)\n        finally:\n            os.remove(\"test-save.tab\")\n            os.remove(\"test-save.tab.metadata\")\n\n        dom = data.Domain([data.ContinuousVariable(\"a\")])\n        d = data.Table.from_list(dom, [[i] for i in range(3)])\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            self.assertEqual(len(d.domain.attributes), 1)\n            self.assertEqual(d.domain.class_var, None)\n            for i in range(3):\n                self.assertEqual(d2[i], [i])\n        finally:\n            os.remove(\"test-save.tab\")\n\n        dom = data.Domain([data.ContinuousVariable(\"a\")], None)\n        d = data.Table.from_list(dom, [[i] for i in range(3)])\n        d.save(\"test-save.tab\")\n        try:\n            d2 = data.Table(\"test-save.tab\")\n            self.assertEqual(len(d.domain.attributes), 1)\n            for i in range(3):\n                self.assertEqual(d2[i], [i])\n        finally:\n            os.remove(\"test-save.tab\")\n\n        d = data.Table(\"zoo\")\n        d.save(\"test-zoo.tab\")\n        dd = data.Table(\"test-zoo\")\n        try:\n            self.assertTupleEqual(d.domain.metas, dd.domain.metas,\n                                  msg=\"Meta attributes don't match.\")\n            self.assertTupleEqual(d.domain.variables, dd.domain.variables,\n                                  msg=\"Attributes don't match.\")\n\n            np.testing.assert_almost_equal(d.W, dd.W,\n                                           err_msg=\"Weights don't match.\")\n            for i in range(10):\n                for j in d.domain.variables:\n                    self.assertEqual(d[i][j], dd[i][j])\n        finally:\n            os.remove(\"test-zoo.tab\")\n            os.remove(\"test-zoo.tab.metadata\")\n\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d.set_weights(range(len(d)))\n        d.save(\"test-zoo-weights.tab\")\n        dd = data.Table(\"test-zoo-weights\")\n        try:\n            self.assertTupleEqual(d.domain.metas, dd.domain.metas,\n                                  msg=\"Meta attributes don't match.\")\n            self.assertTupleEqual(d.domain.variables, dd.domain.variables,\n                                  msg=\"Attributes don't match.\")\n\n            np.testing.assert_almost_equal(d.W, dd.W,\n                                           err_msg=\"Weights don't match.\")\n            for i in range(10):\n                for j in d.domain.variables:\n                    self.assertEqual(d[i][j], dd[i][j])\n        finally:\n            os.remove(\"test-zoo-weights.tab\")\n            os.remove(\"test-zoo-weights.tab.metadata\")\n\n    def test_save_pickle(self):\n        table = data.Table(\"iris\")\n        try:\n            table.save(\"iris.pickle\")\n            table2 = data.Table.from_file(\"iris.pickle\")\n            np.testing.assert_almost_equal(table.X, table2.X)\n            np.testing.assert_almost_equal(table.Y, table2.Y)\n            self.assertEqual(table.domain[0], table2.domain[0])\n        finally:\n            os.remove(\"iris.pickle\")\n\n    def test_from_numpy(self):\n        a = np.arange(20, dtype=\"d\").reshape((4, 5)).copy()\n        a[:, -1] = [0, 0, 0, 1]\n        dom = data.Domain([data.ContinuousVariable(x) for x in \"abcd\"],\n                          data.DiscreteVariable(\"e\", values=(\"no\", \"yes\")))\n        table = data.Table(dom, a)\n        with table.unlocked():\n            for i in range(4):\n                self.assertEqual(table[i].get_class(), \"no\" if i < 3 else \"yes\")\n                for j in range(5):\n                    self.assertEqual(a[i, j], table[i, j])\n\n        with table.unlocked(), self.assertRaises(IndexError):\n            table[0, -5] = 5\n\n    def test_filter_is_defined(self):\n        d = data.Table(\"iris\")\n        with d.unlocked():\n            d[1, 4] = Unknown\n        self.assertTrue(isnan(d[1, 4]))\n        with d.unlocked():\n            d[140, 0] = Unknown\n        e = filter.IsDefined()(d)\n        self.assertEqual(len(e), len(d) - 2)\n        self.assertEqual(e[0], d[0])\n        self.assertEqual(e[1], d[2])\n        self.assertEqual(e[147], d[149])\n        self.assertTrue(d.has_missing())\n        self.assertFalse(e.has_missing())\n\n    def test_filter_has_class(self):\n        d = data.Table(\"iris\")\n        with d.unlocked():\n            d[1, 4] = Unknown\n        self.assertTrue(isnan(d[1, 4]))\n        with d.unlocked():\n            d[140, 0] = Unknown\n        e = filter.HasClass()(d)\n        self.assertEqual(len(e), len(d) - 1)\n        self.assertEqual(e[0], d[0])\n        self.assertEqual(e[1], d[2])\n        self.assertEqual(e[148], d[149])\n        self.assertTrue(d.has_missing())\n        self.assertTrue(e.has_missing())\n        self.assertFalse(e.has_missing_class())\n\n    def test_filter_random(self):\n        d = data.Table(\"iris\")\n        e = filter.Random(50)(d)\n        self.assertEqual(len(e), 50)\n        e = filter.Random(50, negate=True)(d)\n        self.assertEqual(len(e), 100)\n        for _ in range(5):\n            e = filter.Random(0.2)(d)\n            self.assertEqual(len(e), 30)\n            bc = np.bincount(np.array(e.Y[:], dtype=int))\n            if min(bc) > 7:\n                break\n        else:\n            self.fail(\"Filter returns too uneven distributions\")\n\n    def test_filter_values_nested(self):\n        d = data.Table(\"iris\")\n        f1 = filter.FilterContinuous(d.columns.sepal_length,\n                                     filter.FilterContinuous.Between,\n                                     min=4.5, max=5.0)\n        f2 = filter.FilterContinuous(d.columns.sepal_width,\n                                     filter.FilterContinuous.Between,\n                                     min=3.1, max=3.4)\n        f3 = filter.FilterDiscrete(d.columns.iris, [0, 1])\n        f = filter.Values([filter.Values([f1, f2], conjunction=False), f3])\n        self.assertEqual(41, len(f(d)))\n\n    def test_filter_string_works_for_numeric_columns(self):\n        var = StringVariable(\"s\")\n        data = Table.from_list(Domain([], metas=[var]),\n                               [[x] for x in range(21)])\n        # 1, 2, 3, ..., 18, 19, 20\n\n        fs = filter.FilterString\n        filters = [\n            ((fs.Greater, \"5\"), dict(rows=4)),\n            # 6, 7, 8, 9\n            ((fs.Between, \"15\", \"2\"), dict(rows=6)),\n            # 15, 16, 17, 18, 19, 2\n            ((fs.Contains, \"2\"), dict(rows=3)),\n            # 2, 12, 20\n        ]\n\n        for args, expected in filters:\n            f = fs(var, *args)\n            filtered_data = filter.Values([f])(data)\n            self.assertEqual(len(filtered_data), expected[\"rows\"],\n                             \"{} returned wrong number of rows\".format(args))\n\n    def test_filter_value_continuous(self):\n        d = data.Table(\"iris\")\n        col = d.X[:, 2]\n\n        v = d.columns\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Between,\n                                    min=4.5, max=5.1)\n\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] >= 4.5))\n        self.assertTrue(np.all(x.X[:, 2] <= 5.1))\n        self.assertEqual(sum((col >= 4.5) * (col <= 5.1)), len(x))\n\n        f.ref = 5.1\n        f.oper = filter.FilterContinuous.Equal\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.NotEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] != 5.1))\n        self.assertEqual(sum(col != 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Less\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] < 5.1))\n        self.assertEqual(sum(col < 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.LessEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] <= 5.1))\n        self.assertEqual(sum(col <= 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Greater\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] > 5.1))\n        self.assertEqual(sum(col > 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] >= 5.1))\n        self.assertEqual(sum(col >= 5.1), len(x))\n\n        f.oper = filter.FilterContinuous.Outside\n        f.ref, f.max = 4.5, 5.1\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(e[2] < 4.5 or e[2] > 5.1)\n        self.assertEqual(sum((col < 4.5) + (col > 5.1)), len(x))\n\n        f.oper = filter.FilterContinuous.IsDefined\n        f.ref = f.max = None\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d))\n\n        with d.unlocked():\n            d[:30, v.petal_length] = Unknown\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 30)\n\n    def test_filter_value_continuous_args(self):\n        d = data.Table(\"iris\")\n        col = d.X[:, 2]\n        v = d.columns\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(2,\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"petal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"sepal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        f.column = 2\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(\"sepal length\",\n                                    filter.FilterContinuous.Equal, ref=5.1)\n        f.column = v.petal_length\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=18)\n        f.ref = 5.1\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n        f = filter.FilterContinuous(v.petal_length,\n                                    filter.FilterContinuous.Equal, ref=18)\n        f.ref = 5.1\n        x = filter.Values([f])(d)\n        self.assertTrue(np.all(x.X[:, 2] == 5.1))\n        self.assertEqual(sum(col == 5.1), len(x))\n\n    def test_valueFilter_discrete(self):\n        d = data.Table(\"zoo\")\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, 3, 4])\n        for e in filter.Values([f])(d):\n            self.assertTrue(e.get_class() in [2, 3, 4])\n\n        f.values = [\"mammal\"]\n        for e in filter.Values([f])(d):\n            self.assertEqual(e.get_class(), \"mammal\")\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, \"mammal\"])\n        for e in filter.Values([f])(d):\n            self.assertTrue(e.get_class() in [2, \"mammal\"])\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=[2, \"martian\"])\n        self.assertRaises(ValueError, d._filter_values, f)\n\n        f = filter.FilterDiscrete(d.domain.class_var, values=(2, data.Table))\n        self.assertRaises(TypeError, d._filter_values, f)\n\n        v = d.columns\n        f = filter.FilterDiscrete(v.hair, values=None)\n        self.assertEqual(len(filter.Values([f])(d)), len(d))\n\n        with d.unlocked():\n            d[:5, v.hair] = Unknown\n        self.assertEqual(len(filter.Values([f])(d)), len(d) - 5)\n\n    def test_valueFilter_string_is_defined(self):\n        d = data.Table(\"datasets/test9.tab\")\n        f = filter.FilterString(-5, filter.FilterString.IsDefined)\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 7)\n\n    def test_valueFilter_discrete_meta_is_defined(self):\n        d = data.Table(\"datasets/test9.tab\")\n        f = filter.FilterDiscrete(-4, None)\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 8)\n\n    def test_valueFilter_string_case_sens(self):\n        d = data.Table(\"zoo\")\n        col = d[:, \"name\"].metas[:, 0]\n\n        f = filter.FilterString(\"name\",\n                                filter.FilterString.Equal, \"girl\")\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 1)\n        self.assertEqual(x[0, \"name\"], \"girl\")\n        self.assertTrue(np.all(x.metas == \"girl\"))\n\n        f.oper = f.NotEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 1)\n        self.assertTrue(np.all(x[:, \"name\"] != \"girl\"))\n\n        f.oper = f.Less\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"girl\"))\n        self.assertTrue(np.all(x.metas < \"girl\"))\n\n        f.oper = f.LessEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col <= \"girl\"))\n        self.assertTrue(np.all(x.metas <= \"girl\"))\n\n        f.oper = f.Greater\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col > \"girl\"))\n        self.assertTrue(np.all(x.metas > \"girl\"))\n\n        f.oper = f.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col >= \"girl\"))\n        self.assertTrue(np.all(x.metas >= \"girl\"))\n\n        f.oper = f.Between\n        f.max = \"lion\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum((col >= \"girl\") * (col <= \"lion\")))\n        self.assertTrue(np.all(x.metas >= \"girl\"))\n        self.assertTrue(np.all(x.metas <= \"lion\"))\n\n        f.oper = f.Outside\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"girl\") + sum(col > \"lion\"))\n        self.assertTrue(np.all((x.metas < \"girl\") + (x.metas > \"lion\")))\n\n        f.oper = f.Contains\n        f.ref = \"ea\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(\"ea\" in e[\"name\"])\n        self.assertEqual(len(x), len([e for e in col if \"ea\" in e]))\n\n        f.oper = f.StartsWith\n        f.ref = \"sea\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).startswith(\"sea\"))\n        self.assertEqual(len(x), len([e for e in col if e.startswith(\"sea\")]))\n\n        f.oper = f.EndsWith\n        f.ref = \"ion\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n        self.assertEqual(len(x), len([e for e in col if e.endswith(\"ion\")]))\n\n    def test_valueFilter_string_case_insens(self):\n        d = data.Table(\"zoo\")\n        with d.unlocked():\n            d[d[:, \"name\"].metas[:, 0] == \"girl\", \"name\"] = \"GIrl\"\n\n        col = d[:, \"name\"].metas[:, 0]\n\n        f = filter.FilterString(\"name\",\n                                filter.FilterString.Equal, \"giRL\")\n        f.case_sensitive = False\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 1)\n        self.assertEqual(x[0, \"name\"], \"GIrl\")\n        self.assertTrue(np.all(x.metas == \"GIrl\"))\n\n        f.oper = f.NotEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), len(d) - 1)\n        self.assertTrue(np.all(x[:, \"name\"] != \"GIrl\"))\n\n        f.oper = f.Less\n        f.ref = \"CHiCKEN\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"chicken\") - 1)  # girl!\n        self.assertTrue(np.all(x.metas < \"chicken\"))\n\n        f.oper = f.LessEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col <= \"chicken\") - 1)\n        self.assertTrue(np.all(x.metas <= \"chicken\"))\n\n        f.oper = f.Greater\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col > \"chicken\") + 1)\n        for e in x:\n            self.assertGreater(str(e[\"name\"]).lower(), \"chicken\")\n\n        f.oper = f.GreaterEqual\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col >= \"chicken\") + 1)\n        for e in x:\n            self.assertGreaterEqual(str(e[\"name\"]).lower(), \"chicken\")\n\n        f.oper = f.Between\n        f.max = \"liOn\"\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum((col >= \"chicken\") * (col <= \"lion\")) + 1)\n        for e in x:\n            self.assertTrue(\"chicken\" <= str(e[\"name\"]).lower() <= \"lion\")\n\n        f.oper = f.Outside\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), sum(col < \"chicken\") + sum(col > \"lion\") - 1)\n        self.assertTrue(np.all((x.metas < \"chicken\") + (x.metas > \"lion\")))\n\n        f.oper = f.Contains\n        f.ref = \"iR\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(\"ir\" in str(e[\"name\"]).lower())\n        self.assertEqual(len(x), len([e for e in col if \"ir\" in e]) + 1)\n\n        f.oper = f.StartsWith\n        f.ref = \"GI\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).lower().startswith(\"gi\"))\n        self.assertEqual(len(x),\n                         len([e for e in col if e.lower().startswith(\"gi\")]))\n\n        f.oper = f.EndsWith\n        f.ref = \"ion\"\n        x = filter.Values([f])(d)\n        for e in x:\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n            self.assertTrue(str(e[\"name\"]).endswith(\"ion\"))\n        self.assertEqual(len(x), len([e for e in col if e.endswith(\"ion\")]))\n\n    def test_valueFilter_regex(self):\n        d = data.Table(\"zoo\")\n        f = filter.FilterRegex(d.domain['name'], '^c...$')\n        x = filter.Values([f])(d)\n        self.assertEqual(len(x), 7)\n\n    def test_valueFilter_stringList(self):\n        data = Table(\"zoo\")\n        var = data.domain[\"name\"]\n\n        fs = filter.FilterStringList\n        filters = [\n            (([\"swan\", \"tuna\", \"wasp\"], True), dict(rows=3)),\n            (([\"swan\", \"tuna\", \"wasp\"], False), dict(rows=3)),\n            (([\"WoRm\", \"TOad\", \"vOLe\"], True), dict(rows=0)),\n            (([\"WoRm\", \"TOad\", \"vOLe\"], False), dict(rows=3)),\n        ]\n\n        for args, expected in filters:\n            f = fs(var, *args)\n            filtered_data = filter.Values([f])(data)\n            self.assertEqual(len(filtered_data), expected[\"rows\"],\n                             \"{} returned wrong number of rows\".format(args))\n\n    def test_table_dtypes(self):\n        table = data.Table(\"iris\")\n        metas = np.hstack((table.metas, table.Y.reshape(len(table), 1)))\n        attributes_metas = table.domain.metas + table.domain.class_vars\n        domain_metas = data.Domain(table.domain.attributes[:2],\n                                   table.domain.attributes[2:],\n                                   attributes_metas)\n        table_metas = data.Table(domain_metas, table.X[:, : 2], table.X[:, 2:],\n                                 metas)\n        new_table = data.Table.from_table(data.Domain(table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.X.dtype, np.float64)\n        new_table = data.Table.from_table(data.Domain((), table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.Y.dtype, np.float64)\n        new_table = data.Table.from_table(data.Domain((), (), table_metas.domain.metas),\n                                          table_metas)\n        self.assertEqual(new_table.metas.dtype, np.float64)\n\n    def test_attributes(self):\n        table = data.Table(\"iris\")\n        table.attributes = {1: \"test\"}\n        table2 = table[:4]\n        self.assertEqual(table2.attributes[1], \"test\")\n        table2.attributes[1] = \"modified\"\n        self.assertEqual(table.attributes[1], \"modified\")\n\n    # TODO Test conjunctions and disjunctions of conditions\n\n    def test_is_sparse(self):\n        table = data.Table(\"iris\")\n        self.assertFalse(table.is_sparse())\n\n        with table.unlocked():\n            table.X = sp.csr_matrix(table.X)\n            self.assertTrue(table.is_sparse())\n\n    def test_repr_sparse_with_one_row(self):\n        table = data.Table(\"iris\")[:1]\n        with table.unlocked():\n            table.X = sp.csr_matrix(table.X)\n        repr(table)     # make sure repr does not crash\n\n    def test_inf(self):\n        a = np.array([[2, 0, 0, 0],\n                      [0, np.nan, np.nan, 1],\n                      [0, 0, np.inf, 0]])\n        with self.assertWarns(Warning):\n            tab = data.Table.from_numpy(None, a)\n        self.assertEqual(tab.get_nan_frequency_attribute(), 3/12)\n\n\ndef column_sizes(table):\n    return (len(table.domain.attributes),\n            len(table.domain.class_vars),\n            len(table.domain.metas))\n\n\nclass TableTests(unittest.TestCase):\n    attributes = [\"Feature %i\" % i for i in range(10)]\n    class_vars = [\"Class %i\" % i for i in range(1)]\n    metas = [\"Meta %i\" % i for i in range(5)]\n    nrows = 10\n    row_indices = (1, 5, 7, 9)\n\n    def setUp(self):\n        self.data = np.random.random((self.nrows, len(self.attributes)))\n        self.class_data = np.random.random((self.nrows, len(self.class_vars)))\n        if len(self.class_vars) == 1:\n            self.class_data = self.class_data.flatten()\n        self.meta_data = np.random.randint(0, 5, (self.nrows, len(self.metas))\n                                          ).astype(object)\n        self.weight_data = np.random.random((self.nrows, 1))\n\n    def mock_domain(self, with_classes=False, with_metas=False):\n        attributes = self.attributes\n        class_var = self.class_vars[0] if with_classes else None\n        class_vars = self.class_vars if with_classes else []\n        metas = self.metas if with_metas else []\n        variables = attributes + class_vars\n        return MagicMock(data.Domain,\n                         attributes=attributes,\n                         class_var=class_var,\n                         class_vars=class_vars,\n                         metas=metas,\n                         variables=variables)\n\n    def create_domain(self, attributes=(), classes=(), metas=()):\n        attr_vars = [data.ContinuousVariable(name=a) if isinstance(a, str)\n                     else a for a in attributes]\n        class_vars = [data.ContinuousVariable(name=c) if isinstance(c, str)\n                      else c for c in classes]\n        meta_vars = [data.DiscreteVariable(name=m, values=map(str, range(5)))\n                     if isinstance(m, str) else m for m in metas]\n\n        domain = data.Domain(attr_vars, class_vars, meta_vars)\n        return domain\n\n\nclass CreateEmptyTable(TableTests):\n    def test_calling_new_with_no_parameters_constructs_a_new_instance(self):\n        table = data.Table()\n        self.assertIsInstance(table, data.Table)\n\n    def test_table_has_file(self):\n        table = data.Table()\n        self.assertIsNone(table.__file__)\n\n\nclass CreateTableWithFilename(TableTests):\n    filename = \"data.tab\"\n\n    @patch(\"os.path.exists\", Mock(return_value=True))\n    def test_read_data_calls_reader(self):\n        table_mock = Mock(data.Table)\n        reader_instance = Mock(read=Mock(return_value=table_mock))\n        reader_mock = Mock(return_value=reader_instance)\n\n        with patch.dict(data.io.FileFormat.readers,\n                        {'.xlsx': reader_mock}):\n            table = data.Table.from_file(\"test.xlsx\")\n\n        reader_mock.assert_called_with(\"test.xlsx\")\n        reader_instance.read.assert_called_with()\n        self.assertEqual(table, table_mock)\n\n    @patch(\"os.path.exists\", Mock(return_value=False))\n    def test_raises_error_if_file_does_not_exist(self):\n        with self.assertRaises(IOError):\n            data.Table.from_file(self.filename)\n\n    @patch(\"os.path.exists\", Mock(return_value=True))\n    def test_raises_error_if_file_has_unknown_extension(self):\n        with self.assertRaises(IOError):\n            data.Table.from_file(\"file.invalid_extension\")\n\n    @patch(\"Orange.data.table.Table.from_file\")\n    def test_calling_new_with_string_argument_calls_read_data(self, read_data):\n        data.Table(self.filename)\n\n        read_data.assert_called_with(self.filename)\n\n    @patch(\"Orange.data.table.Table.from_file\")\n    def test_calling_new_with_keyword_argument_filename_calls_read_data(\n            self, read_data):\n        data.Table(self.filename)\n        read_data.assert_called_with(self.filename)\n\n\nclass CreateTableWithUrl(TableTests):\n    def test_url_no_scheme(self):\n\n        class SkipRest(Exception):\n            pass\n\n        mock_urlopen = Mock(side_effect=SkipRest())\n        url = 'www.foo.bar/xx.csv'\n\n        with patch('Orange.data.io.UrlReader.urlopen', mock_urlopen):\n            try:\n                Table.from_url(url)\n            except SkipRest:\n                pass\n\n        mock_urlopen.assert_called_once_with('http://' + url)\n\n    class _MockUrlOpen(MagicMock):\n        headers = {'content-disposition': 'attachment; filename=\"Something-FormResponses.tsv\"; '\n                                          'filename*=UTF-8''Something%20%28Responses%29.tsv'}\n        def __enter__(self):\n            return self\n\n        def __exit__(self, *args, **kwargs):\n            pass\n\n        def read(self):\n            return b'''\\\na\\tb\\tc\n1\\t2\\t3\n2\\t3\\t4'''\n\n    urlopen = _MockUrlOpen()\n\n    @patch('Orange.data.io.urlopen', urlopen)\n    def test_trimmed_urls(self):\n        for url in ('https://docs.google.com/spreadsheets/d/ABCD/edit',\n                    'https://www.dropbox.com/s/ABCD/filename.csv'):\n            self._MockUrlOpen.url = url\n            d = data.Table(url)\n            request = self.urlopen.call_args[0][0]\n            self.assertNotEqual(url, request.full_url)\n            self.assertIn('Mozilla/5.0', request.headers.get('User-agent', ''))\n            self.assertEqual(len(d), 2)\n            self.assertEqual(d.name, 'Something-FormResponses')\n\n\nclass CreateTableWithDomain(TableTests):\n    def test_creates_an_empty_table_with_given_domain(self):\n        domain = self.mock_domain()\n        table = data.Table.from_domain(domain)\n\n        self.assertEqual(table.domain, domain)\n\n    def test_creates_zero_filled_rows_in_X_if_domain_contains_attributes(self):\n        domain = self.mock_domain()\n        table = data.Table.from_domain(domain, self.nrows)\n\n        self.assertEqual(table.X.shape, (self.nrows, len(domain.attributes)))\n        self.assertFalse(table.X.any())\n\n    def test_creates_zero_filled_rows_in_Y_if_domain_contains_class_vars(self):\n        domain = self.mock_domain(with_classes=True)\n        table = data.Table.from_domain(domain, self.nrows)\n\n        if len(domain.class_vars) != 1:\n            self.assertEqual(table.Y.shape,\n                             (self.nrows, len(domain.class_vars)))\n        else:\n            self.assertEqual(table.Y.shape, (self.nrows,))\n        self.assertFalse(table.Y.any())\n\n    def test_creates_zero_filled_rows_in_metas_if_domain_contains_metas(self):\n        domain = self.mock_domain(with_metas=True)\n        table = data.Table.from_domain(domain, self.nrows)\n\n        self.assertEqual(table.metas.shape, (self.nrows, len(domain.metas)))\n        self.assertFalse(table.metas.any())\n\n    def test_creates_weights_if_weights_are_true(self):\n        domain = self.mock_domain()\n        table = data.Table.from_domain(domain, self.nrows, True)\n\n        self.assertEqual(table.W.shape, (self.nrows, ))\n\n    def test_does_not_create_weights_if_weights_are_false(self):\n        domain = self.mock_domain()\n        table = data.Table.from_domain(domain, self.nrows, False)\n\n        self.assertEqual(table.W.shape, (self.nrows, 0))\n\n    @patch(\"Orange.data.table.Table.from_domain\")\n    def test_calling_new_with_domain_calls_new_from_domain(\n            self, new_from_domain):\n        domain = self.mock_domain()\n        data.Table.from_domain(domain)\n\n        new_from_domain.assert_called_with(domain)\n\n\nclass CreateTableWithData(TableTests):\n    def test_creates_a_table_with_given_X(self):\n        # from numpy\n        table = data.Table.from_numpy(None, np.array(self.data))\n        self.assertIsInstance(table.domain, data.Domain)\n        np.testing.assert_almost_equal(table.X, self.data)\n\n        # from list\n        table = data.Table.from_numpy(None, list(self.data))\n        self.assertIsInstance(table.domain, data.Domain)\n        np.testing.assert_almost_equal(table.X, self.data)\n\n        # from tuple\n        table = data.Table.from_numpy(None, tuple(self.data))\n        self.assertIsInstance(table.domain, data.Domain)\n        np.testing.assert_almost_equal(table.X, self.data)\n\n    def test_creates_a_table_from_domain_and_list(self):\n        domain = data.Domain([data.DiscreteVariable(name=\"a\", values=\"mf\"),\n                              data.ContinuousVariable(name=\"b\")],\n                             data.DiscreteVariable(name=\"y\", values=\"abc\"))\n        table = data.Table.from_list(domain, [[0, 1, 2],\n                                              [1, 2, \"?\"],\n                                              [\"m\", 3, \"a\"],\n                                              [\"?\", \"?\", \"c\"]])\n        self.assertIs(table.domain, domain)\n        np.testing.assert_almost_equal(\n            table.X, np.array([[0, 1], [1, 2], [0, 3], [np.nan, np.nan]]))\n        np.testing.assert_almost_equal(table.Y, np.array([2, np.nan, 0, 2]))\n\n    def test_creates_a_table_from_domain_and_list_and_weights(self):\n        domain = data.Domain([data.DiscreteVariable(name=\"a\", values=\"mf\"),\n                              data.ContinuousVariable(name=\"b\")],\n                             data.DiscreteVariable(name=\"y\", values=\"abc\"))\n        table = data.Table.from_list(domain, [[0, 1, 2],\n                                              [1, 2, \"?\"],\n                                              [\"m\", 3, \"a\"],\n                                              [\"?\", \"?\", \"c\"]], [1, 2, 3, 4])\n        self.assertIs(table.domain, domain)\n        np.testing.assert_almost_equal(\n            table.X, np.array([[0, 1], [1, 2], [0, 3], [np.nan, np.nan]]))\n        np.testing.assert_almost_equal(table.Y, np.array([2, np.nan, 0, 2]))\n        np.testing.assert_almost_equal(table.W, np.array([1, 2, 3, 4]))\n\n    def test_creates_a_table_from_domain_and_list_and_metas(self):\n        metas = [data.DiscreteVariable(\"Meta 1\", values=\"XYZ\"),\n                 data.ContinuousVariable(\"Meta 2\"),\n                 data.StringVariable(\"Meta 3\")]\n        domain = data.Domain([data.DiscreteVariable(name=\"a\", values=\"mf\"),\n                              data.ContinuousVariable(name=\"b\")],\n                             data.DiscreteVariable(name=\"y\", values=\"abc\"),\n                             metas=metas)\n        table = data.Table.from_list(domain, [[0, 1, 2, \"X\", 2, \"bb\"],\n                                              [1, 2, \"?\", \"Y\", 1, \"aa\"],\n                                              [\"m\", 3, \"a\", \"Z\", 3, \"bb\"],\n                                              [\"?\", \"?\", \"c\", \"X\", 1, \"aa\"]])\n        self.assertIs(table.domain, domain)\n        np.testing.assert_almost_equal(\n            table.X, np.array([[0, 1], [1, 2], [0, 3], [np.nan, np.nan]]))\n        np.testing.assert_almost_equal(table.Y, np.array([2, np.nan, 0, 2]))\n        np.testing.assert_array_equal(table.metas,\n                                      np.array([[0, 2., \"bb\"],\n                                                [1, 1., \"aa\"],\n                                                [2, 3., \"bb\"],\n                                                [0, 1., \"aa\"]],\n                                               dtype=object))\n\n    def test_creates_a_table_from_list_of_instances(self):\n        table = data.Table('iris')\n        new_table = data.Table.from_list(table.domain, [d for d in table])\n        self.assertIs(table.domain, new_table.domain)\n        np.testing.assert_almost_equal(table.X, new_table.X)\n        np.testing.assert_almost_equal(table.Y, new_table.Y)\n        np.testing.assert_almost_equal(table.W, new_table.W)\n        self.assertEqual(table.domain, new_table.domain)\n        np.testing.assert_array_equal(table.metas, new_table.metas)\n\n    def test_creates_a_table_from_list_of_instances_with_metas(self):\n        table = data.Table('zoo')\n        new_table = data.Table.from_list(table.domain, [d for d in table])\n        self.assertIs(table.domain, new_table.domain)\n        np.testing.assert_almost_equal(table.X, new_table.X)\n        np.testing.assert_almost_equal(table.Y, new_table.Y)\n        np.testing.assert_almost_equal(table.W, new_table.W)\n        self.assertEqual(table.domain, new_table.domain)\n        np.testing.assert_array_equal(table.metas, new_table.metas)\n\n    def test_creates_a_table_with_domain_and_given_X(self):\n        domain = self.mock_domain()\n\n        table = data.Table(domain, self.data)\n        self.assertIsInstance(table.domain, data.Domain)\n        self.assertEqual(table.domain, domain)\n        np.testing.assert_almost_equal(table.X, self.data)\n\n    def test_creates_a_table_with_given_X_and_Y(self):\n        table = data.Table.from_numpy(None, self.data, self.class_data)\n\n        self.assertIsInstance(table.domain, data.Domain)\n        np.testing.assert_almost_equal(table.X, self.data)\n        np.testing.assert_almost_equal(table.Y, self.class_data)\n\n    def test_creates_a_table_with_given_X_Y_and_metas(self):\n        table = data.Table.from_numpy(\n            None, self.data, self.class_data, self.meta_data)\n\n        self.assertIsInstance(table.domain, data.Domain)\n        np.testing.assert_almost_equal(table.X, self.data)\n        np.testing.assert_almost_equal(table.Y, self.class_data)\n        np.testing.assert_almost_equal(table.metas, self.meta_data)\n\n    def test_creates_a_discrete_class_if_Y_has_few_distinct_values(self):\n        Y = np.array([float(np.random.randint(0, 2)) for i in self.data])\n        table = data.Table.from_numpy(None, self.data, Y, self.meta_data)\n\n        np.testing.assert_almost_equal(table.Y, Y)\n        self.assertIsInstance(table.domain.class_vars[0],\n                              data.DiscreteVariable)\n        self.assertEqual(table.domain.class_vars[0].values, (\"v1\", \"v2\"))\n\n    def test_creates_a_table_with_given_domain(self):\n        domain = self.mock_domain()\n        table = data.Table.from_numpy(domain, self.data)\n\n        self.assertEqual(table.domain, domain)\n\n    def test_sets_Y_if_given(self):\n        domain = self.mock_domain(with_classes=True)\n        table = data.Table.from_numpy(domain, self.data, self.class_data)\n\n        np.testing.assert_almost_equal(table.Y, self.class_data)\n\n    def test_sets_metas_if_given(self):\n        domain = self.mock_domain(with_metas=True)\n        table = data.Table.from_numpy(domain, self.data, metas=self.meta_data)\n\n        np.testing.assert_almost_equal(table.metas, self.meta_data)\n\n    def test_sets_weights_if_given(self):\n        domain = self.mock_domain()\n        table = data.Table.from_numpy(domain, self.data, W=self.weight_data)\n\n        np.testing.assert_equal(table.W.shape, (len(self.data), ))\n        np.testing.assert_almost_equal(table.W.flatten(),\n                                       self.weight_data.flatten())\n\n    def test_splits_X_and_Y_if_given_in_same_array(self):\n        joined_data = np.column_stack((self.data, self.class_data))\n        domain = self.mock_domain(with_classes=True)\n        table = data.Table.from_numpy(domain, joined_data)\n\n        np.testing.assert_almost_equal(table.X, self.data)\n        np.testing.assert_almost_equal(table.Y, self.class_data)\n\n    def test_initializes_Y_metas_and_W_if_not_given(self):\n        domain = self.mock_domain()\n        table = data.Table.from_numpy(domain, self.data)\n\n        self.assertEqual(table.Y.shape, (self.nrows, len(domain.class_vars)))\n        self.assertEqual(table.metas.shape, (self.nrows, len(domain.metas)))\n        self.assertEqual(table.W.shape, (self.nrows, 0))\n\n    def test_raises_error_if_columns_in_domain_and_data_do_not_match(self):\n        domain = self.mock_domain(with_classes=True, with_metas=True)\n        ones = np.zeros((self.nrows, 1))\n\n        with self.assertRaises(ValueError):\n            data_ = np.hstack((self.data, ones))\n            data.Table.from_numpy(domain, data_, self.class_data,\n                                  self.meta_data)\n\n        with self.assertRaises(ValueError):\n            classes_ = np.hstack((self.class_data, ones))\n            data.Table.from_numpy(domain, self.data, classes_,\n                                  self.meta_data)\n\n        with self.assertRaises(ValueError):\n            metas_ = np.hstack((self.meta_data, ones))\n            data.Table.from_numpy(domain, self.data, self.class_data,\n                                  metas_)\n\n    def test_raises_error_if_lengths_of_data_do_not_match(self):\n        domain = self.mock_domain(with_classes=True, with_metas=True)\n\n        with self.assertRaises(ValueError):\n            data_ = np.vstack((self.data, np.zeros((1, len(self.attributes)))))\n            data.Table(domain, data_, self.class_data, self.meta_data)\n\n        with self.assertRaises(ValueError):\n            class_data_ = np.vstack((self.class_data,\n                                     np.zeros((1, len(self.class_vars)))))\n            data.Table(domain, self.data, class_data_, self.meta_data)\n\n        with self.assertRaises(ValueError):\n            meta_data_ = np.vstack((self.meta_data,\n                                    np.zeros((1, len(self.metas)))))\n            data.Table(domain, self.data, self.class_data, meta_data_)\n\n    @patch(\"Orange.data.table.Table.from_numpy\")\n    def test_calling_new_with_domain_and_numpy_arrays_calls_new_from_numpy(\n            self, new_from_numpy):\n        domain = self.mock_domain()\n        data.Table(domain, self.data)\n        new_from_numpy.assert_called_with(domain, self.data)\n\n        domain = self.mock_domain(with_classes=True)\n        data.Table(domain, self.data, self.class_data)\n        new_from_numpy.assert_called_with(domain, self.data, self.class_data)\n\n        domain = self.mock_domain(with_classes=True, with_metas=True)\n        data.Table(domain, self.data, self.class_data, self.meta_data)\n        new_from_numpy.assert_called_with(\n            domain, self.data, self.class_data, self.meta_data)\n\n        data.Table(domain, self.data, self.class_data,\n                   self.meta_data, self.weight_data)\n        new_from_numpy.assert_called_with(domain, self.data, self.class_data,\n                                          self.meta_data, self.weight_data)\n\n    def test_from_numpy_reconstructable(self):\n        def assert_equal(t1, t2):\n            np.testing.assert_array_equal(t1.X, t2.X)\n            np.testing.assert_array_equal(t1.Y, t2.Y)\n            np.testing.assert_array_equal(t1.metas, t2.metas)\n            np.testing.assert_array_equal(t1.W, t2.W)\n\n        nullcol = np.empty((self.nrows, 0))\n        domain = self.create_domain(self.attributes)\n        table = data.Table(domain, self.data)\n\n        table_1 = data.Table.from_numpy(\n            domain, table.X, table.Y, table.metas, table.W)\n        assert_equal(table, table_1)\n\n        domain = self.create_domain(classes=self.class_vars)\n        table = data.Table(domain, nullcol, self.class_data)\n\n        table_1 = data.Table.from_numpy(\n            domain, table.X, table.Y, table.metas, table.W)\n        assert_equal(table, table_1)\n\n        domain = self.create_domain(metas=self.metas)\n        table = data.Table(domain, nullcol, nullcol, self.meta_data)\n\n        table_1 = data.Table.from_numpy(\n            domain, table.X, table.Y, table.metas, table.W)\n        assert_equal(table, table_1)\n\n\nclass CreateTableWithDomainAndTable(TableTests):\n    interesting_slices = [\n        slice(0, 0),  # [0:0] - empty slice\n        slice(1),  # [:1]  - only first element\n        slice(1, None),  # [1:]  - all but first\n        slice(-1, None),  # [-1:] - only last element\n        slice(-1),  # [:-1] - all but last\n        slice(None),  # [:]   - all elements\n        slice(None, None, 2),  # [::2] - even elements\n        slice(None, None, -1),  # [::-1]- all elements reversed\n        slice(9, 5, -10),  # slice a big negative stride and thus 1 element\n    ]\n\n    row_indices = [1, 5, 6, 7]\n\n    def setUp(self):\n        super().setUp()\n        self.domain = self.create_domain(\n            self.attributes, self.class_vars, self.metas)\n        self.table = data.Table(\n            self.domain, self.data, self.class_data, self.meta_data)\n\n    def test_creates_table_with_given_domain(self):\n        new_table = data.Table.from_table(self.table.domain, self.table)\n\n        self.assertIsInstance(new_table, data.Table)\n        self.assertIsNot(self.table, new_table)\n        self.assertEqual(new_table.domain, self.domain)\n\n    def test_transform(self):\n        class MyTableClass(data.Table):\n            pass\n\n        table = MyTableClass.from_table(self.table.domain, self.table)\n        domain = table.domain\n        attr = ContinuousVariable(\"x\")\n        new_domain = data.Domain(list(domain.attributes) + [attr], None)\n        new_table = table.transform(new_domain)\n\n        self.assertIsInstance(new_table, MyTableClass)\n        self.assertIsNot(table, new_table)\n        self.assertIs(new_table.domain, new_domain)\n\n    def test_transform_same_domain(self):\n        iris = data.Table(\"iris\")\n        new_domain = copy.copy(iris.domain)\n        new_data = iris.transform(new_domain)\n        self.assertIs(new_data.domain, new_domain)\n\n    def test_can_copy_table(self):\n        new_table = data.Table.from_table(self.domain, self.table)\n        self.assert_table_with_filter_matches(new_table, self.table)\n\n    def test_can_filter_rows_with_list(self):\n        for indices in ([0], [1, 5, 6, 7]):\n            new_table = data.Table.from_table(\n                self.domain, self.table, row_indices=indices)\n            self.assert_table_with_filter_matches(\n                new_table, self.table, rows=indices)\n\n    @patch.object(Table, \"from_table_rows\", wraps=Table.from_table_rows)\n    def test_can_filter_row_with_slice_from_table_rows(self, from_table_rows):\n        # calling from_table with the same domain will forward to from_table_rows\n        for slice_ in self.interesting_slices:\n            from_table_rows.reset_mock()\n            new_table = data.Table.from_table(\n                self.domain, self.table, row_indices=slice_)\n            self.assert_table_with_filter_matches(\n                new_table, self.table, rows=slice_)\n            from_table_rows.assert_called()\n\n    def test_can_filter_row_with_slice_from_table(self):\n        # calling from_table with a domain copy will use indexing in from_table\n        for slice_ in self.interesting_slices:\n            new_table = data.Table.from_table(\n                self.domain.copy(), self.table, row_indices=slice_)\n            self.assert_table_with_filter_matches(\n                new_table, self.table, rows=slice_)\n\n    def test_can_use_attributes_as_new_columns(self):\n        a, _, _ = column_sizes(self.table)\n        order = np.random.permutation(a)\n        new_attributes = [self.domain.attributes[i] for i in order]\n        new_domain = self.create_domain(\n            new_attributes[:2], new_attributes[2:4], new_attributes[4:])\n        new_table = data.Table.from_table(new_domain, self.table)\n\n        self.assert_table_with_filter_matches(\n            new_table, self.table, xcols=order[:2], ycols=order[2:4], mcols=order[4:])\n\n    def test_can_use_class_vars_as_new_columns(self):\n        a, _, _ = column_sizes(self.table)\n        order = np.random.permutation(range(a))\n        cvs = [self.domain.attributes[i] for i in order[:2]]\n        metas = [self.domain.attributes[i] for i in order[2:]]\n        new_domain = self.create_domain(self.domain.class_vars,\n                                        cvs,\n                                        metas)\n        new_table = data.Table.from_table(new_domain, self.table)\n\n        self.assert_table_with_filter_matches(\n            new_table, self.table, xcols=[a], ycols=order[:2], mcols=order[2:])\n\n    def test_can_use_metas_as_new_columns(self):\n        _, _, m = column_sizes(self.table)\n        order = np.random.permutation(range(-m, 0))\n        new_metas = [self.domain.metas[::-1][i] for i in order]\n        new_domain = self.create_domain(new_metas[0:2], [new_metas[2]], new_metas[3:5])\n        new_table = data.Table.from_table(new_domain, self.table)\n\n        self.assert_table_with_filter_matches(\n            new_table, self.table, xcols=order[0:2], ycols=order[2], mcols=order[3:5])\n\n    def test_can_use_combination_of_all_as_new_columns(self):\n        a, c, m = column_sizes(self.table)\n        order = (list(range(a+c)) + list(range(-m+1, 0)))\n        random. shuffle(order)\n        vars_ = list(self.domain.variables) + list(self.domain.metas[::-1])\n        atrs = [vars_[order[i]] for i in range(a)]\n        cv = [vars_[order[i]] for i in range(a, a+c)]\n        metas = [vars_[order[i]] for i in range(a+c, a+c+m-1)]\n\n        new_domain = self.create_domain(atrs, cv, metas)\n        new_table = data.Table.from_table(new_domain, self.table)\n        self.assert_table_with_filter_matches(\n            new_table, self.table, xcols=order[:a], ycols=order[a:a+c], mcols=order[a+c:])\n\n    def test_creates_table_with_given_domain_and_row_filter(self):\n        a, c, m = column_sizes(self.table)\n        order = (list(range(a+c)) + list(range(-m+1, 0)))\n        random.shuffle(order)\n        vars_ = list(self.domain.variables) + list(self.domain.metas[::-1])\n        atrs = [vars_[order[i]] for i in range(a)]\n        cv = [vars_[order[i]] for i in range(a, a+c)]\n        metas = [vars_[order[i]] for i in range(a+c, a+c+m-1)]\n\n        new_domain = self.create_domain(atrs, cv, metas)\n        new_table = data.Table.from_table(new_domain, self.table, [0])\n        self.assert_table_with_filter_matches(\n            new_table, self.table[:1], xcols=order[:a], ycols=order[a:a+c], mcols=order[a+c:])\n\n        new_table = data.Table.from_table(new_domain, self.table, [2, 1, 0])\n        self.assert_table_with_filter_matches(\n            new_table, self.table[2::-1], xcols=order[:a], ycols=order[a:a+c], mcols=order[a+c:])\n\n        new_table = data.Table.from_table(new_domain, self.table, [])\n        self.assert_table_with_filter_matches(\n            new_table, self.table[:0], xcols=order[:a], ycols=order[a:a+c], mcols=order[a+c:])\n\n    def test_from_table_sparse_move_some_to_empty_metas(self):\n        iris = data.Table(\"iris\").to_sparse()\n        new_domain = data.domain.Domain(\n            iris.domain.attributes[:2], iris.domain.class_vars,\n            iris.domain.attributes[2:], source=iris.domain)\n        new_iris = iris.transform(new_domain)\n\n        self.assertTrue(sp.issparse(new_iris.X))\n        self.assertTrue(sp.issparse(new_iris.metas))\n        self.assertEqual(new_iris.X.shape, (len(iris), 2))\n        self.assertEqual(new_iris.metas.shape, (len(iris), 2))\n\n        # move back\n        back_iris = new_iris.transform(iris.domain)\n        self.assertEqual(back_iris.domain, iris.domain)\n        self.assertTrue(sp.issparse(back_iris.X))\n        self.assertFalse(sp.issparse(back_iris.metas))\n        self.assertEqual(back_iris.X.shape, iris.X.shape)\n        self.assertEqual(back_iris.metas.shape, iris.metas.shape)\n\n    def test_from_table_sparse_move_all_to_empty_metas(self):\n        iris = data.Table(\"iris\").to_sparse()\n        new_domain = data.domain.Domain(\n            [], iris.domain.class_vars, iris.domain.attributes,\n            source=iris.domain)\n        new_iris = iris.transform(new_domain)\n\n        self.assertFalse(sp.issparse(new_iris.X))\n        self.assertTrue(sp.issparse(new_iris.metas))\n        self.assertEqual(new_iris.X.shape, (len(iris), 0))\n        self.assertEqual(new_iris.metas.shape, (len(iris), 4))\n\n        # move back\n        back_iris = new_iris.transform(iris.domain)\n        self.assertEqual(back_iris.domain, iris.domain)\n        self.assertTrue(sp.issparse(back_iris.X))\n        self.assertFalse(sp.issparse(back_iris.metas))\n        self.assertEqual(back_iris.X.shape, iris.X.shape)\n        self.assertEqual(back_iris.metas.shape, iris.metas.shape)\n\n    def test_from_table_sparse_move_to_nonempty_metas(self):\n        brown = data.Table(\"brown-selected\").to_sparse()\n        n_attr = len(brown.domain.attributes)\n        n_metas = len(brown.domain.metas)\n        new_domain = data.domain.Domain(\n            brown.domain.attributes[:-10],\n            brown.domain.class_vars,\n            brown.domain.attributes[-10:] + brown.domain.metas,\n            source=brown.domain)\n        new_brown = data.Table.from_table(new_domain, brown)\n\n        self.assertTrue(sp.issparse(new_brown.X))\n        self.assertFalse(sp.issparse(new_brown.metas))\n        self.assertEqual(new_brown.X.shape, (len(new_brown), n_attr-10))\n        self.assertEqual(new_brown.metas.shape, (len(new_brown), n_metas+10))\n\n        # move back\n        back_brown = data.Table.from_table(brown.domain, new_brown)\n        self.assertEqual(brown.domain, back_brown.domain)\n        self.assertTrue(sp.issparse(back_brown.X))\n        self.assertFalse(sp.issparse(back_brown.metas))\n        self.assertEqual(back_brown.X.shape, brown.X.shape)\n        self.assertEqual(back_brown.metas.shape, brown.metas.shape)\n\n    def test_from_table_shared_compute_value(self):\n        iris = data.Table(\"iris\").to_sparse()\n        d1 = Domain(\n            [\n                ContinuousVariable(\n                    name=at.name,\n                    compute_value=PreprocessSharedComputeValue(\n                        i, None, PreprocessShared(iris.domain, None)\n                    )\n                )\n                for i, at in enumerate(iris.domain.attributes)\n            ]\n        )\n\n        new_table = Table.from_table(d1, iris)\n        np.testing.assert_array_equal(new_table.X, iris.X.todense() * 2)\n\n        new_table = Table.from_table(d1, iris, row_indices=[0, 1, 2])\n        np.testing.assert_array_equal(new_table.X, iris.X.todense()[:3] * 2)\n\n    def assert_table_with_filter_matches(\n            self, new_table, old_table,\n            rows=..., xcols=..., ycols=..., mcols=...):\n        a, c, m = column_sizes(old_table)\n        xcols = slice(a) if xcols is Ellipsis else xcols\n        ycols = slice(a, a + c) if ycols is Ellipsis else ycols\n        mcols = slice(None, -m - 1, -1) if mcols is Ellipsis else mcols\n\n        # Indexing used by convert_domain uses positive indices for variables\n        # and classes (classes come after attributes) and negative indices for\n        # meta features. This is equivalent to ordinary indexing in a magic\n        # table below.\n        magic = np.hstack((old_table.X, old_table.Y[:, None],\n                           old_table.metas[:, ::-1]))\n        np.testing.assert_almost_equal(new_table.X, magic[rows, xcols])\n        Y = magic[rows, ycols]\n        if len(Y.shape) == 2 and Y.shape[1] == 1:\n            Y = Y.flatten()\n        np.testing.assert_almost_equal(new_table.Y, Y)\n        np.testing.assert_almost_equal(new_table.metas, magic[rows, mcols])\n        np.testing.assert_almost_equal(new_table.W, old_table.W[rows])\n\n\ndef isspecial(s):\n    return isinstance(s, slice) or s is Ellipsis\n\n\ndef split_columns(indices, t):\n    a, c, m = column_sizes(t)\n    if indices is ...:\n        return slice(a), slice(c), slice(m)\n    elif isinstance(indices, slice):\n        return indices, slice(0, 0), slice(0, 0)\n    elif not isinstance(indices, list) and not isinstance(indices, tuple):\n        indices = [indices]\n    return (\n        [t.domain.index(x)\n         for x in indices if 0 <= t.domain.index(x) < a] or slice(0, 0),\n        [t.domain.index(x) - a\n         for x in indices if t.domain.index(x) >= a] or slice(0, 0),\n        [-t.domain.index(x) - 1\n         for x in indices if t.domain.index(x) < 0] or slice(0, 0))\n\n\ndef getname(variable):\n    return variable.name\n\n\nclass TableIndexingTests(TableTests):\n    def setUp(self):\n        super().setUp()\n        d = self.domain = \\\n            self.create_domain(self.attributes, self.class_vars, self.metas)\n        t = self.table = \\\n            data.Table(self.domain, self.data, self.class_data, self.meta_data)\n        self.magic_table = \\\n            np.column_stack((self.table.X, self.table.Y,\n                             self.table.metas[:, ::-1]))\n\n        self.rows = [0, -1]\n        self.multiple_rows = [slice(0, 0), ..., slice(1, -1, -1)]\n        a, c, m = column_sizes(t)\n        columns = [0, a - 1, a, a + c - 1, -1, -m]\n        self.columns = chain(columns,\n                             map(lambda x: d[x], columns),\n                             map(lambda x: d[x].name, columns))\n        self.multiple_columns = chain(\n            self.multiple_rows,\n            [d.attributes, d.class_vars, d.metas, [0, a, -1]],\n            [self.attributes, self.class_vars, self.metas],\n            [self.attributes + self.class_vars + self.metas])\n\n        # TODO: indexing with [[0,1], [0,1]] produces weird results\n        # TODO: what should be the results of table[1, :]\n\n    def test_can_select_a_single_value(self):\n        for r in self.rows:\n            for c in self.columns:\n                value = self.table[r, c]\n                self.assertAlmostEqual(\n                    value, self.magic_table[r, self.domain.index(c)])\n\n                value = self.table[r][c]\n                self.assertAlmostEqual(\n                    value, self.magic_table[r, self.domain.index(c)])\n\n    def test_can_select_a_single_row(self):\n        for r in self.rows:\n            row = self.table[r]\n            new_row = np.hstack(\n                (self.data[r, :],\n                 self.class_data[r, None]))\n            np.testing.assert_almost_equal(\n                np.array(list(row)), new_row)\n\n\n    def test_can_select_a_subset_of_rows_and_columns(self):\n        for r in self.rows:\n            for c in self.multiple_columns:\n                table = self.table[r, c]\n\n                attr, cls, metas = split_columns(c, self.table)\n                X = self.table.X[[r], attr]\n                if X.ndim == 1:\n                    X = X.reshape(-1, len(table.domain.attributes))\n                np.testing.assert_almost_equal(table.X, X)\n                Y = self.table.Y[:, None][[r], cls]\n                if len(Y.shape) == 1 or Y.shape[1] == 1:\n                    Y = Y.flatten()\n                np.testing.assert_almost_equal(table.Y, Y)\n                metas_ = self.table.metas[[r], metas]\n                if metas_.ndim == 1:\n                    metas_ = metas_.reshape(-1, len(table.domain.metas))\n                np.testing.assert_almost_equal(table.metas, metas_)\n\n        for r in self.multiple_rows:\n            for c in chain(self.columns, self.multiple_rows):\n                table = self.table[r, c]\n\n                attr, cls, metas = split_columns(c, self.table)\n                np.testing.assert_almost_equal(table.X, self.table.X[r, attr])\n                Y = self.table.Y[:, None][r, cls]\n                if len(Y.shape) > 1 and Y.shape[1] == 1:\n                    Y = Y.flatten()\n                np.testing.assert_almost_equal(table.Y, Y)\n                np.testing.assert_almost_equal(table.metas,\n                                               self.table.metas[r, metas])\n\n\n    def test_optimize_indices(self):\n        # ordinary conversion\n        self.assertEqual(_optimize_indices([1, 2, 3], 4), slice(1, 4, 1))\n        self.assertEqual(_optimize_indices([], 1), [])\n        self.assertEqual(_optimize_indices([0, 2], 3), slice(0, 4, 2))\n\n        # not slices\n        np.testing.assert_equal(_optimize_indices([1, 2, 4], 5), [1, 2, 4])\n        np.testing.assert_equal(_optimize_indices((1, 2, 4), 5), [1, 2, 4])\n\n        # leave boolean arrays\n        np.testing.assert_equal(_optimize_indices([True, False, True], 3), [True, False, True])\n\n        # do not convert if step is negative\n        np.testing.assert_equal(_optimize_indices([4, 2, 0], 5), [4, 2, 0])\n\n        # try range\n        np.testing.assert_equal(_optimize_indices([3, 4, 5], 5), [3, 4, 5])  # out of range\n        self.assertEqual(_optimize_indices((3, 4, 5), 6), slice(3, 6, 1))\n\n        # negative elements\n        np.testing.assert_equal(_optimize_indices([-1, 0, 1], 5), [-1, 0, 1])\n\n        # single element\n        self.assertEqual(_optimize_indices([1], 2), slice(1, 2, 1))\n        self.assertEqual(_optimize_indices([-2], 5), slice(-2, -3, -1))\n\n\nclass TableElementAssignmentTest(TableTests):\n    def setUp(self):\n        super().setUp()\n        self.domain = \\\n            self.create_domain(self.attributes, self.class_vars, self.metas)\n        self.table = \\\n            data.Table(self.domain, self.data, self.class_data, self.meta_data)\n\n    def test_can_assign_values(self):\n        with self.table.unlocked():\n            self.table[0, 0] = 42.\n        self.assertAlmostEqual(self.table.X[0, 0], 42.)\n\n    def test_can_assign_values_to_classes(self):\n        a, _, _ = column_sizes(self.table)\n        with self.table.unlocked():\n            self.table[0, a] = 42.\n        self.assertAlmostEqual(self.table.Y[0], 42.)\n\n    def test_can_assign_values_to_metas(self):\n        with self.table.unlocked():\n            self.table[0, -1] = 42.\n        self.assertAlmostEqual(self.table.metas[0, 0], 42.)\n\n    def test_can_assign_rows_to_rows(self):\n        with self.table.unlocked():\n            self.table[0] = self.table[1]\n        np.testing.assert_almost_equal(\n            self.table.X[0], self.table.X[1])\n        np.testing.assert_almost_equal(\n            self.table.Y[0], self.table.Y[1])\n        np.testing.assert_almost_equal(\n            self.table.metas[0], self.table.metas[1])\n\n    def test_can_assign_lists(self):\n        a, _, _ = column_sizes(self.table)\n        new_example = [float(i)\n                       for i in range(len(self.attributes + self.class_vars))]\n        with self.table.unlocked():\n            self.table[0] = new_example\n        np.testing.assert_almost_equal(\n            self.table.X[0], np.array(new_example[:a]))\n        np.testing.assert_almost_equal(\n            self.table.Y[0], np.array(new_example[a:]))\n\n    def test_can_assign_np_array(self):\n        a, _, _ = column_sizes(self.table)\n        new_example = \\\n            np.array([float(i)\n                      for i in range(len(self.attributes + self.class_vars))])\n        with self.table.unlocked():\n            self.table[0] = new_example\n        np.testing.assert_almost_equal(self.table.X[0], new_example[:a])\n        np.testing.assert_almost_equal(self.table.Y[0], new_example[a:])\n\n\nclass InterfaceTest(unittest.TestCase):\n    \"\"\"Basic tests each implementation of Table should pass.\"\"\"\n\n    features = (\n        data.ContinuousVariable(name=\"Continuous Feature 1\"),\n        data.ContinuousVariable(name=\"Continuous Feature 2\"),\n        data.DiscreteVariable(name=\"Discrete Feature 1\", values=(\"0\", \"1\")),\n        data.DiscreteVariable(name=\"Discrete Feature 2\",\n                              values=(\"value1\", \"value2\")),\n    )\n\n    class_vars = (\n        data.ContinuousVariable(name=\"Continuous Class\"),\n        data.DiscreteVariable(name=\"Discrete Class\", values=(\"m\", \"f\"))\n    )\n\n    feature_data = (\n        (1, 0, 0, 0),\n        (0, 1, 0, 0),\n        (0, 0, 1, 0),\n        (0, 0, 0, 1),\n    )\n\n    class_data = (\n        (1, 0),\n        (0, 1),\n        (1, 0),\n        (0, 1)\n    )\n\n    data = tuple(a + c for a, c in zip(feature_data, class_data))\n\n    nrows = 4\n\n    def setUp(self):\n        self.domain = data.Domain(attributes=self.features,\n                                  class_vars=self.class_vars)\n        self.table = data.Table.from_numpy(\n            self.domain,\n            np.array(self.feature_data),\n            np.array(self.class_data),\n        )\n\n    def test_len(self):\n        self.assertEqual(len(self.table), self.nrows)\n\n    def test_row_len(self):\n        for i in range(self.nrows):\n            self.assertEqual(len(self.table[i]), len(self.data[i]))\n\n    def test_iteration(self):\n        for row, expected_data in zip(self.table, self.data):\n            self.assertEqual(tuple(row), expected_data)\n\n    def test_row_indexing(self):\n        for i in range(self.nrows):\n            self.assertEqual(tuple(self.table[i]), self.data[i])\n\n    def test_row_slicing(self):\n        t = self.table[1:]\n        self.assertEqual(len(t), self.nrows - 1)\n\n    def test_value_indexing(self):\n        for i in range(self.nrows):\n            for j in range(len(self.table[i])):\n                self.assertEqual(self.table[i, j], self.data[i][j])\n\n    def test_row_assignment(self):\n        new_value = 2.\n        with self.table.unlocked():\n            for i in range(self.nrows):\n                new_row = [new_value] * len(self.data[i])\n                self.table[i] = np.array(new_row)\n                self.assertEqual(list(self.table[i]), new_row)\n\n    def test_value_assignment(self):\n        new_value = 0.\n        with self.table.unlocked():\n            for i in range(self.nrows):\n                for j in range(len(self.table[i])):\n                    self.table[i, j] = new_value\n                    self.assertEqual(self.table[i, j], new_value)\n\n    def test_subclasses(self):\n        from pathlib import Path\n\n        class _ExtendedTable(data.Table):\n            pass\n\n        data_file = _ExtendedTable('iris')\n        data_url = _ExtendedTable.from_url(\n            Path(os.path.dirname(__file__), 'datasets/test1.tab').as_uri())\n\n        self.assertIsInstance(data_file, _ExtendedTable)\n        self.assertIsInstance(data_url, _ExtendedTable)\n\n\nclass TestTableStats(TableTests):\n    def test_get_nan_frequency(self):\n        domain = self.create_domain(self.attributes, self.class_vars)\n        table = data.Table(domain, self.data, self.class_data)\n        self.assertEqual(table.get_nan_frequency_attribute(), 0)\n        self.assertEqual(table.get_nan_frequency_class(), 0)\n\n        with table.unlocked():\n            table.X[1, 2] = table.X[4, 5] = np.nan\n        self.assertEqual(table.get_nan_frequency_attribute(), 2 / table.X.size)\n        self.assertEqual(table.get_nan_frequency_class(), 0)\n\n        with table.unlocked():\n            table.Y[3:6] = np.nan\n        self.assertEqual(table.get_nan_frequency_attribute(), 2 / table.X.size)\n        self.assertEqual(table.get_nan_frequency_class(), 3 / table.Y.size)\n\n        with table.unlocked():\n            table.X[1, 2] = table.X[4, 5] = 0\n        self.assertEqual(table.get_nan_frequency_attribute(), 0)\n        self.assertEqual(table.get_nan_frequency_class(), 3 / table.Y.size)\n\n    def test_get_nan_frequency_empty_table(self):\n        domain = self.create_domain(self.attributes, self.class_vars)\n        table = data.Table.from_domain(domain)\n        self.assertEqual(table.get_nan_frequency_attribute(), 0)\n        self.assertEqual(table.get_nan_frequency_class(), 0)\n\n\nclass TestRowInstance(unittest.TestCase):\n    def test_assignment(self):\n        table = data.Table(\"zoo\")\n        inst = table[2]\n        self.assertIsInstance(inst, data.RowInstance)\n\n        with table.unlocked():\n            inst[1] = 0\n        self.assertEqual(table[2, 1], 0)\n        with table.unlocked():\n            inst[1] = 1\n        self.assertEqual(table[2, 1], 1)\n\n        with table.unlocked():\n            inst.set_class(\"mammal\")\n        self.assertEqual(table[2, len(table.domain.attributes)], \"mammal\")\n        with table.unlocked():\n            inst.set_class(\"fish\")\n        self.assertEqual(table[2, len(table.domain.attributes)], \"fish\")\n\n        with table.unlocked():\n            inst[-1] = \"Foo\"\n        self.assertEqual(table[2, -1], \"Foo\")\n\n    def test_iteration_with_assignment(self):\n        table = data.Table(\"iris\")\n        with table.unlocked():\n            for i, row in enumerate(table):\n                row[0] = i\n        np.testing.assert_array_equal(table.X[:, 0], np.arange(len(table)))\n\n    def test_sparse_assignment(self):\n        X = np.eye(4)\n        Y = X[2].copy()\n        table = data.Table.from_numpy(None, X, Y)\n        row = table[1]\n        self.assertFalse(sp.issparse(row.sparse_x))\n        self.assertEqual(row[0], 0)\n        self.assertEqual(row[1], 1)\n\n        with table.unlocked():\n            table.X = sp.csr_matrix(table.X)\n            table.Y = sp.csr_matrix(table.Y)\n        sparse_row = table[1]\n        self.assertTrue(sp.issparse(sparse_row.sparse_x))\n        self.assertEqual(sparse_row[0], 0)\n        self.assertEqual(sparse_row[1], 1)\n\n        with table.unlocked():\n            sparse_row[1] = 0\n        self.assertEqual(sparse_row[1], 0)\n        self.assertEqual(table.X[1, 1], 0)\n        self.assertEqual(table[2][4], 1)\n\n        with table.unlocked():\n            table[2][4] = 0\n        self.assertEqual(table[2][4], 0)\n\n\nclass TestTableTranspose(unittest.TestCase):\n    def test_transpose_no_class(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        table = Table(Domain(attrs), np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose is original\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_discrete_class(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        domain = Domain(attrs, [DiscreteVariable(\"cls\", values=(\"a\", \"b\"))])\n        table = Table(domain, np.arange(8).reshape((4, 2)),\n                     np.array([1, 1, 0, 0]))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"cls\": \"b\"}\n        att[1].attributes = {\"cls\": \"b\"}\n        att[2].attributes = {\"cls\": \"a\"}\n        att[3].attributes = {\"cls\": \"a\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose is original\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_continuous_class(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")])\n        table = Table(domain, np.arange(8).reshape((4, 2)), np.arange(4, 0, -1))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"cls\": \"4\"}\n        att[1].attributes = {\"cls\": \"3\"}\n        att[2].attributes = {\"cls\": \"2\"}\n        att[3].attributes = {\"cls\": \"1\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_missing_class(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")])\n        table = Table(domain, np.arange(8).reshape((4, 2)),\n                     np.array([np.nan, 3, 2, 1]))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[1].attributes = {\"cls\": \"3\"}\n        att[2].attributes = {\"cls\": \"2\"}\n        att[3].attributes = {\"cls\": \"1\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_multiple_class(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        class_vars = [ContinuousVariable(\"cls1\"), ContinuousVariable(\"cls2\")]\n        domain = Domain(attrs, class_vars)\n        table = Table(domain, np.arange(8).reshape((4, 2)),\n                      np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"cls1\": \"0\", \"cls2\": \"1\"}\n        att[1].attributes = {\"cls1\": \"2\", \"cls2\": \"3\"}\n        att[2].attributes = {\"cls1\": \"4\", \"cls2\": \"5\"}\n        att[3].attributes = {\"cls1\": \"6\", \"cls2\": \"7\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_metas(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([\"aa\", \"bb\", \"cc\", \"dd\"])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"m1\": \"aa\"}\n        att[1].attributes = {\"m1\": \"bb\"}\n        att[2].attributes = {\"m1\": \"cc\"}\n        att[3].attributes = {\"m1\": \"dd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_discrete_metas(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [DiscreteVariable(\"m1\", values=(\"aa\", \"bb\"))]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([0, 1, 0, 1])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"m1\": \"aa\"}\n        att[1].attributes = {\"m1\": \"bb\"}\n        att[2].attributes = {\"m1\": \"aa\"}\n        att[3].attributes = {\"m1\": \"bb\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose is original\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_continuous_metas(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [ContinuousVariable(\"m1\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([0.0, 1.0, 0.0, 1.0])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"m1\": \"0\"}\n        att[1].attributes = {\"m1\": \"1\"}\n        att[2].attributes = {\"m1\": \"0\"}\n        att[3].attributes = {\"m1\": \"1\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose is original\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_missing_metas(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([\"aa\", \"bb\", \"\", \"dd\"])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"m1\": \"aa\"}\n        att[1].attributes = {\"m1\": \"bb\"}\n        att[3].attributes = {\"m1\": \"dd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_multiple_metas(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\"), StringVariable(\"m2\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([[\"aa\", \"aaa\"], [\"bb\", \"bbb\"],\n                      [\"cc\", \"ccc\"], [\"dd\", \"ddd\"]])\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"m1\": \"aa\", \"m2\": \"aaa\"}\n        att[1].attributes = {\"m1\": \"bb\", \"m2\": \"bbb\"}\n        att[2].attributes = {\"m1\": \"cc\", \"m2\": \"ccc\"}\n        att[3].attributes = {\"m1\": \"dd\", \"m2\": \"ddd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_class_and_metas(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\"), StringVariable(\"m2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")], metas)\n        M = np.array([[\"aa\", \"aaa\"], [\"bb\", \"bbb\"],\n                      [\"cc\", \"ccc\"], [\"dd\", \"ddd\"]])\n        table = Table(domain, np.arange(8).reshape((4, 2)), np.arange(1, 5), M)\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"cls\": \"1\", \"m1\": \"aa\", \"m2\": \"aaa\"}\n        att[1].attributes = {\"cls\": \"2\", \"m1\": \"bb\", \"m2\": \"bbb\"}\n        att[2].attributes = {\"cls\": \"3\", \"m1\": \"cc\", \"m2\": \"ccc\"}\n        att[3].attributes = {\"cls\": \"4\", \"m1\": \"dd\", \"m2\": \"ddd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([\"c1\", \"c2\"])[:, None])\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_attributes_of_attributes_discrete(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"a\", \"attr2\": \"aa\"}\n        attrs[1].attributes = {\"attr1\": \"b\", \"attr2\": \"bb\"}\n        domain = Domain(attrs)\n        table = Table(domain, np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        metas = [StringVariable(\"Feature name\"),\n                 DiscreteVariable(\"attr1\", values=(\"a\", \"b\")),\n                 DiscreteVariable(\"attr2\", values=(\"aa\", \"bb\"))]\n        domain = Domain(att, metas=metas)\n        M = np.array([[\"c1\", 0.0, 0.0], [\"c2\", 1.0, 1.0]], dtype=object)\n        result = Table(domain, np.arange(8).reshape((4, 2)).T, metas=M)\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"a\", \"attr2\": \"aa\"})\n\n    def test_transpose_attributes_of_attributes_continuous(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"1.1\", \"attr2\": \"1.3\"}\n        attrs[1].attributes = {\"attr1\": \"2.2\", \"attr2\": \"2.3\"}\n        domain = Domain(attrs)\n        table = Table(domain, np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        metas = [StringVariable(\"Feature name\"), ContinuousVariable(\"attr1\"),\n                 ContinuousVariable(\"attr2\")]\n        domain = Domain(att, metas=metas)\n        result = Table(domain, np.arange(8).reshape((4, 2)).T,\n                       metas=np.array([[\"c1\", 1.1, 1.3],\n                                       [\"c2\", 2.2, 2.3]], dtype=object))\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"1.1\", \"attr2\": \"1.3\"})\n\n    def test_transpose_attributes_of_attributes_missings(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"a\", \"attr2\": \"aa\"}\n        attrs[1].attributes = {\"attr1\": \"b\"}\n        domain = Domain(attrs)\n        table = Table(domain, np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        metas = [StringVariable(\"Feature name\"),\n                 DiscreteVariable(\"attr1\", values=(\"a\", \"b\")),\n                 DiscreteVariable(\"attr2\", values=(\"aa\",))]\n        domain = Domain(att, metas=metas)\n        M = np.array([[\"c1\", 0.0, 0.0], [\"c2\", 1.0, np.nan]], dtype=object)\n        result = Table(domain, np.arange(8).reshape((4, 2)).T, metas=M)\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"a\", \"attr2\": \"aa\"})\n\n    def test_transpose_class_metas_attributes(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"a1\", \"attr2\": \"aa1\"}\n        attrs[1].attributes = {\"attr1\": \"b1\", \"attr2\": \"bb1\"}\n        metas = [StringVariable(\"m1\"), StringVariable(\"m2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")], metas)\n        M = np.array([[\"aa\", \"aaa\"], [\"bb\", \"bbb\"],\n                      [\"cc\", \"ccc\"], [\"dd\", \"ddd\"]])\n        table = Table(domain, np.arange(8).reshape((4, 2)), np.arange(1, 5), M)\n\n        att = [ContinuousVariable(\"Feature 1\"), ContinuousVariable(\"Feature 2\"),\n               ContinuousVariable(\"Feature 3\"), ContinuousVariable(\"Feature 4\")]\n        att[0].attributes = {\"cls\": \"1\", \"m1\": \"aa\", \"m2\": \"aaa\"}\n        att[1].attributes = {\"cls\": \"2\", \"m1\": \"bb\", \"m2\": \"bbb\"}\n        att[2].attributes = {\"cls\": \"3\", \"m1\": \"cc\", \"m2\": \"ccc\"}\n        att[3].attributes = {\"cls\": \"4\", \"m1\": \"dd\", \"m2\": \"ddd\"}\n        metas = [StringVariable(\"Feature name\"),\n                 DiscreteVariable(\"attr1\", values=(\"a1\", \"b1\")),\n                 DiscreteVariable(\"attr2\", values=(\"aa1\", \"bb1\"))]\n        domain = Domain(att, metas=metas)\n        M = np.array([[\"c1\", 0.0, 0.0], [\"c2\", 1.0, 1.0]], dtype=object)\n        result = Table(domain, np.arange(8).reshape((4, 2)).T, metas=M)\n\n        # transpose and compare\n        self._compare_tables(result, Table.transpose(table))\n\n        # transpose of transpose\n        t = Table.transpose(Table.transpose(table), \"Feature name\")\n        self._compare_tables(table, t)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"a1\", \"attr2\": \"aa1\"})\n\n    def test_transpose_duplicate_feature_names(self):\n        table = Table(\"iris\")\n        domain = table.domain\n        attrs, metas = domain.attributes[:3], domain.attributes[3:]\n        table = table.transform(Domain(attrs, domain.class_vars, metas))\n        transposed = Table.transpose(table, domain.attributes[3].name)\n        names = [f.name for f in transposed.domain.attributes]\n        self.assertEqual(len(names), len(set(names)))\n\n    def test_transpose(self):\n        zoo = Table(\"zoo\")\n        t1 = Table.transpose(zoo)\n        t2 = Table.transpose(t1, \"Feature name\")\n        t3 = Table.transpose(t2)\n        self._compare_tables(zoo, t2)\n        self._compare_tables(t1, t3)\n\n    def test_transpose_callback(self):\n        zoo = Table(\"zoo\")\n        cb = Mock()\n        Table.transpose(zoo, progress_callback=cb)\n        cb.assert_called()\n\n    def test_transpose_no_class_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        table = Table(Domain(attrs), np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_discrete_class_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        domain = Domain(attrs, [DiscreteVariable(\"cls\", values=(\"a\", \"b\"))])\n        table = Table(domain, np.arange(8).reshape((4, 2)),\n                     np.array([1, 1, 0, 0]))\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"cls\": \"b\"}\n        att[1].attributes = {\"cls\": \"b\"}\n        att[2].attributes = {\"cls\": \"a\"}\n        att[3].attributes = {\"cls\": \"a\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_continuous_class_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")])\n        table = Table(domain, np.arange(8).reshape((4, 2)), np.arange(4, 0, -1))\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"cls\": \"4\"}\n        att[1].attributes = {\"cls\": \"3\"}\n        att[2].attributes = {\"cls\": \"2\"}\n        att[3].attributes = {\"cls\": \"1\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_missing_class_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")])\n        table = Table(domain, np.arange(8).reshape((4, 2)),\n                     np.array([np.nan, 3, 2, 1]))\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[1].attributes = {\"cls\": \"3\"}\n        att[2].attributes = {\"cls\": \"2\"}\n        att[3].attributes = {\"cls\": \"1\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_multiple_class_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        class_vars = [ContinuousVariable(\"cls1\"), ContinuousVariable(\"cls2\")]\n        domain = Domain(attrs, class_vars)\n        table = Table(domain, np.arange(8).reshape((4, 2)),\n                     np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"cls1\": \"0\", \"cls2\": \"1\"}\n        att[1].attributes = {\"cls1\": \"2\", \"cls2\": \"3\"}\n        att[2].attributes = {\"cls1\": \"4\", \"cls2\": \"5\"}\n        att[3].attributes = {\"cls1\": \"6\", \"cls2\": \"7\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_metas_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([\"aa\", \"bb\", \"cc\", \"dd\"])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"m1\": \"aa\"}\n        att[1].attributes = {\"m1\": \"bb\"}\n        att[2].attributes = {\"m1\": \"cc\"}\n        att[3].attributes = {\"m1\": \"dd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_discrete_metas_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [DiscreteVariable(\"m1\", values=(\"aa\", \"bb\"))]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([0, 1, 0, 1])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"m1\": \"aa\"}\n        att[1].attributes = {\"m1\": \"bb\"}\n        att[2].attributes = {\"m1\": \"aa\"}\n        att[3].attributes = {\"m1\": \"bb\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_continuous_metas_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [ContinuousVariable(\"m1\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([0.0, 1.0, 0.0, 1.0])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"m1\": \"0\"}\n        att[1].attributes = {\"m1\": \"1\"}\n        att[2].attributes = {\"m1\": \"0\"}\n        att[3].attributes = {\"m1\": \"1\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_missing_metas_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([\"aa\", \"bb\", \"\", \"dd\"])[:, None]\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"m1\": \"aa\"}\n        att[1].attributes = {\"m1\": \"bb\"}\n        att[3].attributes = {\"m1\": \"dd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_multiple_metas_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\"), StringVariable(\"m2\")]\n        domain = Domain(attrs, metas=metas)\n        X = np.arange(8).reshape((4, 2))\n        M = np.array([[\"aa\", \"aaa\"], [\"bb\", \"bbb\"],\n                      [\"cc\", \"ccc\"], [\"dd\", \"ddd\"]])\n        table = Table(domain, X, metas=M)\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"m1\": \"aa\", \"m2\": \"aaa\"}\n        att[1].attributes = {\"m1\": \"bb\", \"m2\": \"bbb\"}\n        att[2].attributes = {\"m1\": \"cc\", \"m2\": \"ccc\"}\n        att[3].attributes = {\"m1\": \"dd\", \"m2\": \"ddd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_class_and_metas_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        metas = [StringVariable(\"m1\"), StringVariable(\"m2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")], metas)\n        M = np.array([[\"aa\", \"aaa\"], [\"bb\", \"bbb\"],\n                      [\"cc\", \"ccc\"], [\"dd\", \"ddd\"]])\n        table = Table(domain, np.arange(8).reshape((4, 2)), np.arange(1, 5), M)\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"cls\": \"1\", \"m1\": \"aa\", \"m2\": \"aaa\"}\n        att[1].attributes = {\"cls\": \"2\", \"m1\": \"bb\", \"m2\": \"bbb\"}\n        att[2].attributes = {\"cls\": \"3\", \"m1\": \"cc\", \"m2\": \"ccc\"}\n        att[3].attributes = {\"cls\": \"4\", \"m1\": \"dd\", \"m2\": \"ddd\"}\n        domain = Domain(att, metas=[StringVariable(\"Feature name\")])\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\"]]))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes, {})\n\n    def test_transpose_attributes_of_attributes_discrete_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"a\", \"attr2\": \"aa\"}\n        attrs[1].attributes = {\"attr1\": \"b\", \"attr2\": \"bb\"}\n        domain = Domain(attrs)\n        table = Table(domain, np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        metas = [StringVariable(\"Feature name\"),\n                 DiscreteVariable(\"attr1\", values=(\"a\", \"b\")),\n                 DiscreteVariable(\"attr2\", values=(\"aa\", \"bb\"))]\n        domain = Domain(att, metas=metas)\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\", 0.0, 0.0]], dtype=object))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"a\", \"attr2\": \"aa\"})\n\n    def test_transpose_attributes_of_attributes_continuous_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"1.1\", \"attr2\": \"1.3\"}\n        attrs[1].attributes = {\"attr1\": \"2.2\", \"attr2\": \"2.3\"}\n        domain = Domain(attrs)\n        table = Table(domain, np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        metas = [StringVariable(\"Feature name\"), ContinuousVariable(\"attr1\"),\n                 ContinuousVariable(\"attr2\")]\n        domain = Domain(att, metas=metas)\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\", 1.1, 1.3]], dtype=object))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"1.1\", \"attr2\": \"1.3\"})\n\n    def test_transpose_attributes_of_attributes_missings_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"a\", \"attr2\": \"aa\"}\n        attrs[1].attributes = {\"attr1\": \"b\"}\n        domain = Domain(attrs)\n        table = Table(domain, np.arange(8).reshape((4, 2)))\n\n        att = [ContinuousVariable(\"0\"), ContinuousVariable(\"2\"),\n               ContinuousVariable(\"4\"), ContinuousVariable(\"6\")]\n        metas = [StringVariable(\"Feature name\"),\n                 DiscreteVariable(\"attr1\", values=(\"b\",))]\n        domain = Domain(att, metas=metas)\n        result = Table(domain, np.array([[1, 3, 5, 7]]),\n                       metas=np.array([[\"c2\", 0.0]], dtype=object))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c1\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"2\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"a\", \"attr2\": \"aa\"})\n\n    def test_transpose_class_metas_attributes_remove_inst(self):\n        attrs = [ContinuousVariable(\"c1\"), ContinuousVariable(\"c2\")]\n        attrs[0].attributes = {\"attr1\": \"a1\", \"attr2\": \"aa1\"}\n        attrs[1].attributes = {\"attr1\": \"b1\", \"attr2\": \"bb1\"}\n        metas = [StringVariable(\"m1\"), StringVariable(\"m2\")]\n        domain = Domain(attrs, [ContinuousVariable(\"cls\")], metas)\n        M = np.array([[\"aa\", \"aaa\"], [\"bb\", \"bbb\"],\n                      [\"cc\", \"ccc\"], [\"dd\", \"ddd\"]])\n        table = Table(domain, np.arange(8).reshape((4, 2)), np.arange(1, 5), M)\n\n        att = [ContinuousVariable(\"1\"), ContinuousVariable(\"3\"),\n               ContinuousVariable(\"5\"), ContinuousVariable(\"7\")]\n        att[0].attributes = {\"cls\": \"1\", \"m1\": \"aa\", \"m2\": \"aaa\"}\n        att[1].attributes = {\"cls\": \"2\", \"m1\": \"bb\", \"m2\": \"bbb\"}\n        att[2].attributes = {\"cls\": \"3\", \"m1\": \"cc\", \"m2\": \"ccc\"}\n        att[3].attributes = {\"cls\": \"4\", \"m1\": \"dd\", \"m2\": \"ddd\"}\n        metas = [StringVariable(\"Feature name\"),\n                 DiscreteVariable(\"attr1\", values=(\"a1\", \"b1\")),\n                 DiscreteVariable(\"attr2\", values=(\"aa1\", \"bb1\"))]\n        domain = Domain(att, metas=metas)\n        result = Table(domain, np.array([[0, 2, 4, 6]]),\n                       metas=np.array([[\"c1\", 0.0, 0.0]], dtype=object))\n\n        # transpose and compare\n        transposed = Table.transpose(table, \"c2\", remove_redundant_inst=True)\n        self._compare_tables(result, transposed)\n\n        # transpose of transpose is not equal to the original\n        Table.transpose(transposed, \"Feature name\")\n        Table.transpose(transposed, \"3\", remove_redundant_inst=True)\n\n        # original should not change\n        self.assertDictEqual(table.domain.attributes[0].attributes,\n                             {\"attr1\": \"a1\", \"attr2\": \"aa1\"})\n\n    def _compare_tables(self, table1, table2):\n        self.assertEqual(table1.n_rows, table2.n_rows)\n        np.testing.assert_array_equal(table1.X, table2.X)\n        np.testing.assert_array_equal(table1.Y, table2.Y)\n        np.testing.assert_array_equal(table1.metas.astype(str),\n                                      table2.metas.astype(str))\n        np.testing.assert_array_equal(table1.W, table2.W)\n\n        self.assertEqual([(type(x), x.name, x.attributes)\n                          for x in table1.domain.attributes],\n                         [(type(x), x.name, x.attributes)\n                          for x in table2.domain.attributes])\n        self.assertEqual([(type(x), x.name, x.attributes)\n                          for x in table1.domain.class_vars],\n                         [(type(x), x.name, x.attributes)\n                          for x in table2.domain.class_vars])\n        self.assertEqual([(type(x), x.name, x.attributes)\n                          for x in table1.domain.metas],\n                         [(type(x), x.name, x.attributes)\n                          for x in table2.domain.metas])\n\n\nclass SparseCV:\n    def __call__(self, data):\n        return sp.csr_matrix((len(data), 1))\n\n\nclass TestTableSparseDense(unittest.TestCase):\n    def setUp(self):\n        self.iris = Table('iris')\n\n    def test_sparse_dense_transformation(self):\n        iris = Table('iris')\n        iris_sparse = iris.to_sparse(sparse_attributes=True)\n        self.assertTrue(sp.issparse(iris_sparse.X))\n        self.assertFalse(sp.issparse(iris_sparse.Y))\n        self.assertFalse(sp.issparse(iris_sparse.metas))\n\n        iris_sparse = iris.to_sparse(sparse_attributes=True, sparse_class=True)\n        self.assertTrue(sp.issparse(iris_sparse.X))\n        self.assertFalse(sp.issparse(iris_sparse.Y))\n        self.assertFalse(sp.issparse(iris_sparse.metas))\n\n        dense_iris = iris_sparse.to_dense()\n        self.assertFalse(sp.issparse(dense_iris.X))\n        self.assertFalse(sp.issparse(dense_iris.Y))\n        self.assertFalse(sp.issparse(dense_iris.metas))\n\n    def test_from_table_add_one_sparse_column(self):\n        # add one sparse feature, should remain dense\n        domain = self.iris.domain.copy()\n        domain.attributes += (\n            ContinuousVariable('S1', compute_value=SparseCV(), sparse=True),\n        )\n        d = self.iris.transform(domain)\n        self.assertFalse(sp.issparse(d.X))\n\n        # try with indices that are not Ellipsis\n        d = Table.from_table(domain, self.iris, row_indices=[0, 1, 2])\n        np.testing.assert_array_equal(\n            d.X,\n            [[5.1, 3.5, 1.4, 0.2, 0],\n             [4.9, 3.0, 1.4, 0.2, 0],\n             [4.7, 3.2, 1.3, 0.2, 0]]\n        )\n        self.assertFalse(sp.issparse(d.X))\n\n    def test_from_table_add_lots_of_sparse_columns(self):\n        n_attrs = len(self.iris.domain.attributes)\n\n        # add 2*n_attrs+1 sparse feature, should became sparse\n        domain = self.iris.domain.copy()\n        domain.attributes += tuple(\n            ContinuousVariable('S' + str(i), compute_value=SparseCV(), sparse=True)\n            for i in range(2*n_attrs + 1)\n        )\n        d = self.iris.transform(domain)\n        self.assertTrue(sp.issparse(d.X))\n\n    def test_from_table_replace_attrs_with_sparse(self):\n        # replace attrs with a sparse feature, should became sparse\n        domain = self.iris.domain.copy()\n        domain.attributes = (\n            ContinuousVariable('S1', compute_value=SparseCV(), sparse=True),\n        )\n        d = self.iris.transform(domain)\n        self.assertTrue(sp.issparse(d.X))\n\n    def test_from_table_sparse_metas(self):\n        # replace metas with a sparse feature, should became sparse\n        domain = self.iris.domain.copy()\n        domain._metas = (\n            ContinuousVariable('S1', compute_value=SparseCV(), sparse=True),\n        )\n        d = self.iris.transform(domain)\n        self.assertTrue(sp.issparse(d.metas))\n\n    def test_from_table_sparse_metas_with_strings(self):\n        # replace metas with text and 100 sparse features, should be dense\n        domain = self.iris.domain.copy()\n        domain._metas = (StringVariable('text'),) + tuple(\n            ContinuousVariable('S' + str(i), compute_value=SparseCV(), sparse=True)\n            for i in range(100)\n        )\n        d = self.iris.transform(domain)\n        self.assertFalse(sp.issparse(d.metas))\n\n\nclass ConcurrencyTests(unittest.TestCase):\n\n    def test_from_table_non_blocking(self):\n        iris = Table(\"iris\")[:10]\n\n        def slow_compute_value(d):\n            sleep(0.1)\n            return d.X[:, 0]\n\n        ndom = Domain([ContinuousVariable(\"a\", compute_value=slow_compute_value)])\n\n        def run_from_table():\n            Table.from_table(ndom, iris)\n\n        start = time()\n\n        threads = []\n        for _ in range(10):\n            thread = Thread(target=run_from_table)\n            thread.start()\n            threads.append(thread)\n        for t in threads:\n            t.join()\n\n        # if from_table was blocking these threads would need at least 0.1*10s\n        duration = time() - start\n        self.assertLess(duration, 0.5)\n\n\nclass PreprocessComputeValue:\n\n    def __init__(self, domain, callback):\n        self.domain = domain\n        self.callback = callback\n\n    def __call__(self, data_):\n        if self.callback:\n            self.callback(data_)\n        transformed = data_.transform(self.domain)\n        return transformed.X[:, 0] * 2\n\n\nclass PreprocessShared:\n\n    def __init__(self, domain, callback):\n        self.domain = domain\n        self.callback = callback\n\n    def __call__(self, data_):\n        if self.callback:\n            self.callback(data_)\n        transformed = data_.transform(self.domain)\n        return transformed.X * 2\n\n\nclass PreprocessSharedComputeValue(SharedComputeValue):\n\n    def __init__(self, col, callback, shared):\n        super().__init__(compute_shared=shared)\n        self.col = col\n        self.callback = callback\n\n    # pylint: disable=arguments-differ\n    def compute(self, data_, shared_data):\n        if self.callback:\n            self.callback(data_)\n        return shared_data[:, self.col]\n\n\ndef preprocess_domain_single(domain, callback):\n    \"\"\" Preprocess domain with single-source compute values.\n    \"\"\"\n    return Domain([\n        ContinuousVariable(name=at.name,\n                           compute_value=PreprocessComputeValue(Domain([at]), callback))\n        for at in domain.attributes])\n\n\ndef preprocess_domain_shared(domain, callback, callback_shared):\n    \"\"\" Preprocess domain with shared compute values.\n    \"\"\"\n    shared = PreprocessShared(domain, callback_shared)\n    return Domain([\n        ContinuousVariable(name=at.name,\n                           compute_value=PreprocessSharedComputeValue(i, callback, shared))\n        for i, at in enumerate(domain.attributes)])\n\n\ndef preprocess_domain_single_stupid(domain, callback):\n    \"\"\" Preprocess domain with single-source compute values with stupid\n    implementation: before applying it, instead of transforming just one column\n    into the input domain, do a needless transform of the whole domain.\n    \"\"\"\n    return Domain([\n        ContinuousVariable(name=at.name,\n                           compute_value=PreprocessComputeValue(domain, callback))\n        for at in domain.attributes])\n\n\nclass EfficientTransformTests(unittest.TestCase):\n\n    def setUp(self):\n        self.iris = Table(\"iris\")[:10]\n\n    def test_simple(self):\n        call_cv = Mock()\n        d1 = preprocess_domain_single(self.iris.domain, call_cv)\n        t = self.iris.transform(d1)\n        self.assertEqual(4, call_cv.call_count)\n        np.testing.assert_equal(t.X, self.iris.X * 2)\n\n    def test_shared(self):\n        call_cv = Mock()\n        call_shared = Mock()\n        d1 = preprocess_domain_shared(self.iris.domain, call_cv, call_shared)\n        t = self.iris.transform(d1)\n        self.assertEqual(4, call_cv.call_count)\n        self.assertEqual(1, call_shared.call_count)\n        np.testing.assert_equal(t.X, self.iris.X * 2)\n\n    def test_simple_simple_shared(self):\n        call_cv = Mock()\n        d1 = preprocess_domain_single(self.iris.domain, call_cv)\n        d2 = preprocess_domain_single(d1, call_cv)\n        call_shared = Mock()\n        d3 = preprocess_domain_shared(d2, call_cv, call_shared)\n        t = self.iris.transform(d3)\n        self.assertEqual(1, call_shared.call_count)\n        self.assertEqual(12, call_cv.call_count)\n        np.testing.assert_equal(t.X, self.iris.X * 2**3)\n\n    def test_simple_simple_shared_simple(self):\n        call_cv = Mock()\n        d1 = preprocess_domain_single(self.iris.domain, call_cv)\n        d2 = preprocess_domain_single(d1, call_cv)\n        call_shared = Mock()\n        d3 = preprocess_domain_shared(d2, call_cv, call_shared)\n        d4 = preprocess_domain_single(d3, call_cv)\n        t = self.iris.transform(d4)\n        self.assertEqual(1, call_shared.call_count)\n        self.assertEqual(16, call_cv.call_count)\n        np.testing.assert_equal(t.X, self.iris.X * 2**4)\n\n    def test_simple_simple_shared_simple_shared_simple(self):\n        call_cv = Mock()\n        d1 = preprocess_domain_single(self.iris.domain, call_cv)\n        d2 = preprocess_domain_single(d1, call_cv)\n        call_shared = Mock()\n        d3 = preprocess_domain_shared(d2, call_cv, call_shared)\n        d4 = preprocess_domain_single(d3, call_cv)\n        d5 = preprocess_domain_shared(d4, call_cv, call_shared)\n        d6 = preprocess_domain_single(d5, call_cv)\n        t = self.iris.transform(d6)\n        self.assertEqual(2, call_shared.call_count)\n        self.assertEqual(24, call_cv.call_count)\n        np.testing.assert_equal(t.X, self.iris.X * 2**6)\n\n    def test_simple_simple_stupid(self):\n        call_cv = Mock()\n        d1 = preprocess_domain_single_stupid(self.iris.domain, call_cv)\n        d2 = preprocess_domain_single_stupid(d1, call_cv)\n        t = self.iris.transform(d2)\n        self.assertEqual(8, call_cv.call_count)\n        np.testing.assert_equal(t.X[:, 0], self.iris.X[:, 0] * 4)\n\n\nif __name__ == \"__main__\":\n    unittest.main()\n"
    ],
    "test_file_names": [
        "test_1.py"
    ],
    "setup_res_code": 0,
    "setup_res_stdout": "Starting Orange installation attempts...\nAttempting installation with Python 3.7...\nrunning build_ext\nCompiling Orange/classification/_tree_scorers.pyx because it changed.\nCompiling Orange/data/_contingency.pyx because it changed.\nCompiling Orange/data/_io.pyx because it changed.\nCompiling Orange/data/_valuecount.pyx because it changed.\nCompiling Orange/data/_variable.pyx because it changed.\nCompiling Orange/distance/_distance.pyx because it changed.\nCompiling Orange/preprocess/_discretize.pyx because it changed.\nCompiling Orange/preprocess/_relieff.pyx because it changed.\nCompiling Orange/projection/_som.pyx because it changed.\n[1/9] Cythonizing Orange/classification/_tree_scorers.pyx\n[2/9] Cythonizing Orange/data/_contingency.pyx\n[3/9] Cythonizing Orange/data/_io.pyx\n[4/9] Cythonizing Orange/data/_valuecount.pyx\n[5/9] Cythonizing Orange/data/_variable.pyx\n[6/9] Cythonizing Orange/distance/_distance.pyx\n[7/9] Cythonizing Orange/preprocess/_discretize.pyx\n[8/9] Cythonizing Orange/preprocess/_relieff.pyx\n[9/9] Cythonizing Orange/projection/_som.pyx\nbuilding 'Orange.classification._tree_scorers' extension\ncreating build\ncreating build/temp.linux-x86_64-3.7\ncreating build/temp.linux-x86_64-3.7/Orange\ncreating build/temp.linux-x86_64-3.7/Orange/classification\ncc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/include -I/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/include/python3.7m -c Orange/classification/_tree_scorers.c -o build/temp.linux-x86_64-3.7/Orange/classification/_tree_scorers.o\ncreating build/lib.linux-x86_64-3.7\ncreating build/lib.linux-x86_64-3.7/Orange\ncreating build/lib.linux-x86_64-3.7/Orange/classification\ncc -pthread -shared -L/tools/deps/lib build/temp.linux-x86_64-3.7/Orange/classification/_tree_scorers.o -L/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib -lm -lpython3.7m -o build/lib.linux-x86_64-3.7/Orange/classification/_tree_scorers.cpython-37m-x86_64-linux-gnu.so\nbuilding 'Orange.data._contingency' extension\ncreating build/temp.linux-x86_64-3.7/Orange/data\ncc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/include -I/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/include/python3.7m -c Orange/data/_contingency.c -o build/temp.linux-x86_64-3.7/Orange/data/_contingency.o\ncreating build/lib.linux-x86_64-3.7/Orange/data\ncc -pthread -shared -L/tools/deps/lib build/temp.linux-x86_64-3.7/Orange/data/_contingency.o -L/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib -lm -lpython3.7m -o build/lib.linux-x86_64-3.7/Orange/data/_contingency.cpython-37m-x86_64-linux-gnu.so\nbuilding 'Orange.data._io' extension\ncc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/include -I/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/include/python3.7m -c Orange/data/_io.c -o build/temp.linux-x86_64-3.7/Orange/data/_io.o\ncc -pthread -shared -L/tools/deps/lib build/temp.linux-x86_64-3.7/Orange/data/_io.o -L/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib -lm -lpython3.7m -o build/lib.linux-x86_64-3.7/Orange/data/_io.cpython-37m-x86_64-linux-gnu.so\nbuilding 'Orange.data._valuecount' extension\ncc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/include -I/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/include/python3.7m -c Orange/data/_valuecount.c -o build/temp.linux-x86_64-3.7/Orange/data/_valuecount.o\ncc -pthread -shared -L/tools/deps/lib build/temp.linux-x86_64-3.7/Orange/data/_valuecount.o -L/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib -lm -lpython3.7m -o build/lib.linux-x86_64-3.7/Orange/data/_valuecount.cpython-37m-x86_64-linux-gnu.so\nbuilding 'Orange.data._variable' extension\ncc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/include -I/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/include/python3.7m -c Orange/data/_variable.c -o build/temp.linux-x86_64-3.7/Orange/data/_variable.o\ncc -pthread -shared -L/tools/deps/lib build/temp.linux-x86_64-3.7/Orange/data/_variable.o -L/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib -lm -lpython3.7m -o build/lib.linux-x86_64-3.7/Orange/data/_variable.cpython-37m-x86_64-linux-gnu.so\nbuilding 'Orange.distance._distance' extension\ncreating build/temp.linux-x86_64-3.7/Orange/distance\ncc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/include -I/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/include/python3.7m -c Orange/distance/_distance.c -o build/temp.linux-x86_64-3.7/Orange/distance/_distance.o\ncreating build/lib.linux-x86_64-3.7/Orange/distance\ncc -pthread -shared -L/tools/deps/lib build/temp.linux-x86_64-3.7/Orange/distance/_distance.o -L/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib -lm -lpython3.7m -o build/lib.linux-x86_64-3.7/Orange/distance/_distance.cpython-37m-x86_64-linux-gnu.so\nbuilding 'Orange.preprocess._discretize' extension\ncreating build/temp.linux-x86_64-3.7/Orange/preprocess\ncc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/include -I/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/include/python3.7m -c Orange/preprocess/_discretize.c -o build/temp.linux-x86_64-3.7/Orange/preprocess/_discretize.o\ncreating build/lib.linux-x86_64-3.7/Orange/preprocess\ncc -pthread -shared -L/tools/deps/lib build/temp.linux-x86_64-3.7/Orange/preprocess/_discretize.o -L/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib -lm -lpython3.7m -o build/lib.linux-x86_64-3.7/Orange/preprocess/_discretize.cpython-37m-x86_64-linux-gnu.so\nbuilding 'Orange.preprocess._relieff' extension\ncc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/include -I/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/include/python3.7m -c Orange/preprocess/_relieff.cpp -o build/temp.linux-x86_64-3.7/Orange/preprocess/_relieff.o\nc++ -pthread -shared -L/tools/deps/lib build/temp.linux-x86_64-3.7/Orange/preprocess/_relieff.o -L/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib -lm -lpython3.7m -o build/lib.linux-x86_64-3.7/Orange/preprocess/_relieff.cpython-37m-x86_64-linux-gnu.so\nbuilding 'Orange.projection._som' extension\ncreating build/temp.linux-x86_64-3.7/Orange/projection\ncc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/include -I/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/include/python3.7m -c Orange/projection/_som.c -o build/temp.linux-x86_64-3.7/Orange/projection/_som.o\ncreating build/lib.linux-x86_64-3.7/Orange/projection\ncc -pthread -shared -L/tools/deps/lib build/temp.linux-x86_64-3.7/Orange/projection/_som.o -L/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib -lm -lpython3.7m -o build/lib.linux-x86_64-3.7/Orange/projection/_som.cpython-37m-x86_64-linux-gnu.so\nbuilding 'Orange.classification._simple_tree' extension\ncc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/include -I/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/include/python3.7m -c Orange/classification/_simple_tree.c -o build/temp.linux-x86_64-3.7/Orange/classification/_simple_tree.o\ncc -pthread -shared -L/tools/deps/lib build/temp.linux-x86_64-3.7/Orange/classification/_simple_tree.o -L/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib -lm -lpython3.7m -o build/lib.linux-x86_64-3.7/Orange/classification/_simple_tree.cpython-37m-x86_64-linux-gnu.so\nbuilding 'Orange.widgets.utils._grid_density' extension\ncreating build/temp.linux-x86_64-3.7/Orange/widgets\ncreating build/temp.linux-x86_64-3.7/Orange/widgets/utils\ncc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tools/deps/include -I/tools/deps/include/ncursesw -fPIC -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include -I/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/include -I/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/include/python3.7m -c Orange/widgets/utils/_grid_density.cpp -o build/temp.linux-x86_64-3.7/Orange/widgets/utils/_grid_density.o\ncreating build/lib.linux-x86_64-3.7/Orange/widgets\ncreating build/lib.linux-x86_64-3.7/Orange/widgets/utils\nc++ -pthread -shared -L/tools/deps/lib build/temp.linux-x86_64-3.7/Orange/widgets/utils/_grid_density.o -L/home/gcpuser/.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib -lm -lpython3.7m -o build/lib.linux-x86_64-3.7/Orange/widgets/utils/_grid_density.cpython-37m-x86_64-linux-gnu.so\ncopying build/lib.linux-x86_64-3.7/Orange/classification/_tree_scorers.cpython-37m-x86_64-linux-gnu.so -> Orange/classification\ncopying build/lib.linux-x86_64-3.7/Orange/data/_contingency.cpython-37m-x86_64-linux-gnu.so -> Orange/data\ncopying build/lib.linux-x86_64-3.7/Orange/data/_io.cpython-37m-x86_64-linux-gnu.so -> Orange/data\ncopying build/lib.linux-x86_64-3.7/Orange/data/_valuecount.cpython-37m-x86_64-linux-gnu.so -> Orange/data\ncopying build/lib.linux-x86_64-3.7/Orange/data/_variable.cpython-37m-x86_64-linux-gnu.so -> Orange/data\ncopying build/lib.linux-x86_64-3.7/Orange/distance/_distance.cpython-37m-x86_64-linux-gnu.so -> Orange/distance\ncopying build/lib.linux-x86_64-3.7/Orange/preprocess/_discretize.cpython-37m-x86_64-linux-gnu.so -> Orange/preprocess\ncopying build/lib.linux-x86_64-3.7/Orange/preprocess/_relieff.cpython-37m-x86_64-linux-gnu.so -> Orange/preprocess\ncopying build/lib.linux-x86_64-3.7/Orange/projection/_som.cpython-37m-x86_64-linux-gnu.so -> Orange/projection\ncopying build/lib.linux-x86_64-3.7/Orange/classification/_simple_tree.cpython-37m-x86_64-linux-gnu.so -> Orange/classification\ncopying build/lib.linux-x86_64-3.7/Orange/widgets/utils/_grid_density.cpython-37m-x86_64-linux-gnu.so -> Orange/widgets/utils\nrunning develop\nrunning egg_info\ncreating Orange3.egg-info\nwriting Orange3.egg-info/PKG-INFO\nwriting dependency_links to Orange3.egg-info/dependency_links.txt\nwriting entry points to Orange3.egg-info/entry_points.txt\nwriting requirements to Orange3.egg-info/requires.txt\nwriting top-level names to Orange3.egg-info/top_level.txt\nwriting manifest file 'Orange3.egg-info/SOURCES.txt'\nreading manifest file 'Orange3.egg-info/SOURCES.txt'\nreading manifest template 'MANIFEST.in'\nadding license file 'LICENSE'\nwriting manifest file 'Orange3.egg-info/SOURCES.txt'\nrunning build_ext\ncopying build/lib.linux-x86_64-3.7/Orange/classification/_tree_scorers.cpython-37m-x86_64-linux-gnu.so -> Orange/classification\ncopying build/lib.linux-x86_64-3.7/Orange/data/_contingency.cpython-37m-x86_64-linux-gnu.so -> Orange/data\ncopying build/lib.linux-x86_64-3.7/Orange/data/_io.cpython-37m-x86_64-linux-gnu.so -> Orange/data\ncopying build/lib.linux-x86_64-3.7/Orange/data/_valuecount.cpython-37m-x86_64-linux-gnu.so -> Orange/data\ncopying build/lib.linux-x86_64-3.7/Orange/data/_variable.cpython-37m-x86_64-linux-gnu.so -> Orange/data\ncopying build/lib.linux-x86_64-3.7/Orange/distance/_distance.cpython-37m-x86_64-linux-gnu.so -> Orange/distance\ncopying build/lib.linux-x86_64-3.7/Orange/preprocess/_discretize.cpython-37m-x86_64-linux-gnu.so -> Orange/preprocess\ncopying build/lib.linux-x86_64-3.7/Orange/preprocess/_relieff.cpython-37m-x86_64-linux-gnu.so -> Orange/preprocess\ncopying build/lib.linux-x86_64-3.7/Orange/projection/_som.cpython-37m-x86_64-linux-gnu.so -> Orange/projection\ncopying build/lib.linux-x86_64-3.7/Orange/classification/_simple_tree.cpython-37m-x86_64-linux-gnu.so -> Orange/classification\ncopying build/lib.linux-x86_64-3.7/Orange/widgets/utils/_grid_density.cpython-37m-x86_64-linux-gnu.so -> Orange/widgets/utils\nCreating /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/Orange3.egg-link (link to .)\nAdding Orange3 3.31.0.dev0+c86388c to easy-install.pth file\nInstalling orange-canvas script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\n\nInstalled /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda\nProcessing dependencies for Orange3==3.31.0.dev0+c86388c\nSearching for XlsxWriter==3.2.0\nBest match: XlsxWriter 3.2.0\nAdding XlsxWriter 3.2.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for xlrd==2.0.1\nBest match: xlrd 2.0.1\nAdding xlrd 2.0.1 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for setuptools==59.8.0\nBest match: setuptools 59.8.0\nAdding setuptools 59.8.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for serverfiles==0.3.1\nBest match: serverfiles 0.3.1\nAdding serverfiles 0.3.1 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for scipy==1.7.3\nBest match: scipy 1.7.3\nAdding scipy 1.7.3 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for scikit-learn==1.0.2\nBest match: scikit-learn 1.0.2\nAdding scikit-learn 1.0.2 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for requests==2.31.0\nBest match: requests 2.31.0\nAdding requests 2.31.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for qtconsole==5.4.4\nBest match: qtconsole 5.4.4\nAdding qtconsole 5.4.4 to easy-install.pth file\nInstalling jupyter-qtconsole script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for PyYAML==6.0.1\nBest match: PyYAML 6.0.1\nAdding PyYAML 6.0.1 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for python-louvain==0.16\nBest match: python-louvain 0.16\nAdding python-louvain 0.16 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for pyqtgraph==0.12.4\nBest match: pyqtgraph 0.12.4\nAdding pyqtgraph 0.12.4 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for pygments==2.17.2\nBest match: pygments 2.17.2\nAdding pygments 2.17.2 to easy-install.pth file\nInstalling pygmentize script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for pip==24.0\nBest match: pip 24.0\nAdding pip 24.0 to easy-install.pth file\nInstalling pip script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\nInstalling pip3 script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\nInstalling pip3.10 script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for pandas==1.3.5\nBest match: pandas 1.3.5\nAdding pandas 1.3.5 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for orange-widget-base==4.22.0\nBest match: orange-widget-base 4.22.0\nAdding orange-widget-base 4.22.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for orange-canvas-core==0.1.35\nBest match: orange-canvas-core 0.1.35\nAdding orange-canvas-core 0.1.35 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for openpyxl==3.1.3\nBest match: openpyxl 3.1.3\nAdding openpyxl 3.1.3 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for openTSNE==1.0.1\nBest match: openTSNE 1.0.1\nAdding openTSNE 1.0.1 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for numpy==1.17.5\nBest match: numpy 1.17.5\nAdding numpy 1.17.5 to easy-install.pth file\nInstalling f2py script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\nInstalling f2py3 script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\nInstalling f2py3.7 script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for networkx==2.6.3\nBest match: networkx 2.6.3\nAdding networkx 2.6.3 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for matplotlib==3.5.3\nBest match: matplotlib 3.5.3\nAdding matplotlib 3.5.3 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for keyrings.alt==4.2.0\nBest match: keyrings.alt 4.2.0\nAdding keyrings.alt 4.2.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for keyring==24.1.1\nBest match: keyring 24.1.1\nAdding keyring 24.1.1 to easy-install.pth file\nInstalling keyring script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for joblib==1.3.2\nBest match: joblib 1.3.2\nAdding joblib 1.3.2 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for httpx==0.19.0\nBest match: httpx 0.19.0\nAdding httpx 0.19.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for chardet==5.2.0\nBest match: chardet 5.2.0\nAdding chardet 5.2.0 to easy-install.pth file\nInstalling chardetect script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for Bottleneck==1.4.0\nBest match: Bottleneck 1.4.0\nAdding Bottleneck 1.4.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for baycomp==1.0.3\nBest match: baycomp 1.0.3\nAdding baycomp 1.0.3 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for PyQtWebEngine==5.15.6\nBest match: PyQtWebEngine 5.15.6\nAdding PyQtWebEngine 5.15.6 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for PyQt5==5.15.10\nBest match: PyQt5 5.15.10\nAdding PyQt5 5.15.10 to easy-install.pth file\nInstalling pylupdate5 script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\nInstalling pyrcc5 script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\nInstalling pyuic5 script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for AnyQt==0.2.0\nBest match: AnyQt 0.2.0\nAdding AnyQt 0.2.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for threadpoolctl==3.1.0\nBest match: threadpoolctl 3.1.0\nAdding threadpoolctl 3.1.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for urllib3==2.0.7\nBest match: urllib3 2.0.7\nAdding urllib3 2.0.7 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for charset-normalizer==3.4.1\nBest match: charset-normalizer 3.4.1\nAdding charset-normalizer 3.4.1 to easy-install.pth file\nInstalling normalizer script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for idna==3.10\nBest match: idna 3.10\nAdding idna 3.10 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for certifi==2024.12.14\nBest match: certifi 2024.12.14\nAdding certifi 2024.12.14 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for ipykernel==6.16.2\nBest match: ipykernel 6.16.2\nAdding ipykernel 6.16.2 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for packaging==24.0\nBest match: packaging 24.0\nAdding packaging 24.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for pyzmq==26.2.0\nBest match: pyzmq 26.2.0\nAdding pyzmq 26.2.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for QtPy==2.4.2\nBest match: QtPy 2.4.2\nAdding QtPy 2.4.2 to easy-install.pth file\nInstalling qtpy script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for ipython-genutils==0.2.0\nBest match: ipython-genutils 0.2.0\nAdding ipython-genutils 0.2.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for traitlets==5.9.0\nBest match: traitlets 5.9.0\nAdding traitlets 5.9.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for jupyter-client==7.4.9\nBest match: jupyter-client 7.4.9\nAdding jupyter-client 7.4.9 to easy-install.pth file\nInstalling jupyter-kernel script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\nInstalling jupyter-kernelspec script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\nInstalling jupyter-run script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for jupyter-core==4.12.0\nBest match: jupyter-core 4.12.0\nAdding jupyter-core 4.12.0 to easy-install.pth file\nInstalling jupyter script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\nInstalling jupyter-migrate script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\nInstalling jupyter-troubleshoot script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for python-dateutil==2.9.0.post0\nBest match: python-dateutil 2.9.0.post0\nAdding python-dateutil 2.9.0.post0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for pytz==2024.2\nBest match: pytz 2024.2\nAdding pytz 2024.2 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for typing-extensions==4.7.1\nBest match: typing-extensions 4.7.1\nAdding typing-extensions 4.7.1 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for requests-cache==1.1.1\nBest match: requests-cache 1.1.1\nAdding requests-cache 1.1.1 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for qasync==0.25.0\nBest match: qasync 0.25.0\nAdding qasync 0.25.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for dictdiffer==0.9.0\nBest match: dictdiffer 0.9.0\nAdding dictdiffer 0.9.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for commonmark==0.9.1\nBest match: commonmark 0.9.1\nAdding commonmark 0.9.1 to easy-install.pth file\nInstalling cmark script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for importlib-metadata==6.7.0\nBest match: importlib-metadata 6.7.0\nAdding importlib-metadata 6.7.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for docutils==0.20.1\nBest match: docutils 0.20.1\nAdding docutils 0.20.1 to easy-install.pth file\nInstalling docutils script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for et-xmlfile==1.1.0\nBest match: et-xmlfile 1.1.0\nAdding et-xmlfile 1.1.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for kiwisolver==1.4.5\nBest match: kiwisolver 1.4.5\nAdding kiwisolver 1.4.5 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for Pillow==9.5.0\nBest match: Pillow 9.5.0\nAdding Pillow 9.5.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for cycler==0.11.0\nBest match: cycler 0.11.0\nAdding cycler 0.11.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for pyparsing==3.1.4\nBest match: pyparsing 3.1.4\nAdding pyparsing 3.1.4 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for fonttools==4.38.0\nBest match: fonttools 4.38.0\nAdding fonttools 4.38.0 to easy-install.pth file\nInstalling fonttools script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\nInstalling pyftmerge script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\nInstalling pyftsubset script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\nInstalling ttx script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for jaraco.classes==3.2.3\nBest match: jaraco.classes 3.2.3\nAdding jaraco.classes 3.2.3 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for SecretStorage==3.3.3\nBest match: SecretStorage 3.3.3\nAdding SecretStorage 3.3.3 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for importlib-resources==5.12.0\nBest match: importlib-resources 5.12.0\nAdding importlib-resources 5.12.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for jeepney==0.8.0\nBest match: jeepney 0.8.0\nAdding jeepney 0.8.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for httpcore==0.13.7\nBest match: httpcore 0.13.7\nAdding httpcore 0.13.7 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for rfc3986==1.5.0\nBest match: rfc3986 1.5.0\nAdding rfc3986 1.5.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for sniffio==1.3.1\nBest match: sniffio 1.3.1\nAdding sniffio 1.3.1 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for PyQtWebEngine-Qt5==5.15.16\nBest match: PyQtWebEngine-Qt5 5.15.16\nAdding PyQtWebEngine-Qt5 5.15.16 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for PyQt5-sip==12.13.0\nBest match: PyQt5-sip 12.13.0\nAdding PyQt5-sip 12.13.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for PyQt5-Qt5==5.15.16\nBest match: PyQt5-Qt5 5.15.16\nAdding PyQt5-Qt5 5.15.16 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for ipython==7.34.0\nBest match: ipython 7.34.0\nAdding ipython 7.34.0 to easy-install.pth file\nInstalling iptest script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\nInstalling iptest3 script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\nInstalling ipython script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\nInstalling ipython3 script to /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/bin\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for nest-asyncio==1.6.0\nBest match: nest-asyncio 1.6.0\nAdding nest-asyncio 1.6.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for tornado==6.2\nBest match: tornado 6.2\nAdding tornado 6.2 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for debugpy==1.7.0\nBest match: debugpy 1.7.0\nAdding debugpy 1.7.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for matplotlib-inline==0.1.6\nBest match: matplotlib-inline 0.1.6\nAdding matplotlib-inline 0.1.6 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for psutil==6.1.1\nBest match: psutil 6.1.1\nAdding psutil 6.1.1 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for entrypoints==0.4\nBest match: entrypoints 0.4\nAdding entrypoints 0.4 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for six==1.17.0\nBest match: six 1.17.0\nAdding six 1.17.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for cattrs==23.1.2\nBest match: cattrs 23.1.2\nAdding cattrs 23.1.2 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for url-normalize==1.4.3\nBest match: url-normalize 1.4.3\nAdding url-normalize 1.4.3 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for attrs==24.2.0\nBest match: attrs 24.2.0\nAdding attrs 24.2.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for platformdirs==4.0.0\nBest match: platformdirs 4.0.0\nAdding platformdirs 4.0.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for zipp==3.15.0\nBest match: zipp 3.15.0\nAdding zipp 3.15.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for more-itertools==9.1.0\nBest match: more-itertools 9.1.0\nAdding more-itertools 9.1.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for cryptography==44.0.0\nBest match: cryptography 44.0.0\nAdding cryptography 44.0.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for anyio==3.7.1\nBest match: anyio 3.7.1\nAdding anyio 3.7.1 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for h11==0.12.0\nBest match: h11 0.12.0\nAdding h11 0.12.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for prompt-toolkit==3.0.48\nBest match: prompt-toolkit 3.0.48\nAdding prompt-toolkit 3.0.48 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for pickleshare==0.7.5\nBest match: pickleshare 0.7.5\nAdding pickleshare 0.7.5 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for jedi==0.19.2\nBest match: jedi 0.19.2\nAdding jedi 0.19.2 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for backcall==0.2.0\nBest match: backcall 0.2.0\nAdding backcall 0.2.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for pexpect==4.9.0\nBest match: pexpect 4.9.0\nAdding pexpect 4.9.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for decorator==5.1.1\nBest match: decorator 5.1.1\nAdding decorator 5.1.1 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for exceptiongroup==1.2.2\nBest match: exceptiongroup 1.2.2\nAdding exceptiongroup 1.2.2 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for cffi==1.15.1\nBest match: cffi 1.15.1\nAdding cffi 1.15.1 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for wcwidth==0.2.13\nBest match: wcwidth 0.2.13\nAdding wcwidth 0.2.13 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for parso==0.8.4\nBest match: parso 0.8.4\nAdding parso 0.8.4 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for ptyprocess==0.7.0\nBest match: ptyprocess 0.7.0\nAdding ptyprocess 0.7.0 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nSearching for pycparser==2.21\nBest match: pycparser 2.21\nAdding pycparser 2.21 to easy-install.pth file\n\nUsing /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages\nFinished processing dependencies for Orange3==3.31.0.dev0+c86388c\nVerifying Orange installation...\n✅ Orange installation successful!\nSuccessfully installed orange using Python 3.7\n",
    "setup_res_stderr": "Using CPython 3.7.9\nCreating virtual environment at: .venv\nActivate with: source .venv/bin/activate\nResolved 18 packages in 131ms\nPrepared 18 packages in 1ms\nInstalled 18 packages in 190ms\n + cython==0.29.37\n + exceptiongroup==1.2.2\n + importlib-metadata==6.7.0\n + iniconfig==2.0.0\n + numpy==1.17.5\n + packaging==24.0\n + pluggy==1.2.0\n + pyqt5==5.15.10\n + pyqt5-qt5==5.15.16\n + pyqt5-sip==12.13.0\n + pyqtwebengine==5.15.6\n + pyqtwebengine-qt5==5.15.16\n + pytest==7.4.4\n + setuptools==59.8.0\n + tomli==2.0.1\n + typing-extensions==4.7.1\n + wheel==0.42.0\n + zipp==3.15.0\nResolved 55 packages in 374ms\nInstalled 48 packages in 843ms\n + anyio==3.7.1\n + baycomp==1.0.3\n + bottleneck==1.4.0\n + certifi==2024.12.14\n + cffi==1.15.1\n + chardet==5.2.0\n + charset-normalizer==3.4.1\n + cryptography==44.0.0\n + cycler==0.11.0\n + et-xmlfile==1.1.0\n + fonttools==4.38.0\n + h11==0.12.0\n + httpcore==0.13.7\n + httpx==0.19.0\n + idna==3.10\n + importlib-resources==5.12.0\n + jaraco-classes==3.2.3\n + jeepney==0.8.0\n + joblib==1.3.2\n + keyring==24.1.1\n + keyrings-alt==4.2.0\n + kiwisolver==1.4.5\n + matplotlib==3.5.3\n + more-itertools==9.1.0\n + networkx==2.6.3\n + openpyxl==3.1.3\n + opentsne==1.0.1\n + pandas==1.3.5\n + pillow==9.5.0\n + pip==24.0\n + pycparser==2.21\n + pyparsing==3.1.4\n + python-dateutil==2.9.0.post0\n + python-louvain==0.16\n + pytz==2024.2\n + pyyaml==6.0.1\n + requests==2.31.0\n + rfc3986==1.5.0\n + scikit-learn==1.0.2\n + scipy==1.7.3\n + secretstorage==3.3.3\n + serverfiles==0.3.1\n + six==1.17.0\n + sniffio==1.3.1\n + threadpoolctl==3.1.0\n + urllib3==2.0.7\n + xlrd==2.0.1\n + xlsxwriter==3.2.0\nResolved 59 packages in 297ms\nInstalled 38 packages in 323ms\n + anyqt==0.2.0\n + attrs==24.2.0\n + backcall==0.2.0\n + cattrs==23.1.2\n + commonmark==0.9.1\n + debugpy==1.7.0\n + decorator==5.1.1\n + dictdiffer==0.9.0\n + docutils==0.20.1\n + entrypoints==0.4\n + ipykernel==6.16.2\n + ipython==7.34.0\n + ipython-genutils==0.2.0\n + jedi==0.19.2\n + jupyter-client==7.4.9\n + jupyter-core==4.12.0\n + matplotlib-inline==0.1.6\n + nest-asyncio==1.6.0\n + orange-canvas-core==0.1.35\n + orange-widget-base==4.22.0\n + parso==0.8.4\n + pexpect==4.9.0\n + pickleshare==0.7.5\n + platformdirs==4.0.0\n + prompt-toolkit==3.0.48\n + psutil==6.1.1\n + ptyprocess==0.7.0\n + pygments==2.17.2\n + pyqtgraph==0.12.4\n + pyzmq==26.2.0\n + qasync==0.25.0\n + qtconsole==5.4.4\n + qtpy==2.4.2\n + requests-cache==1.1.1\n + tornado==6.2\n + traitlets==5.9.0\n + url-normalize==1.4.3\n + wcwidth==0.2.13\nResolved 2 packages in 3ms\nInstalled 2 packages in 6ms\n + psycopg2==2.9.9\n + pymssql==2.3.2\nResolved 19 packages in 76ms\nInstalled 5 packages in 1.06s\n + catboost==1.2.7\n + graphviz==0.20.1\n + plotly==5.18.0\n + tenacity==8.2.3\n + xgboost==1.6.2\nAudited 2 packages in 1ms\nIn file included from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1830,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/arrayobject.h:4,\n                 from Orange/classification/_tree_scorers.c:775:\n/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning \"Using deprecated NumPy API, disable it with \" \"#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\" [-Wcpp]\n   17 | #warning \"Using deprecated NumPy API, disable it with \" \\\n      |  ^~~~~~~\nOrange/classification/_tree_scorers.c: In function ‘__pyx_pf_6Orange_14classification_13_tree_scorers_2find_threshold_entropy’:\nOrange/classification/_tree_scorers.c:3427:27: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]\n 3427 |   __pyx_t_7 = ((__pyx_v_N <= __pyx_v_min_leaf) != 0);\n      |                           ^~\nOrange/classification/_tree_scorers.c: In function ‘__pyx_pf_6Orange_14classification_13_tree_scorers_6find_threshold_MSE’:\nOrange/classification/_tree_scorers.c:4883:27: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]\n 4883 |   __pyx_t_1 = ((__pyx_v_N <= __pyx_v_min_leaf) != 0);\n      |                           ^~\nOrange/classification/_tree_scorers.c: In function ‘__pyx_pf_6Orange_14classification_13_tree_scorers_8find_binarization_MSE’:\nOrange/classification/_tree_scorers.c:5629:43: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]\n 5629 |           for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_18; __pyx_t_19+=1) {\n      |                                           ^\nOrange/classification/_tree_scorers.c:5750:39: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]\n 5750 |           __pyx_t_20 = ((__pyx_v_left >= __pyx_v_min_leaf) != 0);\n      |                                       ^~\nOrange/classification/_tree_scorers.c:5756:53: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]\n 5756 |           __pyx_t_20 = (((__pyx_v_N - __pyx_v_left) >= __pyx_v_min_leaf) != 0);\n      |                                                     ^~\nOrange/classification/_tree_scorers.c: In function ‘__pyx_pf_6Orange_14classification_13_tree_scorers_14compute_predictions_csr’:\nOrange/classification/_tree_scorers.c:7217:41: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]\n 7217 |         for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) {\n      |                                         ^\nOrange/classification/_tree_scorers.c: In function ‘__pyx_pf_6Orange_14classification_13_tree_scorers_16compute_predictions_csc’:\nOrange/classification/_tree_scorers.c:7874:41: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]\n 7874 |         for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) {\n      |                                         ^\nOrange/classification/_tree_scorers.c:7934:150: warning: comparison of integer expressions of different signedness: ‘__pyx_t_5numpy_int32_t’ {aka ‘int’} and ‘unsigned int’ [-Wsign-compare]\n 7934 |               __pyx_t_16 = (((*((__pyx_t_5numpy_int32_t const  *) ( /* dim=0 */ (__pyx_v_indices.data + __pyx_t_15 * __pyx_v_indices.strides[0]) ))) != __pyx_v_i) != 0);\n      |                                                                                                                                                      ^~\nIn file included from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1830,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/arrayobject.h:4,\n                 from Orange/data/_contingency.c:775:\n/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning \"Using deprecated NumPy API, disable it with \" \"#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\" [-Wcpp]\n   17 | #warning \"Using deprecated NumPy API, disable it with \" \\\n      |  ^~~~~~~\nOrange/data/_io.c: In function ‘__pyx_pf_6Orange_4data_3_io_sparse_read_float.constprop’:\nOrange/data/_io.c:4120:43: warning: ‘__pyx_v_decs’ may be used uninitialized in this function [-Wmaybe-uninitialized]\n 4120 |           __pyx_v_value = ((__pyx_v_value * __pyx_v_decs) + (__pyx_v_c & 0xf));\n      |                            ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~\nOrange/data/_io.c:4318:24: warning: ‘__pyx_v_value’ may be used uninitialized in this function [-Wmaybe-uninitialized]\n 4318 |           __pyx_t_10 = PyFloat_FromDouble(__pyx_v_value); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 223, __pyx_L5_error)\n      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nOrange/data/_io.c:683:40: warning: ‘__pyx_v_attr_index’ may be used uninitialized in this function [-Wmaybe-uninitialized]\n  683 |   #define PyInt_FromLong               PyLong_FromLong\n      |                                        ^~~~~~~~~~~~~~~\nOrange/data/_io.c:1590:7: note: ‘__pyx_v_attr_index’ was declared here\n 1590 |   int __pyx_v_attr_index;\n      |       ^~~~~~~~~~~~~~~~~~\nOrange/data/_io.c:3183:25: warning: ‘__pyx_v_atomp’ may be used uninitialized in this function [-Wmaybe-uninitialized]\n 3183 |           __pyx_v_atomp = (__pyx_v_atomp + 1);\n      |           ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~\nIn file included from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1830,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/arrayobject.h:4,\n                 from Orange/data/_valuecount.c:775:\n/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning \"Using deprecated NumPy API, disable it with \" \"#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\" [-Wcpp]\n   17 | #warning \"Using deprecated NumPy API, disable it with \" \\\n      |  ^~~~~~~\nIn file included from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1830,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/arrayobject.h:4,\n                 from Orange/distance/_distance.c:775:\n/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning \"Using deprecated NumPy API, disable it with \" \"#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\" [-Wcpp]\n   17 | #warning \"Using deprecated NumPy API, disable it with \" \\\n      |  ^~~~~~~\nIn file included from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1830,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/arrayobject.h:4,\n                 from Orange/preprocess/_discretize.c:774:\n/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning \"Using deprecated NumPy API, disable it with \" \"#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\" [-Wcpp]\n   17 | #warning \"Using deprecated NumPy API, disable it with \" \\\n      |  ^~~~~~~\nIn file included from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1830,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/arrayobject.h:4,\n                 from Orange/preprocess/_relieff.cpp:790:\n/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning \"Using deprecated NumPy API, disable it with \" \"#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\" [-Wcpp]\n   17 | #warning \"Using deprecated NumPy API, disable it with \" \\\n      |  ^~~~~~~\nIn file included from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1830,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,\n                 from /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/arrayobject.h:4,\n                 from Orange/projection/_som.c:775:\n/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning \"Using deprecated NumPy API, disable it with \" \"#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\" [-Wcpp]\n   17 | #warning \"Using deprecated NumPy API, disable it with \" \\\n      |  ^~~~~~~\nOrange/projection/_som.c: In function ‘__pyx_pw_6Orange_10projection_4_som_5update_hex’:\nOrange/projection/_som.c:3863:7: warning: ‘__pyx_v_win_y’ may be used uninitialized in this function [-Wmaybe-uninitialized]\n 3863 |   int __pyx_v_win_y;\n      |       ^~~~~~~~~~~~~\nOrange/projection/_som.c:3862:7: warning: ‘__pyx_v_win_x’ may be used uninitialized in this function [-Wmaybe-uninitialized]\n 3862 |   int __pyx_v_win_x;\n      |       ^~~~~~~~~~~~~\nOrange/projection/_som.c: In function ‘__pyx_pf_6Orange_10projection_4_som_8update_sparse.constprop’:\nOrange/projection/_som.c:4934:7: warning: ‘__pyx_v_win_y’ may be used uninitialized in this function [-Wmaybe-uninitialized]\n 4934 |   int __pyx_v_win_y;\n      |       ^~~~~~~~~~~~~\nOrange/projection/_som.c:4933:7: warning: ‘__pyx_v_win_x’ may be used uninitialized in this function [-Wmaybe-uninitialized]\n 4933 |   int __pyx_v_win_x;\n      |       ^~~~~~~~~~~~~\nOrange/projection/_som.c: In function ‘__pyx_pw_6Orange_10projection_4_som_7get_winners_sparse’:\nOrange/projection/_som.c:4732:223: warning: ‘__pyx_v_win_y’ may be used uninitialized in this function [-Wmaybe-uninitialized]\n 4732 |           *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int16_t *, __pyx_pybuffernd_winners.rcbuffer->pybuffer.buf, __pyx_t_26, __pyx_pybuffernd_winners.diminfo[0].strides, __pyx_t_27, __pyx_pybuffernd_winners.diminfo[1].strides) = __pyx_v_win_y;\n      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~\nOrange/projection/_som.c:4307:7: note: ‘__pyx_v_win_y’ was declared here\n 4307 |   int __pyx_v_win_y;\n      |       ^~~~~~~~~~~~~\nOrange/projection/_som.c:4721:223: warning: ‘__pyx_v_win_x’ may be used uninitialized in this function [-Wmaybe-uninitialized]\n 4721 |           *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int16_t *, __pyx_pybuffernd_winners.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_winners.diminfo[0].strides, __pyx_t_26, __pyx_pybuffernd_winners.diminfo[1].strides) = __pyx_v_win_x;\n      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~\nOrange/projection/_som.c:4306:7: note: ‘__pyx_v_win_x’ was declared here\n 4306 |   int __pyx_v_win_x;\n      |       ^~~~~~~~~~~~~\nOrange/projection/_som.c: In function ‘__pyx_pf_6Orange_10projection_4_som_10update_sparse_hex.constprop’:\nOrange/projection/_som.c:5682:7: warning: ‘__pyx_v_win_y’ may be used uninitialized in this function [-Wmaybe-uninitialized]\n 5682 |   int __pyx_v_win_y;\n      |       ^~~~~~~~~~~~~\nOrange/projection/_som.c:5681:7: warning: ‘__pyx_v_win_x’ may be used uninitialized in this function [-Wmaybe-uninitialized]\n 5681 |   int __pyx_v_win_x;\n      |       ^~~~~~~~~~~~~\nOrange/projection/_som.c: In function ‘__pyx_pw_6Orange_10projection_4_som_1get_winners’:\nOrange/projection/_som.c:3184:223: warning: ‘__pyx_v_win_y’ may be used uninitialized in this function [-Wmaybe-uninitialized]\n 3184 |           *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int16_t *, __pyx_pybuffernd_winners.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_winners.diminfo[0].strides, __pyx_t_23, __pyx_pybuffernd_winners.diminfo[1].strides) = __pyx_v_win_y;\n      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~\nOrange/projection/_som.c:2887:7: note: ‘__pyx_v_win_y’ was declared here\n 2887 |   int __pyx_v_win_y;\n      |       ^~~~~~~~~~~~~\nOrange/projection/_som.c:3173:223: warning: ‘__pyx_v_win_x’ may be used uninitialized in this function [-Wmaybe-uninitialized]\n 3173 |           *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int16_t *, __pyx_pybuffernd_winners.rcbuffer->pybuffer.buf, __pyx_t_23, __pyx_pybuffernd_winners.diminfo[0].strides, __pyx_t_22, __pyx_pybuffernd_winners.diminfo[1].strides) = __pyx_v_win_x;\n      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~\nOrange/projection/_som.c:2886:7: note: ‘__pyx_v_win_x’ was declared here\n 2886 |   int __pyx_v_win_x;\n      |       ^~~~~~~~~~~~~\nOrange/projection/_som.c: In function ‘__pyx_pw_6Orange_10projection_4_som_3update’:\nOrange/projection/_som.c:3357:7: warning: ‘__pyx_v_win_y’ may be used uninitialized in this function [-Wmaybe-uninitialized]\n 3357 |   int __pyx_v_win_y;\n      |       ^~~~~~~~~~~~~\nOrange/classification/_simple_tree.c: In function ‘gain_ratio_c’:\nOrange/classification/_simple_tree.c:63:9: warning: implicit declaration of function ‘qsort_r’; did you mean ‘qsort’? [-Wimplicit-function-declaration]\n   63 |         qsort_r(base, nel, size, compar, thunk)\n      |         ^~~~~~~\nOrange/classification/_simple_tree.c:147:9: note: in expansion of macro ‘QSORT_R_FUNC’\n  147 |         QSORT_R_FUNC(examples, size, sizeof(struct Example), (void*) &compar_attr, compar_examples);\n      |         ^~~~~~~~~~~~\n/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/setuptools/command/easy_install.py:159: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.\n  EasyInstallDeprecationWarning,\n/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/.venv/lib/python3.7/site-packages/setuptools/command/install.py:37: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.\n  setuptools.SetuptoolsDeprecationWarning,\nwarning: no files found matching 'README*' under directory 'Orange'\nwarning: no files found matching 'LICENSE' under directory 'Orange'\nwarning: no files found matching '*.basket' under directory 'Orange/datasets'\nwarning: no files found matching '*.js' under directory 'Orange/widgets'\nwarning: no files found matching '*.css' under directory 'Orange/widgets'\nwarning: no files found matching '*.html' under directory 'Orange/widgets'\nwarning: no files found matching 'COPYING'\n",
    "new_commit_res_code": 1,
    "new_commit_res_stdout": "============================= test session starts ==============================\nplatform linux -- Python 3.7.9, pytest-7.4.4, pluggy-1.2.0\nrootdir: /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda\nplugins: anyio-3.7.1\ncollected 169 items\n\nr2e_tests/test_1.py .................................................... [ 30%]\n...............................................................F........ [ 73%]\n.............................................                            [100%]\n\n=================================== FAILURES ===================================\n________________________ InterfaceTest.test_subclasses _________________________\n\nself = <urllib.request.FileHandler object at 0x78b80f26c390>\nreq = <urllib.request.Request object at 0x78b80743ac10>\n\n    def open_local_file(self, req):\n        import email.utils\n        import mimetypes\n        host = req.host\n        filename = req.selector\n        localfile = url2pathname(filename)\n        try:\n>           stats = os.stat(localfile)\nE           FileNotFoundError: [Errno 2] No such file or directory: '/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/r2e_tests/datasets/test1.tab'\n\n../../../../.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib/python3.7/urllib/request.py:1506: FileNotFoundError\n\nDuring handling of the above exception, another exception occurred:\n\nself = <r2e_tests.test_1.InterfaceTest testMethod=test_subclasses>\n\n    def test_subclasses(self):\n        from pathlib import Path\n    \n        class _ExtendedTable(data.Table):\n            pass\n    \n        data_file = _ExtendedTable('iris')\n        data_url = _ExtendedTable.from_url(\n>           Path(os.path.dirname(__file__), 'datasets/test1.tab').as_uri())\n\nr2e_tests/test_1.py:2169: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \nOrange/data/table.py:1061: in from_url\n    data = reader.read()\nOrange/data/io.py:421: in read\n    self.filename = self._trim(self._resolve_redirects(self.filename))\nOrange/data/io.py:440: in _resolve_redirects\n    with contextlib.closing(self.urlopen(url)) as response:\nOrange/data/io.py:418: in urlopen\n    return urlopen(req, timeout=10)\n../../../../.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib/python3.7/urllib/request.py:222: in urlopen\n    return opener.open(url, data, timeout)\n../../../../.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib/python3.7/urllib/request.py:525: in open\n    response = self._open(req, data)\n../../../../.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib/python3.7/urllib/request.py:543: in _open\n    '_open', req)\n../../../../.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib/python3.7/urllib/request.py:503: in _call_chain\n    result = func(*args)\n../../../../.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib/python3.7/urllib/request.py:1484: in file_open\n    return self.open_local_file(req)\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <urllib.request.FileHandler object at 0x78b80f26c390>\nreq = <urllib.request.Request object at 0x78b80743ac10>\n\n    def open_local_file(self, req):\n        import email.utils\n        import mimetypes\n        host = req.host\n        filename = req.selector\n        localfile = url2pathname(filename)\n        try:\n            stats = os.stat(localfile)\n            size = stats.st_size\n            modified = email.utils.formatdate(stats.st_mtime, usegmt=True)\n            mtype = mimetypes.guess_type(filename)[0]\n            headers = email.message_from_string(\n                'Content-type: %s\\nContent-length: %d\\nLast-modified: %s\\n' %\n                (mtype or 'text/plain', size, modified))\n            if host:\n                host, port = splitport(host)\n            if not host or \\\n                (not port and _safe_gethostbyname(host) in self.get_names()):\n                if host:\n                    origurl = 'file://' + host + filename\n                else:\n                    origurl = 'file://' + filename\n                return addinfourl(open(localfile, 'rb'), headers, origurl)\n        except OSError as exp:\n>           raise URLError(exp)\nE           urllib.error.URLError: <urlopen error [Errno 2] No such file or directory: '/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/r2e_tests/datasets/test1.tab'>\n\n../../../../.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib/python3.7/urllib/request.py:1523: URLError\n==================================== PASSES ====================================\n=========================== short test summary info ============================\nPASSED r2e_tests/test_1.py::test_dirname\nPASSED r2e_tests/test_1.py::TableTestCase::test_assign_multiple_indices_value\nPASSED r2e_tests/test_1.py::TableTestCase::test_assign_slice_value\nPASSED r2e_tests/test_1.py::TableTestCase::test_attributes\nPASSED r2e_tests/test_1.py::TableTestCase::test_bool\nPASSED r2e_tests/test_1.py::TableTestCase::test_checksum\nPASSED r2e_tests/test_1.py::TableTestCase::test_concatenate\nPASSED r2e_tests/test_1.py::TableTestCase::test_concatenate_exceptions\nPASSED r2e_tests/test_1.py::TableTestCase::test_concatenate_sparse\nPASSED r2e_tests/test_1.py::TableTestCase::test_copy\nPASSED r2e_tests/test_1.py::TableTestCase::test_copy_sparse\nPASSED r2e_tests/test_1.py::TableTestCase::test_filename\nPASSED r2e_tests/test_1.py::TableTestCase::test_filter_has_class\nPASSED r2e_tests/test_1.py::TableTestCase::test_filter_is_defined\nPASSED r2e_tests/test_1.py::TableTestCase::test_filter_random\nPASSED r2e_tests/test_1.py::TableTestCase::test_filter_string_works_for_numeric_columns\nPASSED r2e_tests/test_1.py::TableTestCase::test_filter_value_continuous\nPASSED r2e_tests/test_1.py::TableTestCase::test_filter_value_continuous_args\nPASSED r2e_tests/test_1.py::TableTestCase::test_filter_values_nested\nPASSED r2e_tests/test_1.py::TableTestCase::test_from_numpy\nPASSED r2e_tests/test_1.py::TableTestCase::test_has_missing\nPASSED r2e_tests/test_1.py::TableTestCase::test_indexing\nPASSED r2e_tests/test_1.py::TableTestCase::test_indexing_assign_example\nPASSED r2e_tests/test_1.py::TableTestCase::test_indexing_assign_value\nPASSED r2e_tests/test_1.py::TableTestCase::test_indexing_class\nPASSED r2e_tests/test_1.py::TableTestCase::test_indexing_example\nPASSED r2e_tests/test_1.py::TableTestCase::test_inf\nPASSED r2e_tests/test_1.py::TableTestCase::test_is_sparse\nPASSED r2e_tests/test_1.py::TableTestCase::test_multiple_indices\nPASSED r2e_tests/test_1.py::TableTestCase::test_pickle\nPASSED r2e_tests/test_1.py::TableTestCase::test_pickle_setstate\nPASSED r2e_tests/test_1.py::TableTestCase::test_repr_sparse_with_one_row\nPASSED r2e_tests/test_1.py::TableTestCase::test_saveTab\nPASSED r2e_tests/test_1.py::TableTestCase::test_save_pickle\nPASSED r2e_tests/test_1.py::TableTestCase::test_set_multiple_indices_example\nPASSED r2e_tests/test_1.py::TableTestCase::test_shuffle\nPASSED r2e_tests/test_1.py::TableTestCase::test_slice\nPASSED r2e_tests/test_1.py::TableTestCase::test_table_dtypes\nPASSED r2e_tests/test_1.py::TableTestCase::test_total_weight\nPASSED r2e_tests/test_1.py::TableTestCase::test_translate_through_slice\nPASSED r2e_tests/test_1.py::TableTestCase::test_valueFilter_discrete\nPASSED r2e_tests/test_1.py::TableTestCase::test_valueFilter_discrete_meta_is_defined\nPASSED r2e_tests/test_1.py::TableTestCase::test_valueFilter_regex\nPASSED r2e_tests/test_1.py::TableTestCase::test_valueFilter_stringList\nPASSED r2e_tests/test_1.py::TableTestCase::test_valueFilter_string_case_insens\nPASSED r2e_tests/test_1.py::TableTestCase::test_valueFilter_string_case_sens\nPASSED r2e_tests/test_1.py::TableTestCase::test_valueFilter_string_is_defined\nPASSED r2e_tests/test_1.py::CreateEmptyTable::test_calling_new_with_no_parameters_constructs_a_new_instance\nPASSED r2e_tests/test_1.py::CreateEmptyTable::test_table_has_file\nPASSED r2e_tests/test_1.py::CreateTableWithFilename::test_calling_new_with_keyword_argument_filename_calls_read_data\nPASSED r2e_tests/test_1.py::CreateTableWithFilename::test_calling_new_with_string_argument_calls_read_data\nPASSED r2e_tests/test_1.py::CreateTableWithFilename::test_raises_error_if_file_does_not_exist\nPASSED r2e_tests/test_1.py::CreateTableWithFilename::test_raises_error_if_file_has_unknown_extension\nPASSED r2e_tests/test_1.py::CreateTableWithFilename::test_read_data_calls_reader\nPASSED r2e_tests/test_1.py::CreateTableWithUrl::test_trimmed_urls\nPASSED r2e_tests/test_1.py::CreateTableWithUrl::test_url_no_scheme\nPASSED r2e_tests/test_1.py::CreateTableWithDomain::test_calling_new_with_domain_calls_new_from_domain\nPASSED r2e_tests/test_1.py::CreateTableWithDomain::test_creates_an_empty_table_with_given_domain\nPASSED r2e_tests/test_1.py::CreateTableWithDomain::test_creates_weights_if_weights_are_true\nPASSED r2e_tests/test_1.py::CreateTableWithDomain::test_creates_zero_filled_rows_in_X_if_domain_contains_attributes\nPASSED r2e_tests/test_1.py::CreateTableWithDomain::test_creates_zero_filled_rows_in_Y_if_domain_contains_class_vars\nPASSED r2e_tests/test_1.py::CreateTableWithDomain::test_creates_zero_filled_rows_in_metas_if_domain_contains_metas\nPASSED r2e_tests/test_1.py::CreateTableWithDomain::test_does_not_create_weights_if_weights_are_false\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_calling_new_with_domain_and_numpy_arrays_calls_new_from_numpy\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_creates_a_discrete_class_if_Y_has_few_distinct_values\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_creates_a_table_from_domain_and_list\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_creates_a_table_from_domain_and_list_and_metas\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_creates_a_table_from_domain_and_list_and_weights\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_creates_a_table_from_list_of_instances\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_creates_a_table_from_list_of_instances_with_metas\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_creates_a_table_with_domain_and_given_X\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_creates_a_table_with_given_X\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_creates_a_table_with_given_X_Y_and_metas\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_creates_a_table_with_given_X_and_Y\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_creates_a_table_with_given_domain\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_from_numpy_reconstructable\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_initializes_Y_metas_and_W_if_not_given\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_raises_error_if_columns_in_domain_and_data_do_not_match\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_raises_error_if_lengths_of_data_do_not_match\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_sets_Y_if_given\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_sets_metas_if_given\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_sets_weights_if_given\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_splits_X_and_Y_if_given_in_same_array\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_can_copy_table\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_can_filter_row_with_slice_from_table\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_can_filter_row_with_slice_from_table_rows\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_can_filter_rows_with_list\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_can_use_attributes_as_new_columns\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_can_use_class_vars_as_new_columns\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_can_use_combination_of_all_as_new_columns\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_can_use_metas_as_new_columns\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_creates_table_with_given_domain\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_creates_table_with_given_domain_and_row_filter\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_from_table_shared_compute_value\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_from_table_sparse_move_all_to_empty_metas\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_from_table_sparse_move_some_to_empty_metas\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_from_table_sparse_move_to_nonempty_metas\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_transform\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_transform_same_domain\nPASSED r2e_tests/test_1.py::TableIndexingTests::test_can_select_a_single_row\nPASSED r2e_tests/test_1.py::TableIndexingTests::test_can_select_a_single_value\nPASSED r2e_tests/test_1.py::TableIndexingTests::test_can_select_a_subset_of_rows_and_columns\nPASSED r2e_tests/test_1.py::TableIndexingTests::test_optimize_indices\nPASSED r2e_tests/test_1.py::TableElementAssignmentTest::test_can_assign_lists\nPASSED r2e_tests/test_1.py::TableElementAssignmentTest::test_can_assign_np_array\nPASSED r2e_tests/test_1.py::TableElementAssignmentTest::test_can_assign_rows_to_rows\nPASSED r2e_tests/test_1.py::TableElementAssignmentTest::test_can_assign_values\nPASSED r2e_tests/test_1.py::TableElementAssignmentTest::test_can_assign_values_to_classes\nPASSED r2e_tests/test_1.py::TableElementAssignmentTest::test_can_assign_values_to_metas\nPASSED r2e_tests/test_1.py::InterfaceTest::test_iteration\nPASSED r2e_tests/test_1.py::InterfaceTest::test_len\nPASSED r2e_tests/test_1.py::InterfaceTest::test_row_assignment\nPASSED r2e_tests/test_1.py::InterfaceTest::test_row_indexing\nPASSED r2e_tests/test_1.py::InterfaceTest::test_row_len\nPASSED r2e_tests/test_1.py::InterfaceTest::test_row_slicing\nPASSED r2e_tests/test_1.py::InterfaceTest::test_value_assignment\nPASSED r2e_tests/test_1.py::InterfaceTest::test_value_indexing\nPASSED r2e_tests/test_1.py::TestTableStats::test_get_nan_frequency\nPASSED r2e_tests/test_1.py::TestTableStats::test_get_nan_frequency_empty_table\nPASSED r2e_tests/test_1.py::TestRowInstance::test_assignment\nPASSED r2e_tests/test_1.py::TestRowInstance::test_iteration_with_assignment\nPASSED r2e_tests/test_1.py::TestRowInstance::test_sparse_assignment\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_attributes_of_attributes_continuous\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_attributes_of_attributes_continuous_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_attributes_of_attributes_discrete\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_attributes_of_attributes_discrete_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_attributes_of_attributes_missings\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_attributes_of_attributes_missings_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_callback\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_class_and_metas\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_class_and_metas_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_class_metas_attributes\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_class_metas_attributes_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_continuous_class\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_continuous_class_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_continuous_metas\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_continuous_metas_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_discrete_class\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_discrete_class_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_discrete_metas\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_discrete_metas_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_duplicate_feature_names\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_metas\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_metas_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_missing_class\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_missing_class_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_missing_metas\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_missing_metas_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_multiple_class\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_multiple_class_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_multiple_metas\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_multiple_metas_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_no_class\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_no_class_remove_inst\nPASSED r2e_tests/test_1.py::TestTableSparseDense::test_from_table_add_lots_of_sparse_columns\nPASSED r2e_tests/test_1.py::TestTableSparseDense::test_from_table_add_one_sparse_column\nPASSED r2e_tests/test_1.py::TestTableSparseDense::test_from_table_replace_attrs_with_sparse\nPASSED r2e_tests/test_1.py::TestTableSparseDense::test_from_table_sparse_metas\nPASSED r2e_tests/test_1.py::TestTableSparseDense::test_from_table_sparse_metas_with_strings\nPASSED r2e_tests/test_1.py::TestTableSparseDense::test_sparse_dense_transformation\nPASSED r2e_tests/test_1.py::ConcurrencyTests::test_from_table_non_blocking\nPASSED r2e_tests/test_1.py::EfficientTransformTests::test_shared\nPASSED r2e_tests/test_1.py::EfficientTransformTests::test_simple\nPASSED r2e_tests/test_1.py::EfficientTransformTests::test_simple_simple_shared\nPASSED r2e_tests/test_1.py::EfficientTransformTests::test_simple_simple_shared_simple\nPASSED r2e_tests/test_1.py::EfficientTransformTests::test_simple_simple_shared_simple_shared_simple\nPASSED r2e_tests/test_1.py::EfficientTransformTests::test_simple_simple_stupid\nFAILED r2e_tests/test_1.py::InterfaceTest::test_subclasses - urllib.error.URL...\n======================== 1 failed, 168 passed in 3.18s =========================\n",
    "new_commit_res_stderr": "",
    "old_commit_res_code": 1,
    "old_commit_res_stdout": "============================= test session starts ==============================\nplatform linux -- Python 3.7.9, pytest-7.4.4, pluggy-1.2.0\nrootdir: /home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda\nplugins: anyio-3.7.1\ncollected 169 items\n\nr2e_tests/test_1.py ..............................F..................... [ 30%]\n...............................................................F........ [ 73%]\n.............................................                            [100%]\n\n=================================== FAILURES ===================================\n______________________ TableTestCase.test_pickle_setstate ______________________\n\nself = <r2e_tests.test_1.TableTestCase testMethod=test_pickle_setstate>\n\n    def test_pickle_setstate(self):\n        d = data.Table(\"zoo\")\n        s = pickle.dumps(d)\n        with patch(\"Orange.data.Table.__setstate__\", Mock()) as mock:\n            pickle.loads(s)\n            state = mock.call_args[0][0]\n            for k in [\"X\", \"_Y\", \"metas\"]:\n>               self.assertIn(k, state)\nE               AssertionError: 'X' not found in {'_unlocked': 0, 'domain': [hair, feathers, eggs, milk, airborne, aquatic, predator, toothed, backbone, breathes, venomous, fins, legs, tail, domestic, catsize | type] {name}, '_X': array([[1., 0., 0., ..., 0., 0., 1.],\nE                      [1., 0., 0., ..., 1., 0., 1.],\nE                      [0., 0., 1., ..., 1., 0., 0.],\nE                      ...,\nE                      [1., 0., 0., ..., 1., 0., 1.],\nE                      [0., 0., 1., ..., 0., 0., 0.],\nE                      [0., 1., 1., ..., 1., 0., 0.]]), '_Y': array([5., 5., 2., 5., 5., 5., 5., 2., 2., 5., 5., 1., 2., 4., 4., 4., 1.,\nE                      5., 2., 5., 1., 1., 5., 1., 3., 0., 0., 5., 5., 5., 3., 5., 5., 1.,\nE                      2., 5., 5., 1., 2., 3., 3., 1., 3., 1., 5., 5., 4., 5., 5., 5., 5.,\nE                      3., 0., 4., 5., 5., 1., 1., 1., 1., 2., 2., 6., 5., 5., 5., 5., 5.,\nE                      5., 5., 5., 1., 4., 2., 5., 5., 6., 4., 1., 1., 6., 4., 2., 1., 5.,\nE                      4., 2., 1., 3., 0., 6., 6., 2., 5., 5., 1., 5., 3., 5., 4., 1.]), '_metas': array([['aardvark'],\nE                      ['antelope'],\nE                      ['bass'],\nE                      ['bear'],\nE                      ['boar'],\nE                      ['buffalo'],\nE                      ['calf'],\nE                      ['carp'],\nE                      ['catfish'],\nE                      ['cavy'],\nE                      ['cheetah'],\nE                      ['chicken'],\nE                      ['chub'],\nE                      ['clam'],\nE                      ['crab'],\nE                      ['crayfish'],\nE                      ['crow'],\nE                      ['deer'],\nE                      ['dogfish'],\nE                      ['dolphin'],\nE                      ['dove'],\nE                      ['duck'],\nE                      ['elephant'],\nE                      ['flamingo'],\nE                      ['flea'],\nE                      ['frog'],\nE                      ['frog'],\nE                      ['fruitbat'],\nE                      ['giraffe'],\nE                      ['girl'],\nE                      ['gnat'],\nE                      ['goat'],\nE                      ['gorilla'],\nE                      ['gull'],\nE                      ['haddock'],\nE                      ['hamster'],\nE                      ['hare'],\nE                      ['hawk'],\nE                      ['herring'],\nE                      ['honeybee'],\nE                      ['housefly'],\nE                      ['kiwi'],\nE                      ['ladybird'],\nE                      ['lark'],\nE                      ['leopard'],\nE                      ['lion'],\nE                      ['lobster'],\nE                      ['lynx'],\nE                      ['mink'],\nE                      ['mole'],\nE                      ['mongoose'],\nE                      ['moth'],\nE                      ['newt'],\nE                      ['octopus'],\nE                      ['opossum'],\nE                      ['oryx'],\nE                      ['ostrich'],\nE                      ['parakeet'],\nE                      ['penguin'],\nE                      ['pheasant'],\nE                      ['pike'],\nE                      ['piranha'],\nE                      ['pitviper'],\nE                      ['platypus'],\nE                      ['polecat'],\nE                      ['pony'],\nE                      ['porpoise'],\nE                      ['puma'],\nE                      ['pussycat'],\nE                      ['raccoon'],\nE                      ['reindeer'],\nE                      ['rhea'],\nE                      ['scorpion'],\nE                      ['seahorse'],\nE                      ['seal'],\nE                      ['sealion'],\nE                      ['seasnake'],\nE                      ['seawasp'],\nE                      ['skimmer'],\nE                      ['skua'],\nE                      ['slowworm'],\nE                      ['slug'],\nE                      ['sole'],\nE                      ['sparrow'],\nE                      ['squirrel'],\nE                      ['starfish'],\nE                      ['stingray'],\nE                      ['swan'],\nE                      ['termite'],\nE                      ['toad'],\nE                      ['tortoise'],\nE                      ['tuatara'],\nE                      ['tuna'],\nE                      ['vampire'],\nE                      ['vole'],\nE                      ['vulture'],\nE                      ['wallaby'],\nE                      ['wasp'],\nE                      ['wolf'],\nE                      ['worm'],\nE                      ['wren']], dtype=object), '_W': array([], shape=(101, 0), dtype=float64), 'n_rows': 101, 'ids': array([3093, 3094, 3095, 3096, 3097, 3098, 3099, 3100, 3101, 3102, 3103,\nE                      3104, 3105, 3106, 3107, 3108, 3109, 3110, 3111, 3112, 3113, 3114,\nE                      3115, 3116, 3117, 3118, 3119, 3120, 3121, 3122, 3123, 3124, 3125,\nE                      3126, 3127, 3128, 3129, 3130, 3131, 3132, 3133, 3134, 3135, 3136,\nE                      3137, 3138, 3139, 3140, 3141, 3142, 3143, 3144, 3145, 3146, 3147,\nE                      3148, 3149, 3150, 3151, 3152, 3153, 3154, 3155, 3156, 3157, 3158,\nE                      3159, 3160, 3161, 3162, 3163, 3164, 3165, 3166, 3167, 3168, 3169,\nE                      3170, 3171, 3172, 3173, 3174, 3175, 3176, 3177, 3178, 3179, 3180,\nE                      3181, 3182, 3183, 3184, 3185, 3186, 3187, 3188, 3189, 3190, 3191,\nE                      3192, 3193]), 'attributes': OrderedDict([('Name', 'Zoo dataset'), ('Description', 'This dataset consists of 101 animals with various traits to describe them.'), ('Author', 'Richard Forsyth'), ('Year', '1990')]), 'name': 'zoo', '__file__': '/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/Orange/datasets/zoo.tab'}\n\nr2e_tests/test_1.py:617: AssertionError\n________________________ InterfaceTest.test_subclasses _________________________\n\nself = <urllib.request.FileHandler object at 0x7b6283b5e990>\nreq = <urllib.request.Request object at 0x7b6283b44450>\n\n    def open_local_file(self, req):\n        import email.utils\n        import mimetypes\n        host = req.host\n        filename = req.selector\n        localfile = url2pathname(filename)\n        try:\n>           stats = os.stat(localfile)\nE           FileNotFoundError: [Errno 2] No such file or directory: '/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/r2e_tests/datasets/test1.tab'\n\n../../../../.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib/python3.7/urllib/request.py:1506: FileNotFoundError\n\nDuring handling of the above exception, another exception occurred:\n\nself = <r2e_tests.test_1.InterfaceTest testMethod=test_subclasses>\n\n    def test_subclasses(self):\n        from pathlib import Path\n    \n        class _ExtendedTable(data.Table):\n            pass\n    \n        data_file = _ExtendedTable('iris')\n        data_url = _ExtendedTable.from_url(\n>           Path(os.path.dirname(__file__), 'datasets/test1.tab').as_uri())\n\nr2e_tests/test_1.py:2169: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \nOrange/data/table.py:1045: in from_url\n    data = reader.read()\nOrange/data/io.py:421: in read\n    self.filename = self._trim(self._resolve_redirects(self.filename))\nOrange/data/io.py:440: in _resolve_redirects\n    with contextlib.closing(self.urlopen(url)) as response:\nOrange/data/io.py:418: in urlopen\n    return urlopen(req, timeout=10)\n../../../../.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib/python3.7/urllib/request.py:222: in urlopen\n    return opener.open(url, data, timeout)\n../../../../.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib/python3.7/urllib/request.py:525: in open\n    response = self._open(req, data)\n../../../../.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib/python3.7/urllib/request.py:543: in _open\n    '_open', req)\n../../../../.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib/python3.7/urllib/request.py:503: in _call_chain\n    result = func(*args)\n../../../../.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib/python3.7/urllib/request.py:1484: in file_open\n    return self.open_local_file(req)\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <urllib.request.FileHandler object at 0x7b6283b5e990>\nreq = <urllib.request.Request object at 0x7b6283b44450>\n\n    def open_local_file(self, req):\n        import email.utils\n        import mimetypes\n        host = req.host\n        filename = req.selector\n        localfile = url2pathname(filename)\n        try:\n            stats = os.stat(localfile)\n            size = stats.st_size\n            modified = email.utils.formatdate(stats.st_mtime, usegmt=True)\n            mtype = mimetypes.guess_type(filename)[0]\n            headers = email.message_from_string(\n                'Content-type: %s\\nContent-length: %d\\nLast-modified: %s\\n' %\n                (mtype or 'text/plain', size, modified))\n            if host:\n                host, port = splitport(host)\n            if not host or \\\n                (not port and _safe_gethostbyname(host) in self.get_names()):\n                if host:\n                    origurl = 'file://' + host + filename\n                else:\n                    origurl = 'file://' + filename\n                return addinfourl(open(localfile, 'rb'), headers, origurl)\n        except OSError as exp:\n>           raise URLError(exp)\nE           urllib.error.URLError: <urlopen error [Errno 2] No such file or directory: '/home/gcpuser/buckets/local_repoeval_bucket/repos/orange3_c86388cdfa52cb5be7ea27e2713cc4e38e115dda/r2e_tests/datasets/test1.tab'>\n\n../../../../.local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/lib/python3.7/urllib/request.py:1523: URLError\n==================================== PASSES ====================================\n=========================== short test summary info ============================\nPASSED r2e_tests/test_1.py::test_dirname\nPASSED r2e_tests/test_1.py::TableTestCase::test_assign_multiple_indices_value\nPASSED r2e_tests/test_1.py::TableTestCase::test_assign_slice_value\nPASSED r2e_tests/test_1.py::TableTestCase::test_attributes\nPASSED r2e_tests/test_1.py::TableTestCase::test_bool\nPASSED r2e_tests/test_1.py::TableTestCase::test_checksum\nPASSED r2e_tests/test_1.py::TableTestCase::test_concatenate\nPASSED r2e_tests/test_1.py::TableTestCase::test_concatenate_exceptions\nPASSED r2e_tests/test_1.py::TableTestCase::test_concatenate_sparse\nPASSED r2e_tests/test_1.py::TableTestCase::test_copy\nPASSED r2e_tests/test_1.py::TableTestCase::test_copy_sparse\nPASSED r2e_tests/test_1.py::TableTestCase::test_filename\nPASSED r2e_tests/test_1.py::TableTestCase::test_filter_has_class\nPASSED r2e_tests/test_1.py::TableTestCase::test_filter_is_defined\nPASSED r2e_tests/test_1.py::TableTestCase::test_filter_random\nPASSED r2e_tests/test_1.py::TableTestCase::test_filter_string_works_for_numeric_columns\nPASSED r2e_tests/test_1.py::TableTestCase::test_filter_value_continuous\nPASSED r2e_tests/test_1.py::TableTestCase::test_filter_value_continuous_args\nPASSED r2e_tests/test_1.py::TableTestCase::test_filter_values_nested\nPASSED r2e_tests/test_1.py::TableTestCase::test_from_numpy\nPASSED r2e_tests/test_1.py::TableTestCase::test_has_missing\nPASSED r2e_tests/test_1.py::TableTestCase::test_indexing\nPASSED r2e_tests/test_1.py::TableTestCase::test_indexing_assign_example\nPASSED r2e_tests/test_1.py::TableTestCase::test_indexing_assign_value\nPASSED r2e_tests/test_1.py::TableTestCase::test_indexing_class\nPASSED r2e_tests/test_1.py::TableTestCase::test_indexing_example\nPASSED r2e_tests/test_1.py::TableTestCase::test_inf\nPASSED r2e_tests/test_1.py::TableTestCase::test_is_sparse\nPASSED r2e_tests/test_1.py::TableTestCase::test_multiple_indices\nPASSED r2e_tests/test_1.py::TableTestCase::test_pickle\nPASSED r2e_tests/test_1.py::TableTestCase::test_repr_sparse_with_one_row\nPASSED r2e_tests/test_1.py::TableTestCase::test_saveTab\nPASSED r2e_tests/test_1.py::TableTestCase::test_save_pickle\nPASSED r2e_tests/test_1.py::TableTestCase::test_set_multiple_indices_example\nPASSED r2e_tests/test_1.py::TableTestCase::test_shuffle\nPASSED r2e_tests/test_1.py::TableTestCase::test_slice\nPASSED r2e_tests/test_1.py::TableTestCase::test_table_dtypes\nPASSED r2e_tests/test_1.py::TableTestCase::test_total_weight\nPASSED r2e_tests/test_1.py::TableTestCase::test_translate_through_slice\nPASSED r2e_tests/test_1.py::TableTestCase::test_valueFilter_discrete\nPASSED r2e_tests/test_1.py::TableTestCase::test_valueFilter_discrete_meta_is_defined\nPASSED r2e_tests/test_1.py::TableTestCase::test_valueFilter_regex\nPASSED r2e_tests/test_1.py::TableTestCase::test_valueFilter_stringList\nPASSED r2e_tests/test_1.py::TableTestCase::test_valueFilter_string_case_insens\nPASSED r2e_tests/test_1.py::TableTestCase::test_valueFilter_string_case_sens\nPASSED r2e_tests/test_1.py::TableTestCase::test_valueFilter_string_is_defined\nPASSED r2e_tests/test_1.py::CreateEmptyTable::test_calling_new_with_no_parameters_constructs_a_new_instance\nPASSED r2e_tests/test_1.py::CreateEmptyTable::test_table_has_file\nPASSED r2e_tests/test_1.py::CreateTableWithFilename::test_calling_new_with_keyword_argument_filename_calls_read_data\nPASSED r2e_tests/test_1.py::CreateTableWithFilename::test_calling_new_with_string_argument_calls_read_data\nPASSED r2e_tests/test_1.py::CreateTableWithFilename::test_raises_error_if_file_does_not_exist\nPASSED r2e_tests/test_1.py::CreateTableWithFilename::test_raises_error_if_file_has_unknown_extension\nPASSED r2e_tests/test_1.py::CreateTableWithFilename::test_read_data_calls_reader\nPASSED r2e_tests/test_1.py::CreateTableWithUrl::test_trimmed_urls\nPASSED r2e_tests/test_1.py::CreateTableWithUrl::test_url_no_scheme\nPASSED r2e_tests/test_1.py::CreateTableWithDomain::test_calling_new_with_domain_calls_new_from_domain\nPASSED r2e_tests/test_1.py::CreateTableWithDomain::test_creates_an_empty_table_with_given_domain\nPASSED r2e_tests/test_1.py::CreateTableWithDomain::test_creates_weights_if_weights_are_true\nPASSED r2e_tests/test_1.py::CreateTableWithDomain::test_creates_zero_filled_rows_in_X_if_domain_contains_attributes\nPASSED r2e_tests/test_1.py::CreateTableWithDomain::test_creates_zero_filled_rows_in_Y_if_domain_contains_class_vars\nPASSED r2e_tests/test_1.py::CreateTableWithDomain::test_creates_zero_filled_rows_in_metas_if_domain_contains_metas\nPASSED r2e_tests/test_1.py::CreateTableWithDomain::test_does_not_create_weights_if_weights_are_false\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_calling_new_with_domain_and_numpy_arrays_calls_new_from_numpy\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_creates_a_discrete_class_if_Y_has_few_distinct_values\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_creates_a_table_from_domain_and_list\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_creates_a_table_from_domain_and_list_and_metas\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_creates_a_table_from_domain_and_list_and_weights\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_creates_a_table_from_list_of_instances\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_creates_a_table_from_list_of_instances_with_metas\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_creates_a_table_with_domain_and_given_X\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_creates_a_table_with_given_X\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_creates_a_table_with_given_X_Y_and_metas\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_creates_a_table_with_given_X_and_Y\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_creates_a_table_with_given_domain\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_from_numpy_reconstructable\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_initializes_Y_metas_and_W_if_not_given\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_raises_error_if_columns_in_domain_and_data_do_not_match\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_raises_error_if_lengths_of_data_do_not_match\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_sets_Y_if_given\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_sets_metas_if_given\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_sets_weights_if_given\nPASSED r2e_tests/test_1.py::CreateTableWithData::test_splits_X_and_Y_if_given_in_same_array\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_can_copy_table\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_can_filter_row_with_slice_from_table\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_can_filter_row_with_slice_from_table_rows\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_can_filter_rows_with_list\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_can_use_attributes_as_new_columns\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_can_use_class_vars_as_new_columns\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_can_use_combination_of_all_as_new_columns\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_can_use_metas_as_new_columns\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_creates_table_with_given_domain\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_creates_table_with_given_domain_and_row_filter\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_from_table_shared_compute_value\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_from_table_sparse_move_all_to_empty_metas\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_from_table_sparse_move_some_to_empty_metas\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_from_table_sparse_move_to_nonempty_metas\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_transform\nPASSED r2e_tests/test_1.py::CreateTableWithDomainAndTable::test_transform_same_domain\nPASSED r2e_tests/test_1.py::TableIndexingTests::test_can_select_a_single_row\nPASSED r2e_tests/test_1.py::TableIndexingTests::test_can_select_a_single_value\nPASSED r2e_tests/test_1.py::TableIndexingTests::test_can_select_a_subset_of_rows_and_columns\nPASSED r2e_tests/test_1.py::TableIndexingTests::test_optimize_indices\nPASSED r2e_tests/test_1.py::TableElementAssignmentTest::test_can_assign_lists\nPASSED r2e_tests/test_1.py::TableElementAssignmentTest::test_can_assign_np_array\nPASSED r2e_tests/test_1.py::TableElementAssignmentTest::test_can_assign_rows_to_rows\nPASSED r2e_tests/test_1.py::TableElementAssignmentTest::test_can_assign_values\nPASSED r2e_tests/test_1.py::TableElementAssignmentTest::test_can_assign_values_to_classes\nPASSED r2e_tests/test_1.py::TableElementAssignmentTest::test_can_assign_values_to_metas\nPASSED r2e_tests/test_1.py::InterfaceTest::test_iteration\nPASSED r2e_tests/test_1.py::InterfaceTest::test_len\nPASSED r2e_tests/test_1.py::InterfaceTest::test_row_assignment\nPASSED r2e_tests/test_1.py::InterfaceTest::test_row_indexing\nPASSED r2e_tests/test_1.py::InterfaceTest::test_row_len\nPASSED r2e_tests/test_1.py::InterfaceTest::test_row_slicing\nPASSED r2e_tests/test_1.py::InterfaceTest::test_value_assignment\nPASSED r2e_tests/test_1.py::InterfaceTest::test_value_indexing\nPASSED r2e_tests/test_1.py::TestTableStats::test_get_nan_frequency\nPASSED r2e_tests/test_1.py::TestTableStats::test_get_nan_frequency_empty_table\nPASSED r2e_tests/test_1.py::TestRowInstance::test_assignment\nPASSED r2e_tests/test_1.py::TestRowInstance::test_iteration_with_assignment\nPASSED r2e_tests/test_1.py::TestRowInstance::test_sparse_assignment\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_attributes_of_attributes_continuous\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_attributes_of_attributes_continuous_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_attributes_of_attributes_discrete\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_attributes_of_attributes_discrete_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_attributes_of_attributes_missings\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_attributes_of_attributes_missings_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_callback\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_class_and_metas\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_class_and_metas_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_class_metas_attributes\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_class_metas_attributes_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_continuous_class\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_continuous_class_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_continuous_metas\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_continuous_metas_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_discrete_class\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_discrete_class_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_discrete_metas\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_discrete_metas_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_duplicate_feature_names\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_metas\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_metas_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_missing_class\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_missing_class_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_missing_metas\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_missing_metas_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_multiple_class\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_multiple_class_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_multiple_metas\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_multiple_metas_remove_inst\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_no_class\nPASSED r2e_tests/test_1.py::TestTableTranspose::test_transpose_no_class_remove_inst\nPASSED r2e_tests/test_1.py::TestTableSparseDense::test_from_table_add_lots_of_sparse_columns\nPASSED r2e_tests/test_1.py::TestTableSparseDense::test_from_table_add_one_sparse_column\nPASSED r2e_tests/test_1.py::TestTableSparseDense::test_from_table_replace_attrs_with_sparse\nPASSED r2e_tests/test_1.py::TestTableSparseDense::test_from_table_sparse_metas\nPASSED r2e_tests/test_1.py::TestTableSparseDense::test_from_table_sparse_metas_with_strings\nPASSED r2e_tests/test_1.py::TestTableSparseDense::test_sparse_dense_transformation\nPASSED r2e_tests/test_1.py::ConcurrencyTests::test_from_table_non_blocking\nPASSED r2e_tests/test_1.py::EfficientTransformTests::test_shared\nPASSED r2e_tests/test_1.py::EfficientTransformTests::test_simple\nPASSED r2e_tests/test_1.py::EfficientTransformTests::test_simple_simple_shared\nPASSED r2e_tests/test_1.py::EfficientTransformTests::test_simple_simple_shared_simple\nPASSED r2e_tests/test_1.py::EfficientTransformTests::test_simple_simple_shared_simple_shared_simple\nPASSED r2e_tests/test_1.py::EfficientTransformTests::test_simple_simple_stupid\nFAILED r2e_tests/test_1.py::TableTestCase::test_pickle_setstate - AssertionEr...\nFAILED r2e_tests/test_1.py::InterfaceTest::test_subclasses - urllib.error.URL...\n======================== 2 failed, 167 passed in 3.33s =========================\n",
    "old_commit_res_stderr": ""
}
Orange/data/table.py Orange/tests/test_table.py
We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[ISSUE]
**Title:** Unpickling Table Fails to Restore 'X' Attribute in State

**Description:**
When unpickling a `Table` object, the internal state does not include the 'X' attribute. This omission causes the deserialized `Table` to lack essential data, leading to inconsistencies and potential errors in subsequent operations.

**Example Buggy Code:**
```python
import pickle
from unittest.mock import patch, Mock

def test_pickle_setstate():
    d = data.Table("zoo")
    s = pickle.dumps(d)
    with patch("Orange.data.Table.__setstate__", Mock()) as mock:
        pickle.loads(s)
        state = mock.call_args[0][0]
        # 'X' is expected to be in the state but is missing
```

**Expected Behavior:**
After unpickling, the `Table`'s internal state should include the 'X' attribute as a 2D array along with other attributes like '_Y' and 'metas'. This ensures that all necessary data is correctly restored and the `Table` functions as intended.

**Actual Behavior:**
The 'X' attribute is absent from the internal state during the unpickling process. This leads to the `Table` object missing crucial data, which can cause failures in operations that rely on the 'X' attribute.

[/ISSUE]
--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.

--- BEGIN FILE ---
```
### Orange/data/table.py
import operator
import os
import sys
import threading
import warnings
import weakref
import zlib
from collections.abc import Iterable, Sequence, Sized
from contextlib import contextmanager
from functools import reduce
from itertools import chain
from numbers import Real, Integral
from threading import Lock

import bottleneck as bn
import numpy as np

from scipy import sparse as sp
from scipy.sparse import issparse, csc_matrix

import Orange.data  # import for io.py
from Orange.data import (
    _contingency, _valuecount,
    Domain, Variable, Storage, StringVariable, Unknown, Value, Instance,
    ContinuousVariable, DiscreteVariable, MISSING_VALUES,
    DomainConversion)
from Orange.data.util import SharedComputeValue, \
    assure_array_dense, assure_array_sparse, \
    assure_column_dense, assure_column_sparse, get_unique_names_duplicates
from Orange.misc.collections import frozendict
from Orange.statistics.util import bincount, countnans, contingency, \
    stats as fast_stats, sparse_has_implicit_zeros, sparse_count_implicit_zeros, \
    sparse_implicit_zero_weights
from Orange.util import OrangeDeprecationWarning, dummy_callback

__all__ = ["dataset_dirs", "get_sample_datasets_dir", "RowInstance", "Table"]


def get_sample_datasets_dir():
    orange_data_table = os.path.dirname(__file__)
    dataset_dir = os.path.join(orange_data_table, '..', 'datasets')
    return os.path.realpath(dataset_dir)


dataset_dirs = ['', get_sample_datasets_dir()]


class _ThreadLocal(threading.local):
    def __init__(self):
        super().__init__()
        # Domain conversion cache used in Table.from_table. It is defined
        # here instead of as a class variable of a Table so that caching also works
        # with descendants of Table.
        self.conversion_cache = None
        self.domain_cache = None


_thread_local = _ThreadLocal()


def _idcache_save(cachedict, keys, value):
    cachedict[tuple(map(id, keys))] = \
        value, [weakref.ref(k) for k in keys]


def _idcache_restore(cachedict, keys):
    shared, weakrefs = cachedict.get(tuple(map(id, keys)), (None, []))
    for r in weakrefs:
        if r() is None:
            return None
    return shared


class DomainTransformationError(Exception):
    pass


class RowInstance(Instance):
    sparse_x = None
    sparse_y = None
    sparse_metas = None
    _weight = None

    def __init__(self, table, row_index):
        """
        Construct a data instance representing the given row of the table.
        """
        self.table = table
        self._domain = table.domain
        self.row_index = row_index
        self.id = table.ids[row_index]
        self._x = table.X[row_index]
        if sp.issparse(self._x):
            self.sparse_x = sp.csr_matrix(self._x)
            self._x = np.asarray(self._x.todense())[0]
        self._y = table._Y[row_index]
        if sp.issparse(self._y):
            self.sparse_y = sp.csr_matrix(self._y)
            self._y = np.asarray(self._y.todense())[0]
        self._y = np.atleast_1d(self._y)
        self._metas = table.metas[row_index]
        if sp.issparse(self._metas):
            self.sparse_metas = sp.csr_matrix(self._metas)
            self._metas = np.asarray(self._metas.todense())[0]

    @property
    def weight(self):
        if not self.table.has_weights():
            return 1
        return self.table.W[self.row_index]

    @weight.setter
    def weight(self, weight):
        if not self.table.has_weights():
            self.table.set_weights()
        self.table.W[self.row_index] = weight

    def set_class(self, value):
        # pylint: disable=protected-access
        self._check_single_class()
        if not isinstance(value, Real):
            value = self.table.domain.class_var.to_val(value)
        if self.sparse_y:
            self.table._Y[self.row_index, 0] = value
        else:
            self.table._Y[self.row_index] = value
            if self.table._Y.ndim == 1:  # if _y is not a view
                self._y[0] = value

    def __setitem__(self, key, value):
        if not isinstance(key, Integral):
            key = self._domain.index(key)
        if isinstance(value, str):
            var = self._domain[key]
            value = var.to_val(value)
        if key >= 0:
            if not isinstance(value, Real):
                raise TypeError("Expected primitive value, got '%s'" %
                                type(value).__name__)
            if key < len(self._x):
                # write to self.table.X to support table unlocking for live instances
                self.table.X[self.row_index, key] = value
                if self.sparse_x is not None:
                    self._x[key] = value
            else:
                if self.sparse_y is not None:
                    self.table._Y[self.row_index, key - len(self._x)] = value
                else:
                    self.table._Y[self.row_index] = value
                    if self.table._Y.ndim == 1:  # if _y is not a view
                        self._y[0] = value
        else:
            self.table.metas[self.row_index, -1 - key] = value
            if self.sparse_metas is not None:
                self._metas[-1 - key] = value

    def _str(self, limit):
        def sp_values(matrix, variables):
            if not sp.issparse(matrix):
                if matrix.ndim == 1:
                    matrix = matrix[:, np.newaxis]
                return Instance.str_values(matrix[row], variables, limit)

            row_entries, idx = [], 0
            while idx < len(variables):
                # Make sure to stop printing variables if we limit the output
                if limit and len(row_entries) >= 5:
                    break

                var = variables[idx]
                if var.is_discrete or matrix[row, idx]:
                    row_entries.append("%s=%s" % (var.name, var.str_val(matrix[row, idx])))

                idx += 1

            s = ", ".join(row_entries)

            if limit and idx < len(variables):
                s += ", ..."

            return s

        table = self.table
        domain = table.domain
        row = self.row_index
        s = "[" + sp_values(table.X, domain.attributes)
        if domain.class_vars:
            s += " | " + sp_values(table.Y, domain.class_vars)
        s += "]"
        if self._domain.metas:
            s += " {" + sp_values(table.metas, domain.metas) + "}"
        return s

    def __str__(self):
        return self._str(False)

    def __repr__(self):
        return self._str(True)


class Columns:
    def __init__(self, domain):
        for v in chain(domain.variables, domain.metas):
            setattr(self, v.name.replace(" ", "_"), v)


class _ArrayConversion:

    def __init__(self, target, src_cols, variables, is_sparse, source_domain):
        self.target = target
        self.src_cols = src_cols
        self.is_sparse = is_sparse
        self.subarray_from = self._can_copy_all(src_cols, source_domain)
        self.variables = variables
        dtype = np.float64
        if any(isinstance(var, StringVariable) for var in self.variables):
            dtype = object
        self.dtype = dtype
        self.row_selection_needed = any(not isinstance(x, Integral)
                                        for x in src_cols)

    def _can_copy_all(self, src_cols, source_domain):
        n_src_attrs = len(source_domain.attributes)
        if all(isinstance(x, Integral) and 0 <= x < n_src_attrs
               for x in src_cols):
            return "X"
        if all(isinstance(x, Integral) and x < 0 for x in src_cols):
            return "metas"
        if all(isinstance(x, Integral) and x >= n_src_attrs
               for x in src_cols):
            return "Y"

    def get_subarray(self, source, row_indices, n_rows):
        if not len(self.src_cols):
            if self.is_sparse:
                return sp.csr_matrix((n_rows, 0), dtype=source.X.dtype)
            else:
                return np.zeros((n_rows, 0), dtype=source.X.dtype)

        match_density = assure_array_sparse if self.is_sparse else assure_array_dense
        n_src_attrs = len(source.domain.attributes)
        if self.subarray_from == "X":
            arr = match_density(_subarray(source.X, row_indices, self.src_cols))
        elif self.subarray_from == "metas":
            arr = match_density(_subarray(source.metas, row_indices,
                                          [-1 - x for x in self.src_cols]))
        elif self.subarray_from == "Y":
            Y = source.Y if source.Y.ndim == 2 else source.Y[:, None]
            arr = match_density(_subarray(
                Y, row_indices,
                [x - n_src_attrs for x in self.src_cols]))
        else:
            assert False
        if arr.dtype != self.dtype:
            arr = arr.astype(self.dtype)
        assert arr.ndim == 2 or self.subarray_from == "Y" and arr.ndim == 1
        return arr

    def get_columns(self, source, row_indices, n_rows, out=None, target_indices=None):
        n_src_attrs = len(source.domain.attributes)

        data = []
        sp_col = []
        sp_row = []
        match_density = (
            assure_column_sparse if self.is_sparse else assure_column_dense
        )

        # converting to csc before instead of each column is faster
        # do not convert if not required
        if any(isinstance(x, int) for x in self.src_cols):
            X = source.X
            Y = source.Y
            if Y.ndim == 1:
                Y = Y[:, None]
            if self.is_sparse:
                X = csc_matrix(X)
                Y = csc_matrix(Y)

        if self.row_selection_needed:
            if row_indices is ...:
                sourceri = source
            else:
                sourceri = source[row_indices]

        shared_cache = _thread_local.conversion_cache
        for i, col in enumerate(self.src_cols):
            if col is None:
                col_array = match_density(
                    np.full((n_rows, 1), self.variables[i].Unknown)
                )
            elif not isinstance(col, Integral):
                if isinstance(col, SharedComputeValue):
                    shared = _idcache_restore(shared_cache, (col.compute_shared, source))
                    if shared is None:
                        shared = col.compute_shared(sourceri)
                        _idcache_save(shared_cache, (col.compute_shared, source), shared)
                    col_array = match_density(
                        col(sourceri, shared_data=shared))
                else:
                    col_array = match_density(col(sourceri))
            elif col < 0:
                col_array = match_density(
                    source.metas[row_indices, -1 - col]
                )
            elif col < n_src_attrs:
                col_array = match_density(X[row_indices, col])
            else:
                col_array = match_density(
                    Y[row_indices, col - n_src_attrs]
                )

            if self.is_sparse:
                # col_array should be coo matrix
                data.append(col_array.data)
                sp_col.append(np.full(len(col_array.data), i))
                sp_row.append(col_array.indices)  # row indices should be same
            else:
                out[target_indices, i] = col_array

        if self.is_sparse:
            # creating csr directly would need plenty of manual work which
            # would probably slow down the process - conversion coo to csr
            # is fast
            out = sp.coo_matrix(
                (np.hstack(data), (np.hstack(sp_row), np.hstack(sp_col))),
                shape=(n_rows, len(self.src_cols)),
                dtype=self.dtype
            )
            out = out.tocsr()

        return out


class _FromTableConversion:

    def __init__(self, source, destination):
        conversion = DomainConversion(source, destination)

        self.X = _ArrayConversion("X", conversion.attributes,
                                  destination.attributes, conversion.sparse_X,
                                  source)
        self.Y = _ArrayConversion("Y", conversion.class_vars,
                                  destination.class_vars, conversion.sparse_Y,
                                  source)
        self.metas = _ArrayConversion("metas", conversion.metas,
                                      destination.metas, conversion.sparse_metas,
                                      source)

        self.subarray = []
        self.columnwise = []

        for part in [self.X, self.Y, self.metas]:
            if part.subarray_from is None:
                self.columnwise.append(part)
            else:
                self.subarray.append(part)


# noinspection PyPep8Naming
class Table(Sequence, Storage):

    LOCKING = None
    """ If the class attribute LOCKING is True, tables will throw exceptions
    on in-place modifications unless unlocked explicitly. LOCKING is supposed
    to be set to True for testing to help us find bugs. If set to False
    or None, no safeguards are in place. Two different values are used for
    the same behaviour to distinguish the unchanged default (None) form
    explicit deactivation (False) that some add-ons might need. """

    __file__ = None
    name = "untitled"

    domain = Domain([])
    _X = _Y = _metas = _W = np.zeros((0, 0))  # pylint: disable=invalid-name
    ids = np.zeros(0)
    ids.setflags(write=False)
    attributes = frozendict()

    _Unlocked_X, _Unlocked_Y, _Unlocked_metas, _Unlocked_W = 1, 2, 4, 8
    _unlocked = _Unlocked_X + _Unlocked_Y + \
                _Unlocked_metas + _Unlocked_W  # pylint: disable=invalid-name

    @property
    def columns(self):
        """
        A class whose attributes contain attribute descriptors for columns.
        For a table `table`, setting `c = table.columns` will allow accessing
        the table's variables with, for instance `c.gender`, `c.age` ets.
        Spaces are replaced with underscores.
        """
        return Columns(self.domain)

    _next_instance_id = 0
    _next_instance_lock = Lock()

    def _check_unlocked(self, partflag):
        if not self._unlocked & partflag:
            raise ValueError("Table is read-only unless unlocked")

    @property
    def X(self):  # pylint: disable=invalid-name
        return self._X

    @X.setter
    def X(self, value):
        self._check_unlocked(self._Unlocked_X)
        self._X = _dereferenced(value)

    @property
    def Y(self):  # pylint: disable=invalid-name
        return self._Y

    @Y.setter
    def Y(self, value):
        self._check_unlocked(self._Unlocked_Y)
        if sp.issparse(value) and len(self) != value.shape[0]:
            value = value.T
        if sp.issparse(value):
            value = _dereferenced(value.toarray())
        if value.ndim == 2 and value.shape[1] == 1:
            value = value[:, 0].copy()  # no views!
        self._Y = value

    @property
    def metas(self):
        return self._metas

    @metas.setter
    def metas(self, value):
        self._check_unlocked(self._Unlocked_metas)
        self._metas = _dereferenced(value)

    @property
    def W(self):  # pylint: disable=invalid-name
        return self._W

    @W.setter
    def W(self, value):
        self._check_unlocked(self._Unlocked_W)
        self._W = value

    def __setstate__(self, state):
        # Backward compatibility with pickles before table locking
        self._initialize_unlocked()  # __dict__ seems to be cleared before calling __setstate__
        with self.unlocked():
            for k in ("X", "W", "metas"):
                if k in state:
                    setattr(self, k, state.pop(k))
            self.__dict__.update(state)

    def _lock_parts(self):
        return ((self._X, self._Unlocked_X, "X"),
                (self._Y, self._Unlocked_Y, "Y"),
                (self._metas, self._Unlocked_metas, "metas"),
                (self._W, self._Unlocked_W, "weights"))

    def _initialize_unlocked(self):
        if Table.LOCKING:
            self._unlocked = 0
        else:
            self._unlocked = sum(f for _, f, _ in self._lock_parts())

    def _update_locks(self, force=False, unlock_bases=()):
        if not Table.LOCKING:
            return

        def sync(*xs):
            for x in xs:
                try:
                    undo_on_fail.append((x, x.flags.writeable))
                    x.flags.writeable = writeable
                except ValueError:
                    if force \
                            and writeable \
                            and x.base is not None \
                            and not x.base.flags.writeable:
                        x.base.flags.writeable = writeable
                        x.flags.writeable = writeable
                        forced_bases.append(x.base)
                    else:
                        raise

        forced_bases = []
        undo_on_fail = []
        for base in unlock_bases:
            base.flags.writeable = False
        try:
            for part, flag, _ in self._lock_parts():
                if part is None:
                    continue
                writeable = bool(self._unlocked & flag)
                if sp.isspmatrix_csr(part) or sp.isspmatrix_csc(part):
                    sync(part.data, part.indices, part.indptr)
                elif sp.isspmatrix_coo(part):
                    sync(part.data, part.row, part.col)
                elif sp.issparse(part):
                    raise ValueError("Unsupported sparse data type")
                else:
                    sync(part)
        except:
            for part, flag in undo_on_fail:
                part.flags.writeable = flag
            raise
        return tuple(forced_bases)

    def __unlocked(self, *parts, force=False):
        prev_state = self._unlocked
        for part, flag, _ in self._lock_parts():
            if not parts or any(ppart is part for ppart in parts):
                self._unlocked |= flag
        try:
            forced_bases = self._update_locks(force)
            yield
        finally:
            self._unlocked = prev_state
            self._update_locks(unlock_bases=forced_bases)

    def force_unlocked(self, *parts):
        """
        Unlocking without any checks.

        Use with extreme caution. This is meant primarily for 3rd party
        functions in Cython that expect read-write buffer, but do not
        actually modify it. the given parts (default: all parts) of the table.

        The function will still fail to unlock and raise an exception if the
        table contains view to another table.
        """
        return contextmanager(self.__unlocked)(*parts, force=True)

    def unlocked(self, *parts):
        """
        Unlock the given parts (default: all parts) of the table.

        The caller must ensure that the table is safe to modify. The function
        will raise an exception if the table contains view to other table.
        """
        def can_unlock(x):
            if sp.issparse(x):
                return can_unlock(x.data)
            return x.flags.writeable or x.flags.owndata

        for part, flag, name in self._lock_parts():
            if not flag & self._unlocked \
                    and (not parts or any(ppart is part for ppart in parts)) \
                    and part is not None and not can_unlock(part):
                raise ValueError(f"'{name}' is a view into another table "
                                 "and cannot be unlocked")
        return contextmanager(self.__unlocked)(*parts)

    def __new__(cls, *args, **kwargs):
        def warn_deprecated(method):
            warnings.warn("Direct calls to Table's constructor are deprecated "
                          "and will be removed. Replace this call with "
                          f"Table.{method}", OrangeDeprecationWarning,
                          stacklevel=3)

        if not args:
            if not kwargs:
                return super().__new__(cls)
            else:
                raise TypeError("Table() must not be called directly")

        if isinstance(args[0], str):
            if len(args) > 1:
                raise TypeError("Table(name: str) expects just one argument")
            if args[0].startswith('https://') or args[0].startswith('http://'):
                return cls.from_url(args[0], **kwargs)
            else:
                return cls.from_file(args[0], **kwargs)

        elif isinstance(args[0], Table):
            if len(args) > 1:
                raise TypeError("Table(table: Table) expects just one argument")
            return cls.from_table(args[0].domain, args[0], **kwargs)
        elif isinstance(args[0], Domain):
            domain, args = args[0], args[1:]
            if not args:
                warn_deprecated("from_domain")
                return cls.from_domain(domain, **kwargs)
            if isinstance(args[0], Table):
                warn_deprecated("from_table")
                return cls.from_table(domain, *args, **kwargs)
            elif isinstance(args[0], list):
                warn_deprecated("from_list")
                return cls.from_list(domain, *args, **kwargs)
        else:
            warnings.warn("Omitting domain in a call to Table(X, Y, metas), is "
                          "deprecated and will be removed. "
                          "Call Table.from_numpy(None, X, Y, metas) instead.",
                          OrangeDeprecationWarning, stacklevel=2)
            domain = None

        return cls.from_numpy(domain, *args, **kwargs)

    def __init__(self, *args, **kwargs):  # pylint: disable=unused-argument
        self._initialize_unlocked()
        self._update_locks()

    @classmethod
    def from_domain(cls, domain, n_rows=0, weights=False):
        """
        Construct a new `Table` with the given number of rows for the given
        domain. The optional vector of weights is initialized to 1's.

        :param domain: domain for the `Table`
        :type domain: Orange.data.Domain
        :param n_rows: number of rows in the new table
        :type n_rows: int
        :param weights: indicates whether to construct a vector of weights
        :type weights: bool
        :return: a new table
        :rtype: Orange.data.Table
        """
        self = cls()
        self.domain = domain
        self.n_rows = n_rows
        with self.unlocked():
            self.X = np.zeros((n_rows, len(domain.attributes)))
            if len(domain.class_vars) != 1:
                self.Y = np.zeros((n_rows, len(domain.class_vars)))
            else:
                self.Y = np.zeros(n_rows)
            if weights:
                self.W = np.ones(n_rows)
            else:
                self.W = np.empty((n_rows, 0))
            self.metas = np.empty((n_rows, len(self.domain.metas)), object)
            cls._init_ids(self)
            self.attributes = {}
        return self

    @classmethod
    def from_table(cls, domain, source, row_indices=...):
        """
        Create a new table from selected columns and/or rows of an existing
        one. The columns are chosen using a domain. The domain may also include
        variables that do not appear in the source table; they are computed
        from source variables if possible.

        The resulting data may be a view or a copy of the existing data.

        :param domain: the domain for the new table
        :type domain: Orange.data.Domain
        :param source: the source table
        :type source: Orange.data.Table
        :param row_indices: indices of the rows to include
        :type row_indices: a slice or a sequence
        :return: a new table
        :rtype: Orange.data.Table
        """

        PART = 5000

        new_cache = _thread_local.conversion_cache is None
        try:
            if new_cache:
                _thread_local.conversion_cache = {}
                _thread_local.domain_cache = {}
            else:
                cached = _idcache_restore(_thread_local.conversion_cache, (domain, source))
                if cached is not None:
                    return cached
            if domain is source.domain:
                table = cls.from_table_rows(source, row_indices)
                # assure resulting domain is the instance passed on input
                table.domain = domain
                # since sparse flags are not considered when checking for
                # domain equality, fix manually.
                with table.unlocked():
                    table = assure_domain_conversion_sparsity(table, source)
                return table

            if row_indices is ...:
                n_rows = len(source)
            elif isinstance(row_indices, slice):
                row_indices_range = range(*row_indices.indices(source.X.shape[0]))
                n_rows = len(row_indices_range)
            else:
                n_rows = len(row_indices)

            self = cls()
            self.domain = domain

            table_conversion = \
                _idcache_restore(_thread_local.domain_cache, (domain, source.domain))
            if table_conversion is None:
                table_conversion = _FromTableConversion(source.domain, domain)
                _idcache_save(_thread_local.domain_cache, (domain, source.domain),
                              table_conversion)

            # if an array can be a subarray of the input table, this needs to be done
            # on the whole table, because this avoids needless copies of contents

            with self.unlocked():
                for array_conv in table_conversion.subarray:
                    out = array_conv.get_subarray(source, row_indices, n_rows)
                    setattr(self, array_conv.target, out)

                parts = {}

                for array_conv in table_conversion.columnwise:
                    if array_conv.is_sparse:
                        parts[array_conv.target] = []
                    else:
                        # F-order enables faster writing to the array while accessing and
                        # matrix operations work with same speed (e.g. dot)
                        parts[array_conv.target] = \
                            np.zeros((n_rows, len(array_conv.src_cols)),
                                     order="F", dtype=array_conv.dtype)

                if n_rows <= PART:
                    for array_conv in table_conversion.columnwise:
                        out = array_conv.get_columns(source, row_indices, n_rows,
                                                     parts[array_conv.target],
                                                     ...)
                        setattr(self, array_conv.target, out)
                else:
                    i_done = 0

                    while i_done < n_rows:
                        target_indices = slice(i_done, min(n_rows, i_done + PART))
                        if row_indices is ...:
                            source_indices = target_indices
                        elif isinstance(row_indices, slice):
                            r = row_indices_range[target_indices]
                            source_indices = slice(r.start, r.stop, r.step)
                        else:
                            source_indices = row_indices[target_indices]
                        part_rows = min(n_rows, i_done+PART) - i_done

                        for array_conv in table_conversion.columnwise:
                            out = array_conv.get_columns(source, source_indices, part_rows,
                                                         parts[array_conv.target],
                                                         target_indices)
                            if array_conv.is_sparse:  # dense arrays are populated in-place
                                parts[array_conv.target].append(out)

                        i_done += PART

                        # clear cache after a part is done
                        if new_cache:
                            _thread_local.conversion_cache = {}

                    for array_conv in table_conversion.columnwise:
                        cparts = parts[array_conv.target]
                        out = cparts if not array_conv.is_sparse else sp.vstack(cparts)
                        setattr(self, array_conv.target, out)

                if source.has_weights():
                    self.W = source.W[row_indices]
                else:
                    self.W = np.empty((n_rows, 0))
                self.name = getattr(source, 'name', '')
                if hasattr(source, 'ids'):
                    self.ids = source.ids[row_indices]
                else:
                    cls._init_ids(self)
                self.attributes = getattr(source, 'attributes', {})
                _idcache_save(_thread_local.conversion_cache, (domain, source), self)
            return self
        finally:
            if new_cache:
                _thread_local.conversion_cache = None
                _thread_local.domain_cache = None

    def transform(self, domain):
        """
        Construct a table with a different domain.

        The new table keeps the row ids and other information. If the table
        is a subclass of :obj:`Table`, the resulting table will be of the same
        type.

        In a typical scenario, an existing table is augmented with a new
        column by ::

            domain = Domain(old_domain.attributes + [new_attribute],
                            old_domain.class_vars,
                            old_domain.metas)
            table = data.transform(domain)
            table[:, new_attribute] = new_column

        Args:
            domain (Domain): new domain

        Returns:
            A new table
        """
        return type(self).from_table(domain, self)

    @classmethod
    def from_table_rows(cls, source, row_indices):
        """
        Construct a new table by selecting rows from the source table.

        :param source: an existing table
        :type source: Orange.data.Table
        :param row_indices: indices of the rows to include
        :type row_indices: a slice or a sequence
        :return: a new table
        :rtype: Orange.data.Table
        """
        def get_rows(a):
            a = a[row_indices]
            if isinstance(row_indices, slice) or row_indices is ...:
                a = a.copy()
            return a

        self = cls()
        self.domain = source.domain
        with self.unlocked():
            self.X = get_rows(source.X)
            if self.X.ndim == 1:
                self.X = self.X.reshape(-1, len(self.domain.attributes))
            self.Y = get_rows(source.Y)
            self.metas = get_rows(source.metas)
            if self.metas.ndim == 1:
                self.metas = self.metas.reshape(-1, len(self.domain.metas))
            self.W = get_rows(source.W)
            self.name = getattr(source, 'name', '')
            self.ids = np.array(source.ids[row_indices])
            self.attributes = getattr(source, 'attributes', {})
        return self

    @classmethod
    def from_numpy(cls, domain, X, Y=None, metas=None, W=None,
                   attributes=None, ids=None):
        """
        Construct a table from numpy arrays with the given domain. The number
        of variables in the domain must match the number of columns in the
        corresponding arrays. All arrays must have the same number of rows.
        Arrays may be of different numpy types, and may be dense or sparse.

        :param domain: the domain for the new table
        :type domain: Orange.data.Domain
        :param X: array with attribute values
        :type X: np.array
        :param Y: array with class values
        :type Y: np.array
        :param metas: array with meta attributes
        :type metas: np.array
        :param W: array with weights
        :type W: np.array
        :return:
        """
        X, Y, W = _check_arrays(X, Y, W, dtype='float64')
        metas, = _check_arrays(metas, dtype=object, shape_1=X.shape[0])
        ids, = _check_arrays(ids, dtype=int, shape_1=X.shape[0])

        if domain is None:
            domain = Domain.from_numpy(X, Y, metas)

        if Y is None:
            if not domain.class_vars or sp.issparse(X):
                Y = np.empty((X.shape[0], 0), dtype=np.float64)
            else:
                own_data = X.flags.owndata and X.base is None
                Y = X[:, len(domain.attributes):]
                X = X[:, :len(domain.attributes)]
                if own_data:
                    Y = Y.copy()
                    X = X.copy()
        if metas is None:
            metas = np.empty((X.shape[0], 0), object)
        if W is None or W.size == 0:
            W = np.empty((X.shape[0], 0))
        elif W.shape != (W.size, ):
            W = W.reshape(W.size).copy()

        if X.shape[1] != len(domain.attributes):
            raise ValueError(
                "Invalid number of variable columns ({} != {})".format(
                    X.shape[1], len(domain.attributes))
            )
        if Y.ndim == 1:
            if not domain.class_var:
                raise ValueError(
                    "Invalid number of class columns "
                    f"(1 != {len(domain.class_vars)})")
        elif Y.shape[1] != len(domain.class_vars):
            raise ValueError(
                "Invalid number of class columns ({} != {})".format(
                    Y.shape[1], len(domain.class_vars))
            )
        if metas.shape[1] != len(domain.metas):
            raise ValueError(
                "Invalid number of meta attribute columns ({} != {})".format(
                    metas.shape[1], len(domain.metas))
            )
        if not X.shape[0] == Y.shape[0] == metas.shape[0] == W.shape[0]:
            raise ValueError(
                "Parts of data contain different numbers of rows.")

        self = cls()
        with self.unlocked():
            self.domain = domain
            self.X = X
            self.Y = Y
            self.metas = metas
            self.W = W
            self.n_rows = self.X.shape[0]
            if ids is None:
                cls._init_ids(self)
            else:
                self.ids = ids
            self.attributes = {} if attributes is None else attributes
        return self

    @classmethod
    def from_list(cls, domain, rows, weights=None):
        if weights is not None and len(rows) != len(weights):
            raise ValueError("mismatching number of instances and weights")
        self = cls.from_domain(domain, len(rows), weights is not None)
        all_vars = domain.variables + domain.metas
        nattrs = len(domain.attributes)
        nattrscls = len(domain.variables)
        with self.unlocked():
            for i, row in enumerate(rows):
                if isinstance(row, Instance):
                    row = row.list
                vals = [var.to_val(val) for var, val in zip(all_vars, row)]
                self.X[i] = vals[:nattrs]
                if self._Y.ndim == 1:
                    self._Y[i] = vals[nattrs] if nattrs < len(vals) else np.nan
                else:
                    self._Y[i] = vals[nattrs:nattrscls]
                # for backward compatibility: allow omittine some (or all) metas
                self.metas[i, :len(vals) - nattrscls] = vals[nattrscls:]
            if weights is not None:
                self.W = np.array(weights)
            self.attributes = {}
        return self

    @classmethod
    def _init_ids(cls, obj):
        with cls._next_instance_lock:
            obj.ids = np.array(range(cls._next_instance_id, cls._next_instance_id + obj.X.shape[0]))
            cls._next_instance_id += obj.X.shape[0]

    @classmethod
    def new_id(cls):
        with cls._next_instance_lock:
            id = cls._next_instance_id
            cls._next_instance_id += 1
            return id

    def to_pandas_dfs(self):
        return Orange.data.pandas_compat.table_to_frames(self)

    @staticmethod
    def from_pandas_dfs(xdf, ydf, mdf):
        return Orange.data.pandas_compat.table_from_frames(xdf, ydf, mdf)

    @property
    def X_df(self):
        return Orange.data.pandas_compat.OrangeDataFrame(
            self, orange_role=Role.Attribute
        )

    @X_df.setter
    def X_df(self, df):
        Orange.data.pandas_compat.amend_table_with_frame(
            self, df, role=Role.Attribute
        )

    @property
    def Y_df(self):
        return Orange.data.pandas_compat.OrangeDataFrame(
            self, orange_role=Role.ClassAttribute
        )

    @Y_df.setter
    def Y_df(self, df):
        Orange.data.pandas_compat.amend_table_with_frame(
            self, df, role=Role.ClassAttribute
        )

    @property
    def metas_df(self):
        return Orange.data.pandas_compat.OrangeDataFrame(
            self, orange_role=Role.Meta
        )

    @metas_df.setter
    def metas_df(self, df):
        Orange.data.pandas_compat.amend_table_with_frame(
            self, df, role=Role.Meta
        )

    def save(self, filename):
        """
        Save a data table to a file. The path can be absolute or relative.

        :param filename: File name
        :type filename: str
        """
        ext = os.path.splitext(filename)[1]
        from Orange.data.io import FileFormat
        writer = FileFormat.writers.get(ext)
        if not writer:
            desc = FileFormat.names.get(ext)
            if desc:
                raise IOError(
                    "Writing of {}s is not supported".format(desc.lower()))
            else:
                raise IOError("Unknown file name extension.")
        writer.write_file(filename, self)

    @classmethod
    def from_file(cls, filename, sheet=None):
        """
        Read a data table from a file. The path can be absolute or relative.

        :param filename: File name
        :type filename: str
        :param sheet: Sheet in a file (optional)
        :type sheet: str
        :return: a new data table
        :rtype: Orange.data.Table
        """
        from Orange.data.io import FileFormat

        absolute_filename = FileFormat.locate(filename, dataset_dirs)
        reader = FileFormat.get_reader(absolute_filename)
        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

        data.__file__ = absolute_filename
        return data

    @classmethod
    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__:
    # Set the row of table data matrices
    # noinspection PyProtectedMember
    def _set_row(self, example, row):
        # pylint: disable=protected-access
        domain = self.domain
        if isinstance(example, Instance):
            if example.domain == domain:
                self.X[row] = example._x
                if self._Y.ndim == 1:
                    self._Y[row] = float(example._y)
                else:
                    self._Y[row] = np.atleast_1d(example._y)
                self.metas[row] = example._metas
                return

            self.X[row], self._Y[row], self.metas[row] = \
                self.domain.convert(example)
            try:
                self.ids[row] = example.id
            except:
                with type(self)._next_instance_lock:
                    self.ids[row] = type(self)._next_instance_id
                    type(self)._next_instance_id += 1

        else:
            attrs = domain.attributes
            if len(example) != len(domain.variables):
                raise ValueError("invalid length")
            self._X[row] = [var.to_val(val) for var, val in zip(attrs, example)]
            if self._Y.ndim == 1:
                self._Y[row] = domain.class_var.to_val(example[len(attrs)])
            else:
                self._Y[row] = [var.to_val(val)
                                for var, val in zip(domain.class_vars,
                                                    example[len(attrs):])]
            self.metas[row] = np.array([var.Unknown for var in domain.metas],
                                       dtype=object)

    def _check_all_dense(self):
        return all(x in (Storage.DENSE, Storage.MISSING)
                   for x in (self.X_density(), self.Y_density(),
                             self.metas_density()))

    def __getitem__(self, key):
        if isinstance(key, Integral):
            return RowInstance(self, key)
        if not isinstance(key, tuple):
            return self.from_table_rows(self, key)

        if len(key) != 2:
            raise IndexError("Table indices must be one- or two-dimensional")

        row_idx, col_idx = key
        if isinstance(row_idx, Integral):
            if isinstance(col_idx, (str, Integral, Variable)):
                col_idx = self.domain.index(col_idx)
                var = self.domain[col_idx]
                if 0 <= col_idx < len(self.domain.attributes):
                    val = self.X[row_idx, col_idx]
                elif col_idx == len(self.domain.attributes) and self._Y.ndim == 1:
                    val = self._Y[row_idx]
                elif col_idx >= len(self.domain.attributes):
                    val = self._Y[row_idx,
                                  col_idx - len(self.domain.attributes)]
                else:
                    val = self.metas[row_idx, -1 - col_idx]
                if isinstance(col_idx, DiscreteVariable) and var is not col_idx:
                    val = col_idx.get_mapper_from(var)(val)
                return Value(var, val)
            else:
                row_idx = [row_idx]

        # multiple rows OR single row but multiple columns:
        # construct a new table
        attributes, col_indices = self.domain._compute_col_indices(col_idx)
        if attributes is not None:
            n_attrs = len(self.domain.attributes)
            r_attrs = [attributes[i]
                       for i, col in enumerate(col_indices)
                       if 0 <= col < n_attrs]
            r_classes = [attributes[i]
                         for i, col in enumerate(col_indices)
                         if col >= n_attrs]
            r_metas = [attributes[i]
                       for i, col in enumerate(col_indices) if col < 0]
            domain = Domain(r_attrs, r_classes, r_metas)
        else:
            domain = self.domain
        return self.from_table(domain, self, row_idx)

    def __setitem__(self, key, value):
        if not isinstance(key, tuple):
            if isinstance(value, Real):
                self.X[key, :] = value
                return
            self._set_row(value, key)
            return

        if len(key) != 2:
            raise IndexError("Table indices must be one- or two-dimensional")
        row_idx, col_idx = key

        # single row
        if isinstance(row_idx, Integral):
            if isinstance(col_idx, slice):
                col_idx = range(*slice.indices(col_idx, self.X.shape[1]))
            if not isinstance(col_idx, str) and isinstance(col_idx, Iterable):
                col_idx = list(col_idx)
            if not isinstance(col_idx, str) and isinstance(col_idx, Sized):
                if isinstance(value, (Sequence, np.ndarray)):
                    values = value
                elif isinstance(value, Iterable):
                    values = list(value)
                else:
                    raise TypeError("Setting multiple values requires a "
                                    "sequence or numpy array")
                if len(values) != len(col_idx):
                    raise ValueError("Invalid number of values")
            else:
                col_idx, values = [col_idx], [value]
            if isinstance(col_idx, DiscreteVariable) \
                    and self.domain[col_idx] != col_idx:
                values = self.domain[col_idx].get_mapper_from(col_idx)(values)
            for val, col_idx in zip(values, col_idx):
                if not isinstance(val, Integral):
                    val = self.domain[col_idx].to_val(val)
                if not isinstance(col_idx, Integral):
                    col_idx = self.domain.index(col_idx)
                if col_idx >= 0:
                    if col_idx < self.X.shape[1]:
                        self.X[row_idx, col_idx] = val
                    elif self._Y.ndim == 1 and col_idx == self.X.shape[1]:
                        self._Y[row_idx] = val
                    else:
                        self._Y[row_idx, col_idx - self.X.shape[1]] = val
                else:
                    self.metas[row_idx, -1 - col_idx] = val

        # multiple rows, multiple columns
        attributes, col_indices = self.domain._compute_col_indices(col_idx)
        if col_indices is ...:
            col_indices = range(len(self.domain.variables))
        n_attrs = self.X.shape[1]
        if isinstance(value, str):
            if not attributes:
                attributes = self.domain.attributes
            for var, col in zip(attributes, col_indices):
                val = var.to_val(value)
                if 0 <= col < n_attrs:
                    self.X[row_idx, col] = val
                elif col >= n_attrs:
                    if self._Y.ndim == 1 and col == n_attrs:
                        self._Y[row_idx] = val
                    else:
                        self._Y[row_idx, col - n_attrs] = val
                else:
                    self.metas[row_idx, -1 - col] = val
        else:
            attr_cols = np.fromiter(
                (col for col in col_indices if 0 <= col < n_attrs), int)
            class_cols = np.fromiter(
                (col - n_attrs for col in col_indices if col >= n_attrs), int)
            meta_cols = np.fromiter(
                (-1 - col for col in col_indices if col < 0), int)
            if value is None:
                value = Unknown

            if not isinstance(value, (Real, np.ndarray)) and \
                    (len(attr_cols) or len(class_cols)):
                raise TypeError(
                    "Ordinary attributes can only have primitive values")
            if len(attr_cols):
                self.X[row_idx, attr_cols] = value
            if len(class_cols):
                if self._Y.ndim == 1 and np.all(class_cols == 0):
                    if isinstance(value, np.ndarray):
                        yshape = self._Y[row_idx].shape
                        if value.shape != yshape:
                            value = value.reshape(yshape)
                    self._Y[row_idx] = value
                else:
                    self._Y[row_idx, class_cols] = value
            if len(meta_cols):
                self.metas[row_idx, meta_cols] = value

    def __len__(self):
        return self.X.shape[0]

    def __str__(self):
        return "[" + ",\n ".join(str(ex) for ex in self) + "]"

    def __repr__(self):
        head = 5
        if self.is_sparse():
            head = min(self.X.shape[0], head)
        s = "[" + ",\n ".join(repr(ex) for ex in self[:head])
        if len(self) > head:
            s += ",\n ..."
        s += "\n]"
        return s

    @classmethod
    def concatenate(cls, tables, axis=0):
        """
        Concatenate tables into a new table, either vertically or horizontally.

        If axis=0 (vertical concatenate), all tables must have the same domain.

        If axis=1 (horizontal),
        - all variable names must be unique.
        - ids are copied from the first table.
        - weights are copied from the first table in which they are defined.
        - the dictionary of table's attributes are merged. If the same attribute
          appears in multiple dictionaries, the earlier are used.

        Args:
            tables (Table): tables to be joined

        Returns:
            table (Table)
        """
        if axis not in (0, 1):
            raise ValueError("invalid axis")
        if not tables:
            raise ValueError('need at least one table to concatenate')

        if len(tables) == 1:
            return tables[0].copy()

        if axis == 0:
            conc = cls._concatenate_vertical(tables)
        else:
            conc = cls._concatenate_horizontal(tables)

        # TODO: Add attributes = {} to __init__
        conc.attributes = getattr(conc, "attributes", {})
        for table in reversed(tables):
            conc.attributes.update(table.attributes)

        names = [table.name for table in tables if table.name != "untitled"]
        if names:
            conc.name = names[0]
        return conc

    @classmethod
    def _concatenate_vertical(cls, tables):
        def vstack(arrs):
            return [np, sp][any(sp.issparse(arr) for arr in arrs)].vstack(arrs)

        def merge1d(arrs):
            arrs = list(arrs)
            ydims = {arr.ndim for arr in arrs}
            if ydims == {1}:
                return np.hstack(arrs)
            else:
                return vstack([
                    arr if arr.ndim == 2 else np.atleast_2d(arr).T
                    for arr in arrs
                ])

        def collect(attr):
            return [getattr(arr, attr) for arr in tables]

        domain = tables[0].domain
        if any(table.domain != domain for table in tables):
            raise ValueError('concatenated tables must have the same domain')

        conc = cls.from_numpy(
            domain,
            vstack(collect("X")),
            merge1d(collect("Y")),
            vstack(collect("metas")),
            merge1d(collect("W"))
        )
        conc.ids = np.hstack([t.ids for t in tables])
        return conc

    @classmethod
    def _concatenate_horizontal(cls, tables):
        """
        """
        def all_of(objs, names):
            return (tuple(getattr(obj, name) for obj in objs)
                    for name in names)

        def stack(arrs):
            non_empty = tuple(arr if arr.ndim == 2 else arr[:, np.newaxis]
                              for arr in arrs
                              if arr is not None and arr.size > 0)
            return np.hstack(non_empty) if non_empty else None

        doms, Ws = all_of(tables, ("domain", "W"))
        Xs, Ys, Ms = map(stack, all_of(tables, ("X", "Y", "metas")))
        # pylint: disable=undefined-loop-variable
        for W in Ws:
            if W.size:
                break

        parts = all_of(doms, ("attributes", "class_vars", "metas"))
        domain = Domain(*(tuple(chain(*lst)) for lst in parts))
        return cls.from_numpy(domain, Xs, Ys, Ms, W, ids=tables[0].ids)

    def add_column(self, variable, data, to_metas=None):
        """
        Create a new table with an additional column

        Column's name must be unique

        Args:
            variable (Variable): variable for the new column
            data (np.ndarray): data for the new column
            to_metas (bool, optional): if `True` the column is added as meta
                column. Otherwise, primitive variables are added to attributes
                and non-primitive to metas.

        Returns:
            table (Table): a new table with the additional column
        """
        dom = self.domain
        attrs, classes, metavars = dom.attributes, dom.class_vars, dom.metas
        to_metas = to_metas or not variable.is_primitive()
        if to_metas:
            metavars += (variable, )
        else:
            attrs += (variable, )
        domain = Domain(attrs, classes, metavars)
        new_table = self.transform(domain)
        with new_table.unlocked(new_table.metas if to_metas else new_table.X):
            new_table.get_column_view(variable)[0][:] = data
        return new_table

    def is_view(self):
        """
        Return `True` if all arrays represent a view referring to another table
        """
        return ((not self._X.shape[-1] or self._X.base is not None) and
                (not self._Y.shape[-1] or self._Y.base is not None) and
                (not self._metas.shape[-1] or self._metas.base is not None) and
                (not self._weights.shape[-1] or self._W.base is not None))

    def is_copy(self):
        """
        Return `True` if the table owns its data
        """
        return ((not self._X.shape[-1] or self._X.base is None) and
                (self._Y.base is None) and
                (self._metas.base is None) and
                (self._W.base is None))

    def is_sparse(self):
        """
        Return `True` if the table stores data in sparse format
        """
        return any(sp.issparse(i) for i in [self._X, self._Y, self._metas])

    def ensure_copy(self):
        """
        Ensure that the table owns its data; copy arrays when necessary.
        """

        def is_view(x):
            # Sparse matrices don't have views like numpy arrays. Since indexing on
            # them creates copies in constructor we can skip this check here.
            return not sp.issparse(x) and x.base is not None

        if is_view(self._X):
            self._X = self._X.copy()
        if is_view(self._Y):
            self._Y = self._Y.copy()
        if is_view(self._metas):
            self._metas = self._metas.copy()
        if is_view(self._W):
            self._W = self._W.copy()

    def copy(self):
        """
        Return a copy of the table
        """
        t = self.__class__(self)
        t.ensure_copy()
        return t

    @staticmethod
    def __determine_density(data):
        if data is None:
            return Storage.Missing
        if data is not None and sp.issparse(data):
            return Storage.SPARSE_BOOL if (data.data == 1).all() else Storage.SPARSE
        else:
            return Storage.DENSE

    def X_density(self):
        if not hasattr(self, "_X_density"):
            self._X_density = self.__determine_density(self.X)
        return self._X_density

    def Y_density(self):
        if not hasattr(self, "_Y_density"):
            self._Y_density = self.__determine_density(self._Y)
        return self._Y_density

    def metas_density(self):
        if not hasattr(self, "_metas_density"):
            self._metas_density = self.__determine_density(self.metas)
        return self._metas_density

    def set_weights(self, weight=1):
        """
        Set weights of data instances; create a vector of weights if necessary.
        """
        if not self.W.shape[-1]:
            self.W = np.empty(len(self))
        self.W[:] = weight

    def has_weights(self):
        """Return `True` if the data instances are weighed. """
        return self.W.shape[-1] != 0

    def total_weight(self):
        """
        Return the total weight of instances in the table, or their number if
        they are unweighted.
        """
        if self.W.shape[-1]:
            return sum(self.W)
        return len(self)

    def has_missing(self):
        """Return `True` if there are any missing attribute or class values."""
        missing_x = not sp.issparse(self.X) and bn.anynan(self.X)  # do not check for sparse X
        return missing_x or bn.anynan(self._Y)

    def has_missing_attribute(self):
        """Return `True` if there are any missing attribute values."""
        return not sp.issparse(self.X) and bn.anynan(self.X)  # do not check for sparse X

    def has_missing_class(self):
        """Return `True` if there are any missing class values."""
        return bn.anynan(self._Y)

    def get_nan_frequency_attribute(self):
        if self.X.size == 0:
            return 0
        return np.isnan(self.X).sum() / self.X.size

    def get_nan_frequency_class(self):
        if self.Y.size == 0:
            return 0
        return np.isnan(self._Y).sum() / self._Y.size

    def checksum(self, include_metas=True):
        # TODO: zlib.adler32 does not work for numpy arrays with dtype object
        # (after pickling and unpickling such arrays, checksum changes)
        # Why, and should we fix it or remove it?
        """Return a checksum over X, Y, metas and W."""
        cs = zlib.adler32(np.ascontiguousarray(self._X))
        cs = zlib.adler32(np.ascontiguousarray(self._Y), cs)
        if include_metas:
            cs = zlib.adler32(np.ascontiguousarray(self._metas), cs)
        cs = zlib.adler32(np.ascontiguousarray(self._W), cs)
        return cs

    def shuffle(self):
        """Randomly shuffle the rows of the table."""
        if not self._check_all_dense():
            raise ValueError("Rows of sparse data cannot be shuffled")
        ind = np.arange(self.X.shape[0])
        np.random.shuffle(ind)
        self.X = self.X[ind]
        self._Y = self._Y[ind]
        self.metas = self.metas[ind]
        self.W = self.W[ind]

    def get_column_view(self, index):
        """
        Return a vector - as a view, not a copy - with a column of the table,
        and a bool flag telling whether this column is sparse. Note that
        vertical slicing of sparse matrices is inefficient.

        :param index: the index of the column
        :type index: int, str or Orange.data.Variable
        :return: (one-dimensional numpy array, sparse)
        """

        def rx(M):
            if sp.issparse(M):
                return np.asarray(M.todense())[:, 0], True
            else:
                return M, False

        if isinstance(index, Integral):
            col_index = index
        else:
            col_index = self.domain.index(index)
        if col_index >= 0:
            if col_index < self.X.shape[1]:
                col = rx(self.X[:, col_index])
            elif self._Y.ndim == 1 and col_index == self._X.shape[1]:
                col = rx(self._Y)
            else:
                col = rx(self._Y[:, col_index - self.X.shape[1]])
        else:
            col = rx(self.metas[:, -1 - col_index])

        if isinstance(index, DiscreteVariable) \
                and index.values != self.domain[col_index].values:
            col = index.get_mapper_from(self.domain[col_index])(col[0]), col[1]
            col[0].flags.writeable = False
        return col

    def _filter_is_defined(self, columns=None, negate=False):
        # structure of function is obvious; pylint: disable=too-many-branches
        def _sp_anynan(a):
            return a.indptr[1:] != a[-1:] + a.shape[1]

        if columns is None:
            if sp.issparse(self.X):
                remove = _sp_anynan(self.X)
            else:
                remove = bn.anynan(self.X, axis=1)
            if sp.issparse(self._Y):
                remove += _sp_anynan(self._Y)
            else:
                if self._Y.ndim == 1:
                    remove += np.isnan(self._Y)
                else:
                    remove += bn.anynan(self._Y, axis=1)
            if sp.issparse(self.metas):
                remove += _sp_anynan(self._metas)
            else:
                for i, var in enumerate(self.domain.metas):
                    col = self.metas[:, i].flatten()
                    if var.is_primitive():
                        remove += np.isnan(col.astype(float))
                    else:
                        remove += ~col.astype(bool)
        else:
            remove = np.zeros(len(self), dtype=bool)
            for column in columns:
                col, sparse = self.get_column_view(column)
                if sparse:
                    remove += col == 0
                elif self.domain[column].is_primitive():
                    remove += bn.anynan([col.astype(float)], axis=0)
                else:
                    remove += col.astype(bool)
        retain = remove if negate else np.logical_not(remove)
        return self.from_table_rows(self, retain)

    def _filter_has_class(self, negate=False):
        if sp.issparse(self._Y):
            if negate:
                retain = (self._Y.indptr[1:] !=
                          self._Y.indptr[-1:] + self._Y.shape[1])
            else:
                retain = (self._Y.indptr[1:] ==
                          self._Y.indptr[-1:] + self._Y.shape[1])
        else:
            if self._Y.ndim == 1:
                retain = np.isnan(self._Y)
            else:
                retain = bn.anynan(self._Y, axis=1)
            if not negate:
                retain = np.logical_not(retain)
        return self.from_table_rows(self, retain)

    def _filter_same_value(self, column, value, negate=False):
        if not isinstance(value, Real):
            value = self.domain[column].to_val(value)
        sel = self.get_column_view(column)[0] == value
        if negate:
            sel = np.logical_not(sel)
        return self.from_table_rows(self, sel)

    def _filter_values(self, filter):
        selection = self._values_filter_to_indicator(filter)
        return self.from_table(self.domain, self, selection)

    def _values_filter_to_indicator(self, filter):
        """Return selection of rows matching the filter conditions

        Handles conjunction/disjunction and negate modifiers

        Parameters
        ----------
        filter: Values object containing the conditions

        Returns
        -------
        A 1d bool array. len(result) == len(self)
        """
        from Orange.data.filter import Values

        if isinstance(filter, Values):
            conditions = filter.conditions
            conjunction = filter.conjunction
        else:
            conditions = [filter]
            conjunction = True
        if conjunction:
            sel = np.ones(len(self), dtype=bool)
        else:
            sel = np.zeros(len(self), dtype=bool)

        for f in conditions:
            selection = self._filter_to_indicator(f)

            if conjunction:
                sel *= selection
            else:
                sel += selection

        if filter.negate:
            sel = ~sel
        return sel

    def _filter_to_indicator(self, filter):
        """Return selection of rows that match the condition.

        Parameters
        ----------
        filter: ValueFilter describing the condition

        Returns
        -------
        A 1d bool array. len(result) == len(self)
        """
        from Orange.data.filter import (
            FilterContinuous, FilterDiscrete, FilterRegex, FilterString,
            FilterStringList, IsDefined, Values
        )
        if isinstance(filter, Values):
            return self._values_filter_to_indicator(filter)

        def get_col_indices():
            cols = chain(self.domain.variables, self.domain.metas)
            if isinstance(filter, IsDefined):
                if filter.columns is not None:
                    return list(filter.columns)
                else:
                    return list(cols)

            if filter.column is not None:
                return [filter.column]

            if isinstance(filter, FilterDiscrete):
                raise ValueError("Discrete filter can't be applied across rows")
            if isinstance(filter, FilterContinuous):
                return [col for col in cols if col.is_continuous]
            if isinstance(filter,
                          (FilterString, FilterStringList, FilterRegex)):
                return [col for col in cols if col.is_string]
            raise TypeError("Invalid filter")

        def col_filter(col_idx):
            col = self.get_column_view(col_idx)[0]
            if isinstance(filter, IsDefined):
                if self.domain[col_idx].is_primitive():
                    return ~np.isnan(col.astype(float))
                else:
                    return col.astype(bool)
            if isinstance(filter, FilterDiscrete):
                return self._discrete_filter_to_indicator(filter, col)
            if isinstance(filter, FilterContinuous):
                return self._continuous_filter_to_indicator(filter, col)
            if isinstance(filter, FilterString):
                return self._string_filter_to_indicator(filter, col)
            if isinstance(filter, FilterStringList):
                if not filter.case_sensitive:
                    col = np.char.lower(np.array(col, dtype=str))
                    vals = [val.lower() for val in filter.values]
                else:
                    vals = filter.values
                return reduce(operator.add, (col == val for val in vals))
            if isinstance(filter, FilterRegex):
                return np.vectorize(filter)(col)
            raise TypeError("Invalid filter")

        col_indices = get_col_indices()
        if len(col_indices) == 1:
            sel = col_filter(col_indices[0])
        else:
            sel = np.ones(len(self), dtype=bool)
            for col_idx in col_indices:
                sel *= col_filter(col_idx)

        if isinstance(filter, IsDefined) and filter.negate:
            sel = ~sel
        return sel

    def _discrete_filter_to_indicator(self, filter, col):
        """Return selection of rows matched by the given discrete filter.

        Parameters
        ----------
        filter: FilterDiscrete
        col: np.ndarray

        Returns
        -------
        A 1d bool array. len(result) == len(self)
        """
        if filter.values is None:  # <- is defined filter
            col = col.astype(float)
            return ~np.isnan(col)

        sel = np.zeros(len(self), dtype=bool)
        for val in filter.values:
            if not isinstance(val, Real):
                val = self.domain[filter.column].to_val(val)
            sel += (col == val)
        return sel

    def _continuous_filter_to_indicator(self, filter, col):
        """Return selection of rows matched by the given continuous filter.

        Parameters
        ----------
        filter: FilterContinuous
        col: np.ndarray

        Returns
        -------
        A 1d bool array. len(result) == len(self)
        """
        if filter.oper == filter.IsDefined:
            col = col.astype(float)
            return ~np.isnan(col)

        return self._range_filter_to_indicator(filter, col, filter.min, filter.max)

    def _string_filter_to_indicator(self, filter, col):
        """Return selection of rows matched by the given string filter.

        Parameters
        ----------
        filter: FilterString
        col: np.ndarray

        Returns
        -------
        A 1d bool array. len(result) == len(self)
        """
        if filter.oper == filter.IsDefined:
            return col.astype(bool)

        col = col.astype(str)
        fmin = filter.min or ""
        fmax = filter.max or ""

        if not filter.case_sensitive:
            # convert all to lower case
            col = np.char.lower(col)
            fmin = fmin.lower()
            fmax = fmax.lower()

        if filter.oper == filter.Contains:
            return np.fromiter((fmin in e for e in col),
                               dtype=bool)
        if filter.oper == filter.StartsWith:
            return np.fromiter((e.startswith(fmin) for e in col),
                               dtype=bool)
        if filter.oper == filter.EndsWith:
            return np.fromiter((e.endswith(fmin) for e in col),
                               dtype=bool)

        return self._range_filter_to_indicator(filter, col, fmin, fmax)

    @staticmethod
    def _range_filter_to_indicator(filter, col, fmin, fmax):
        with np.errstate(invalid="ignore"):  # nan's are properly discarded
            if filter.oper == filter.Equal:
                return col == fmin
            if filter.oper == filter.NotEqual:
                return col != fmin
            if filter.oper == filter.Less:
                return col < fmin
            if filter.oper == filter.LessEqual:
                return col <= fmin
            if filter.oper == filter.Greater:
                return col > fmin
            if filter.oper == filter.GreaterEqual:
                return col >= fmin
            if filter.oper == filter.Between:
                return (col >= fmin) * (col <= fmax)
            if filter.oper == filter.Outside:
                return (col < fmin) + (col > fmax)

            raise TypeError("Invalid operator")

    def _compute_basic_stats(self, columns=None,
                             include_metas=False, compute_variance=False):
        if compute_variance:
            raise NotImplementedError("computation of variance is "
                                      "not implemented yet")
        W = self._W if self.has_weights() else None
        rr = []
        stats = []
        if not columns:
            if self.domain.attributes:
                rr.append(fast_stats(self._X, W))
            if self.domain.class_vars:
                rr.append(fast_stats(self._Y, W))
            if include_metas and self.domain.metas:
                rr.append(fast_stats(self.metas, W))
            if len(rr):
                stats = np.vstack(tuple(rr))
        else:
            nattrs = len(self.domain.attributes)
            for column in columns:
                c = self.domain.index(column)
                if 0 <= c < nattrs:
                    S = fast_stats(self._X[:, [c]], W and W[:, [c]])
                elif c >= nattrs:
                    if self._Y.ndim == 1 and c == nattrs:
                        S = fast_stats(self._Y[:, None], W and W[:, None])
                    else:
                        S = fast_stats(self._Y[:, [c - nattrs]], W and W[:, [c - nattrs]])
                else:
                    S = fast_stats(self._metas[:, [-1 - c]], W and W[:, [-1 - c]])
                stats.append(S[0])
        return stats

    def _compute_distributions(self, columns=None):
        if columns is None:
            columns = range(len(self.domain.variables))
        else:
            columns = [self.domain.index(var) for var in columns]

        distributions = []
        X = self.X
        if sp.issparse(X):
            X = X.tocsc()


        W = self.W.ravel() if self.has_weights() else None

        for col in columns:
            variable = self.domain[col]

            # Select the correct data column from X, Y or metas
            if 0 <= col < X.shape[1]:
                x = X[:, col]
            elif col < 0:
                x = self.metas[:, col * (-1) - 1]
                if np.issubdtype(x.dtype, np.dtype(object)):
                    x = x.astype(float)
            elif self._Y.ndim == 1 and col == X.shape[1]:
                x = self._Y
            else:
                x = self._Y[:, col - X.shape[1]]

            if variable.is_discrete:
                dist, unknowns = bincount(x, weights=W, max_val=len(variable.values) - 1)
            elif not x.shape[0]:
                dist, unknowns = np.zeros((2, 0)), 0
            else:
                if W is not None:
                    if sp.issparse(x):
                        arg_sort = np.argsort(x.data)
                        ranks = x.indices[arg_sort]
                        vals = np.vstack((x.data[arg_sort], W[ranks]))
                    else:
                        ranks = np.argsort(x)
                        vals = np.vstack((x[ranks], W[ranks]))
                else:
                    x_values = x.data if sp.issparse(x) else x
                    vals = np.ones((2, x_values.shape[0]))
                    vals[0, :] = x_values
                    vals[0, :].sort()

                dist = np.array(_valuecount.valuecount(vals))
                # If sparse, then 0s will not be counted with `valuecount`, so
                # we have to add them to the result manually.
                if sp.issparse(x) and sparse_has_implicit_zeros(x):
                    if W is not None:
                        zero_weights = sparse_implicit_zero_weights(x, W).sum()
                    else:
                        zero_weights = sparse_count_implicit_zeros(x)
                    zero_vec = [0, zero_weights]
                    dist = np.insert(dist, np.searchsorted(dist[0], 0), zero_vec, axis=1)
                # Since `countnans` assumes vector shape to be (1, n) and `x`
                # shape is (n, 1), we pass the transpose
                unknowns = countnans(x.T, W)
            distributions.append((dist, unknowns))

        return distributions

    def _compute_contingency(self, col_vars=None, row_var=None):
        n_atts = self.X.shape[1]

        if col_vars is None:
            col_vars = range(len(self.domain.variables))
        else:
            col_vars = [self.domain.index(var) for var in col_vars]
        if row_var is None:
            row_var = self.domain.class_var
            if row_var is None:
                raise ValueError("No row variable")

        row_desc = self.domain[row_var]
        if not row_desc.is_discrete:
            raise TypeError("Row variable must be discrete")
        row_indi = self.domain.index(row_var)
        n_rows = len(row_desc.values)
        if 0 <= row_indi < n_atts:
            row_data = self.X[:, row_indi]
        elif row_indi < 0:
            row_data = self.metas[:, -1 - row_indi]
        elif self._Y.ndim == 1 and row_indi == n_atts:
            row_data = self._Y
        else:
            row_data = self._Y[:, row_indi - n_atts]

        W = self.W if self.has_weights() else None

        col_desc = [self.domain[var] for var in col_vars]
        col_indi = [self.domain.index(var) for var in col_vars]

        if any(not (var.is_discrete or var.is_continuous)
               for var in col_desc):
            raise ValueError("Contingency can be computed only for categorical "
                             "and numeric values.")

        # when we select a column in sparse matrix it is still two dimensional
        # and sparse - since it is just a column we can afford to transform
        # it to dense and make it 1D
        if issparse(row_data):
            row_data = row_data.toarray().ravel()
        if row_data.dtype.kind != "f":  # meta attributes can be stored as type object
            row_data = row_data.astype(float)

        contingencies = [None] * len(col_desc)
        for arr, f_cond, f_ind in (
                (self.X, lambda i: 0 <= i < n_atts, lambda i: i),
                (self._Y, lambda i: i >= n_atts, lambda i: i - n_atts),
                (self.metas, lambda i: i < 0, lambda i: -1 - i)):

            arr_indi = [e for e, ind in enumerate(col_indi) if f_cond(ind)]

            vars = [(e, f_ind(col_indi[e]), col_desc[e]) for e in arr_indi]
            disc_vars = [v for v in vars if v[2].is_discrete]
            if disc_vars:
                if sp.issparse(arr):
                    max_vals = max(len(v[2].values) for v in disc_vars)
                    disc_indi = {i for _, i, _ in disc_vars}
                    mask = [i in disc_indi for i in range(arr.shape[1])]
                    conts, nans_cols, nans_rows, nans = contingency(
                        arr, row_data, max_vals - 1, n_rows - 1, W, mask)
                    for col_i, arr_i, var in disc_vars:
                        n_vals = len(var.values)
                        contingencies[col_i] = (
                            conts[arr_i][:, :n_vals], nans_cols[arr_i],
                            nans_rows[arr_i], nans[arr_i])
                else:
                    for col_i, arr_i, var in disc_vars:
                        col = arr if arr.ndim == 1 else arr[:, arr_i]
                        contingencies[col_i] = contingency(
                            col.astype(float),
                            row_data, len(var.values) - 1, n_rows - 1, W)

            cont_vars = [v for v in vars if v[2].is_continuous]
            if cont_vars:
                W_ = None
                if W is not None:
                    W_ = W.astype(dtype=np.float64)
                if sp.issparse(arr):
                    arr = sp.csc_matrix(arr)

                for col_i, arr_i, _ in cont_vars:
                    if sp.issparse(arr):
                        col_data = arr.data[arr.indptr[arr_i]:arr.indptr[arr_i + 1]]
                        rows = arr.indices[arr.indptr[arr_i]:arr.indptr[arr_i + 1]]
                        W_ = None if W_ is None else W_[rows]
                        classes_ = row_data[rows]
                    else:
                        col_data, W_, classes_ = arr[:, arr_i], W_, row_data

                    col_data = col_data.astype(dtype=np.float64)
                    contingencies[col_i] = _contingency.contingency_floatarray(
                        col_data, classes_, n_rows, W_)

        return contingencies

    @classmethod
    def transpose(cls, table, feature_names_column="",
                  meta_attr_name="Feature name", feature_name="Feature",
                  remove_redundant_inst=False, progress_callback=None):
        """
        Transpose the table.

        :param table: Table - table to transpose
        :param feature_names_column: str - name of (String) meta attribute to
            use for feature names
        :param meta_attr_name: str - name of new meta attribute into which
            feature names are mapped
        :param feature_name: str - default feature name prefix
        :param remove_redundant_inst: bool - remove instance that
            represents feature_names_column
        :param progress_callback: callable - to report the progress
        :return: Table - transposed table
        """
        if progress_callback is None:
            progress_callback = dummy_callback
        progress_callback(0, "Transposing...")

        if isinstance(feature_names_column, Variable):
            feature_names_column = feature_names_column.name

        self = cls()
        n_cols, self.n_rows = table.X.shape
        old_domain = table.attributes.get("old_domain")
        table_domain_attributes = list(table.domain.attributes)
        attr_index = None
        if remove_redundant_inst:
            attr_names = [a.name for a in table_domain_attributes]
            if feature_names_column and feature_names_column in attr_names:
                attr_index = attr_names.index(feature_names_column)
                self.n_rows = self.n_rows - 1
                table_domain_attributes.remove(
                    table_domain_attributes[attr_index])

        # attributes
        # - classes and metas to attributes of attributes
        # - arbitrary meta column to feature names
        with self.unlocked():
            self.X = table.X.T
            if attr_index is not None:
                self.X = np.delete(self.X, attr_index, 0)
            if feature_names_column:
                names = [str(row[feature_names_column]) for row in table]
                progress_callback(0.1)
                names = get_unique_names_duplicates(names)
                progress_callback(0.3)
                attributes = [ContinuousVariable(name) for name in names]
            else:
                places = int(np.ceil(np.log10(n_cols))) if n_cols else 1
                attributes = [ContinuousVariable(f"{feature_name} {i:0{places}}")
                              for i in range(1, n_cols + 1)]
            progress_callback(0.4)

            if old_domain is not None and feature_names_column:
                for i, _ in enumerate(attributes):
                    if attributes[i].name in old_domain:
                        var = old_domain[attributes[i].name]
                        attr = ContinuousVariable(var.name) if var.is_continuous \
                            else DiscreteVariable(var.name, var.values)
                        attr.attributes = var.attributes.copy()
                        attributes[i] = attr

            def set_attributes_of_attributes(_vars, _table):
                for i, variable in enumerate(_vars):
                    if variable.name == feature_names_column:
                        continue
                    for j, row in enumerate(_table):
                        value = variable.repr_val(row) if np.isscalar(row) \
                            else row[i] if isinstance(row[i], str) \
                            else variable.repr_val(row[i])

                        if value not in MISSING_VALUES:
                            attributes[j].attributes[variable.name] = value

            set_attributes_of_attributes(table.domain.class_vars, table.Y)
            progress_callback(0.5)
            set_attributes_of_attributes(table.domain.metas, table.metas)

            # weights
            self.W = np.empty((self.n_rows, 0))

            def get_table_from_attributes_of_attributes(_vars, _dtype=float):
                T = np.empty((self.n_rows, len(_vars)), dtype=_dtype)
                for i, _attr in enumerate(table_domain_attributes):
                    for j, _var in enumerate(_vars):
                        val = str(_attr.attributes.get(_var.name, ""))
                        if not _var.is_string:
                            val = np.nan if val in MISSING_VALUES else \
                                _var.values.index(val) if \
                                    _var.is_discrete else float(val)
                        T[i, j] = val
                return T

            # class_vars - attributes of attributes to class - from old domain
            class_vars = []
            if old_domain is not None:
                class_vars = old_domain.class_vars
            self.Y = get_table_from_attributes_of_attributes(class_vars)

            # metas
            # - feature names and attributes of attributes to metas
            self.metas, metas = np.empty((self.n_rows, 0), dtype=object), []
            if meta_attr_name not in [m.name for m in table.domain.metas] and \
                    table_domain_attributes:
                self.metas = np.array([[a.name] for a in table_domain_attributes],
                                      dtype=object)
                metas.append(StringVariable(meta_attr_name))

            names = chain.from_iterable(list(attr.attributes)
                                        for attr in table_domain_attributes)
            names = sorted(set(names) - {var.name for var in class_vars})
            progress_callback(0.6)

            def guessed_var(i, var_name):
                orig_vals = M[:, i]
                val_map, vals, var_type = Orange.data.io.guess_data_type(orig_vals)
                values, variable = Orange.data.io.sanitize_variable(
                    val_map, vals, orig_vals, var_type, {}, name=var_name)
                M[:, i] = values
                return variable

            _metas = [StringVariable(n) for n in names]
            if old_domain is not None:
                _metas = [m for m in old_domain.metas if m.name != meta_attr_name]
            M = get_table_from_attributes_of_attributes(_metas, _dtype=object)
            progress_callback(0.7)
            if old_domain is None:
                _metas = [guessed_var(i, m.name) for i, m in enumerate(_metas)]
            if _metas:
                self.metas = np.hstack((self.metas, M))
                metas.extend(_metas)

            self.domain = Domain(attributes, class_vars, metas)
            progress_callback(0.9)
            cls._init_ids(self)
            self.attributes = table.attributes.copy()
            self.attributes["old_domain"] = table.domain
            progress_callback(1)
            return self

    def to_sparse(self, sparse_attributes=True, sparse_class=False,
                  sparse_metas=False):
        def sparsify(features):
            for f in features:
                f.sparse = True

        new_domain = self.domain.copy()

        if sparse_attributes:
            sparsify(new_domain.attributes)
        if sparse_class:
            sparsify(new_domain.class_vars)
        if sparse_metas:
            sparsify(new_domain.metas)
        return self.transform(new_domain)

    def to_dense(self, dense_attributes=True, dense_class=True,
                 dense_metas=True):
        def densify(features):
            for f in features:
                f.sparse = False

        new_domain = self.domain.copy()

        if dense_attributes:
            densify(new_domain.attributes)
        if dense_class:
            densify(new_domain.class_vars)
        if dense_metas:
            densify(new_domain.metas)
        t = self.transform(new_domain)
        t.ids = self.ids  # preserve indices
        return t


def _dereferenced(array):
    # CSR and CSC matrices are constructed so that array.data is a
    # view to a base, which prevents unlocking them. Therefore, if
    # sparse matrix doesn't own its data, but its base array is
    # referenced only by this matrix, we copy it. This doesn't
    # increase memory use, but allows unlocking.
    if sp.issparse(array) \
            and array.data.base is not None \
            and sys.getrefcount(array.data.base) == 2:  # 2 = 1 real + 1 for arg
        array.data = array.data.copy()
    return array


def _check_arrays(*arrays, dtype=None, shape_1=None):
    checked = []
    if not len(arrays):
        return checked

    def ninstances(array):
        if hasattr(array, "shape"):
            return array.shape[0]
        else:
            return len(array) if array is not None else 0

    if shape_1 is None:
        shape_1 = ninstances(arrays[0])

    for array in arrays:
        if array is None:
            checked.append(array)
            continue

        if ninstances(array) != shape_1:
            raise ValueError("Leading dimension mismatch (%d != %d)"
                             % (ninstances(array), shape_1))

        if sp.issparse(array):
            if not (sp.isspmatrix_csr(array) or sp.isspmatrix_csc(array)):
                array = array.tocsr()
            array.data = np.asarray(array.data)
            array = _dereferenced(array)
            has_inf = _check_inf(array.data)
        else:
            if dtype is not None:
                array = np.asarray(array, dtype=dtype)
            else:
                array = np.asarray(array)
            has_inf = _check_inf(array)

        if has_inf:
            array[np.isinf(array)] = np.nan
            warnings.warn("Array contains infinity.", RuntimeWarning)
        checked.append(array)

    return checked


def _check_inf(array):
    return array.dtype.char in np.typecodes['AllFloat'] and \
           np.isinf(array.data).any()


def _subarray(arr, rows, cols):
    rows = _optimize_indices(rows, arr.shape[0])
    if arr.ndim == 1:
        return arr[rows]
    cols = _optimize_indices(cols, arr.shape[1])
    return arr[_rxc_ix(rows, cols)]


def _optimize_indices(indices, maxlen):
    """
    Convert integer indices to slice if possible. It only converts increasing
    integer ranges with positive steps and valid starts and ends.
    Only convert valid ends so that invalid ranges will still raise
    an exception.

    Allows numpy to reuse the data array, because it defaults to copying
    if given indices.

    Parameters
    ----------
    indices : 1D sequence, slice or Ellipsis
    """
    if isinstance(indices, slice):
        return indices

    if indices is ...:
        return slice(None, None, 1)

    # a very common case for column selection
    if len(indices) == 1 and not isinstance(indices[0], bool):
        if indices[0] >= 0:
            return slice(indices[0], indices[0] + 1, 1)
        else:
            return slice(indices[0], indices[0] - 1, -1)

    if len(indices) >= 1:
        indices = np.asarray(indices)
        if indices.dtype != bool:
            begin = indices[0]
            end = indices[-1]
            steps = np.diff(indices) if len(indices) > 1 else np.array([1])
            step = steps[0]

            # continuous ranges with constant step and valid start and stop index can be slices
            if np.all(steps == step) and step > 0 and begin >= 0 and end < maxlen:
                return slice(begin, end + step, step)

    return indices


def _rxc_ix(rows, cols):
    """
    Construct an index object to index the `rows` x `cols` cross product.

    Rows and columns can be a 1d bool or int sequence, or a slice.
    The later is a convenience and is interpreted the same
    as `slice(None, None, -1)`

    Parameters
    ----------
    rows : 1D sequence, slice
        Row indices.
    cols : 1D sequence, slice
        Column indices.

    See Also
    --------
    numpy.ix_

    Examples
    --------
    >>> import numpy as np
    >>> a = np.arange(10).reshape(2, 5)
    >>> a[_rxc_ix([0, 1], [3, 4])]
    array([[3, 4],
           [8, 9]])
    >>> a[_rxc_ix([False, True], slice(None, None, 1))]
    array([[5, 6, 7, 8, 9]])

    """
    isslice = (isinstance(rows, slice), isinstance(cols, slice))
    if isslice == (True, True):
        return rows, cols
    elif isslice == (True, False):
        return rows, np.asarray(np.ix_(cols), int).ravel()
    elif isslice == (False, True):
        return np.asarray(np.ix_(rows), int).ravel(), cols
    else:
        r, c = np.ix_(rows, cols)
        return np.asarray(r, int), np.asarray(c, int)


def assure_domain_conversion_sparsity(target, source):
    """
    Assure that the table obeys the domain conversion's suggestions about sparsity.

    Args:
        target (Table): the target table.
        source (Table): the source table.

    Returns:
        Table: with fixed sparsity. The sparsity is set as it is recommended by domain conversion
            for transformation from source to the target domain.
    """
    conversion = DomainConversion(source.domain, target.domain)
    match_density = [assure_array_dense, assure_array_sparse]
    target.X = match_density[conversion.sparse_X](target.X)
    target.Y = match_density[conversion.sparse_Y](target.Y)
    target.metas = match_density[conversion.sparse_metas](target.metas)
    return target


class Role:
    Attribute = 0
    ClassAttribute = 1
    Meta = 2

    @staticmethod
    def get_arr(role, table):
        return table.X if role == Role.Attribute else \
               table.Y if role == Role.ClassAttribute else \
               table.metas

```
--- END FILE ---

Please first localize the bug based on the issue statement, and then generate *SEARCH/REPLACE* edits to fix the issue.

Every *SEARCH/REPLACE* edit must use this format:
1. The file path
2. The start of search block: <<<<<<< SEARCH
3. A contiguous chunk of lines to search for in the existing source code
4. The dividing line: =======
5. The lines to replace into the source code
6. The end of the replace block: >>>>>>> REPLACE

Here is an example:

```python
### mathweb/flask/app.py
<<<<<<< SEARCH
from flask import Flask
=======
import math
from flask import Flask
>>>>>>> REPLACE
```
</solution>

Please note that the *SEARCH/REPLACE* edit REQUIRES PROPER INDENTATION. If you would like to add the line '        print(x)', you must fully write that out, with all those spaces before the code!
Wrap each *SEARCH/REPLACE* edit in a code block as shown in the example above. If you have multiple *SEARCH/REPLACE* edits, use a separate code block for each one.
[ISSUE]
**Title:** Unpickling Table Fails to Restore 'X' Attribute in State

**Description:**
When unpickling a `Table` object, the internal state does not include the 'X' attribute. This omission causes the deserialized `Table` to lack essential data, leading to inconsistencies and potential errors in subsequent operations.

**Example Buggy Code:**
```python
import pickle
from unittest.mock import patch, Mock

def test_pickle_setstate():
    d = data.Table("zoo")
    s = pickle.dumps(d)
    with patch("Orange.data.Table.__setstate__", Mock()) as mock:
        pickle.loads(s)
        state = mock.call_args[0][0]
        # 'X' is expected to be in the state but is missing
```

**Expected Behavior:**
After unpickling, the `Table`'s internal state should include the 'X' attribute as a 2D array along with other attributes like '_Y' and 'metas'. This ensures that all necessary data is correctly restored and the `Table` functions as intended.

**Actual Behavior:**
The 'X' attribute is absent from the internal state during the unpickling process. This leads to the `Table` object missing crucial data, which can cause failures in operations that rely on the 'X' attribute.

[/ISSUE]
{
    "test_dirname": "PASSED",
    "TableTestCase.test_assign_multiple_indices_value": "PASSED",
    "TableTestCase.test_assign_slice_value": "PASSED",
    "TableTestCase.test_attributes": "PASSED",
    "TableTestCase.test_bool": "PASSED",
    "TableTestCase.test_checksum": "PASSED",
    "TableTestCase.test_concatenate": "PASSED",
    "TableTestCase.test_concatenate_exceptions": "PASSED",
    "TableTestCase.test_concatenate_sparse": "PASSED",
    "TableTestCase.test_copy": "PASSED",
    "TableTestCase.test_copy_sparse": "PASSED",
    "TableTestCase.test_filename": "PASSED",
    "TableTestCase.test_filter_has_class": "PASSED",
    "TableTestCase.test_filter_is_defined": "PASSED",
    "TableTestCase.test_filter_random": "PASSED",
    "TableTestCase.test_filter_string_works_for_numeric_columns": "PASSED",
    "TableTestCase.test_filter_value_continuous": "PASSED",
    "TableTestCase.test_filter_value_continuous_args": "PASSED",
    "TableTestCase.test_filter_values_nested": "PASSED",
    "TableTestCase.test_from_numpy": "PASSED",
    "TableTestCase.test_has_missing": "PASSED",
    "TableTestCase.test_indexing": "PASSED",
    "TableTestCase.test_indexing_assign_example": "PASSED",
    "TableTestCase.test_indexing_assign_value": "PASSED",
    "TableTestCase.test_indexing_class": "PASSED",
    "TableTestCase.test_indexing_example": "PASSED",
    "TableTestCase.test_inf": "PASSED",
    "TableTestCase.test_is_sparse": "PASSED",
    "TableTestCase.test_multiple_indices": "PASSED",
    "TableTestCase.test_pickle": "PASSED",
    "TableTestCase.test_pickle_setstate": "PASSED",
    "TableTestCase.test_repr_sparse_with_one_row": "PASSED",
    "TableTestCase.test_saveTab": "PASSED",
    "TableTestCase.test_save_pickle": "PASSED",
    "TableTestCase.test_set_multiple_indices_example": "PASSED",
    "TableTestCase.test_shuffle": "PASSED",
    "TableTestCase.test_slice": "PASSED",
    "TableTestCase.test_table_dtypes": "PASSED",
    "TableTestCase.test_total_weight": "PASSED",
    "TableTestCase.test_translate_through_slice": "PASSED",
    "TableTestCase.test_valueFilter_discrete": "PASSED",
    "TableTestCase.test_valueFilter_discrete_meta_is_defined": "PASSED",
    "TableTestCase.test_valueFilter_regex": "PASSED",
    "TableTestCase.test_valueFilter_stringList": "PASSED",
    "TableTestCase.test_valueFilter_string_case_insens": "PASSED",
    "TableTestCase.test_valueFilter_string_case_sens": "PASSED",
    "TableTestCase.test_valueFilter_string_is_defined": "PASSED",
    "CreateEmptyTable.test_calling_new_with_no_parameters_constructs_a_new_instance": "PASSED",
    "CreateEmptyTable.test_table_has_file": "PASSED",
    "CreateTableWithFilename.test_calling_new_with_keyword_argument_filename_calls_read_data": "PASSED",
    "CreateTableWithFilename.test_calling_new_with_string_argument_calls_read_data": "PASSED",
    "CreateTableWithFilename.test_raises_error_if_file_does_not_exist": "PASSED",
    "CreateTableWithFilename.test_raises_error_if_file_has_unknown_extension": "PASSED",
    "CreateTableWithFilename.test_read_data_calls_reader": "PASSED",
    "CreateTableWithUrl.test_trimmed_urls": "PASSED",
    "CreateTableWithUrl.test_url_no_scheme": "PASSED",
    "CreateTableWithDomain.test_calling_new_with_domain_calls_new_from_domain": "PASSED",
    "CreateTableWithDomain.test_creates_an_empty_table_with_given_domain": "PASSED",
    "CreateTableWithDomain.test_creates_weights_if_weights_are_true": "PASSED",
    "CreateTableWithDomain.test_creates_zero_filled_rows_in_X_if_domain_contains_attributes": "PASSED",
    "CreateTableWithDomain.test_creates_zero_filled_rows_in_Y_if_domain_contains_class_vars": "PASSED",
    "CreateTableWithDomain.test_creates_zero_filled_rows_in_metas_if_domain_contains_metas": "PASSED",
    "CreateTableWithDomain.test_does_not_create_weights_if_weights_are_false": "PASSED",
    "CreateTableWithData.test_calling_new_with_domain_and_numpy_arrays_calls_new_from_numpy": "PASSED",
    "CreateTableWithData.test_creates_a_discrete_class_if_Y_has_few_distinct_values": "PASSED",
    "CreateTableWithData.test_creates_a_table_from_domain_and_list": "PASSED",
    "CreateTableWithData.test_creates_a_table_from_domain_and_list_and_metas": "PASSED",
    "CreateTableWithData.test_creates_a_table_from_domain_and_list_and_weights": "PASSED",
    "CreateTableWithData.test_creates_a_table_from_list_of_instances": "PASSED",
    "CreateTableWithData.test_creates_a_table_from_list_of_instances_with_metas": "PASSED",
    "CreateTableWithData.test_creates_a_table_with_domain_and_given_X": "PASSED",
    "CreateTableWithData.test_creates_a_table_with_given_X": "PASSED",
    "CreateTableWithData.test_creates_a_table_with_given_X_Y_and_metas": "PASSED",
    "CreateTableWithData.test_creates_a_table_with_given_X_and_Y": "PASSED",
    "CreateTableWithData.test_creates_a_table_with_given_domain": "PASSED",
    "CreateTableWithData.test_from_numpy_reconstructable": "PASSED",
    "CreateTableWithData.test_initializes_Y_metas_and_W_if_not_given": "PASSED",
    "CreateTableWithData.test_raises_error_if_columns_in_domain_and_data_do_not_match": "PASSED",
    "CreateTableWithData.test_raises_error_if_lengths_of_data_do_not_match": "PASSED",
    "CreateTableWithData.test_sets_Y_if_given": "PASSED",
    "CreateTableWithData.test_sets_metas_if_given": "PASSED",
    "CreateTableWithData.test_sets_weights_if_given": "PASSED",
    "CreateTableWithData.test_splits_X_and_Y_if_given_in_same_array": "PASSED",
    "CreateTableWithDomainAndTable.test_can_copy_table": "PASSED",
    "CreateTableWithDomainAndTable.test_can_filter_row_with_slice_from_table": "PASSED",
    "CreateTableWithDomainAndTable.test_can_filter_row_with_slice_from_table_rows": "PASSED",
    "CreateTableWithDomainAndTable.test_can_filter_rows_with_list": "PASSED",
    "CreateTableWithDomainAndTable.test_can_use_attributes_as_new_columns": "PASSED",
    "CreateTableWithDomainAndTable.test_can_use_class_vars_as_new_columns": "PASSED",
    "CreateTableWithDomainAndTable.test_can_use_combination_of_all_as_new_columns": "PASSED",
    "CreateTableWithDomainAndTable.test_can_use_metas_as_new_columns": "PASSED",
    "CreateTableWithDomainAndTable.test_creates_table_with_given_domain": "PASSED",
    "CreateTableWithDomainAndTable.test_creates_table_with_given_domain_and_row_filter": "PASSED",
    "CreateTableWithDomainAndTable.test_from_table_shared_compute_value": "PASSED",
    "CreateTableWithDomainAndTable.test_from_table_sparse_move_all_to_empty_metas": "PASSED",
    "CreateTableWithDomainAndTable.test_from_table_sparse_move_some_to_empty_metas": "PASSED",
    "CreateTableWithDomainAndTable.test_from_table_sparse_move_to_nonempty_metas": "PASSED",
    "CreateTableWithDomainAndTable.test_transform": "PASSED",
    "CreateTableWithDomainAndTable.test_transform_same_domain": "PASSED",
    "TableIndexingTests.test_can_select_a_single_row": "PASSED",
    "TableIndexingTests.test_can_select_a_single_value": "PASSED",
    "TableIndexingTests.test_can_select_a_subset_of_rows_and_columns": "PASSED",
    "TableIndexingTests.test_optimize_indices": "PASSED",
    "TableElementAssignmentTest.test_can_assign_lists": "PASSED",
    "TableElementAssignmentTest.test_can_assign_np_array": "PASSED",
    "TableElementAssignmentTest.test_can_assign_rows_to_rows": "PASSED",
    "TableElementAssignmentTest.test_can_assign_values": "PASSED",
    "TableElementAssignmentTest.test_can_assign_values_to_classes": "PASSED",
    "TableElementAssignmentTest.test_can_assign_values_to_metas": "PASSED",
    "InterfaceTest.test_iteration": "PASSED",
    "InterfaceTest.test_len": "PASSED",
    "InterfaceTest.test_row_assignment": "PASSED",
    "InterfaceTest.test_row_indexing": "PASSED",
    "InterfaceTest.test_row_len": "PASSED",
    "InterfaceTest.test_row_slicing": "PASSED",
    "InterfaceTest.test_value_assignment": "PASSED",
    "InterfaceTest.test_value_indexing": "PASSED",
    "TestTableStats.test_get_nan_frequency": "PASSED",
    "TestTableStats.test_get_nan_frequency_empty_table": "PASSED",
    "TestRowInstance.test_assignment": "PASSED",
    "TestRowInstance.test_iteration_with_assignment": "PASSED",
    "TestRowInstance.test_sparse_assignment": "PASSED",
    "TestTableTranspose.test_transpose": "PASSED",
    "TestTableTranspose.test_transpose_attributes_of_attributes_continuous": "PASSED",
    "TestTableTranspose.test_transpose_attributes_of_attributes_continuous_remove_inst": "PASSED",
    "TestTableTranspose.test_transpose_attributes_of_attributes_discrete": "PASSED",
    "TestTableTranspose.test_transpose_attributes_of_attributes_discrete_remove_inst": "PASSED",
    "TestTableTranspose.test_transpose_attributes_of_attributes_missings": "PASSED",
    "TestTableTranspose.test_transpose_attributes_of_attributes_missings_remove_inst": "PASSED",
    "TestTableTranspose.test_transpose_callback": "PASSED",
    "TestTableTranspose.test_transpose_class_and_metas": "PASSED",
    "TestTableTranspose.test_transpose_class_and_metas_remove_inst": "PASSED",
    "TestTableTranspose.test_transpose_class_metas_attributes": "PASSED",
    "TestTableTranspose.test_transpose_class_metas_attributes_remove_inst": "PASSED",
    "TestTableTranspose.test_transpose_continuous_class": "PASSED",
    "TestTableTranspose.test_transpose_continuous_class_remove_inst": "PASSED",
    "TestTableTranspose.test_transpose_continuous_metas": "PASSED",
    "TestTableTranspose.test_transpose_continuous_metas_remove_inst": "PASSED",
    "TestTableTranspose.test_transpose_discrete_class": "PASSED",
    "TestTableTranspose.test_transpose_discrete_class_remove_inst": "PASSED",
    "TestTableTranspose.test_transpose_discrete_metas": "PASSED",
    "TestTableTranspose.test_transpose_discrete_metas_remove_inst": "PASSED",
    "TestTableTranspose.test_transpose_duplicate_feature_names": "PASSED",
    "TestTableTranspose.test_transpose_metas": "PASSED",
    "TestTableTranspose.test_transpose_metas_remove_inst": "PASSED",
    "TestTableTranspose.test_transpose_missing_class": "PASSED",
    "TestTableTranspose.test_transpose_missing_class_remove_inst": "PASSED",
    "TestTableTranspose.test_transpose_missing_metas": "PASSED",
    "TestTableTranspose.test_transpose_missing_metas_remove_inst": "PASSED",
    "TestTableTranspose.test_transpose_multiple_class": "PASSED",
    "TestTableTranspose.test_transpose_multiple_class_remove_inst": "PASSED",
    "TestTableTranspose.test_transpose_multiple_metas": "PASSED",
    "TestTableTranspose.test_transpose_multiple_metas_remove_inst": "PASSED",
    "TestTableTranspose.test_transpose_no_class": "PASSED",
    "TestTableTranspose.test_transpose_no_class_remove_inst": "PASSED",
    "TestTableSparseDense.test_from_table_add_lots_of_sparse_columns": "PASSED",
    "TestTableSparseDense.test_from_table_add_one_sparse_column": "PASSED",
    "TestTableSparseDense.test_from_table_replace_attrs_with_sparse": "PASSED",
    "TestTableSparseDense.test_from_table_sparse_metas": "PASSED",
    "TestTableSparseDense.test_from_table_sparse_metas_with_strings": "PASSED",
    "TestTableSparseDense.test_sparse_dense_transformation": "PASSED",
    "ConcurrencyTests.test_from_table_non_blocking": "PASSED",
    "EfficientTransformTests.test_shared": "PASSED",
    "EfficientTransformTests.test_simple": "PASSED",
    "EfficientTransformTests.test_simple_simple_shared": "PASSED",
    "EfficientTransformTests.test_simple_simple_shared_simple": "PASSED",
    "EfficientTransformTests.test_simple_simple_shared_simple_shared_simple": "PASSED",
    "EfficientTransformTests.test_simple_simple_stupid": "PASSED",
    "InterfaceTest.test_subclasses": "FAILED"
}
diff --git a/Orange/data/table.py b/Orange/data/table.py
index b785109c3..a3800c046 100644
--- a/Orange/data/table.py
+++ b/Orange/data/table.py
@@ -447,8 +447,24 @@ class Table(Sequence, Storage):
             for k in ("X", "W", "metas"):
                 if k in state:
                     setattr(self, k, state.pop(k))
+            if "_Y" in state:
+                setattr(self, "Y", state.pop("_Y"))  # state["_Y"] is a 2d array
             self.__dict__.update(state)
 
+    def __getstate__(self):
+        # Compatibility with pickles before table locking:
+        # return the same state as before table lock
+        state = self.__dict__.copy()
+        for k in ["X", "metas", "W"]:
+            if "_" + k in state:  # Check existence; SQL tables do not contain them
+                state[k] = state.pop("_" + k)
+        # before locking, _Y was always a 2d array: save it as such
+        if "_Y" in state:
+            y = state.pop("_Y")
+            y2d = y.reshape(-1, 1) if y.ndim == 1 else y
+            state["_Y"] = y2d
+        return state
+
     def _lock_parts(self):
         return ((self._X, self._Unlocked_X, "X"),
                 (self._Y, self._Unlocked_Y, "Y"),

{"Orange/data/table.py": "import operator\nimport os\nimport sys\nimport threading\nimport warnings\nimport weakref\nimport zlib\nfrom collections.abc import Iterable, Sequence, Sized\nfrom contextlib import contextmanager\nfrom functools import reduce\nfrom itertools import chain\nfrom numbers import Real, Integral\nfrom threading import Lock\n\nimport bottleneck as bn\nimport numpy as np\n\nfrom scipy import sparse as sp\nfrom scipy.sparse import issparse, csc_matrix\n\nimport Orange.data  # import for io.py\nfrom Orange.data import (\n    _contingency, _valuecount,\n    Domain, Variable, Storage, StringVariable, Unknown, Value, Instance,\n    ContinuousVariable, DiscreteVariable, MISSING_VALUES,\n    DomainConversion)\nfrom Orange.data.util import SharedComputeValue, \\\n    assure_array_dense, assure_array_sparse, \\\n    assure_column_dense, assure_column_sparse, get_unique_names_duplicates\nfrom Orange.misc.collections import frozendict\nfrom Orange.statistics.util import bincount, countnans, contingency, \\\n    stats as fast_stats, sparse_has_implicit_zeros, sparse_count_implicit_zeros, \\\n    sparse_implicit_zero_weights\nfrom Orange.util import OrangeDeprecationWarning, dummy_callback\n\n__all__ = [\"dataset_dirs\", \"get_sample_datasets_dir\", \"RowInstance\", \"Table\"]\n\n\ndef get_sample_datasets_dir():\n    orange_data_table = os.path.dirname(__file__)\n    dataset_dir = os.path.join(orange_data_table, '..', 'datasets')\n    return os.path.realpath(dataset_dir)\n\n\ndataset_dirs = ['', get_sample_datasets_dir()]\n\n\nclass _ThreadLocal(threading.local):\n    def __init__(self):\n        super().__init__()\n        # Domain conversion cache used in Table.from_table. It is defined\n        # here instead of as a class variable of a Table so that caching also works\n        # with descendants of Table.\n        self.conversion_cache = None\n        self.domain_cache = None\n\n\n_thread_local = _ThreadLocal()\n\n\ndef _idcache_save(cachedict, keys, value):\n    cachedict[tuple(map(id, keys))] = \\\n        value, [weakref.ref(k) for k in keys]\n\n\ndef _idcache_restore(cachedict, keys):\n    shared, weakrefs = cachedict.get(tuple(map(id, keys)), (None, []))\n    for r in weakrefs:\n        if r() is None:\n            return None\n    return shared\n\n\nclass DomainTransformationError(Exception):\n    pass\n\n\nclass RowInstance(Instance):\n    sparse_x = None\n    sparse_y = None\n    sparse_metas = None\n    _weight = None\n\n    def __init__(self, table, row_index):\n        \"\"\"\n        Construct a data instance representing the given row of the table.\n        \"\"\"\n        self.table = table\n        self._domain = table.domain\n        self.row_index = row_index\n        self.id = table.ids[row_index]\n        self._x = table.X[row_index]\n        if sp.issparse(self._x):\n            self.sparse_x = sp.csr_matrix(self._x)\n            self._x = np.asarray(self._x.todense())[0]\n        self._y = table._Y[row_index]\n        if sp.issparse(self._y):\n            self.sparse_y = sp.csr_matrix(self._y)\n            self._y = np.asarray(self._y.todense())[0]\n        self._y = np.atleast_1d(self._y)\n        self._metas = table.metas[row_index]\n        if sp.issparse(self._metas):\n            self.sparse_metas = sp.csr_matrix(self._metas)\n            self._metas = np.asarray(self._metas.todense())[0]\n\n    @property\n    def weight(self):\n        if not self.table.has_weights():\n            return 1\n        return self.table.W[self.row_index]\n\n    @weight.setter\n    def weight(self, weight):\n        if not self.table.has_weights():\n            self.table.set_weights()\n        self.table.W[self.row_index] = weight\n\n    def set_class(self, value):\n        # pylint: disable=protected-access\n        self._check_single_class()\n        if not isinstance(value, Real):\n            value = self.table.domain.class_var.to_val(value)\n        if self.sparse_y:\n            self.table._Y[self.row_index, 0] = value\n        else:\n            self.table._Y[self.row_index] = value\n            if self.table._Y.ndim == 1:  # if _y is not a view\n                self._y[0] = value\n\n    def __setitem__(self, key, value):\n        if not isinstance(key, Integral):\n            key = self._domain.index(key)\n        if isinstance(value, str):\n            var = self._domain[key]\n            value = var.to_val(value)\n        if key >= 0:\n            if not isinstance(value, Real):\n                raise TypeError(\"Expected primitive value, got '%s'\" %\n                                type(value).__name__)\n            if key < len(self._x):\n                # write to self.table.X to support table unlocking for live instances\n                self.table.X[self.row_index, key] = value\n                if self.sparse_x is not None:\n                    self._x[key] = value\n            else:\n                if self.sparse_y is not None:\n                    self.table._Y[self.row_index, key - len(self._x)] = value\n                else:\n                    self.table._Y[self.row_index] = value\n                    if self.table._Y.ndim == 1:  # if _y is not a view\n                        self._y[0] = value\n        else:\n            self.table.metas[self.row_index, -1 - key] = value\n            if self.sparse_metas is not None:\n                self._metas[-1 - key] = value\n\n    def _str(self, limit):\n        def sp_values(matrix, variables):\n            if not sp.issparse(matrix):\n                if matrix.ndim == 1:\n                    matrix = matrix[:, np.newaxis]\n                return Instance.str_values(matrix[row], variables, limit)\n\n            row_entries, idx = [], 0\n            while idx < len(variables):\n                # Make sure to stop printing variables if we limit the output\n                if limit and len(row_entries) >= 5:\n                    break\n\n                var = variables[idx]\n                if var.is_discrete or matrix[row, idx]:\n                    row_entries.append(\"%s=%s\" % (var.name, var.str_val(matrix[row, idx])))\n\n                idx += 1\n\n            s = \", \".join(row_entries)\n\n            if limit and idx < len(variables):\n                s += \", ...\"\n\n            return s\n\n        table = self.table\n        domain = table.domain\n        row = self.row_index\n        s = \"[\" + sp_values(table.X, domain.attributes)\n        if domain.class_vars:\n            s += \" | \" + sp_values(table.Y, domain.class_vars)\n        s += \"]\"\n        if self._domain.metas:\n            s += \" {\" + sp_values(table.metas, domain.metas) + \"}\"\n        return s\n\n    def __str__(self):\n        return self._str(False)\n\n    def __repr__(self):\n        return self._str(True)\n\n\nclass Columns:\n    def __init__(self, domain):\n        for v in chain(domain.variables, domain.metas):\n            setattr(self, v.name.replace(\" \", \"_\"), v)\n\n\nclass _ArrayConversion:\n\n    def __init__(self, target, src_cols, variables, is_sparse, source_domain):\n        self.target = target\n        self.src_cols = src_cols\n        self.is_sparse = is_sparse\n        self.subarray_from = self._can_copy_all(src_cols, source_domain)\n        self.variables = variables\n        dtype = np.float64\n        if any(isinstance(var, StringVariable) for var in self.variables):\n            dtype = object\n        self.dtype = dtype\n        self.row_selection_needed = any(not isinstance(x, Integral)\n                                        for x in src_cols)\n\n    def _can_copy_all(self, src_cols, source_domain):\n        n_src_attrs = len(source_domain.attributes)\n        if all(isinstance(x, Integral) and 0 <= x < n_src_attrs\n               for x in src_cols):\n            return \"X\"\n        if all(isinstance(x, Integral) and x < 0 for x in src_cols):\n            return \"metas\"\n        if all(isinstance(x, Integral) and x >= n_src_attrs\n               for x in src_cols):\n            return \"Y\"\n\n    def get_subarray(self, source, row_indices, n_rows):\n        if not len(self.src_cols):\n            if self.is_sparse:\n                return sp.csr_matrix((n_rows, 0), dtype=source.X.dtype)\n            else:\n                return np.zeros((n_rows, 0), dtype=source.X.dtype)\n\n        match_density = assure_array_sparse if self.is_sparse else assure_array_dense\n        n_src_attrs = len(source.domain.attributes)\n        if self.subarray_from == \"X\":\n            arr = match_density(_subarray(source.X, row_indices, self.src_cols))\n        elif self.subarray_from == \"metas\":\n            arr = match_density(_subarray(source.metas, row_indices,\n                                          [-1 - x for x in self.src_cols]))\n        elif self.subarray_from == \"Y\":\n            Y = source.Y if source.Y.ndim == 2 else source.Y[:, None]\n            arr = match_density(_subarray(\n                Y, row_indices,\n                [x - n_src_attrs for x in self.src_cols]))\n        else:\n            assert False\n        if arr.dtype != self.dtype:\n            arr = arr.astype(self.dtype)\n        assert arr.ndim == 2 or self.subarray_from == \"Y\" and arr.ndim == 1\n        return arr\n\n    def get_columns(self, source, row_indices, n_rows, out=None, target_indices=None):\n        n_src_attrs = len(source.domain.attributes)\n\n        data = []\n        sp_col = []\n        sp_row = []\n        match_density = (\n            assure_column_sparse if self.is_sparse else assure_column_dense\n        )\n\n        # converting to csc before instead of each column is faster\n        # do not convert if not required\n        if any(isinstance(x, int) for x in self.src_cols):\n            X = source.X\n            Y = source.Y\n            if Y.ndim == 1:\n                Y = Y[:, None]\n            if self.is_sparse:\n                X = csc_matrix(X)\n                Y = csc_matrix(Y)\n\n        if self.row_selection_needed:\n            if row_indices is ...:\n                sourceri = source\n            else:\n                sourceri = source[row_indices]\n\n        shared_cache = _thread_local.conversion_cache\n        for i, col in enumerate(self.src_cols):\n            if col is None:\n                col_array = match_density(\n                    np.full((n_rows, 1), self.variables[i].Unknown)\n                )\n            elif not isinstance(col, Integral):\n                if isinstance(col, SharedComputeValue):\n                    shared = _idcache_restore(shared_cache, (col.compute_shared, source))\n                    if shared is None:\n                        shared = col.compute_shared(sourceri)\n                        _idcache_save(shared_cache, (col.compute_shared, source), shared)\n                    col_array = match_density(\n                        col(sourceri, shared_data=shared))\n                else:\n                    col_array = match_density(col(sourceri))\n            elif col < 0:\n                col_array = match_density(\n                    source.metas[row_indices, -1 - col]\n                )\n            elif col < n_src_attrs:\n                col_array = match_density(X[row_indices, col])\n            else:\n                col_array = match_density(\n                    Y[row_indices, col - n_src_attrs]\n                )\n\n            if self.is_sparse:\n                # col_array should be coo matrix\n                data.append(col_array.data)\n                sp_col.append(np.full(len(col_array.data), i))\n                sp_row.append(col_array.indices)  # row indices should be same\n            else:\n                out[target_indices, i] = col_array\n\n        if self.is_sparse:\n            # creating csr directly would need plenty of manual work which\n            # would probably slow down the process - conversion coo to csr\n            # is fast\n            out = sp.coo_matrix(\n                (np.hstack(data), (np.hstack(sp_row), np.hstack(sp_col))),\n                shape=(n_rows, len(self.src_cols)),\n                dtype=self.dtype\n            )\n            out = out.tocsr()\n\n        return out\n\n\nclass _FromTableConversion:\n\n    def __init__(self, source, destination):\n        conversion = DomainConversion(source, destination)\n\n        self.X = _ArrayConversion(\"X\", conversion.attributes,\n                                  destination.attributes, conversion.sparse_X,\n                                  source)\n        self.Y = _ArrayConversion(\"Y\", conversion.class_vars,\n                                  destination.class_vars, conversion.sparse_Y,\n                                  source)\n        self.metas = _ArrayConversion(\"metas\", conversion.metas,\n                                      destination.metas, conversion.sparse_metas,\n                                      source)\n\n        self.subarray = []\n        self.columnwise = []\n\n        for part in [self.X, self.Y, self.metas]:\n            if part.subarray_from is None:\n                self.columnwise.append(part)\n            else:\n                self.subarray.append(part)\n\n\n# noinspection PyPep8Naming\nclass Table(Sequence, Storage):\n\n    LOCKING = None\n    \"\"\" If the class attribute LOCKING is True, tables will throw exceptions\n    on in-place modifications unless unlocked explicitly. LOCKING is supposed\n    to be set to True for testing to help us find bugs. If set to False\n    or None, no safeguards are in place. Two different values are used for\n    the same behaviour to distinguish the unchanged default (None) form\n    explicit deactivation (False) that some add-ons might need. \"\"\"\n\n    __file__ = None\n    name = \"untitled\"\n\n    domain = Domain([])\n    _X = _Y = _metas = _W = np.zeros((0, 0))  # pylint: disable=invalid-name\n    ids = np.zeros(0)\n    ids.setflags(write=False)\n    attributes = frozendict()\n\n    _Unlocked_X, _Unlocked_Y, _Unlocked_metas, _Unlocked_W = 1, 2, 4, 8\n    _unlocked = _Unlocked_X + _Unlocked_Y + \\\n                _Unlocked_metas + _Unlocked_W  # pylint: disable=invalid-name\n\n    @property\n    def columns(self):\n        \"\"\"\n        A class whose attributes contain attribute descriptors for columns.\n        For a table `table`, setting `c = table.columns` will allow accessing\n        the table's variables with, for instance `c.gender`, `c.age` ets.\n        Spaces are replaced with underscores.\n        \"\"\"\n        return Columns(self.domain)\n\n    _next_instance_id = 0\n    _next_instance_lock = Lock()\n\n    def _check_unlocked(self, partflag):\n        if not self._unlocked & partflag:\n            raise ValueError(\"Table is read-only unless unlocked\")\n\n    @property\n    def X(self):  # pylint: disable=invalid-name\n        return self._X\n\n    @X.setter\n    def X(self, value):\n        self._check_unlocked(self._Unlocked_X)\n        self._X = _dereferenced(value)\n\n    @property\n    def Y(self):  # pylint: disable=invalid-name\n        return self._Y\n\n    @Y.setter\n    def Y(self, value):\n        self._check_unlocked(self._Unlocked_Y)\n        if sp.issparse(value) and len(self) != value.shape[0]:\n            value = value.T\n        if sp.issparse(value):\n            value = _dereferenced(value.toarray())\n        if value.ndim == 2 and value.shape[1] == 1:\n            value = value[:, 0].copy()  # no views!\n        self._Y = value\n\n    @property\n    def metas(self):\n        return self._metas\n\n    @metas.setter\n    def metas(self, value):\n        self._check_unlocked(self._Unlocked_metas)\n        self._metas = _dereferenced(value)\n\n    @property\n    def W(self):  # pylint: disable=invalid-name\n        return self._W\n\n    @W.setter\n    def W(self, value):\n        self._check_unlocked(self._Unlocked_W)\n        self._W = value\n\n    def __setstate__(self, state):\n        # Backward compatibility with pickles before table locking\n        self._initialize_unlocked()  # __dict__ seems to be cleared before calling __setstate__\n        with self.unlocked():\n            for k in (\"X\", \"W\", \"metas\"):\n                if k in state:\n                    setattr(self, k, state.pop(k))\n            self.__dict__.update(state)\n\n    def _lock_parts(self):\n        return ((self._X, self._Unlocked_X, \"X\"),\n                (self._Y, self._Unlocked_Y, \"Y\"),\n                (self._metas, self._Unlocked_metas, \"metas\"),\n                (self._W, self._Unlocked_W, \"weights\"))\n\n    def _initialize_unlocked(self):\n        if Table.LOCKING:\n            self._unlocked = 0\n        else:\n            self._unlocked = sum(f for _, f, _ in self._lock_parts())\n\n    def _update_locks(self, force=False, unlock_bases=()):\n        if not Table.LOCKING:\n            return\n\n        def sync(*xs):\n            for x in xs:\n                try:\n                    undo_on_fail.append((x, x.flags.writeable))\n                    x.flags.writeable = writeable\n                except ValueError:\n                    if force \\\n                            and writeable \\\n                            and x.base is not None \\\n                            and not x.base.flags.writeable:\n                        x.base.flags.writeable = writeable\n                        x.flags.writeable = writeable\n                        forced_bases.append(x.base)\n                    else:\n                        raise\n\n        forced_bases = []\n        undo_on_fail = []\n        for base in unlock_bases:\n            base.flags.writeable = False\n        try:\n            for part, flag, _ in self._lock_parts():\n                if part is None:\n                    continue\n                writeable = bool(self._unlocked & flag)\n                if sp.isspmatrix_csr(part) or sp.isspmatrix_csc(part):\n                    sync(part.data, part.indices, part.indptr)\n                elif sp.isspmatrix_coo(part):\n                    sync(part.data, part.row, part.col)\n                elif sp.issparse(part):\n                    raise ValueError(\"Unsupported sparse data type\")\n                else:\n                    sync(part)\n        except:\n            for part, flag in undo_on_fail:\n                part.flags.writeable = flag\n            raise\n        return tuple(forced_bases)\n\n    def __unlocked(self, *parts, force=False):\n        prev_state = self._unlocked\n        for part, flag, _ in self._lock_parts():\n            if not parts or any(ppart is part for ppart in parts):\n                self._unlocked |= flag\n        try:\n            forced_bases = self._update_locks(force)\n            yield\n        finally:\n            self._unlocked = prev_state\n            self._update_locks(unlock_bases=forced_bases)\n\n    def force_unlocked(self, *parts):\n        \"\"\"\n        Unlocking without any checks.\n\n        Use with extreme caution. This is meant primarily for 3rd party\n        functions in Cython that expect read-write buffer, but do not\n        actually modify it. the given parts (default: all parts) of the table.\n\n        The function will still fail to unlock and raise an exception if the\n        table contains view to another table.\n        \"\"\"\n        return contextmanager(self.__unlocked)(*parts, force=True)\n\n    def unlocked(self, *parts):\n        \"\"\"\n        Unlock the given parts (default: all parts) of the table.\n\n        The caller must ensure that the table is safe to modify. The function\n        will raise an exception if the table contains view to other table.\n        \"\"\"\n        def can_unlock(x):\n            if sp.issparse(x):\n                return can_unlock(x.data)\n            return x.flags.writeable or x.flags.owndata\n\n        for part, flag, name in self._lock_parts():\n            if not flag & self._unlocked \\\n                    and (not parts or any(ppart is part for ppart in parts)) \\\n                    and part is not None and not can_unlock(part):\n                raise ValueError(f\"'{name}' is a view into another table \"\n                                 \"and cannot be unlocked\")\n        return contextmanager(self.__unlocked)(*parts)\n\n    def __new__(cls, *args, **kwargs):\n        def warn_deprecated(method):\n            warnings.warn(\"Direct calls to Table's constructor are deprecated \"\n                          \"and will be removed. Replace this call with \"\n                          f\"Table.{method}\", OrangeDeprecationWarning,\n                          stacklevel=3)\n\n        if not args:\n            if not kwargs:\n                return super().__new__(cls)\n            else:\n                raise TypeError(\"Table() must not be called directly\")\n\n        if isinstance(args[0], str):\n            if len(args) > 1:\n                raise TypeError(\"Table(name: str) expects just one argument\")\n            if args[0].startswith('https://') or args[0].startswith('http://'):\n                return cls.from_url(args[0], **kwargs)\n            else:\n                return cls.from_file(args[0], **kwargs)\n\n        elif isinstance(args[0], Table):\n            if len(args) > 1:\n                raise TypeError(\"Table(table: Table) expects just one argument\")\n            return cls.from_table(args[0].domain, args[0], **kwargs)\n        elif isinstance(args[0], Domain):\n            domain, args = args[0], args[1:]\n            if not args:\n                warn_deprecated(\"from_domain\")\n                return cls.from_domain(domain, **kwargs)\n            if isinstance(args[0], Table):\n                warn_deprecated(\"from_table\")\n                return cls.from_table(domain, *args, **kwargs)\n            elif isinstance(args[0], list):\n                warn_deprecated(\"from_list\")\n                return cls.from_list(domain, *args, **kwargs)\n        else:\n            warnings.warn(\"Omitting domain in a call to Table(X, Y, metas), is \"\n                          \"deprecated and will be removed. \"\n                          \"Call Table.from_numpy(None, X, Y, metas) instead.\",\n                          OrangeDeprecationWarning, stacklevel=2)\n            domain = None\n\n        return cls.from_numpy(domain, *args, **kwargs)\n\n    def __init__(self, *args, **kwargs):  # pylint: disable=unused-argument\n        self._initialize_unlocked()\n        self._update_locks()\n\n    @classmethod\n    def from_domain(cls, domain, n_rows=0, weights=False):\n        \"\"\"\n        Construct a new `Table` with the given number of rows for the given\n        domain. The optional vector of weights is initialized to 1's.\n\n        :param domain: domain for the `Table`\n        :type domain: Orange.data.Domain\n        :param n_rows: number of rows in the new table\n        :type n_rows: int\n        :param weights: indicates whether to construct a vector of weights\n        :type weights: bool\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n        self = cls()\n        self.domain = domain\n        self.n_rows = n_rows\n        with self.unlocked():\n            self.X = np.zeros((n_rows, len(domain.attributes)))\n            if len(domain.class_vars) != 1:\n                self.Y = np.zeros((n_rows, len(domain.class_vars)))\n            else:\n                self.Y = np.zeros(n_rows)\n            if weights:\n                self.W = np.ones(n_rows)\n            else:\n                self.W = np.empty((n_rows, 0))\n            self.metas = np.empty((n_rows, len(self.domain.metas)), object)\n            cls._init_ids(self)\n            self.attributes = {}\n        return self\n\n    @classmethod\n    def from_table(cls, domain, source, row_indices=...):\n        \"\"\"\n        Create a new table from selected columns and/or rows of an existing\n        one. The columns are chosen using a domain. The domain may also include\n        variables that do not appear in the source table; they are computed\n        from source variables if possible.\n\n        The resulting data may be a view or a copy of the existing data.\n\n        :param domain: the domain for the new table\n        :type domain: Orange.data.Domain\n        :param source: the source table\n        :type source: Orange.data.Table\n        :param row_indices: indices of the rows to include\n        :type row_indices: a slice or a sequence\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n\n        PART = 5000\n\n        new_cache = _thread_local.conversion_cache is None\n        try:\n            if new_cache:\n                _thread_local.conversion_cache = {}\n                _thread_local.domain_cache = {}\n            else:\n                cached = _idcache_restore(_thread_local.conversion_cache, (domain, source))\n                if cached is not None:\n                    return cached\n            if domain is source.domain:\n                table = cls.from_table_rows(source, row_indices)\n                # assure resulting domain is the instance passed on input\n                table.domain = domain\n                # since sparse flags are not considered when checking for\n                # domain equality, fix manually.\n                with table.unlocked():\n                    table = assure_domain_conversion_sparsity(table, source)\n                return table\n\n            if row_indices is ...:\n                n_rows = len(source)\n            elif isinstance(row_indices, slice):\n                row_indices_range = range(*row_indices.indices(source.X.shape[0]))\n                n_rows = len(row_indices_range)\n            else:\n                n_rows = len(row_indices)\n\n            self = cls()\n            self.domain = domain\n\n            table_conversion = \\\n                _idcache_restore(_thread_local.domain_cache, (domain, source.domain))\n            if table_conversion is None:\n                table_conversion = _FromTableConversion(source.domain, domain)\n                _idcache_save(_thread_local.domain_cache, (domain, source.domain),\n                              table_conversion)\n\n            # if an array can be a subarray of the input table, this needs to be done\n            # on the whole table, because this avoids needless copies of contents\n\n            with self.unlocked():\n                for array_conv in table_conversion.subarray:\n                    out = array_conv.get_subarray(source, row_indices, n_rows)\n                    setattr(self, array_conv.target, out)\n\n                parts = {}\n\n                for array_conv in table_conversion.columnwise:\n                    if array_conv.is_sparse:\n                        parts[array_conv.target] = []\n                    else:\n                        # F-order enables faster writing to the array while accessing and\n                        # matrix operations work with same speed (e.g. dot)\n                        parts[array_conv.target] = \\\n                            np.zeros((n_rows, len(array_conv.src_cols)),\n                                     order=\"F\", dtype=array_conv.dtype)\n\n                if n_rows <= PART:\n                    for array_conv in table_conversion.columnwise:\n                        out = array_conv.get_columns(source, row_indices, n_rows,\n                                                     parts[array_conv.target],\n                                                     ...)\n                        setattr(self, array_conv.target, out)\n                else:\n                    i_done = 0\n\n                    while i_done < n_rows:\n                        target_indices = slice(i_done, min(n_rows, i_done + PART))\n                        if row_indices is ...:\n                            source_indices = target_indices\n                        elif isinstance(row_indices, slice):\n                            r = row_indices_range[target_indices]\n                            source_indices = slice(r.start, r.stop, r.step)\n                        else:\n                            source_indices = row_indices[target_indices]\n                        part_rows = min(n_rows, i_done+PART) - i_done\n\n                        for array_conv in table_conversion.columnwise:\n                            out = array_conv.get_columns(source, source_indices, part_rows,\n                                                         parts[array_conv.target],\n                                                         target_indices)\n                            if array_conv.is_sparse:  # dense arrays are populated in-place\n                                parts[array_conv.target].append(out)\n\n                        i_done += PART\n\n                        # clear cache after a part is done\n                        if new_cache:\n                            _thread_local.conversion_cache = {}\n\n                    for array_conv in table_conversion.columnwise:\n                        cparts = parts[array_conv.target]\n                        out = cparts if not array_conv.is_sparse else sp.vstack(cparts)\n                        setattr(self, array_conv.target, out)\n\n                if source.has_weights():\n                    self.W = source.W[row_indices]\n                else:\n                    self.W = np.empty((n_rows, 0))\n                self.name = getattr(source, 'name', '')\n                if hasattr(source, 'ids'):\n                    self.ids = source.ids[row_indices]\n                else:\n                    cls._init_ids(self)\n                self.attributes = getattr(source, 'attributes', {})\n                _idcache_save(_thread_local.conversion_cache, (domain, source), self)\n            return self\n        finally:\n            if new_cache:\n                _thread_local.conversion_cache = None\n                _thread_local.domain_cache = None\n\n    def transform(self, domain):\n        \"\"\"\n        Construct a table with a different domain.\n\n        The new table keeps the row ids and other information. If the table\n        is a subclass of :obj:`Table`, the resulting table will be of the same\n        type.\n\n        In a typical scenario, an existing table is augmented with a new\n        column by ::\n\n            domain = Domain(old_domain.attributes + [new_attribute],\n                            old_domain.class_vars,\n                            old_domain.metas)\n            table = data.transform(domain)\n            table[:, new_attribute] = new_column\n\n        Args:\n            domain (Domain): new domain\n\n        Returns:\n            A new table\n        \"\"\"\n        return type(self).from_table(domain, self)\n\n    @classmethod\n    def from_table_rows(cls, source, row_indices):\n        \"\"\"\n        Construct a new table by selecting rows from the source table.\n\n        :param source: an existing table\n        :type source: Orange.data.Table\n        :param row_indices: indices of the rows to include\n        :type row_indices: a slice or a sequence\n        :return: a new table\n        :rtype: Orange.data.Table\n        \"\"\"\n        def get_rows(a):\n            a = a[row_indices]\n            if isinstance(row_indices, slice) or row_indices is ...:\n                a = a.copy()\n            return a\n\n        self = cls()\n        self.domain = source.domain\n        with self.unlocked():\n            self.X = get_rows(source.X)\n            if self.X.ndim == 1:\n                self.X = self.X.reshape(-1, len(self.domain.attributes))\n            self.Y = get_rows(source.Y)\n            self.metas = get_rows(source.metas)\n            if self.metas.ndim == 1:\n                self.metas = self.metas.reshape(-1, len(self.domain.metas))\n            self.W = get_rows(source.W)\n            self.name = getattr(source, 'name', '')\n            self.ids = np.array(source.ids[row_indices])\n            self.attributes = getattr(source, 'attributes', {})\n        return self\n\n    @classmethod\n    def from_numpy(cls, domain, X, Y=None, metas=None, W=None,\n                   attributes=None, ids=None):\n        \"\"\"\n        Construct a table from numpy arrays with the given domain. The number\n        of variables in the domain must match the number of columns in the\n        corresponding arrays. All arrays must have the same number of rows.\n        Arrays may be of different numpy types, and may be dense or sparse.\n\n        :param domain: the domain for the new table\n        :type domain: Orange.data.Domain\n        :param X: array with attribute values\n        :type X: np.array\n        :param Y: array with class values\n        :type Y: np.array\n        :param metas: array with meta attributes\n        :type metas: np.array\n        :param W: array with weights\n        :type W: np.array\n        :return:\n        \"\"\"\n        X, Y, W = _check_arrays(X, Y, W, dtype='float64')\n        metas, = _check_arrays(metas, dtype=object, shape_1=X.shape[0])\n        ids, = _check_arrays(ids, dtype=int, shape_1=X.shape[0])\n\n        if domain is None:\n            domain = Domain.from_numpy(X, Y, metas)\n\n        if Y is None:\n            if not domain.class_vars or sp.issparse(X):\n                Y = np.empty((X.shape[0], 0), dtype=np.float64)\n            else:\n                own_data = X.flags.owndata and X.base is None\n                Y = X[:, len(domain.attributes):]\n                X = X[:, :len(domain.attributes)]\n                if own_data:\n                    Y = Y.copy()\n                    X = X.copy()\n        if metas is None:\n            metas = np.empty((X.shape[0], 0), object)\n        if W is None or W.size == 0:\n            W = np.empty((X.shape[0], 0))\n        elif W.shape != (W.size, ):\n            W = W.reshape(W.size).copy()\n\n        if X.shape[1] != len(domain.attributes):\n            raise ValueError(\n                \"Invalid number of variable columns ({} != {})\".format(\n                    X.shape[1], len(domain.attributes))\n            )\n        if Y.ndim == 1:\n            if not domain.class_var:\n                raise ValueError(\n                    \"Invalid number of class columns \"\n                    f\"(1 != {len(domain.class_vars)})\")\n        elif Y.shape[1] != len(domain.class_vars):\n            raise ValueError(\n                \"Invalid number of class columns ({} != {})\".format(\n                    Y.shape[1], len(domain.class_vars))\n            )\n        if metas.shape[1] != len(domain.metas):\n            raise ValueError(\n                \"Invalid number of meta attribute columns ({} != {})\".format(\n                    metas.shape[1], len(domain.metas))\n            )\n        if not X.shape[0] == Y.shape[0] == metas.shape[0] == W.shape[0]:\n            raise ValueError(\n                \"Parts of data contain different numbers of rows.\")\n\n        self = cls()\n        with self.unlocked():\n            self.domain = domain\n            self.X = X\n            self.Y = Y\n            self.metas = metas\n            self.W = W\n            self.n_rows = self.X.shape[0]\n            if ids is None:\n                cls._init_ids(self)\n            else:\n                self.ids = ids\n            self.attributes = {} if attributes is None else attributes\n        return self\n\n    @classmethod\n    def from_list(cls, domain, rows, weights=None):\n        if weights is not None and len(rows) != len(weights):\n            raise ValueError(\"mismatching number of instances and weights\")\n        self = cls.from_domain(domain, len(rows), weights is not None)\n        all_vars = domain.variables + domain.metas\n        nattrs = len(domain.attributes)\n        nattrscls = len(domain.variables)\n        with self.unlocked():\n            for i, row in enumerate(rows):\n                if isinstance(row, Instance):\n                    row = row.list\n                vals = [var.to_val(val) for var, val in zip(all_vars, row)]\n                self.X[i] = vals[:nattrs]\n                if self._Y.ndim == 1:\n                    self._Y[i] = vals[nattrs] if nattrs < len(vals) else np.nan\n                else:\n                    self._Y[i] = vals[nattrs:nattrscls]\n                # for backward compatibility: allow omittine some (or all) metas\n                self.metas[i, :len(vals) - nattrscls] = vals[nattrscls:]\n            if weights is not None:\n                self.W = np.array(weights)\n            self.attributes = {}\n        return self\n\n    @classmethod\n    def _init_ids(cls, obj):\n        with cls._next_instance_lock:\n            obj.ids = np.array(range(cls._next_instance_id, cls._next_instance_id + obj.X.shape[0]))\n            cls._next_instance_id += obj.X.shape[0]\n\n    @classmethod\n    def new_id(cls):\n        with cls._next_instance_lock:\n            id = cls._next_instance_id\n            cls._next_instance_id += 1\n            return id\n\n    def to_pandas_dfs(self):\n        return Orange.data.pandas_compat.table_to_frames(self)\n\n    @staticmethod\n    def from_pandas_dfs(xdf, ydf, mdf):\n        return Orange.data.pandas_compat.table_from_frames(xdf, ydf, mdf)\n\n    @property\n    def X_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.Attribute\n        )\n\n    @X_df.setter\n    def X_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.Attribute\n        )\n\n    @property\n    def Y_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.ClassAttribute\n        )\n\n    @Y_df.setter\n    def Y_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.ClassAttribute\n        )\n\n    @property\n    def metas_df(self):\n        return Orange.data.pandas_compat.OrangeDataFrame(\n            self, orange_role=Role.Meta\n        )\n\n    @metas_df.setter\n    def metas_df(self, df):\n        Orange.data.pandas_compat.amend_table_with_frame(\n            self, df, role=Role.Meta\n        )\n\n    def save(self, filename):\n        \"\"\"\n        Save a data table to a file. The path can be absolute or relative.\n\n        :param filename: File name\n        :type filename: str\n        \"\"\"\n        ext = os.path.splitext(filename)[1]\n        from Orange.data.io import FileFormat\n        writer = FileFormat.writers.get(ext)\n        if not writer:\n            desc = FileFormat.names.get(ext)\n            if desc:\n                raise IOError(\n                    \"Writing of {}s is not supported\".format(desc.lower()))\n            else:\n                raise IOError(\"Unknown file name extension.\")\n        writer.write_file(filename, self)\n\n    @classmethod\n    def from_file(cls, filename, sheet=None):\n        \"\"\"\n        Read a data table from a file. The path can be absolute or relative.\n\n        :param filename: File name\n        :type filename: str\n        :param sheet: Sheet in a file (optional)\n        :type sheet: str\n        :return: a new data table\n        :rtype: Orange.data.Table\n        \"\"\"\n        from Orange.data.io import FileFormat\n\n        absolute_filename = FileFormat.locate(filename, dataset_dirs)\n        reader = FileFormat.get_reader(absolute_filename)\n        reader.select_sheet(sheet)\n        data = reader.read()\n\n        # Readers return plain table. Make sure to cast it to appropriate\n        # (subclass) type\n        if cls != data.__class__:\n            data = cls(data)\n\n        # no need to call _init_ids as fuctions from .io already\n        # construct a table with .ids\n\n        data.__file__ = absolute_filename\n        return data\n\n    @classmethod\n    def from_url(cls, url):\n        from Orange.data.io import UrlReader\n        reader = UrlReader(url)\n        data = reader.read()\n        if cls != data.__class__:\n            data = cls(data)\n        return data\n\n    # Helper function for __setitem__:\n    # Set the row of table data matrices\n    # noinspection PyProtectedMember\n    def _set_row(self, example, row):\n        # pylint: disable=protected-access\n        domain = self.domain\n        if isinstance(example, Instance):\n            if example.domain == domain:\n                self.X[row] = example._x\n                if self._Y.ndim == 1:\n                    self._Y[row] = float(example._y)\n                else:\n                    self._Y[row] = np.atleast_1d(example._y)\n                self.metas[row] = example._metas\n                return\n\n            self.X[row], self._Y[row], self.metas[row] = \\\n                self.domain.convert(example)\n            try:\n                self.ids[row] = example.id\n            except:\n                with type(self)._next_instance_lock:\n                    self.ids[row] = type(self)._next_instance_id\n                    type(self)._next_instance_id += 1\n\n        else:\n            attrs = domain.attributes\n            if len(example) != len(domain.variables):\n                raise ValueError(\"invalid length\")\n            self._X[row] = [var.to_val(val) for var, val in zip(attrs, example)]\n            if self._Y.ndim == 1:\n                self._Y[row] = domain.class_var.to_val(example[len(attrs)])\n            else:\n                self._Y[row] = [var.to_val(val)\n                                for var, val in zip(domain.class_vars,\n                                                    example[len(attrs):])]\n            self.metas[row] = np.array([var.Unknown for var in domain.metas],\n                                       dtype=object)\n\n    def _check_all_dense(self):\n        return all(x in (Storage.DENSE, Storage.MISSING)\n                   for x in (self.X_density(), self.Y_density(),\n                             self.metas_density()))\n\n    def __getitem__(self, key):\n        if isinstance(key, Integral):\n            return RowInstance(self, key)\n        if not isinstance(key, tuple):\n            return self.from_table_rows(self, key)\n\n        if len(key) != 2:\n            raise IndexError(\"Table indices must be one- or two-dimensional\")\n\n        row_idx, col_idx = key\n        if isinstance(row_idx, Integral):\n            if isinstance(col_idx, (str, Integral, Variable)):\n                col_idx = self.domain.index(col_idx)\n                var = self.domain[col_idx]\n                if 0 <= col_idx < len(self.domain.attributes):\n                    val = self.X[row_idx, col_idx]\n                elif col_idx == len(self.domain.attributes) and self._Y.ndim == 1:\n                    val = self._Y[row_idx]\n                elif col_idx >= len(self.domain.attributes):\n                    val = self._Y[row_idx,\n                                  col_idx - len(self.domain.attributes)]\n                else:\n                    val = self.metas[row_idx, -1 - col_idx]\n                if isinstance(col_idx, DiscreteVariable) and var is not col_idx:\n                    val = col_idx.get_mapper_from(var)(val)\n                return Value(var, val)\n            else:\n                row_idx = [row_idx]\n\n        # multiple rows OR single row but multiple columns:\n        # construct a new table\n        attributes, col_indices = self.domain._compute_col_indices(col_idx)\n        if attributes is not None:\n            n_attrs = len(self.domain.attributes)\n            r_attrs = [attributes[i]\n                       for i, col in enumerate(col_indices)\n                       if 0 <= col < n_attrs]\n            r_classes = [attributes[i]\n                         for i, col in enumerate(col_indices)\n                         if col >= n_attrs]\n            r_metas = [attributes[i]\n                       for i, col in enumerate(col_indices) if col < 0]\n            domain = Domain(r_attrs, r_classes, r_metas)\n        else:\n            domain = self.domain\n        return self.from_table(domain, self, row_idx)\n\n    def __setitem__(self, key, value):\n        if not isinstance(key, tuple):\n            if isinstance(value, Real):\n                self.X[key, :] = value\n                return\n            self._set_row(value, key)\n            return\n\n        if len(key) != 2:\n            raise IndexError(\"Table indices must be one- or two-dimensional\")\n        row_idx, col_idx = key\n\n        # single row\n        if isinstance(row_idx, Integral):\n            if isinstance(col_idx, slice):\n                col_idx = range(*slice.indices(col_idx, self.X.shape[1]))\n            if not isinstance(col_idx, str) and isinstance(col_idx, Iterable):\n                col_idx = list(col_idx)\n            if not isinstance(col_idx, str) and isinstance(col_idx, Sized):\n                if isinstance(value, (Sequence, np.ndarray)):\n                    values = value\n                elif isinstance(value, Iterable):\n                    values = list(value)\n                else:\n                    raise TypeError(\"Setting multiple values requires a \"\n                                    \"sequence or numpy array\")\n                if len(values) != len(col_idx):\n                    raise ValueError(\"Invalid number of values\")\n            else:\n                col_idx, values = [col_idx], [value]\n            if isinstance(col_idx, DiscreteVariable) \\\n                    and self.domain[col_idx] != col_idx:\n                values = self.domain[col_idx].get_mapper_from(col_idx)(values)\n            for val, col_idx in zip(values, col_idx):\n                if not isinstance(val, Integral):\n                    val = self.domain[col_idx].to_val(val)\n                if not isinstance(col_idx, Integral):\n                    col_idx = self.domain.index(col_idx)\n                if col_idx >= 0:\n                    if col_idx < self.X.shape[1]:\n                        self.X[row_idx, col_idx] = val\n                    elif self._Y.ndim == 1 and col_idx == self.X.shape[1]:\n                        self._Y[row_idx] = val\n                    else:\n                        self._Y[row_idx, col_idx - self.X.shape[1]] = val\n                else:\n                    self.metas[row_idx, -1 - col_idx] = val\n\n        # multiple rows, multiple columns\n        attributes, col_indices = self.domain._compute_col_indices(col_idx)\n        if col_indices is ...:\n            col_indices = range(len(self.domain.variables))\n        n_attrs = self.X.shape[1]\n        if isinstance(value, str):\n            if not attributes:\n                attributes = self.domain.attributes\n            for var, col in zip(attributes, col_indices):\n                val = var.to_val(value)\n                if 0 <= col < n_attrs:\n                    self.X[row_idx, col] = val\n                elif col >= n_attrs:\n                    if self._Y.ndim == 1 and col == n_attrs:\n                        self._Y[row_idx] = val\n                    else:\n                        self._Y[row_idx, col - n_attrs] = val\n                else:\n                    self.metas[row_idx, -1 - col] = val\n        else:\n            attr_cols = np.fromiter(\n                (col for col in col_indices if 0 <= col < n_attrs), int)\n            class_cols = np.fromiter(\n                (col - n_attrs for col in col_indices if col >= n_attrs), int)\n            meta_cols = np.fromiter(\n                (-1 - col for col in col_indices if col < 0), int)\n            if value is None:\n                value = Unknown\n\n            if not isinstance(value, (Real, np.ndarray)) and \\\n                    (len(attr_cols) or len(class_cols)):\n                raise TypeError(\n                    \"Ordinary attributes can only have primitive values\")\n            if len(attr_cols):\n                self.X[row_idx, attr_cols] = value\n            if len(class_cols):\n                if self._Y.ndim == 1 and np.all(class_cols == 0):\n                    if isinstance(value, np.ndarray):\n                        yshape = self._Y[row_idx].shape\n                        if value.shape != yshape:\n                            value = value.reshape(yshape)\n                    self._Y[row_idx] = value\n                else:\n                    self._Y[row_idx, class_cols] = value\n            if len(meta_cols):\n                self.metas[row_idx, meta_cols] = value\n\n    def __len__(self):\n        return self.X.shape[0]\n\n    def __str__(self):\n        return \"[\" + \",\\n \".join(str(ex) for ex in self) + \"]\"\n\n    def __repr__(self):\n        head = 5\n        if self.is_sparse():\n            head = min(self.X.shape[0], head)\n        s = \"[\" + \",\\n \".join(repr(ex) for ex in self[:head])\n        if len(self) > head:\n            s += \",\\n ...\"\n        s += \"\\n]\"\n        return s\n\n    @classmethod\n    def concatenate(cls, tables, axis=0):\n        \"\"\"\n        Concatenate tables into a new table, either vertically or horizontally.\n\n        If axis=0 (vertical concatenate), all tables must have the same domain.\n\n        If axis=1 (horizontal),\n        - all variable names must be unique.\n        - ids are copied from the first table.\n        - weights are copied from the first table in which they are defined.\n        - the dictionary of table's attributes are merged. If the same attribute\n          appears in multiple dictionaries, the earlier are used.\n\n        Args:\n            tables (Table): tables to be joined\n\n        Returns:\n            table (Table)\n        \"\"\"\n        if axis not in (0, 1):\n            raise ValueError(\"invalid axis\")\n        if not tables:\n            raise ValueError('need at least one table to concatenate')\n\n        if len(tables) == 1:\n            return tables[0].copy()\n\n        if axis == 0:\n            conc = cls._concatenate_vertical(tables)\n        else:\n            conc = cls._concatenate_horizontal(tables)\n\n        # TODO: Add attributes = {} to __init__\n        conc.attributes = getattr(conc, \"attributes\", {})\n        for table in reversed(tables):\n            conc.attributes.update(table.attributes)\n\n        names = [table.name for table in tables if table.name != \"untitled\"]\n        if names:\n            conc.name = names[0]\n        return conc\n\n    @classmethod\n    def _concatenate_vertical(cls, tables):\n        def vstack(arrs):\n            return [np, sp][any(sp.issparse(arr) for arr in arrs)].vstack(arrs)\n\n        def merge1d(arrs):\n            arrs = list(arrs)\n            ydims = {arr.ndim for arr in arrs}\n            if ydims == {1}:\n                return np.hstack(arrs)\n            else:\n                return vstack([\n                    arr if arr.ndim == 2 else np.atleast_2d(arr).T\n                    for arr in arrs\n                ])\n\n        def collect(attr):\n            return [getattr(arr, attr) for arr in tables]\n\n        domain = tables[0].domain\n        if any(table.domain != domain for table in tables):\n            raise ValueError('concatenated tables must have the same domain')\n\n        conc = cls.from_numpy(\n            domain,\n            vstack(collect(\"X\")),\n            merge1d(collect(\"Y\")),\n            vstack(collect(\"metas\")),\n            merge1d(collect(\"W\"))\n        )\n        conc.ids = np.hstack([t.ids for t in tables])\n        return conc\n\n    @classmethod\n    def _concatenate_horizontal(cls, tables):\n        \"\"\"\n        \"\"\"\n        def all_of(objs, names):\n            return (tuple(getattr(obj, name) for obj in objs)\n                    for name in names)\n\n        def stack(arrs):\n            non_empty = tuple(arr if arr.ndim == 2 else arr[:, np.newaxis]\n                              for arr in arrs\n                              if arr is not None and arr.size > 0)\n            return np.hstack(non_empty) if non_empty else None\n\n        doms, Ws = all_of(tables, (\"domain\", \"W\"))\n        Xs, Ys, Ms = map(stack, all_of(tables, (\"X\", \"Y\", \"metas\")))\n        # pylint: disable=undefined-loop-variable\n        for W in Ws:\n            if W.size:\n                break\n\n        parts = all_of(doms, (\"attributes\", \"class_vars\", \"metas\"))\n        domain = Domain(*(tuple(chain(*lst)) for lst in parts))\n        return cls.from_numpy(domain, Xs, Ys, Ms, W, ids=tables[0].ids)\n\n    def add_column(self, variable, data, to_metas=None):\n        \"\"\"\n        Create a new table with an additional column\n\n        Column's name must be unique\n\n        Args:\n            variable (Variable): variable for the new column\n            data (np.ndarray): data for the new column\n            to_metas (bool, optional): if `True` the column is added as meta\n                column. Otherwise, primitive variables are added to attributes\n                and non-primitive to metas.\n\n        Returns:\n            table (Table): a new table with the additional column\n        \"\"\"\n        dom = self.domain\n        attrs, classes, metavars = dom.attributes, dom.class_vars, dom.metas\n        to_metas = to_metas or not variable.is_primitive()\n        if to_metas:\n            metavars += (variable, )\n        else:\n            attrs += (variable, )\n        domain = Domain(attrs, classes, metavars)\n        new_table = self.transform(domain)\n        with new_table.unlocked(new_table.metas if to_metas else new_table.X):\n            new_table.get_column_view(variable)[0][:] = data\n        return new_table\n\n    def is_view(self):\n        \"\"\"\n        Return `True` if all arrays represent a view referring to another table\n        \"\"\"\n        return ((not self._X.shape[-1] or self._X.base is not None) and\n                (not self._Y.shape[-1] or self._Y.base is not None) and\n                (not self._metas.shape[-1] or self._metas.base is not None) and\n                (not self._weights.shape[-1] or self._W.base is not None))\n\n    def is_copy(self):\n        \"\"\"\n        Return `True` if the table owns its data\n        \"\"\"\n        return ((not self._X.shape[-1] or self._X.base is None) and\n                (self._Y.base is None) and\n                (self._metas.base is None) and\n                (self._W.base is None))\n\n    def is_sparse(self):\n        \"\"\"\n        Return `True` if the table stores data in sparse format\n        \"\"\"\n        return any(sp.issparse(i) for i in [self._X, self._Y, self._metas])\n\n    def ensure_copy(self):\n        \"\"\"\n        Ensure that the table owns its data; copy arrays when necessary.\n        \"\"\"\n\n        def is_view(x):\n            # Sparse matrices don't have views like numpy arrays. Since indexing on\n            # them creates copies in constructor we can skip this check here.\n            return not sp.issparse(x) and x.base is not None\n\n        if is_view(self._X):\n            self._X = self._X.copy()\n        if is_view(self._Y):\n            self._Y = self._Y.copy()\n        if is_view(self._metas):\n            self._metas = self._metas.copy()\n        if is_view(self._W):\n            self._W = self._W.copy()\n\n    def copy(self):\n        \"\"\"\n        Return a copy of the table\n        \"\"\"\n        t = self.__class__(self)\n        t.ensure_copy()\n        return t\n\n    @staticmethod\n    def __determine_density(data):\n        if data is None:\n            return Storage.Missing\n        if data is not None and sp.issparse(data):\n            return Storage.SPARSE_BOOL if (data.data == 1).all() else Storage.SPARSE\n        else:\n            return Storage.DENSE\n\n    def X_density(self):\n        if not hasattr(self, \"_X_density\"):\n            self._X_density = self.__determine_density(self.X)\n        return self._X_density\n\n    def Y_density(self):\n        if not hasattr(self, \"_Y_density\"):\n            self._Y_density = self.__determine_density(self._Y)\n        return self._Y_density\n\n    def metas_density(self):\n        if not hasattr(self, \"_metas_density\"):\n            self._metas_density = self.__determine_density(self.metas)\n        return self._metas_density\n\n    def set_weights(self, weight=1):\n        \"\"\"\n        Set weights of data instances; create a vector of weights if necessary.\n        \"\"\"\n        if not self.W.shape[-1]:\n            self.W = np.empty(len(self))\n        self.W[:] = weight\n\n    def has_weights(self):\n        \"\"\"Return `True` if the data instances are weighed. \"\"\"\n        return self.W.shape[-1] != 0\n\n    def total_weight(self):\n        \"\"\"\n        Return the total weight of instances in the table, or their number if\n        they are unweighted.\n        \"\"\"\n        if self.W.shape[-1]:\n            return sum(self.W)\n        return len(self)\n\n    def has_missing(self):\n        \"\"\"Return `True` if there are any missing attribute or class values.\"\"\"\n        missing_x = not sp.issparse(self.X) and bn.anynan(self.X)  # do not check for sparse X\n        return missing_x or bn.anynan(self._Y)\n\n    def has_missing_attribute(self):\n        \"\"\"Return `True` if there are any missing attribute values.\"\"\"\n        return not sp.issparse(self.X) and bn.anynan(self.X)  # do not check for sparse X\n\n    def has_missing_class(self):\n        \"\"\"Return `True` if there are any missing class values.\"\"\"\n        return bn.anynan(self._Y)\n\n    def get_nan_frequency_attribute(self):\n        if self.X.size == 0:\n            return 0\n        return np.isnan(self.X).sum() / self.X.size\n\n    def get_nan_frequency_class(self):\n        if self.Y.size == 0:\n            return 0\n        return np.isnan(self._Y).sum() / self._Y.size\n\n    def checksum(self, include_metas=True):\n        # TODO: zlib.adler32 does not work for numpy arrays with dtype object\n        # (after pickling and unpickling such arrays, checksum changes)\n        # Why, and should we fix it or remove it?\n        \"\"\"Return a checksum over X, Y, metas and W.\"\"\"\n        cs = zlib.adler32(np.ascontiguousarray(self._X))\n        cs = zlib.adler32(np.ascontiguousarray(self._Y), cs)\n        if include_metas:\n            cs = zlib.adler32(np.ascontiguousarray(self._metas), cs)\n        cs = zlib.adler32(np.ascontiguousarray(self._W), cs)\n        return cs\n\n    def shuffle(self):\n        \"\"\"Randomly shuffle the rows of the table.\"\"\"\n        if not self._check_all_dense():\n            raise ValueError(\"Rows of sparse data cannot be shuffled\")\n        ind = np.arange(self.X.shape[0])\n        np.random.shuffle(ind)\n        self.X = self.X[ind]\n        self._Y = self._Y[ind]\n        self.metas = self.metas[ind]\n        self.W = self.W[ind]\n\n    def get_column_view(self, index):\n        \"\"\"\n        Return a vector - as a view, not a copy - with a column of the table,\n        and a bool flag telling whether this column is sparse. Note that\n        vertical slicing of sparse matrices is inefficient.\n\n        :param index: the index of the column\n        :type index: int, str or Orange.data.Variable\n        :return: (one-dimensional numpy array, sparse)\n        \"\"\"\n\n        def rx(M):\n            if sp.issparse(M):\n                return np.asarray(M.todense())[:, 0], True\n            else:\n                return M, False\n\n        if isinstance(index, Integral):\n            col_index = index\n        else:\n            col_index = self.domain.index(index)\n        if col_index >= 0:\n            if col_index < self.X.shape[1]:\n                col = rx(self.X[:, col_index])\n            elif self._Y.ndim == 1 and col_index == self._X.shape[1]:\n                col = rx(self._Y)\n            else:\n                col = rx(self._Y[:, col_index - self.X.shape[1]])\n        else:\n            col = rx(self.metas[:, -1 - col_index])\n\n        if isinstance(index, DiscreteVariable) \\\n                and index.values != self.domain[col_index].values:\n            col = index.get_mapper_from(self.domain[col_index])(col[0]), col[1]\n            col[0].flags.writeable = False\n        return col\n\n    def _filter_is_defined(self, columns=None, negate=False):\n        # structure of function is obvious; pylint: disable=too-many-branches\n        def _sp_anynan(a):\n            return a.indptr[1:] != a[-1:] + a.shape[1]\n\n        if columns is None:\n            if sp.issparse(self.X):\n                remove = _sp_anynan(self.X)\n            else:\n                remove = bn.anynan(self.X, axis=1)\n            if sp.issparse(self._Y):\n                remove += _sp_anynan(self._Y)\n            else:\n                if self._Y.ndim == 1:\n                    remove += np.isnan(self._Y)\n                else:\n                    remove += bn.anynan(self._Y, axis=1)\n            if sp.issparse(self.metas):\n                remove += _sp_anynan(self._metas)\n            else:\n                for i, var in enumerate(self.domain.metas):\n                    col = self.metas[:, i].flatten()\n                    if var.is_primitive():\n                        remove += np.isnan(col.astype(float))\n                    else:\n                        remove += ~col.astype(bool)\n        else:\n            remove = np.zeros(len(self), dtype=bool)\n            for column in columns:\n                col, sparse = self.get_column_view(column)\n                if sparse:\n                    remove += col == 0\n                elif self.domain[column].is_primitive():\n                    remove += bn.anynan([col.astype(float)], axis=0)\n                else:\n                    remove += col.astype(bool)\n        retain = remove if negate else np.logical_not(remove)\n        return self.from_table_rows(self, retain)\n\n    def _filter_has_class(self, negate=False):\n        if sp.issparse(self._Y):\n            if negate:\n                retain = (self._Y.indptr[1:] !=\n                          self._Y.indptr[-1:] + self._Y.shape[1])\n            else:\n                retain = (self._Y.indptr[1:] ==\n                          self._Y.indptr[-1:] + self._Y.shape[1])\n        else:\n            if self._Y.ndim == 1:\n                retain = np.isnan(self._Y)\n            else:\n                retain = bn.anynan(self._Y, axis=1)\n            if not negate:\n                retain = np.logical_not(retain)\n        return self.from_table_rows(self, retain)\n\n    def _filter_same_value(self, column, value, negate=False):\n        if not isinstance(value, Real):\n            value = self.domain[column].to_val(value)\n        sel = self.get_column_view(column)[0] == value\n        if negate:\n            sel = np.logical_not(sel)\n        return self.from_table_rows(self, sel)\n\n    def _filter_values(self, filter):\n        selection = self._values_filter_to_indicator(filter)\n        return self.from_table(self.domain, self, selection)\n\n    def _values_filter_to_indicator(self, filter):\n        \"\"\"Return selection of rows matching the filter conditions\n\n        Handles conjunction/disjunction and negate modifiers\n\n        Parameters\n        ----------\n        filter: Values object containing the conditions\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        from Orange.data.filter import Values\n\n        if isinstance(filter, Values):\n            conditions = filter.conditions\n            conjunction = filter.conjunction\n        else:\n            conditions = [filter]\n            conjunction = True\n        if conjunction:\n            sel = np.ones(len(self), dtype=bool)\n        else:\n            sel = np.zeros(len(self), dtype=bool)\n\n        for f in conditions:\n            selection = self._filter_to_indicator(f)\n\n            if conjunction:\n                sel *= selection\n            else:\n                sel += selection\n\n        if filter.negate:\n            sel = ~sel\n        return sel\n\n    def _filter_to_indicator(self, filter):\n        \"\"\"Return selection of rows that match the condition.\n\n        Parameters\n        ----------\n        filter: ValueFilter describing the condition\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        from Orange.data.filter import (\n            FilterContinuous, FilterDiscrete, FilterRegex, FilterString,\n            FilterStringList, IsDefined, Values\n        )\n        if isinstance(filter, Values):\n            return self._values_filter_to_indicator(filter)\n\n        def get_col_indices():\n            cols = chain(self.domain.variables, self.domain.metas)\n            if isinstance(filter, IsDefined):\n                if filter.columns is not None:\n                    return list(filter.columns)\n                else:\n                    return list(cols)\n\n            if filter.column is not None:\n                return [filter.column]\n\n            if isinstance(filter, FilterDiscrete):\n                raise ValueError(\"Discrete filter can't be applied across rows\")\n            if isinstance(filter, FilterContinuous):\n                return [col for col in cols if col.is_continuous]\n            if isinstance(filter,\n                          (FilterString, FilterStringList, FilterRegex)):\n                return [col for col in cols if col.is_string]\n            raise TypeError(\"Invalid filter\")\n\n        def col_filter(col_idx):\n            col = self.get_column_view(col_idx)[0]\n            if isinstance(filter, IsDefined):\n                if self.domain[col_idx].is_primitive():\n                    return ~np.isnan(col.astype(float))\n                else:\n                    return col.astype(bool)\n            if isinstance(filter, FilterDiscrete):\n                return self._discrete_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterContinuous):\n                return self._continuous_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterString):\n                return self._string_filter_to_indicator(filter, col)\n            if isinstance(filter, FilterStringList):\n                if not filter.case_sensitive:\n                    col = np.char.lower(np.array(col, dtype=str))\n                    vals = [val.lower() for val in filter.values]\n                else:\n                    vals = filter.values\n                return reduce(operator.add, (col == val for val in vals))\n            if isinstance(filter, FilterRegex):\n                return np.vectorize(filter)(col)\n            raise TypeError(\"Invalid filter\")\n\n        col_indices = get_col_indices()\n        if len(col_indices) == 1:\n            sel = col_filter(col_indices[0])\n        else:\n            sel = np.ones(len(self), dtype=bool)\n            for col_idx in col_indices:\n                sel *= col_filter(col_idx)\n\n        if isinstance(filter, IsDefined) and filter.negate:\n            sel = ~sel\n        return sel\n\n    def _discrete_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given discrete filter.\n\n        Parameters\n        ----------\n        filter: FilterDiscrete\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.values is None:  # <- is defined filter\n            col = col.astype(float)\n            return ~np.isnan(col)\n\n        sel = np.zeros(len(self), dtype=bool)\n        for val in filter.values:\n            if not isinstance(val, Real):\n                val = self.domain[filter.column].to_val(val)\n            sel += (col == val)\n        return sel\n\n    def _continuous_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given continuous filter.\n\n        Parameters\n        ----------\n        filter: FilterContinuous\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.oper == filter.IsDefined:\n            col = col.astype(float)\n            return ~np.isnan(col)\n\n        return self._range_filter_to_indicator(filter, col, filter.min, filter.max)\n\n    def _string_filter_to_indicator(self, filter, col):\n        \"\"\"Return selection of rows matched by the given string filter.\n\n        Parameters\n        ----------\n        filter: FilterString\n        col: np.ndarray\n\n        Returns\n        -------\n        A 1d bool array. len(result) == len(self)\n        \"\"\"\n        if filter.oper == filter.IsDefined:\n            return col.astype(bool)\n\n        col = col.astype(str)\n        fmin = filter.min or \"\"\n        fmax = filter.max or \"\"\n\n        if not filter.case_sensitive:\n            # convert all to lower case\n            col = np.char.lower(col)\n            fmin = fmin.lower()\n            fmax = fmax.lower()\n\n        if filter.oper == filter.Contains:\n            return np.fromiter((fmin in e for e in col),\n                               dtype=bool)\n        if filter.oper == filter.StartsWith:\n            return np.fromiter((e.startswith(fmin) for e in col),\n                               dtype=bool)\n        if filter.oper == filter.EndsWith:\n            return np.fromiter((e.endswith(fmin) for e in col),\n                               dtype=bool)\n\n        return self._range_filter_to_indicator(filter, col, fmin, fmax)\n\n    @staticmethod\n    def _range_filter_to_indicator(filter, col, fmin, fmax):\n        with np.errstate(invalid=\"ignore\"):  # nan's are properly discarded\n            if filter.oper == filter.Equal:\n                return col == fmin\n            if filter.oper == filter.NotEqual:\n                return col != fmin\n            if filter.oper == filter.Less:\n                return col < fmin\n            if filter.oper == filter.LessEqual:\n                return col <= fmin\n            if filter.oper == filter.Greater:\n                return col > fmin\n            if filter.oper == filter.GreaterEqual:\n                return col >= fmin\n            if filter.oper == filter.Between:\n                return (col >= fmin) * (col <= fmax)\n            if filter.oper == filter.Outside:\n                return (col < fmin) + (col > fmax)\n\n            raise TypeError(\"Invalid operator\")\n\n    def _compute_basic_stats(self, columns=None,\n                             include_metas=False, compute_variance=False):\n        if compute_variance:\n            raise NotImplementedError(\"computation of variance is \"\n                                      \"not implemented yet\")\n        W = self._W if self.has_weights() else None\n        rr = []\n        stats = []\n        if not columns:\n            if self.domain.attributes:\n                rr.append(fast_stats(self._X, W))\n            if self.domain.class_vars:\n                rr.append(fast_stats(self._Y, W))\n            if include_metas and self.domain.metas:\n                rr.append(fast_stats(self.metas, W))\n            if len(rr):\n                stats = np.vstack(tuple(rr))\n        else:\n            nattrs = len(self.domain.attributes)\n            for column in columns:\n                c = self.domain.index(column)\n                if 0 <= c < nattrs:\n                    S = fast_stats(self._X[:, [c]], W and W[:, [c]])\n                elif c >= nattrs:\n                    if self._Y.ndim == 1 and c == nattrs:\n                        S = fast_stats(self._Y[:, None], W and W[:, None])\n                    else:\n                        S = fast_stats(self._Y[:, [c - nattrs]], W and W[:, [c - nattrs]])\n                else:\n                    S = fast_stats(self._metas[:, [-1 - c]], W and W[:, [-1 - c]])\n                stats.append(S[0])\n        return stats\n\n    def _compute_distributions(self, columns=None):\n        if columns is None:\n            columns = range(len(self.domain.variables))\n        else:\n            columns = [self.domain.index(var) for var in columns]\n\n        distributions = []\n        X = self.X\n        if sp.issparse(X):\n            X = X.tocsc()\n\n\n        W = self.W.ravel() if self.has_weights() else None\n\n        for col in columns:\n            variable = self.domain[col]\n\n            # Select the correct data column from X, Y or metas\n            if 0 <= col < X.shape[1]:\n                x = X[:, col]\n            elif col < 0:\n                x = self.metas[:, col * (-1) - 1]\n                if np.issubdtype(x.dtype, np.dtype(object)):\n                    x = x.astype(float)\n            elif self._Y.ndim == 1 and col == X.shape[1]:\n                x = self._Y\n            else:\n                x = self._Y[:, col - X.shape[1]]\n\n            if variable.is_discrete:\n                dist, unknowns = bincount(x, weights=W, max_val=len(variable.values) - 1)\n            elif not x.shape[0]:\n                dist, unknowns = np.zeros((2, 0)), 0\n            else:\n                if W is not None:\n                    if sp.issparse(x):\n                        arg_sort = np.argsort(x.data)\n                        ranks = x.indices[arg_sort]\n                        vals = np.vstack((x.data[arg_sort], W[ranks]))\n                    else:\n                        ranks = np.argsort(x)\n                        vals = np.vstack((x[ranks], W[ranks]))\n                else:\n                    x_values = x.data if sp.issparse(x) else x\n                    vals = np.ones((2, x_values.shape[0]))\n                    vals[0, :] = x_values\n                    vals[0, :].sort()\n\n                dist = np.array(_valuecount.valuecount(vals))\n                # If sparse, then 0s will not be counted with `valuecount`, so\n                # we have to add them to the result manually.\n                if sp.issparse(x) and sparse_has_implicit_zeros(x):\n                    if W is not None:\n                        zero_weights = sparse_implicit_zero_weights(x, W).sum()\n                    else:\n                        zero_weights = sparse_count_implicit_zeros(x)\n                    zero_vec = [0, zero_weights]\n                    dist = np.insert(dist, np.searchsorted(dist[0], 0), zero_vec, axis=1)\n                # Since `countnans` assumes vector shape to be (1, n) and `x`\n                # shape is (n, 1), we pass the transpose\n                unknowns = countnans(x.T, W)\n            distributions.append((dist, unknowns))\n\n        return distributions\n\n    def _compute_contingency(self, col_vars=None, row_var=None):\n        n_atts = self.X.shape[1]\n\n        if col_vars is None:\n            col_vars = range(len(self.domain.variables))\n        else:\n            col_vars = [self.domain.index(var) for var in col_vars]\n        if row_var is None:\n            row_var = self.domain.class_var\n            if row_var is None:\n                raise ValueError(\"No row variable\")\n\n        row_desc = self.domain[row_var]\n        if not row_desc.is_discrete:\n            raise TypeError(\"Row variable must be discrete\")\n        row_indi = self.domain.index(row_var)\n        n_rows = len(row_desc.values)\n        if 0 <= row_indi < n_atts:\n            row_data = self.X[:, row_indi]\n        elif row_indi < 0:\n            row_data = self.metas[:, -1 - row_indi]\n        elif self._Y.ndim == 1 and row_indi == n_atts:\n            row_data = self._Y\n        else:\n            row_data = self._Y[:, row_indi - n_atts]\n\n        W = self.W if self.has_weights() else None\n\n        col_desc = [self.domain[var] for var in col_vars]\n        col_indi = [self.domain.index(var) for var in col_vars]\n\n        if any(not (var.is_discrete or var.is_continuous)\n               for var in col_desc):\n            raise ValueError(\"Contingency can be computed only for categorical \"\n                             \"and numeric values.\")\n\n        # when we select a column in sparse matrix it is still two dimensional\n        # and sparse - since it is just a column we can afford to transform\n        # it to dense and make it 1D\n        if issparse(row_data):\n            row_data = row_data.toarray().ravel()\n        if row_data.dtype.kind != \"f\":  # meta attributes can be stored as type object\n            row_data = row_data.astype(float)\n\n        contingencies = [None] * len(col_desc)\n        for arr, f_cond, f_ind in (\n                (self.X, lambda i: 0 <= i < n_atts, lambda i: i),\n                (self._Y, lambda i: i >= n_atts, lambda i: i - n_atts),\n                (self.metas, lambda i: i < 0, lambda i: -1 - i)):\n\n            arr_indi = [e for e, ind in enumerate(col_indi) if f_cond(ind)]\n\n            vars = [(e, f_ind(col_indi[e]), col_desc[e]) for e in arr_indi]\n            disc_vars = [v for v in vars if v[2].is_discrete]\n            if disc_vars:\n                if sp.issparse(arr):\n                    max_vals = max(len(v[2].values) for v in disc_vars)\n                    disc_indi = {i for _, i, _ in disc_vars}\n                    mask = [i in disc_indi for i in range(arr.shape[1])]\n                    conts, nans_cols, nans_rows, nans = contingency(\n                        arr, row_data, max_vals - 1, n_rows - 1, W, mask)\n                    for col_i, arr_i, var in disc_vars:\n                        n_vals = len(var.values)\n                        contingencies[col_i] = (\n                            conts[arr_i][:, :n_vals], nans_cols[arr_i],\n                            nans_rows[arr_i], nans[arr_i])\n                else:\n                    for col_i, arr_i, var in disc_vars:\n                        col = arr if arr.ndim == 1 else arr[:, arr_i]\n                        contingencies[col_i] = contingency(\n                            col.astype(float),\n                            row_data, len(var.values) - 1, n_rows - 1, W)\n\n            cont_vars = [v for v in vars if v[2].is_continuous]\n            if cont_vars:\n                W_ = None\n                if W is not None:\n                    W_ = W.astype(dtype=np.float64)\n                if sp.issparse(arr):\n                    arr = sp.csc_matrix(arr)\n\n                for col_i, arr_i, _ in cont_vars:\n                    if sp.issparse(arr):\n                        col_data = arr.data[arr.indptr[arr_i]:arr.indptr[arr_i + 1]]\n                        rows = arr.indices[arr.indptr[arr_i]:arr.indptr[arr_i + 1]]\n                        W_ = None if W_ is None else W_[rows]\n                        classes_ = row_data[rows]\n                    else:\n                        col_data, W_, classes_ = arr[:, arr_i], W_, row_data\n\n                    col_data = col_data.astype(dtype=np.float64)\n                    contingencies[col_i] = _contingency.contingency_floatarray(\n                        col_data, classes_, n_rows, W_)\n\n        return contingencies\n\n    @classmethod\n    def transpose(cls, table, feature_names_column=\"\",\n                  meta_attr_name=\"Feature name\", feature_name=\"Feature\",\n                  remove_redundant_inst=False, progress_callback=None):\n        \"\"\"\n        Transpose the table.\n\n        :param table: Table - table to transpose\n        :param feature_names_column: str - name of (String) meta attribute to\n            use for feature names\n        :param meta_attr_name: str - name of new meta attribute into which\n            feature names are mapped\n        :param feature_name: str - default feature name prefix\n        :param remove_redundant_inst: bool - remove instance that\n            represents feature_names_column\n        :param progress_callback: callable - to report the progress\n        :return: Table - transposed table\n        \"\"\"\n        if progress_callback is None:\n            progress_callback = dummy_callback\n        progress_callback(0, \"Transposing...\")\n\n        if isinstance(feature_names_column, Variable):\n            feature_names_column = feature_names_column.name\n\n        self = cls()\n        n_cols, self.n_rows = table.X.shape\n        old_domain = table.attributes.get(\"old_domain\")\n        table_domain_attributes = list(table.domain.attributes)\n        attr_index = None\n        if remove_redundant_inst:\n            attr_names = [a.name for a in table_domain_attributes]\n            if feature_names_column and feature_names_column in attr_names:\n                attr_index = attr_names.index(feature_names_column)\n                self.n_rows = self.n_rows - 1\n                table_domain_attributes.remove(\n                    table_domain_attributes[attr_index])\n\n        # attributes\n        # - classes and metas to attributes of attributes\n        # - arbitrary meta column to feature names\n        with self.unlocked():\n            self.X = table.X.T\n            if attr_index is not None:\n                self.X = np.delete(self.X, attr_index, 0)\n            if feature_names_column:\n                names = [str(row[feature_names_column]) for row in table]\n                progress_callback(0.1)\n                names = get_unique_names_duplicates(names)\n                progress_callback(0.3)\n                attributes = [ContinuousVariable(name) for name in names]\n            else:\n                places = int(np.ceil(np.log10(n_cols))) if n_cols else 1\n                attributes = [ContinuousVariable(f\"{feature_name} {i:0{places}}\")\n                              for i in range(1, n_cols + 1)]\n            progress_callback(0.4)\n\n            if old_domain is not None and feature_names_column:\n                for i, _ in enumerate(attributes):\n                    if attributes[i].name in old_domain:\n                        var = old_domain[attributes[i].name]\n                        attr = ContinuousVariable(var.name) if var.is_continuous \\\n                            else DiscreteVariable(var.name, var.values)\n                        attr.attributes = var.attributes.copy()\n                        attributes[i] = attr\n\n            def set_attributes_of_attributes(_vars, _table):\n                for i, variable in enumerate(_vars):\n                    if variable.name == feature_names_column:\n                        continue\n                    for j, row in enumerate(_table):\n                        value = variable.repr_val(row) if np.isscalar(row) \\\n                            else row[i] if isinstance(row[i], str) \\\n                            else variable.repr_val(row[i])\n\n                        if value not in MISSING_VALUES:\n                            attributes[j].attributes[variable.name] = value\n\n            set_attributes_of_attributes(table.domain.class_vars, table.Y)\n            progress_callback(0.5)\n            set_attributes_of_attributes(table.domain.metas, table.metas)\n\n            # weights\n            self.W = np.empty((self.n_rows, 0))\n\n            def get_table_from_attributes_of_attributes(_vars, _dtype=float):\n                T = np.empty((self.n_rows, len(_vars)), dtype=_dtype)\n                for i, _attr in enumerate(table_domain_attributes):\n                    for j, _var in enumerate(_vars):\n                        val = str(_attr.attributes.get(_var.name, \"\"))\n                        if not _var.is_string:\n                            val = np.nan if val in MISSING_VALUES else \\\n                                _var.values.index(val) if \\\n                                    _var.is_discrete else float(val)\n                        T[i, j] = val\n                return T\n\n            # class_vars - attributes of attributes to class - from old domain\n            class_vars = []\n            if old_domain is not None:\n                class_vars = old_domain.class_vars\n            self.Y = get_table_from_attributes_of_attributes(class_vars)\n\n            # metas\n            # - feature names and attributes of attributes to metas\n            self.metas, metas = np.empty((self.n_rows, 0), dtype=object), []\n            if meta_attr_name not in [m.name for m in table.domain.metas] and \\\n                    table_domain_attributes:\n                self.metas = np.array([[a.name] for a in table_domain_attributes],\n                                      dtype=object)\n                metas.append(StringVariable(meta_attr_name))\n\n            names = chain.from_iterable(list(attr.attributes)\n                                        for attr in table_domain_attributes)\n            names = sorted(set(names) - {var.name for var in class_vars})\n            progress_callback(0.6)\n\n            def guessed_var(i, var_name):\n                orig_vals = M[:, i]\n                val_map, vals, var_type = Orange.data.io.guess_data_type(orig_vals)\n                values, variable = Orange.data.io.sanitize_variable(\n                    val_map, vals, orig_vals, var_type, {}, name=var_name)\n                M[:, i] = values\n                return variable\n\n            _metas = [StringVariable(n) for n in names]\n            if old_domain is not None:\n                _metas = [m for m in old_domain.metas if m.name != meta_attr_name]\n            M = get_table_from_attributes_of_attributes(_metas, _dtype=object)\n            progress_callback(0.7)\n            if old_domain is None:\n                _metas = [guessed_var(i, m.name) for i, m in enumerate(_metas)]\n            if _metas:\n                self.metas = np.hstack((self.metas, M))\n                metas.extend(_metas)\n\n            self.domain = Domain(attributes, class_vars, metas)\n            progress_callback(0.9)\n            cls._init_ids(self)\n            self.attributes = table.attributes.copy()\n            self.attributes[\"old_domain\"] = table.domain\n            progress_callback(1)\n            return self\n\n    def to_sparse(self, sparse_attributes=True, sparse_class=False,\n                  sparse_metas=False):\n        def sparsify(features):\n            for f in features:\n                f.sparse = True\n\n        new_domain = self.domain.copy()\n\n        if sparse_attributes:\n            sparsify(new_domain.attributes)\n        if sparse_class:\n            sparsify(new_domain.class_vars)\n        if sparse_metas:\n            sparsify(new_domain.metas)\n        return self.transform(new_domain)\n\n    def to_dense(self, dense_attributes=True, dense_class=True,\n                 dense_metas=True):\n        def densify(features):\n            for f in features:\n                f.sparse = False\n\n        new_domain = self.domain.copy()\n\n        if dense_attributes:\n            densify(new_domain.attributes)\n        if dense_class:\n            densify(new_domain.class_vars)\n        if dense_metas:\n            densify(new_domain.metas)\n        t = self.transform(new_domain)\n        t.ids = self.ids  # preserve indices\n        return t\n\n\ndef _dereferenced(array):\n    # CSR and CSC matrices are constructed so that array.data is a\n    # view to a base, which prevents unlocking them. Therefore, if\n    # sparse matrix doesn't own its data, but its base array is\n    # referenced only by this matrix, we copy it. This doesn't\n    # increase memory use, but allows unlocking.\n    if sp.issparse(array) \\\n            and array.data.base is not None \\\n            and sys.getrefcount(array.data.base) == 2:  # 2 = 1 real + 1 for arg\n        array.data = array.data.copy()\n    return array\n\n\ndef _check_arrays(*arrays, dtype=None, shape_1=None):\n    checked = []\n    if not len(arrays):\n        return checked\n\n    def ninstances(array):\n        if hasattr(array, \"shape\"):\n            return array.shape[0]\n        else:\n            return len(array) if array is not None else 0\n\n    if shape_1 is None:\n        shape_1 = ninstances(arrays[0])\n\n    for array in arrays:\n        if array is None:\n            checked.append(array)\n            continue\n\n        if ninstances(array) != shape_1:\n            raise ValueError(\"Leading dimension mismatch (%d != %d)\"\n                             % (ninstances(array), shape_1))\n\n        if sp.issparse(array):\n            if not (sp.isspmatrix_csr(array) or sp.isspmatrix_csc(array)):\n                array = array.tocsr()\n            array.data = np.asarray(array.data)\n            array = _dereferenced(array)\n            has_inf = _check_inf(array.data)\n        else:\n            if dtype is not None:\n                array = np.asarray(array, dtype=dtype)\n            else:\n                array = np.asarray(array)\n            has_inf = _check_inf(array)\n\n        if has_inf:\n            array[np.isinf(array)] = np.nan\n            warnings.warn(\"Array contains infinity.\", RuntimeWarning)\n        checked.append(array)\n\n    return checked\n\n\ndef _check_inf(array):\n    return array.dtype.char in np.typecodes['AllFloat'] and \\\n           np.isinf(array.data).any()\n\n\ndef _subarray(arr, rows, cols):\n    rows = _optimize_indices(rows, arr.shape[0])\n    if arr.ndim == 1:\n        return arr[rows]\n    cols = _optimize_indices(cols, arr.shape[1])\n    return arr[_rxc_ix(rows, cols)]\n\n\ndef _optimize_indices(indices, maxlen):\n    \"\"\"\n    Convert integer indices to slice if possible. It only converts increasing\n    integer ranges with positive steps and valid starts and ends.\n    Only convert valid ends so that invalid ranges will still raise\n    an exception.\n\n    Allows numpy to reuse the data array, because it defaults to copying\n    if given indices.\n\n    Parameters\n    ----------\n    indices : 1D sequence, slice or Ellipsis\n    \"\"\"\n    if isinstance(indices, slice):\n        return indices\n\n    if indices is ...:\n        return slice(None, None, 1)\n\n    # a very common case for column selection\n    if len(indices) == 1 and not isinstance(indices[0], bool):\n        if indices[0] >= 0:\n            return slice(indices[0], indices[0] + 1, 1)\n        else:\n            return slice(indices[0], indices[0] - 1, -1)\n\n    if len(indices) >= 1:\n        indices = np.asarray(indices)\n        if indices.dtype != bool:\n            begin = indices[0]\n            end = indices[-1]\n            steps = np.diff(indices) if len(indices) > 1 else np.array([1])\n            step = steps[0]\n\n            # continuous ranges with constant step and valid start and stop index can be slices\n            if np.all(steps == step) and step > 0 and begin >= 0 and end < maxlen:\n                return slice(begin, end + step, step)\n\n    return indices\n\n\ndef _rxc_ix(rows, cols):\n    \"\"\"\n    Construct an index object to index the `rows` x `cols` cross product.\n\n    Rows and columns can be a 1d bool or int sequence, or a slice.\n    The later is a convenience and is interpreted the same\n    as `slice(None, None, -1)`\n\n    Parameters\n    ----------\n    rows : 1D sequence, slice\n        Row indices.\n    cols : 1D sequence, slice\n        Column indices.\n\n    See Also\n    --------\n    numpy.ix_\n\n    Examples\n    --------\n    >>> import numpy as np\n    >>> a = np.arange(10).reshape(2, 5)\n    >>> a[_rxc_ix([0, 1], [3, 4])]\n    array([[3, 4],\n           [8, 9]])\n    >>> a[_rxc_ix([False, True], slice(None, None, 1))]\n    array([[5, 6, 7, 8, 9]])\n\n    \"\"\"\n    isslice = (isinstance(rows, slice), isinstance(cols, slice))\n    if isslice == (True, True):\n        return rows, cols\n    elif isslice == (True, False):\n        return rows, np.asarray(np.ix_(cols), int).ravel()\n    elif isslice == (False, True):\n        return np.asarray(np.ix_(rows), int).ravel(), cols\n    else:\n        r, c = np.ix_(rows, cols)\n        return np.asarray(r, int), np.asarray(c, int)\n\n\ndef assure_domain_conversion_sparsity(target, source):\n    \"\"\"\n    Assure that the table obeys the domain conversion's suggestions about sparsity.\n\n    Args:\n        target (Table): the target table.\n        source (Table): the source table.\n\n    Returns:\n        Table: with fixed sparsity. The sparsity is set as it is recommended by domain conversion\n            for transformation from source to the target domain.\n    \"\"\"\n    conversion = DomainConversion(source.domain, target.domain)\n    match_density = [assure_array_dense, assure_array_sparse]\n    target.X = match_density[conversion.sparse_X](target.X)\n    target.Y = match_density[conversion.sparse_Y](target.Y)\n    target.metas = match_density[conversion.sparse_metas](target.metas)\n    return target\n\n\nclass Role:\n    Attribute = 0\n    ClassAttribute = 1\n    Meta = 2\n\n    @staticmethod\n    def get_arr(role, table):\n        return table.X if role == Role.Attribute else \\\n               table.Y if role == Role.ClassAttribute else \\\n               table.metas\n"}
A user will ask you to solve a task. You should first draft your thinking process (inner monologue). Then, generate the solution.

Your response format must follow the template below:
<think>
Your thoughts or/and draft, like working through an exercise on scratch paper. Be as casual and as long as you want until you are confident to generate a correct solution.
</think>
<solution>
Final solution presented to the user.
</solution>
system
We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[ISSUE]
**Title:** Unpickling Table Fails to Restore 'X' Attribute in State

**Description:**
When unpickling a `Table` object, the internal state does not include the 'X' attribute. This omission causes the deserialized `Table` to lack essential data, leading to inconsistencies and potential errors in subsequent operations.

**Example Buggy Code:**
```python
import pickle
from unittest.mock import patch, Mock

def test_pickle_setstate():
    d = data.Table("zoo")
    s = pickle.dumps(d)
    with patch("Orange.data.Table.__setstate__", Mock()) as mock:
        pickle.loads(s)
        state = mock.call_args[0][0]
        # 'X' is expected to be in the state but is missing
```

**Expected Behavior:**
After unpickling, the `Table`'s internal state should include the 'X' attribute as a 2D array along with other attributes like '_Y' and 'metas'. This ensures that all necessary data is correctly restored and the `Table` functions as intended.

**Actual Behavior:**
The 'X' attribute is absent from the internal state during the unpickling process. This leads to the `Table` object missing crucial data, which can cause failures in operations that rely on the 'X' attribute.

[/ISSUE]
--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.

--- BEGIN FILE ---
```
### Orange/data/table.py
import operator
import os
import sys
import threading
import warnings
import weakref
import zlib
from collections.abc import Iterable, Sequence, Sized
from contextlib import contextmanager
from functools import reduce
from itertools import chain
from numbers import Real, Integral
from threading import Lock

import bottleneck as bn
import numpy as np

from scipy import sparse as sp
from scipy.sparse import issparse, csc_matrix

import Orange.data  # import for io.py
from Orange.data import (
    _contingency, _valuecount,
    Domain, Variable, Storage, StringVariable, Unknown, Value, Instance,
    ContinuousVariable, DiscreteVariable, MISSING_VALUES,
    DomainConversion)
from Orange.data.util import SharedComputeValue, \
    assure_array_dense, assure_array_sparse, \
    assure_column_dense, assure_column_sparse, get_unique_names_duplicates
from Orange.misc.collections import frozendict
from Orange.statistics.util import bincount, countnans, contingency, \
    stats as fast_stats, sparse_has_implicit_zeros, sparse_count_implicit_zeros, \
    sparse_implicit_zero_weights
from Orange.util import OrangeDeprecationWarning, dummy_callback

__all__ = ["dataset_dirs", "get_sample_datasets_dir", "RowInstance", "Table"]


def get_sample_datasets_dir():
    orange_data_table = os.path.dirname(__file__)
    dataset_dir = os.path.join(orange_data_table, '..', 'datasets')
    return os.path.realpath(dataset_dir)


dataset_dirs = ['', get_sample_datasets_dir()]


class _ThreadLocal(threading.local):
    def __init__(self):
        super().__init__()
        # Domain conversion cache used in Table.from_table. It is defined
        # here instead of as a class variable of a Table so that caching also works
        # with descendants of Table.
        self.conversion_cache = None
        self.domain_cache = None


_thread_local = _ThreadLocal()


def _idcache_save(cachedict, keys, value):
    cachedict[tuple(map(id, keys))] = \
        value, [weakref.ref(k) for k in keys]


def _idcache_restore(cachedict, keys):
    shared, weakrefs = cachedict.get(tuple(map(id, keys)), (None, []))
    for r in weakrefs:
        if r() is None:
            return None
    return shared


class DomainTransformationError(Exception):
    pass


class RowInstance(Instance):
    sparse_x = None
    sparse_y = None
    sparse_metas = None
    _weight = None

    def __init__(self, table, row_index):
        """
        Construct a data instance representing the given row of the table.
        """
        self.table = table
        self._domain = table.domain
        self.row_index = row_index
        self.id = table.ids[row_index]
        self._x = table.X[row_index]
        if sp.issparse(self._x):
            self.sparse_x = sp.csr_matrix(self._x)
            self._x = np.asarray(self._x.todense())[0]
        self._y = table._Y[row_index]
        if sp.issparse(self._y):
            self.sparse_y = sp.csr_matrix(self._y)
            self._y = np.asarray(self._y.todense())[0]
        self._y = np.atleast_1d(self._y)
        self._metas = table.metas[row_index]
        if sp.issparse(self._metas):
            self.sparse_metas = sp.csr_matrix(self._metas)
            self._metas = np.asarray(self._metas.todense())[0]

    @property
    def weight(self):
        if not self.table.has_weights():
            return 1
        return self.table.W[self.row_index]

    @weight.setter
    def weight(self, weight):
        if not self.table.has_weights():
            self.table.set_weights()
        self.table.W[self.row_index] = weight

    def set_class(self, value):
        # pylint: disable=protected-access
        self._check_single_class()
        if not isinstance(value, Real):
            value = self.table.domain.class_var.to_val(value)
        if self.sparse_y:
            self.table._Y[self.row_index, 0] = value
        else:
            self.table._Y[self.row_index] = value
            if self.table._Y.ndim == 1:  # if _y is not a view
                self._y[0] = value

    def __setitem__(self, key, value):
        if not isinstance(key, Integral):
            key = self._domain.index(key)
        if isinstance(value, str):
            var = self._domain[key]
            value = var.to_val(value)
        if key >= 0:
            if not isinstance(value, Real):
                raise TypeError("Expected primitive value, got '%s'" %
                                type(value).__name__)
            if key < len(self._x):
                # write to self.table.X to support table unlocking for live instances
                self.table.X[self.row_index, key] = value
                if self.sparse_x is not None:
                    self._x[key] = value
            else:
                if self.sparse_y is not None:
                    self.table._Y[self.row_index, key - len(self._x)] = value
                else:
                    self.table._Y[self.row_index] = value
                    if self.table._Y.ndim == 1:  # if _y is not a view
                        self._y[0] = value
        else:
            self.table.metas[self.row_index, -1 - key] = value
            if self.sparse_metas is not None:
                self._metas[-1 - key] = value

    def _str(self, limit):
        def sp_values(matrix, variables):
            if not sp.issparse(matrix):
                if matrix.ndim == 1:
                    matrix = matrix[:, np.newaxis]
                return Instance.str_values(matrix[row], variables, limit)

            row_entries, idx = [], 0
            while idx < len(variables):
                # Make sure to stop printing variables if we limit the output
                if limit and len(row_entries) >= 5:
                    break

                var = variables[idx]
                if var.is_discrete or matrix[row, idx]:
                    row_entries.append("%s=%s" % (var.name, var.str_val(matrix[row, idx])))

                idx += 1

            s = ", ".join(row_entries)

            if limit and idx < len(variables):
                s += ", ..."

            return s

        table = self.table
        domain = table.domain
        row = self.row_index
        s = "[" + sp_values(table.X, domain.attributes)
        if domain.class_vars:
            s += " | " + sp_values(table.Y, domain.class_vars)
        s += "]"
        if self._domain.metas:
            s += " {" + sp_values(table.metas, domain.metas) + "}"
        return s

    def __str__(self):
        return self._str(False)

    def __repr__(self):
        return self._str(True)


class Columns:
    def __init__(self, domain):
        for v in chain(domain.variables, domain.metas):
            setattr(self, v.name.replace(" ", "_"), v)


class _ArrayConversion:

    def __init__(self, target, src_cols, variables, is_sparse, source_domain):
        self.target = target
        self.src_cols = src_cols
        self.is_sparse = is_sparse
        self.subarray_from = self._can_copy_all(src_cols, source_domain)
        self.variables = variables
        dtype = np.float64
        if any(isinstance(var, StringVariable) for var in self.variables):
            dtype = object
        self.dtype = dtype
        self.row_selection_needed = any(not isinstance(x, Integral)
                                        for x in src_cols)

    def _can_copy_all(self, src_cols, source_domain):
        n_src_attrs = len(source_domain.attributes)
        if all(isinstance(x, Integral) and 0 <= x < n_src_attrs
               for x in src_cols):
            return "X"
        if all(isinstance(x, Integral) and x < 0 for x in src_cols):
            return "metas"
        if all(isinstance(x, Integral) and x >= n_src_attrs
               for x in src_cols):
            return "Y"

    def get_subarray(self, source, row_indices, n_rows):
        if not len(self.src_cols):
            if self.is_sparse:
                return sp.csr_matrix((n_rows, 0), dtype=source.X.dtype)
            else:
                return np.zeros((n_rows, 0), dtype=source.X.dtype)

        match_density = assure_array_sparse if self.is_sparse else assure_array_dense
        n_src_attrs = len(source.domain.attributes)
        if self.subarray_from == "X":
            arr = match_density(_subarray(source.X, row_indices, self.src_cols))
        elif self.subarray_from == "metas":
            arr = match_density(_subarray(source.metas, row_indices,
                                          [-1 - x for x in self.src_cols]))
        elif self.subarray_from == "Y":
            Y = source.Y if source.Y.ndim == 2 else source.Y[:, None]
            arr = match_density(_subarray(
                Y, row_indices,
                [x - n_src_attrs for x in self.src_cols]))
        else:
            assert False
        if arr.dtype != self.dtype:
            arr = arr.astype(self.dtype)
        assert arr.ndim == 2 or self.subarray_from == "Y" and arr.ndim == 1
        return arr

    def get_columns(self, source, row_indices, n_rows, out=None, target_indices=None):
        n_src_attrs = len(source.domain.attributes)

        data = []
        sp_col = []
        sp_row = []
        match_density = (
            assure_column_sparse if self.is_sparse else assure_column_dense
        )

        # converting to csc before instead of each column is faster
        # do not convert if not required
        if any(isinstance(x, int) for x in self.src_cols):
            X = source.X
            Y = source.Y
            if Y.ndim == 1:
                Y = Y[:, None]
            if self.is_sparse:
                X = csc_matrix(X)
                Y = csc_matrix(Y)

        if self.row_selection_needed:
            if row_indices is ...:
                sourceri = source
            else:
                sourceri = source[row_indices]

        shared_cache = _thread_local.conversion_cache
        for i, col in enumerate(self.src_cols):
            if col is None:
                col_array = match_density(
                    np.full((n_rows, 1), self.variables[i].Unknown)
                )
            elif not isinstance(col, Integral):
                if isinstance(col, SharedComputeValue):
                    shared = _idcache_restore(shared_cache, (col.compute_shared, source))
                    if shared is None:
                        shared = col.compute_shared(sourceri)
                        _idcache_save(shared_cache, (col.compute_shared, source), shared)
                    col_array = match_density(
                        col(sourceri, shared_data=shared))
                else:
                    col_array = match_density(col(sourceri))
            elif col < 0:
                col_array = match_density(
                    source.metas[row_indices, -1 - col]
                )
            elif col < n_src_attrs:
                col_array = match_density(X[row_indices, col])
            else:
                col_array = match_density(
                    Y[row_indices, col - n_src_attrs]
                )

            if self.is_sparse:
                # col_array should be coo matrix
                data.append(col_array.data)
                sp_col.append(np.full(len(col_array.data), i))
                sp_row.append(col_array.indices)  # row indices should be same
            else:
                out[target_indices, i] = col_array

        if self.is_sparse:
            # creating csr directly would need plenty of manual work which
            # would probably slow down the process - conversion coo to csr
            # is fast
            out = sp.coo_matrix(
                (np.hstack(data), (np.hstack(sp_row), np.hstack(sp_col))),
                shape=(n_rows, len(self.src_cols)),
                dtype=self.dtype
            )
            out = out.tocsr()

        return out


class _FromTableConversion:

    def __init__(self, source, destination):
        conversion = DomainConversion(source, destination)

        self.X = _ArrayConversion("X", conversion.attributes,
                                  destination.attributes, conversion.sparse_X,
                                  source)
        self.Y = _ArrayConversion("Y", conversion.class_vars,
                                  destination.class_vars, conversion.sparse_Y,
                                  source)
        self.metas = _ArrayConversion("metas", conversion.metas,
                                      destination.metas, conversion.sparse_metas,
                                      source)

        self.subarray = []
        self.columnwise = []

        for part in [self.X, self.Y, self.metas]:
            if part.subarray_from is None:
                self.columnwise.append(part)
            else:
                self.subarray.append(part)


# noinspection PyPep8Naming
class Table(Sequence, Storage):

    LOCKING = None
    """ If the class attribute LOCKING is True, tables will throw exceptions
    on in-place modifications unless unlocked explicitly. LOCKING is supposed
    to be set to True for testing to help us find bugs. If set to False
    or None, no safeguards are in place. Two different values are used for
    the same behaviour to distinguish the unchanged default (None) form
    explicit deactivation (False) that some add-ons might need. """

    __file__ = None
    name = "untitled"

    domain = Domain([])
    _X = _Y = _metas = _W = np.zeros((0, 0))  # pylint: disable=invalid-name
    ids = np.zeros(0)
    ids.setflags(write=False)
    attributes = frozendict()

    _Unlocked_X, _Unlocked_Y, _Unlocked_metas, _Unlocked_W = 1, 2, 4, 8
    _unlocked = _Unlocked_X + _Unlocked_Y + \
                _Unlocked_metas + _Unlocked_W  # pylint: disable=invalid-name

    @property
    def columns(self):
        """
        A class whose attributes contain attribute descriptors for columns.
        For a table `table`, setting `c = table.columns` will allow accessing
        the table's variables with, for instance `c.gender`, `c.age` ets.
        Spaces are replaced with underscores.
        """
        return Columns(self.domain)

    _next_instance_id = 0
    _next_instance_lock = Lock()

    def _check_unlocked(self, partflag):
        if not self._unlocked & partflag:
            raise ValueError("Table is read-only unless unlocked")

    @property
    def X(self):  # pylint: disable=invalid-name
        return self._X

    @X.setter
    def X(self, value):
        self._check_unlocked(self._Unlocked_X)
        self._X = _dereferenced(value)

    @property
    def Y(self):  # pylint: disable=invalid-name
        return self._Y

    @Y.setter
    def Y(self, value):
        self._check_unlocked(self._Unlocked_Y)
        if sp.issparse(value) and len(self) != value.shape[0]:
            value = value.T
        if sp.issparse(value):
            value = _dereferenced(value.toarray())
        if value.ndim == 2 and value.shape[1] == 1:
            value = value[:, 0].copy()  # no views!
        self._Y = value

    @property
    def metas(self):
        return self._metas

    @metas.setter
    def metas(self, value):
        self._check_unlocked(self._Unlocked_metas)
        self._metas = _dereferenced(value)

    @property
    def W(self):  # pylint: disable=invalid-name
        return self._W

    @W.setter
    def W(self, value):
        self._check_unlocked(self._Unlocked_W)
        self._W = value

    def __setstate__(self, state):
        # Backward compatibility with pickles before table locking
        self._initialize_unlocked()  # __dict__ seems to be cleared before calling __setstate__
        with self.unlocked():
            for k in ("X", "W", "metas"):
                if k in state:
                    setattr(self, k, state.pop(k))
            self.__dict__.update(state)

    def _lock_parts(self):
        return ((self._X, self._Unlocked_X, "X"),
                (self._Y, self._Unlocked_Y, "Y"),
                (self._metas, self._Unlocked_metas, "metas"),
                (self._W, self._Unlocked_W, "weights"))

    def _initialize_unlocked(self):
        if Table.LOCKING:
            self._unlocked = 0
        else:
            self._unlocked = sum(f for _, f, _ in self._lock_parts())

    def _update_locks(self, force=False, unlock_bases=()):
        if not Table.LOCKING:
            return

        def sync(*xs):
            for x in xs:
                try:
                    undo_on_fail.append((x, x.flags.writeable))
                    x.flags.writeable = writeable
                except ValueError:
                    if force \
                            and writeable \
                            and x.base is not None \
                            and not x.base.flags.writeable:
                        x.base.flags.writeable = writeable
                        x.flags.writeable = writeable
                        forced_bases.append(x.base)
                    else:
                        raise

        forced_bases = []
        undo_on_fail = []
        for base in unlock_bases:
            base.flags.writeable = False
        try:
            for part, flag, _ in self._lock_parts():
                if part is None:
                    continue
                writeable = bool(self._unlocked & flag)
                if sp.isspmatrix_csr(part) or sp.isspmatrix_csc(part):
                    sync(part.data, part.indices, part.indptr)
                elif sp.isspmatrix_coo(part):
                    sync(part.data, part.row, part.col)
                elif sp.issparse(part):
                    raise ValueError("Unsupported sparse data type")
                else:
                    sync(part)
        except:
            for part, flag in undo_on_fail:
                part.flags.writeable = flag
            raise
        return tuple(forced_bases)

    def __unlocked(self, *parts, force=False):
        prev_state = self._unlocked
        for part, flag, _ in self._lock_parts():
            if not parts or any(ppart is part for ppart in parts):
                self._unlocked |= flag
        try:
            forced_bases = self._update_locks(force)
            yield
        finally:
            self._unlocked = prev_state
            self._update_locks(unlock_bases=forced_bases)

    def force_unlocked(self, *parts):
        """
        Unlocking without any checks.

        Use with extreme caution. This is meant primarily for 3rd party
        functions in Cython that expect read-write buffer, but do not
        actually modify it. the given parts (default: all parts) of the table.

        The function will still fail to unlock and raise an exception if the
        table contains view to another table.
        """
        return contextmanager(self.__unlocked)(*parts, force=True)

    def unlocked(self, *parts):
        """
        Unlock the given parts (default: all parts) of the table.

        The caller must ensure that the table is safe to modify. The function
        will raise an exception if the table contains view to other table.
        """
        def can_unlock(x):
            if sp.issparse(x):
                return can_unlock(x.data)
            return x.flags.writeable or x.flags.owndata

        for part, flag, name in self._lock_parts():
            if not flag & self._unlocked \
                    and (not parts or any(ppart is part for ppart in parts)) \
                    and part is not None and not can_unlock(part):
                raise ValueError(f"'{name}' is a view into another table "
                                 "and cannot be unlocked")
        return contextmanager(self.__unlocked)(*parts)

    def __new__(cls, *args, **kwargs):
        def warn_deprecated(method):
            warnings.warn("Direct calls to Table's constructor are deprecated "
                          "and will be removed. Replace this call with "
                          f"Table.{method}", OrangeDeprecationWarning,
                          stacklevel=3)

        if not args:
            if not kwargs:
                return super().__new__(cls)
            else:
                raise TypeError("Table() must not be called directly")

        if isinstance(args[0], str):
            if len(args) > 1:
                raise TypeError("Table(name: str) expects just one argument")
            if args[0].startswith('https://') or args[0].startswith('http://'):
                return cls.from_url(args[0], **kwargs)
            else:
                return cls.from_file(args[0], **kwargs)

        elif isinstance(args[0], Table):
            if len(args) > 1:
                raise TypeError("Table(table: Table) expects just one argument")
            return cls.from_table(args[0].domain, args[0], **kwargs)
        elif isinstance(args[0], Domain):
            domain, args = args[0], args[1:]
            if not args:
                warn_deprecated("from_domain")
                return cls.from_domain(domain, **kwargs)
            if isinstance(args[0], Table):
                warn_deprecated("from_table")
                return cls.from_table(domain, *args, **kwargs)
            elif isinstance(args[0], list):
                warn_deprecated("from_list")
                return cls.from_list(domain, *args, **kwargs)
        else:
            warnings.warn("Omitting domain in a call to Table(X, Y, metas), is "
                          "deprecated and will be removed. "
                          "Call Table.from_numpy(None, X, Y, metas) instead.",
                          OrangeDeprecationWarning, stacklevel=2)
            domain = None

        return cls.from_numpy(domain, *args, **kwargs)

    def __init__(self, *args, **kwargs):  # pylint: disable=unused-argument
        self._initialize_unlocked()
        self._update_locks()

    @classmethod
    def from_domain(cls, domain, n_rows=0, weights=False):
        """
        Construct a new `Table` with the given number of rows for the given
        domain. The optional vector of weights is initialized to 1's.

        :param domain: domain for the `Table`
        :type domain: Orange.data.Domain
        :param n_rows: number of rows in the new table
        :type n_rows: int
        :param weights: indicates whether to construct a vector of weights
        :type weights: bool
        :return: a new table
        :rtype: Orange.data.Table
        """
        self = cls()
        self.domain = domain
        self.n_rows = n_rows
        with self.unlocked():
            self.X = np.zeros((n_rows, len(domain.attributes)))
            if len(domain.class_vars) != 1:
                self.Y = np.zeros((n_rows, len(domain.class_vars)))
            else:
                self.Y = np.zeros(n_rows)
            if weights:
                self.W = np.ones(n_rows)
            else:
                self.W = np.empty((n_rows, 0))
            self.metas = np.empty((n_rows, len(self.domain.metas)), object)
            cls._init_ids(self)
            self.attributes = {}
        return self

    @classmethod
    def from_table(cls, domain, source, row_indices=...):
        """
        Create a new table from selected columns and/or rows of an existing
        one. The columns are chosen using a domain. The domain may also include
        variables that do not appear in the source table; they are computed
        from source variables if possible.

        The resulting data may be a view or a copy of the existing data.

        :param domain: the domain for the new table
        :type domain: Orange.data.Domain
        :param source: the source table
        :type source: Orange.data.Table
        :param row_indices: indices of the rows to include
        :type row_indices: a slice or a sequence
        :return: a new table
        :rtype: Orange.data.Table
        """

        PART = 5000

        new_cache = _thread_local.conversion_cache is None
        try:
            if new_cache:
                _thread_local.conversion_cache = {}
                _thread_local.domain_cache = {}
            else:
                cached = _idcache_restore(_thread_local.conversion_cache, (domain, source))
                if cached is not None:
                    return cached
            if domain is source.domain:
                table = cls.from_table_rows(source, row_indices)
                # assure resulting domain is the instance passed on input
                table.domain = domain
                # since sparse flags are not considered when checking for
                # domain equality, fix manually.
                with table.unlocked():
                    table = assure_domain_conversion_sparsity(table, source)
                return table

            if row_indices is ...:
                n_rows = len(source)
            elif isinstance(row_indices, slice):
                row_indices_range = range(*row_indices.indices(source.X.shape[0]))
                n_rows = len(row_indices_range)
            else:
                n_rows = len(row_indices)

            self = cls()
            self.domain = domain

            table_conversion = \
                _idcache_restore(_thread_local.domain_cache, (domain, source.domain))
            if table_conversion is None:
                table_conversion = _FromTableConversion(source.domain, domain)
                _idcache_save(_thread_local.domain_cache, (domain, source.domain),
                              table_conversion)

            # if an array can be a subarray of the input table, this needs to be done
            # on the whole table, because this avoids needless copies of contents

            with self.unlocked():
                for array_conv in table_conversion.subarray:
                    out = array_conv.get_subarray(source, row_indices, n_rows)
                    setattr(self, array_conv.target, out)

                parts = {}

                for array_conv in table_conversion.columnwise:
                    if array_conv.is_sparse:
                        parts[array_conv.target] = []
                    else:
                        # F-order enables faster writing to the array while accessing and
                        # matrix operations work with same speed (e.g. dot)
                        parts[array_conv.target] = \
                            np.zeros((n_rows, len(array_conv.src_cols)),
                                     order="F", dtype=array_conv.dtype)

                if n_rows <= PART:
                    for array_conv in table_conversion.columnwise:
                        out = array_conv.get_columns(source, row_indices, n_rows,
                                                     parts[array_conv.target],
                                                     ...)
                        setattr(self, array_conv.target, out)
                else:
                    i_done = 0

                    while i_done < n_rows:
                        target_indices = slice(i_done, min(n_rows, i_done + PART))
                        if row_indices is ...:
                            source_indices = target_indices
                        elif isinstance(row_indices, slice):
                            r = row_indices_range[target_indices]
                            source_indices = slice(r.start, r.stop, r.step)
                        else:
                            source_indices = row_indices[target_indices]
                        part_rows = min(n_rows, i_done+PART) - i_done

                        for array_conv in table_conversion.columnwise:
                            out = array_conv.get_columns(source, source_indices, part_rows,
                                                         parts[array_conv.target],
                                                         target_indices)
                            if array_conv.is_sparse:  # dense arrays are populated in-place
                                parts[array_conv.target].append(out)

                        i_done += PART

                        # clear cache after a part is done
                        if new_cache:
                            _thread_local.conversion_cache = {}

                    for array_conv in table_conversion.columnwise:
                        cparts = parts[array_conv.target]
                        out = cparts if not array_conv.is_sparse else sp.vstack(cparts)
                        setattr(self, array_conv.target, out)

                if source.has_weights():
                    self.W = source.W[row_indices]
                else:
                    self.W = np.empty((n_rows, 0))
                self.name = getattr(source, 'name', '')
                if hasattr(source, 'ids'):
                    self.ids = source.ids[row_indices]
                else:
                    cls._init_ids(self)
                self.attributes = getattr(source, 'attributes', {})
                _idcache_save(_thread_local.conversion_cache, (domain, source), self)
            return self
        finally:
            if new_cache:
                _thread_local.conversion_cache = None
                _thread_local.domain_cache = None

    def transform(self, domain):
        """
        Construct a table with a different domain.

        The new table keeps the row ids and other information. If the table
        is a subclass of :obj:`Table`, the resulting table will be of the same
        type.

        In a typical scenario, an existing table is augmented with a new
        column by ::

            domain = Domain(old_domain.attributes + [new_attribute],
                            old_domain.class_vars,
                            old_domain.metas)
            table = data.transform(domain)
            table[:, new_attribute] = new_column

        Args:
            domain (Domain): new domain

        Returns:
            A new table
        """
        return type(self).from_table(domain, self)

    @classmethod
    def from_table_rows(cls, source, row_indices):
        """
        Construct a new table by selecting rows from the source table.

        :param source: an existing table
        :type source: Orange.data.Table
        :param row_indices: indices of the rows to include
        :type row_indices: a slice or a sequence
        :return: a new table
        :rtype: Orange.data.Table
        """
        def get_rows(a):
            a = a[row_indices]
            if isinstance(row_indices, slice) or row_indices is ...:
                a = a.copy()
            return a

        self = cls()
        self.domain = source.domain
        with self.unlocked():
            self.X = get_rows(source.X)
            if self.X.ndim == 1:
                self.X = self.X.reshape(-1, len(self.domain.attributes))
            self.Y = get_rows(source.Y)
            self.metas = get_rows(source.metas)
            if self.metas.ndim == 1:
                self.metas = self.metas.reshape(-1, len(self.domain.metas))
            self.W = get_rows(source.W)
            self.name = getattr(source, 'name', '')
            self.ids = np.array(source.ids[row_indices])
            self.attributes = getattr(source, 'attributes', {})
        return self

    @classmethod
    def from_numpy(cls, domain, X, Y=None, metas=None, W=None,
                   attributes=None, ids=None):
        """
        Construct a table from numpy arrays with the given domain. The number
        of variables in the domain must match the number of columns in the
        corresponding arrays. All arrays must have the same number of rows.
        Arrays may be of different numpy types, and may be dense or sparse.

        :param domain: the domain for the new table
        :type domain: Orange.data.Domain
        :param X: array with attribute values
        :type X: np.array
        :param Y: array with class values
        :type Y: np.array
        :param metas: array with meta attributes
        :type metas: np.array
        :param W: array with weights
        :type W: np.array
        :return:
        """
        X, Y, W = _check_arrays(X, Y, W, dtype='float64')
        metas, = _check_arrays(metas, dtype=object, shape_1=X.shape[0])
        ids, = _check_arrays(ids, dtype=int, shape_1=X.shape[0])

        if domain is None:
            domain = Domain.from_numpy(X, Y, metas)

        if Y is None:
            if not domain.class_vars or sp.issparse(X):
                Y = np.empty((X.shape[0], 0), dtype=np.float64)
            else:
                own_data = X.flags.owndata and X.base is None
                Y = X[:, len(domain.attributes):]
                X = X[:, :len(domain.attributes)]
                if own_data:
                    Y = Y.copy()
                    X = X.copy()
        if metas is None:
            metas = np.empty((X.shape[0], 0), object)
        if W is None or W.size == 0:
            W = np.empty((X.shape[0], 0))
        elif W.shape != (W.size, ):
            W = W.reshape(W.size).copy()

        if X.shape[1] != len(domain.attributes):
            raise ValueError(
                "Invalid number of variable columns ({} != {})".format(
                    X.shape[1], len(domain.attributes))
            )
        if Y.ndim == 1:
            if not domain.class_var:
                raise ValueError(
                    "Invalid number of class columns "
                    f"(1 != {len(domain.class_vars)})")
        elif Y.shape[1] != len(domain.class_vars):
            raise ValueError(
                "Invalid number of class columns ({} != {})".format(
                    Y.shape[1], len(domain.class_vars))
            )
        if metas.shape[1] != len(domain.metas):
            raise ValueError(
                "Invalid number of meta attribute columns ({} != {})".format(
                    metas.shape[1], len(domain.metas))
            )
        if not X.shape[0] == Y.shape[0] == metas.shape[0] == W.shape[0]:
            raise ValueError(
                "Parts of data contain different numbers of rows.")

        self = cls()
        with self.unlocked():
            self.domain = domain
            self.X = X
            self.Y = Y
            self.metas = metas
            self.W = W
            self.n_rows = self.X.shape[0]
            if ids is None:
                cls._init_ids(self)
            else:
                self.ids = ids
            self.attributes = {} if attributes is None else attributes
        return self

    @classmethod
    def from_list(cls, domain, rows, weights=None):
        if weights is not None and len(rows) != len(weights):
            raise ValueError("mismatching number of instances and weights")
        self = cls.from_domain(domain, len(rows), weights is not None)
        all_vars = domain.variables + domain.metas
        nattrs = len(domain.attributes)
        nattrscls = len(domain.variables)
        with self.unlocked():
            for i, row in enumerate(rows):
                if isinstance(row, Instance):
                    row = row.list
                vals = [var.to_val(val) for var, val in zip(all_vars, row)]
                self.X[i] = vals[:nattrs]
                if self._Y.ndim == 1:
                    self._Y[i] = vals[nattrs] if nattrs < len(vals) else np.nan
                else:
                    self._Y[i] = vals[nattrs:nattrscls]
                # for backward compatibility: allow omittine some (or all) metas
                self.metas[i, :len(vals) - nattrscls] = vals[nattrscls:]
            if weights is not None:
                self.W = np.array(weights)
            self.attributes = {}
        return self

    @classmethod
    def _init_ids(cls, obj):
        with cls._next_instance_lock:
            obj.ids = np.array(range(cls._next_instance_id, cls._next_instance_id + obj.X.shape[0]))
            cls._next_instance_id += obj.X.shape[0]

    @classmethod
    def new_id(cls):
        with cls._next_instance_lock:
            id = cls._next_instance_id
            cls._next_instance_id += 1
            return id

    def to_pandas_dfs(self):
        return Orange.data.pandas_compat.table_to_frames(self)

    @staticmethod
    def from_pandas_dfs(xdf, ydf, mdf):
        return Orange.data.pandas_compat.table_from_frames(xdf, ydf, mdf)

    @property
    def X_df(self):
        return Orange.data.pandas_compat.OrangeDataFrame(
            self, orange_role=Role.Attribute
        )

    @X_df.setter
    def X_df(self, df):
        Orange.data.pandas_compat.amend_table_with_frame(
            self, df, role=Role.Attribute
        )

    @property
    def Y_df(self):
        return Orange.data.pandas_compat.OrangeDataFrame(
            self, orange_role=Role.ClassAttribute
        )

    @Y_df.setter
    def Y_df(self, df):
        Orange.data.pandas_compat.amend_table_with_frame(
            self, df, role=Role.ClassAttribute
        )

    @property
    def metas_df(self):
        return Orange.data.pandas_compat.OrangeDataFrame(
            self, orange_role=Role.Meta
        )

    @metas_df.setter
    def metas_df(self, df):
        Orange.data.pandas_compat.amend_table_with_frame(
            self, df, role=Role.Meta
        )

    def save(self, filename):
        """
        Save a data table to a file. The path can be absolute or relative.

        :param filename: File name
        :type filename: str
        """
        ext = os.path.splitext(filename)[1]
        from Orange.data.io import FileFormat
        writer = FileFormat.writers.get(ext)
        if not writer:
            desc = FileFormat.names.get(ext)
            if desc:
                raise IOError(
                    "Writing of {}s is not supported".format(desc.lower()))
            else:
                raise IOError("Unknown file name extension.")
        writer.write_file(filename, self)

    @classmethod
    def from_file(cls, filename, sheet=None):
        """
        Read a data table from a file. The path can be absolute or relative.

        :param filename: File name
        :type filename: str
        :param sheet: Sheet in a file (optional)
        :type sheet: str
        :return: a new data table
        :rtype: Orange.data.Table
        """
        from Orange.data.io import FileFormat

        absolute_filename = FileFormat.locate(filename, dataset_dirs)
        reader = FileFormat.get_reader(absolute_filename)
        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

        data.__file__ = absolute_filename
        return data

    @classmethod
    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__:
    # Set the row of table data matrices
    # noinspection PyProtectedMember
    def _set_row(self, example, row):
        # pylint: disable=protected-access
        domain = self.domain
        if isinstance(example, Instance):
            if example.domain == domain:
                self.X[row] = example._x
                if self._Y.ndim == 1:
                    self._Y[row] = float(example._y)
                else:
                    self._Y[row] = np.atleast_1d(example._y)
                self.metas[row] = example._metas
                return

            self.X[row], self._Y[row], self.metas[row] = \
                self.domain.convert(example)
            try:
                self.ids[row] = example.id
            except:
                with type(self)._next_instance_lock:
                    self.ids[row] = type(self)._next_instance_id
                    type(self)._next_instance_id += 1

        else:
            attrs = domain.attributes
            if len(example) != len(domain.variables):
                raise ValueError("invalid length")
            self._X[row] = [var.to_val(val) for var, val in zip(attrs, example)]
            if self._Y.ndim == 1:
                self._Y[row] = domain.class_var.to_val(example[len(attrs)])
            else:
                self._Y[row] = [var.to_val(val)
                                for var, val in zip(domain.class_vars,
                                                    example[len(attrs):])]
            self.metas[row] = np.array([var.Unknown for var in domain.metas],
                                       dtype=object)

    def _check_all_dense(self):
        return all(x in (Storage.DENSE, Storage.MISSING)
                   for x in (self.X_density(), self.Y_density(),
                             self.metas_density()))

    def __getitem__(self, key):
        if isinstance(key, Integral):
            return RowInstance(self, key)
        if not isinstance(key, tuple):
            return self.from_table_rows(self, key)

        if len(key) != 2:
            raise IndexError("Table indices must be one- or two-dimensional")

        row_idx, col_idx = key
        if isinstance(row_idx, Integral):
            if isinstance(col_idx, (str, Integral, Variable)):
                col_idx = self.domain.index(col_idx)
                var = self.domain[col_idx]
                if 0 <= col_idx < len(self.domain.attributes):
                    val = self.X[row_idx, col_idx]
                elif col_idx == len(self.domain.attributes) and self._Y.ndim == 1:
                    val = self._Y[row_idx]
                elif col_idx >= len(self.domain.attributes):
                    val = self._Y[row_idx,
                                  col_idx - len(self.domain.attributes)]
                else:
                    val = self.metas[row_idx, -1 - col_idx]
                if isinstance(col_idx, DiscreteVariable) and var is not col_idx:
                    val = col_idx.get_mapper_from(var)(val)
                return Value(var, val)
            else:
                row_idx = [row_idx]

        # multiple rows OR single row but multiple columns:
        # construct a new table
        attributes, col_indices = self.domain._compute_col_indices(col_idx)
        if attributes is not None:
            n_attrs = len(self.domain.attributes)
            r_attrs = [attributes[i]
                       for i, col in enumerate(col_indices)
                       if 0 <= col < n_attrs]
            r_classes = [attributes[i]
                         for i, col in enumerate(col_indices)
                         if col >= n_attrs]
            r_metas = [attributes[i]
                       for i, col in enumerate(col_indices) if col < 0]
            domain = Domain(r_attrs, r_classes, r_metas)
        else:
            domain = self.domain
        return self.from_table(domain, self, row_idx)

    def __setitem__(self, key, value):
        if not isinstance(key, tuple):
            if isinstance(value, Real):
                self.X[key, :] = value
                return
            self._set_row(value, key)
            return

        if len(key) != 2:
            raise IndexError("Table indices must be one- or two-dimensional")
        row_idx, col_idx = key

        # single row
        if isinstance(row_idx, Integral):
            if isinstance(col_idx, slice):
                col_idx = range(*slice.indices(col_idx, self.X.shape[1]))
            if not isinstance(col_idx, str) and isinstance(col_idx, Iterable):
                col_idx = list(col_idx)
            if not isinstance(col_idx, str) and isinstance(col_idx, Sized):
                if isinstance(value, (Sequence, np.ndarray)):
                    values = value
                elif isinstance(value, Iterable):
                    values = list(value)
                else:
                    raise TypeError("Setting multiple values requires a "
                                    "sequence or numpy array")
                if len(values) != len(col_idx):
                    raise ValueError("Invalid number of values")
            else:
                col_idx, values = [col_idx], [value]
            if isinstance(col_idx, DiscreteVariable) \
                    and self.domain[col_idx] != col_idx:
                values = self.domain[col_idx].get_mapper_from(col_idx)(values)
            for val, col_idx in zip(values, col_idx):
                if not isinstance(val, Integral):
                    val = self.domain[col_idx].to_val(val)
                if not isinstance(col_idx, Integral):
                    col_idx = self.domain.index(col_idx)
                if col_idx >= 0:
                    if col_idx < self.X.shape[1]:
                        self.X[row_idx, col_idx] = val
                    elif self._Y.ndim == 1 and col_idx == self.X.shape[1]:
                        self._Y[row_idx] = val
                    else:
                        self._Y[row_idx, col_idx - self.X.shape[1]] = val
                else:
                    self.metas[row_idx, -1 - col_idx] = val

        # multiple rows, multiple columns
        attributes, col_indices = self.domain._compute_col_indices(col_idx)
        if col_indices is ...:
            col_indices = range(len(self.domain.variables))
        n_attrs = self.X.shape[1]
        if isinstance(value, str):
            if not attributes:
                attributes = self.domain.attributes
            for var, col in zip(attributes, col_indices):
                val = var.to_val(value)
                if 0 <= col < n_attrs:
                    self.X[row_idx, col] = val
                elif col >= n_attrs:
                    if self._Y.ndim == 1 and col == n_attrs:
                        self._Y[row_idx] = val
                    else:
                        self._Y[row_idx, col - n_attrs] = val
                else:
                    self.metas[row_idx, -1 - col] = val
        else:
            attr_cols = np.fromiter(
                (col for col in col_indices if 0 <= col < n_attrs), int)
            class_cols = np.fromiter(
                (col - n_attrs for col in col_indices if col >= n_attrs), int)
            meta_cols = np.fromiter(
                (-1 - col for col in col_indices if col < 0), int)
            if value is None:
                value = Unknown

            if not isinstance(value, (Real, np.ndarray)) and \
                    (len(attr_cols) or len(class_cols)):
                raise TypeError(
                    "Ordinary attributes can only have primitive values")
            if len(attr_cols):
                self.X[row_idx, attr_cols] = value
            if len(class_cols):
                if self._Y.ndim == 1 and np.all(class_cols == 0):
                    if isinstance(value, np.ndarray):
                        yshape = self._Y[row_idx].shape
                        if value.shape != yshape:
                            value = value.reshape(yshape)
                    self._Y[row_idx] = value
                else:
                    self._Y[row_idx, class_cols] = value
            if len(meta_cols):
                self.metas[row_idx, meta_cols] = value

    def __len__(self):
        return self.X.shape[0]

    def __str__(self):
        return "[" + ",\n ".join(str(ex) for ex in self) + "]"

    def __repr__(self):
        head = 5
        if self.is_sparse():
            head = min(self.X.shape[0], head)
        s = "[" + ",\n ".join(repr(ex) for ex in self[:head])
        if len(self) > head:
            s += ",\n ..."
        s += "\n]"
        return s

    @classmethod
    def concatenate(cls, tables, axis=0):
        """
        Concatenate tables into a new table, either vertically or horizontally.

        If axis=0 (vertical concatenate), all tables must have the same domain.

        If axis=1 (horizontal),
        - all variable names must be unique.
        - ids are copied from the first table.
        - weights are copied from the first table in which they are defined.
        - the dictionary of table's attributes are merged. If the same attribute
          appears in multiple dictionaries, the earlier are used.

        Args:
            tables (Table): tables to be joined

        Returns:
            table (Table)
        """
        if axis not in (0, 1):
            raise ValueError("invalid axis")
        if not tables:
            raise ValueError('need at least one table to concatenate')

        if len(tables) == 1:
            return tables[0].copy()

        if axis == 0:
            conc = cls._concatenate_vertical(tables)
        else:
            conc = cls._concatenate_horizontal(tables)

        # TODO: Add attributes = {} to __init__
        conc.attributes = getattr(conc, "attributes", {})
        for table in reversed(tables):
            conc.attributes.update(table.attributes)

        names = [table.name for table in tables if table.name != "untitled"]
        if names:
            conc.name = names[0]
        return conc

    @classmethod
    def _concatenate_vertical(cls, tables):
        def vstack(arrs):
            return [np, sp][any(sp.issparse(arr) for arr in arrs)].vstack(arrs)

        def merge1d(arrs):
            arrs = list(arrs)
            ydims = {arr.ndim for arr in arrs}
            if ydims == {1}:
                return np.hstack(arrs)
            else:
                return vstack([
                    arr if arr.ndim == 2 else np.atleast_2d(arr).T
                    for arr in arrs
                ])

        def collect(attr):
            return [getattr(arr, attr) for arr in tables]

        domain = tables[0].domain
        if any(table.domain != domain for table in tables):
            raise ValueError('concatenated tables must have the same domain')

        conc = cls.from_numpy(
            domain,
            vstack(collect("X")),
            merge1d(collect("Y")),
            vstack(collect("metas")),
            merge1d(collect("W"))
        )
        conc.ids = np.hstack([t.ids for t in tables])
        return conc

    @classmethod
    def _concatenate_horizontal(cls, tables):
        """
        """
        def all_of(objs, names):
            return (tuple(getattr(obj, name) for obj in objs)
                    for name in names)

        def stack(arrs):
            non_empty = tuple(arr if arr.ndim == 2 else arr[:, np.newaxis]
                              for arr in arrs
                              if arr is not None and arr.size > 0)
            return np.hstack(non_empty) if non_empty else None

        doms, Ws = all_of(tables, ("domain", "W"))
        Xs, Ys, Ms = map(stack, all_of(tables, ("X", "Y", "metas")))
        # pylint: disable=undefined-loop-variable
        for W in Ws:
            if W.size:
                break

        parts = all_of(doms, ("attributes", "class_vars", "metas"))
        domain = Domain(*(tuple(chain(*lst)) for lst in parts))
        return cls.from_numpy(domain, Xs, Ys, Ms, W, ids=tables[0].ids)

    def add_column(self, variable, data, to_metas=None):
        """
        Create a new table with an additional column

        Column's name must be unique

        Args:
            variable (Variable): variable for the new column
            data (np.ndarray): data for the new column
            to_metas (bool, optional): if `True` the column is added as meta
                column. Otherwise, primitive variables are added to attributes
                and non-primitive to metas.

        Returns:
            table (Table): a new table with the additional column
        """
        dom = self.domain
        attrs, classes, metavars = dom.attributes, dom.class_vars, dom.metas
        to_metas = to_metas or not variable.is_primitive()
        if to_metas:
            metavars += (variable, )
        else:
            attrs += (variable, )
        domain = Domain(attrs, classes, metavars)
        new_table = self.transform(domain)
        with new_table.unlocked(new_table.metas if to_metas else new_table.X):
            new_table.get_column_view(variable)[0][:] = data
        return new_table

    def is_view(self):
        """
        Return `True` if all arrays represent a view referring to another table
        """
        return ((not self._X.shape[-1] or self._X.base is not None) and
                (not self._Y.shape[-1] or self._Y.base is not None) and
                (not self._metas.shape[-1] or self._metas.base is not None) and
                (not self._weights.shape[-1] or self._W.base is not None))

    def is_copy(self):
        """
        Return `True` if the table owns its data
        """
        return ((not self._X.shape[-1] or self._X.base is None) and
                (self._Y.base is None) and
                (self._metas.base is None) and
                (self._W.base is None))

    def is_sparse(self):
        """
        Return `True` if the table stores data in sparse format
        """
        return any(sp.issparse(i) for i in [self._X, self._Y, self._metas])

    def ensure_copy(self):
        """
        Ensure that the table owns its data; copy arrays when necessary.
        """

        def is_view(x):
            # Sparse matrices don't have views like numpy arrays. Since indexing on
            # them creates copies in constructor we can skip this check here.
            return not sp.issparse(x) and x.base is not None

        if is_view(self._X):
            self._X = self._X.copy()
        if is_view(self._Y):
            self._Y = self._Y.copy()
        if is_view(self._metas):
            self._metas = self._metas.copy()
        if is_view(self._W):
            self._W = self._W.copy()

    def copy(self):
        """
        Return a copy of the table
        """
        t = self.__class__(self)
        t.ensure_copy()
        return t

    @staticmethod
    def __determine_density(data):
        if data is None:
            return Storage.Missing
        if data is not None and sp.issparse(data):
            return Storage.SPARSE_BOOL if (data.data == 1).all() else Storage.SPARSE
        else:
            return Storage.DENSE

    def X_density(self):
        if not hasattr(self, "_X_density"):
            self._X_density = self.__determine_density(self.X)
        return self._X_density

    def Y_density(self):
        if not hasattr(self, "_Y_density"):
            self._Y_density = self.__determine_density(self._Y)
        return self._Y_density

    def metas_density(self):
        if not hasattr(self, "_metas_density"):
            self._metas_density = self.__determine_density(self.metas)
        return self._metas_density

    def set_weights(self, weight=1):
        """
        Set weights of data instances; create a vector of weights if necessary.
        """
        if not self.W.shape[-1]:
            self.W = np.empty(len(self))
        self.W[:] = weight

    def has_weights(self):
        """Return `True` if the data instances are weighed. """
        return self.W.shape[-1] != 0

    def total_weight(self):
        """
        Return the total weight of instances in the table, or their number if
        they are unweighted.
        """
        if self.W.shape[-1]:
            return sum(self.W)
        return len(self)

    def has_missing(self):
        """Return `True` if there are any missing attribute or class values."""
        missing_x = not sp.issparse(self.X) and bn.anynan(self.X)  # do not check for sparse X
        return missing_x or bn.anynan(self._Y)

    def has_missing_attribute(self):
        """Return `True` if there are any missing attribute values."""
        return not sp.issparse(self.X) and bn.anynan(self.X)  # do not check for sparse X

    def has_missing_class(self):
        """Return `True` if there are any missing class values."""
        return bn.anynan(self._Y)

    def get_nan_frequency_attribute(self):
        if self.X.size == 0:
            return 0
        return np.isnan(self.X).sum() / self.X.size

    def get_nan_frequency_class(self):
        if self.Y.size == 0:
            return 0
        return np.isnan(self._Y).sum() / self._Y.size

    def checksum(self, include_metas=True):
        # TODO: zlib.adler32 does not work for numpy arrays with dtype object
        # (after pickling and unpickling such arrays, checksum changes)
        # Why, and should we fix it or remove it?
        """Return a checksum over X, Y, metas and W."""
        cs = zlib.adler32(np.ascontiguousarray(self._X))
        cs = zlib.adler32(np.ascontiguousarray(self._Y), cs)
        if include_metas:
            cs = zlib.adler32(np.ascontiguousarray(self._metas), cs)
        cs = zlib.adler32(np.ascontiguousarray(self._W), cs)
        return cs

    def shuffle(self):
        """Randomly shuffle the rows of the table."""
        if not self._check_all_dense():
            raise ValueError("Rows of sparse data cannot be shuffled")
        ind = np.arange(self.X.shape[0])
        np.random.shuffle(ind)
        self.X = self.X[ind]
        self._Y = self._Y[ind]
        self.metas = self.metas[ind]
        self.W = self.W[ind]

    def get_column_view(self, index):
        """
        Return a vector - as a view, not a copy - with a column of the table,
        and a bool flag telling whether this column is sparse. Note that
        vertical slicing of sparse matrices is inefficient.

        :param index: the index of the column
        :type index: int, str or Orange.data.Variable
        :return: (one-dimensional numpy array, sparse)
        """

        def rx(M):
            if sp.issparse(M):
                return np.asarray(M.todense())[:, 0], True
            else:
                return M, False

        if isinstance(index, Integral):
            col_index = index
        else:
            col_index = self.domain.index(index)
        if col_index >= 0:
            if col_index < self.X.shape[1]:
                col = rx(self.X[:, col_index])
            elif self._Y.ndim == 1 and col_index == self._X.shape[1]:
                col = rx(self._Y)
            else:
                col = rx(self._Y[:, col_index - self.X.shape[1]])
        else:
            col = rx(self.metas[:, -1 - col_index])

        if isinstance(index, DiscreteVariable) \
                and index.values != self.domain[col_index].values:
            col = index.get_mapper_from(self.domain[col_index])(col[0]), col[1]
            col[0].flags.writeable = False
        return col

    def _filter_is_defined(self, columns=None, negate=False):
        # structure of function is obvious; pylint: disable=too-many-branches
        def _sp_anynan(a):
            return a.indptr[1:] != a[-1:] + a.shape[1]

        if columns is None:
            if sp.issparse(self.X):
                remove = _sp_anynan(self.X)
            else:
                remove = bn.anynan(self.X, axis=1)
            if sp.issparse(self._Y):
                remove += _sp_anynan(self._Y)
            else:
                if self._Y.ndim == 1:
                    remove += np.isnan(self._Y)
                else:
                    remove += bn.anynan(self._Y, axis=1)
            if sp.issparse(self.metas):
                remove += _sp_anynan(self._metas)
            else:
                for i, var in enumerate(self.domain.metas):
                    col = self.metas[:, i].flatten()
                    if var.is_primitive():
                        remove += np.isnan(col.astype(float))
                    else:
                        remove += ~col.astype(bool)
        else:
            remove = np.zeros(len(self), dtype=bool)
            for column in columns:
                col, sparse = self.get_column_view(column)
                if sparse:
                    remove += col == 0
                elif self.domain[column].is_primitive():
                    remove += bn.anynan([col.astype(float)], axis=0)
                else:
                    remove += col.astype(bool)
        retain = remove if negate else np.logical_not(remove)
        return self.from_table_rows(self, retain)

    def _filter_has_class(self, negate=False):
        if sp.issparse(self._Y):
            if negate:
                retain = (self._Y.indptr[1:] !=
                          self._Y.indptr[-1:] + self._Y.shape[1])
            else:
                retain = (self._Y.indptr[1:] ==
                          self._Y.indptr[-1:] + self._Y.shape[1])
        else:
            if self._Y.ndim == 1:
                retain = np.isnan(self._Y)
            else:
                retain = bn.anynan(self._Y, axis=1)
            if not negate:
                retain = np.logical_not(retain)
        return self.from_table_rows(self, retain)

    def _filter_same_value(self, column, value, negate=False):
        if not isinstance(value, Real):
            value = self.domain[column].to_val(value)
        sel = self.get_column_view(column)[0] == value
        if negate:
            sel = np.logical_not(sel)
        return self.from_table_rows(self, sel)

    def _filter_values(self, filter):
        selection = self._values_filter_to_indicator(filter)
        return self.from_table(self.domain, self, selection)

    def _values_filter_to_indicator(self, filter):
        """Return selection of rows matching the filter conditions

        Handles conjunction/disjunction and negate modifiers

        Parameters
        ----------
        filter: Values object containing the conditions

        Returns
        -------
        A 1d bool array. len(result) == len(self)
        """
        from Orange.data.filter import Values

        if isinstance(filter, Values):
            conditions = filter.conditions
            conjunction = filter.conjunction
        else:
            conditions = [filter]
            conjunction = True
        if conjunction:
            sel = np.ones(len(self), dtype=bool)
        else:
            sel = np.zeros(len(self), dtype=bool)

        for f in conditions:
            selection = self._filter_to_indicator(f)

            if conjunction:
                sel *= selection
            else:
                sel += selection

        if filter.negate:
            sel = ~sel
        return sel

    def _filter_to_indicator(self, filter):
        """Return selection of rows that match the condition.

        Parameters
        ----------
        filter: ValueFilter describing the condition

        Returns
        -------
        A 1d bool array. len(result) == len(self)
        """
        from Orange.data.filter import (
            FilterContinuous, FilterDiscrete, FilterRegex, FilterString,
            FilterStringList, IsDefined, Values
        )
        if isinstance(filter, Values):
            return self._values_filter_to_indicator(filter)

        def get_col_indices():
            cols = chain(self.domain.variables, self.domain.metas)
            if isinstance(filter, IsDefined):
                if filter.columns is not None:
                    return list(filter.columns)
                else:
                    return list(cols)

            if filter.column is not None:
                return [filter.column]

            if isinstance(filter, FilterDiscrete):
                raise ValueError("Discrete filter can't be applied across rows")
            if isinstance(filter, FilterContinuous):
                return [col for col in cols if col.is_continuous]
            if isinstance(filter,
                          (FilterString, FilterStringList, FilterRegex)):
                return [col for col in cols if col.is_string]
            raise TypeError("Invalid filter")

        def col_filter(col_idx):
            col = self.get_column_view(col_idx)[0]
            if isinstance(filter, IsDefined):
                if self.domain[col_idx].is_primitive():
                    return ~np.isnan(col.astype(float))
                else:
                    return col.astype(bool)
            if isinstance(filter, FilterDiscrete):
                return self._discrete_filter_to_indicator(filter, col)
            if isinstance(filter, FilterContinuous):
                return self._continuous_filter_to_indicator(filter, col)
            if isinstance(filter, FilterString):
                return self._string_filter_to_indicator(filter, col)
            if isinstance(filter, FilterStringList):
                if not filter.case_sensitive:
                    col = np.char.lower(np.array(col, dtype=str))
                    vals = [val.lower() for val in filter.values]
                else:
                    vals = filter.values
                return reduce(operator.add, (col == val for val in vals))
            if isinstance(filter, FilterRegex):
                return np.vectorize(filter)(col)
            raise TypeError("Invalid filter")

        col_indices = get_col_indices()
        if len(col_indices) == 1:
            sel = col_filter(col_indices[0])
        else:
            sel = np.ones(len(self), dtype=bool)
            for col_idx in col_indices:
                sel *= col_filter(col_idx)

        if isinstance(filter, IsDefined) and filter.negate:
            sel = ~sel
        return sel

    def _discrete_filter_to_indicator(self, filter, col):
        """Return selection of rows matched by the given discrete filter.

        Parameters
        ----------
        filter: FilterDiscrete
        col: np.ndarray

        Returns
        -------
        A 1d bool array. len(result) == len(self)
        """
        if filter.values is None:  # <- is defined filter
            col = col.astype(float)
            return ~np.isnan(col)

        sel = np.zeros(len(self), dtype=bool)
        for val in filter.values:
            if not isinstance(val, Real):
                val = self.domain[filter.column].to_val(val)
            sel += (col == val)
        return sel

    def _continuous_filter_to_indicator(self, filter, col):
        """Return selection of rows matched by the given continuous filter.

        Parameters
        ----------
        filter: FilterContinuous
        col: np.ndarray

        Returns
        -------
        A 1d bool array. len(result) == len(self)
        """
        if filter.oper == filter.IsDefined:
            col = col.astype(float)
            return ~np.isnan(col)

        return self._range_filter_to_indicator(filter, col, filter.min, filter.max)

    def _string_filter_to_indicator(self, filter, col):
        """Return selection of rows matched by the given string filter.

        Parameters
        ----------
        filter: FilterString
        col: np.ndarray

        Returns
        -------
        A 1d bool array. len(result) == len(self)
        """
        if filter.oper == filter.IsDefined:
            return col.astype(bool)

        col = col.astype(str)
        fmin = filter.min or ""
        fmax = filter.max or ""

        if not filter.case_sensitive:
            # convert all to lower case
            col = np.char.lower(col)
            fmin = fmin.lower()
            fmax = fmax.lower()

        if filter.oper == filter.Contains:
            return np.fromiter((fmin in e for e in col),
                               dtype=bool)
        if filter.oper == filter.StartsWith:
            return np.fromiter((e.startswith(fmin) for e in col),
                               dtype=bool)
        if filter.oper == filter.EndsWith:
            return np.fromiter((e.endswith(fmin) for e in col),
                               dtype=bool)

        return self._range_filter_to_indicator(filter, col, fmin, fmax)

    @staticmethod
    def _range_filter_to_indicator(filter, col, fmin, fmax):
        with np.errstate(invalid="ignore"):  # nan's are properly discarded
            if filter.oper == filter.Equal:
                return col == fmin
            if filter.oper == filter.NotEqual:
                return col != fmin
            if filter.oper == filter.Less:
                return col < fmin
            if filter.oper == filter.LessEqual:
                return col <= fmin
            if filter.oper == filter.Greater:
                return col > fmin
            if filter.oper == filter.GreaterEqual:
                return col >= fmin
            if filter.oper == filter.Between:
                return (col >= fmin) * (col <= fmax)
            if filter.oper == filter.Outside:
                return (col < fmin) + (col > fmax)

            raise TypeError("Invalid operator")

    def _compute_basic_stats(self, columns=None,
                             include_metas=False, compute_variance=False):
        if compute_variance:
            raise NotImplementedError("computation of variance is "
                                      "not implemented yet")
        W = self._W if self.has_weights() else None
        rr = []
        stats = []
        if not columns:
            if self.domain.attributes:
                rr.append(fast_stats(self._X, W))
            if self.domain.class_vars:
                rr.append(fast_stats(self._Y, W))
            if include_metas and self.domain.metas:
                rr.append(fast_stats(self.metas, W))
            if len(rr):
                stats = np.vstack(tuple(rr))
        else:
            nattrs = len(self.domain.attributes)
            for column in columns:
                c = self.domain.index(column)
                if 0 <= c < nattrs:
                    S = fast_stats(self._X[:, [c]], W and W[:, [c]])
                elif c >= nattrs:
                    if self._Y.ndim == 1 and c == nattrs:
                        S = fast_stats(self._Y[:, None], W and W[:, None])
                    else:
                        S = fast_stats(self._Y[:, [c - nattrs]], W and W[:, [c - nattrs]])
                else:
                    S = fast_stats(self._metas[:, [-1 - c]], W and W[:, [-1 - c]])
                stats.append(S[0])
        return stats

    def _compute_distributions(self, columns=None):
        if columns is None:
            columns = range(len(self.domain.variables))
        else:
            columns = [self.domain.index(var) for var in columns]

        distributions = []
        X = self.X
        if sp.issparse(X):
            X = X.tocsc()


        W = self.W.ravel() if self.has_weights() else None

        for col in columns:
            variable = self.domain[col]

            # Select the correct data column from X, Y or metas
            if 0 <= col < X.shape[1]:
                x = X[:, col]
            elif col < 0:
                x = self.metas[:, col * (-1) - 1]
                if np.issubdtype(x.dtype, np.dtype(object)):
                    x = x.astype(float)
            elif self._Y.ndim == 1 and col == X.shape[1]:
                x = self._Y
            else:
                x = self._Y[:, col - X.shape[1]]

            if variable.is_discrete:
                dist, unknowns = bincount(x, weights=W, max_val=len(variable.values) - 1)
            elif not x.shape[0]:
                dist, unknowns = np.zeros((2, 0)), 0
            else:
                if W is not None:
                    if sp.issparse(x):
                        arg_sort = np.argsort(x.data)
                        ranks = x.indices[arg_sort]
                        vals = np.vstack((x.data[arg_sort], W[ranks]))
                    else:
                        ranks = np.argsort(x)
                        vals = np.vstack((x[ranks], W[ranks]))
                else:
                    x_values = x.data if sp.issparse(x) else x
                    vals = np.ones((2, x_values.shape[0]))
                    vals[0, :] = x_values
                    vals[0, :].sort()

                dist = np.array(_valuecount.valuecount(vals))
                # If sparse, then 0s will not be counted with `valuecount`, so
                # we have to add them to the result manually.
                if sp.issparse(x) and sparse_has_implicit_zeros(x):
                    if W is not None:
                        zero_weights = sparse_implicit_zero_weights(x, W).sum()
                    else:
                        zero_weights = sparse_count_implicit_zeros(x)
                    zero_vec = [0, zero_weights]
                    dist = np.insert(dist, np.searchsorted(dist[0], 0), zero_vec, axis=1)
                # Since `countnans` assumes vector shape to be (1, n) and `x`
                # shape is (n, 1), we pass the transpose
                unknowns = countnans(x.T, W)
            distributions.append((dist, unknowns))

        return distributions

    def _compute_contingency(self, col_vars=None, row_var=None):
        n_atts = self.X.shape[1]

        if col_vars is None:
            col_vars = range(len(self.domain.variables))
        else:
            col_vars = [self.domain.index(var) for var in col_vars]
        if row_var is None:
            row_var = self.domain.class_var
            if row_var is None:
                raise ValueError("No row variable")

        row_desc = self.domain[row_var]
        if not row_desc.is_discrete:
            raise TypeError("Row variable must be discrete")
        row_indi = self.domain.index(row_var)
        n_rows = len(row_desc.values)
        if 0 <= row_indi < n_atts:
            row_data = self.X[:, row_indi]
        elif row_indi < 0:
            row_data = self.metas[:, -1 - row_indi]
        elif self._Y.ndim == 1 and row_indi == n_atts:
            row_data = self._Y
        else:
            row_data = self._Y[:, row_indi - n_atts]

        W = self.W if self.has_weights() else None

        col_desc = [self.domain[var] for var in col_vars]
        col_indi = [self.domain.index(var) for var in col_vars]

        if any(not (var.is_discrete or var.is_continuous)
               for var in col_desc):
            raise ValueError("Contingency can be computed only for categorical "
                             "and numeric values.")

        # when we select a column in sparse matrix it is still two dimensional
        # and sparse - since it is just a column we can afford to transform
        # it to dense and make it 1D
        if issparse(row_data):
            row_data = row_data.toarray().ravel()
        if row_data.dtype.kind != "f":  # meta attributes can be stored as type object
            row_data = row_data.astype(float)

        contingencies = [None] * len(col_desc)
        for arr, f_cond, f_ind in (
                (self.X, lambda i: 0 <= i < n_atts, lambda i: i),
                (self._Y, lambda i: i >= n_atts, lambda i: i - n_atts),
                (self.metas, lambda i: i < 0, lambda i: -1 - i)):

            arr_indi = [e for e, ind in enumerate(col_indi) if f_cond(ind)]

            vars = [(e, f_ind(col_indi[e]), col_desc[e]) for e in arr_indi]
            disc_vars = [v for v in vars if v[2].is_discrete]
            if disc_vars:
                if sp.issparse(arr):
                    max_vals = max(len(v[2].values) for v in disc_vars)
                    disc_indi = {i for _, i, _ in disc_vars}
                    mask = [i in disc_indi for i in range(arr.shape[1])]
                    conts, nans_cols, nans_rows, nans = contingency(
                        arr, row_data, max_vals - 1, n_rows - 1, W, mask)
                    for col_i, arr_i, var in disc_vars:
                        n_vals = len(var.values)
                        contingencies[col_i] = (
                            conts[arr_i][:, :n_vals], nans_cols[arr_i],
                            nans_rows[arr_i], nans[arr_i])
                else:
                    for col_i, arr_i, var in disc_vars:
                        col = arr if arr.ndim == 1 else arr[:, arr_i]
                        contingencies[col_i] = contingency(
                            col.astype(float),
                            row_data, len(var.values) - 1, n_rows - 1, W)

            cont_vars = [v for v in vars if v[2].is_continuous]
            if cont_vars:
                W_ = None
                if W is not None:
                    W_ = W.astype(dtype=np.float64)
                if sp.issparse(arr):
                    arr = sp.csc_matrix(arr)

                for col_i, arr_i, _ in cont_vars:
                    if sp.issparse(arr):
                        col_data = arr.data[arr.indptr[arr_i]:arr.indptr[arr_i + 1]]
                        rows = arr.indices[arr.indptr[arr_i]:arr.indptr[arr_i + 1]]
                        W_ = None if W_ is None else W_[rows]
                        classes_ = row_data[rows]
                    else:
                        col_data, W_, classes_ = arr[:, arr_i], W_, row_data

                    col_data = col_data.astype(dtype=np.float64)
                    contingencies[col_i] = _contingency.contingency_floatarray(
                        col_data, classes_, n_rows, W_)

        return contingencies

    @classmethod
    def transpose(cls, table, feature_names_column="",
                  meta_attr_name="Feature name", feature_name="Feature",
                  remove_redundant_inst=False, progress_callback=None):
        """
        Transpose the table.

        :param table: Table - table to transpose
        :param feature_names_column: str - name of (String) meta attribute to
            use for feature names
        :param meta_attr_name: str - name of new meta attribute into which
            feature names are mapped
        :param feature_name: str - default feature name prefix
        :param remove_redundant_inst: bool - remove instance that
            represents feature_names_column
        :param progress_callback: callable - to report the progress
        :return: Table - transposed table
        """
        if progress_callback is None:
            progress_callback = dummy_callback
        progress_callback(0, "Transposing...")

        if isinstance(feature_names_column, Variable):
            feature_names_column = feature_names_column.name

        self = cls()
        n_cols, self.n_rows = table.X.shape
        old_domain = table.attributes.get("old_domain")
        table_domain_attributes = list(table.domain.attributes)
        attr_index = None
        if remove_redundant_inst:
            attr_names = [a.name for a in table_domain_attributes]
            if feature_names_column and feature_names_column in attr_names:
                attr_index = attr_names.index(feature_names_column)
                self.n_rows = self.n_rows - 1
                table_domain_attributes.remove(
                    table_domain_attributes[attr_index])

        # attributes
        # - classes and metas to attributes of attributes
        # - arbitrary meta column to feature names
        with self.unlocked():
            self.X = table.X.T
            if attr_index is not None:
                self.X = np.delete(self.X, attr_index, 0)
            if feature_names_column:
                names = [str(row[feature_names_column]) for row in table]
                progress_callback(0.1)
                names = get_unique_names_duplicates(names)
                progress_callback(0.3)
                attributes = [ContinuousVariable(name) for name in names]
            else:
                places = int(np.ceil(np.log10(n_cols))) if n_cols else 1
                attributes = [ContinuousVariable(f"{feature_name} {i:0{places}}")
                              for i in range(1, n_cols + 1)]
            progress_callback(0.4)

            if old_domain is not None and feature_names_column:
                for i, _ in enumerate(attributes):
                    if attributes[i].name in old_domain:
                        var = old_domain[attributes[i].name]
                        attr = ContinuousVariable(var.name) if var.is_continuous \
                            else DiscreteVariable(var.name, var.values)
                        attr.attributes = var.attributes.copy()
                        attributes[i] = attr

            def set_attributes_of_attributes(_vars, _table):
                for i, variable in enumerate(_vars):
                    if variable.name == feature_names_column:
                        continue
                    for j, row in enumerate(_table):
                        value = variable.repr_val(row) if np.isscalar(row) \
                            else row[i] if isinstance(row[i], str) \
                            else variable.repr_val(row[i])

                        if value not in MISSING_VALUES:
                            attributes[j].attributes[variable.name] = value

            set_attributes_of_attributes(table.domain.class_vars, table.Y)
            progress_callback(0.5)
            set_attributes_of_attributes(table.domain.metas, table.metas)

            # weights
            self.W = np.empty((self.n_rows, 0))

            def get_table_from_attributes_of_attributes(_vars, _dtype=float):
                T = np.empty((self.n_rows, len(_vars)), dtype=_dtype)
                for i, _attr in enumerate(table_domain_attributes):
                    for j, _var in enumerate(_vars):
                        val = str(_attr.attributes.get(_var.name, ""))
                        if not _var.is_string:
                            val = np.nan if val in MISSING_VALUES else \
                                _var.values.index(val) if \
                                    _var.is_discrete else float(val)
                        T[i, j] = val
                return T

            # class_vars - attributes of attributes to class - from old domain
            class_vars = []
            if old_domain is not None:
                class_vars = old_domain.class_vars
            self.Y = get_table_from_attributes_of_attributes(class_vars)

            # metas
            # - feature names and attributes of attributes to metas
            self.metas, metas = np.empty((self.n_rows, 0), dtype=object), []
            if meta_attr_name not in [m.name for m in table.domain.metas] and \
                    table_domain_attributes:
                self.metas = np.array([[a.name] for a in table_domain_attributes],
                                      dtype=object)
                metas.append(StringVariable(meta_attr_name))

            names = chain.from_iterable(list(attr.attributes)
                                        for attr in table_domain_attributes)
            names = sorted(set(names) - {var.name for var in class_vars})
            progress_callback(0.6)

            def guessed_var(i, var_name):
                orig_vals = M[:, i]
                val_map, vals, var_type = Orange.data.io.guess_data_type(orig_vals)
                values, variable = Orange.data.io.sanitize_variable(
                    val_map, vals, orig_vals, var_type, {}, name=var_name)
                M[:, i] = values
                return variable

            _metas = [StringVariable(n) for n in names]
            if old_domain is not None:
                _metas = [m for m in old_domain.metas if m.name != meta_attr_name]
            M = get_table_from_attributes_of_attributes(_metas, _dtype=object)
            progress_callback(0.7)
            if old_domain is None:
                _metas = [guessed_var(i, m.name) for i, m in enumerate(_metas)]
            if _metas:
                self.metas = np.hstack((self.metas, M))
                metas.extend(_metas)

            self.domain = Domain(attributes, class_vars, metas)
            progress_callback(0.9)
            cls._init_ids(self)
            self.attributes = table.attributes.copy()
            self.attributes["old_domain"] = table.domain
            progress_callback(1)
            return self

    def to_sparse(self, sparse_attributes=True, sparse_class=False,
                  sparse_metas=False):
        def sparsify(features):
            for f in features:
                f.sparse = True

        new_domain = self.domain.copy()

        if sparse_attributes:
            sparsify(new_domain.attributes)
        if sparse_class:
            sparsify(new_domain.class_vars)
        if sparse_metas:
            sparsify(new_domain.metas)
        return self.transform(new_domain)

    def to_dense(self, dense_attributes=True, dense_class=True,
                 dense_metas=True):
        def densify(features):
            for f in features:
                f.sparse = False

        new_domain = self.domain.copy()

        if dense_attributes:
            densify(new_domain.attributes)
        if dense_class:
            densify(new_domain.class_vars)
        if dense_metas:
            densify(new_domain.metas)
        t = self.transform(new_domain)
        t.ids = self.ids  # preserve indices
        return t


def _dereferenced(array):
    # CSR and CSC matrices are constructed so that array.data is a
    # view to a base, which prevents unlocking them. Therefore, if
    # sparse matrix doesn't own its data, but its base array is
    # referenced only by this matrix, we copy it. This doesn't
    # increase memory use, but allows unlocking.
    if sp.issparse(array) \
            and array.data.base is not None \
            and sys.getrefcount(array.data.base) == 2:  # 2 = 1 real + 1 for arg
        array.data = array.data.copy()
    return array


def _check_arrays(*arrays, dtype=None, shape_1=None):
    checked = []
    if not len(arrays):
        return checked

    def ninstances(array):
        if hasattr(array, "shape"):
            return array.shape[0]
        else:
            return len(array) if array is not None else 0

    if shape_1 is None:
        shape_1 = ninstances(arrays[0])

    for array in arrays:
        if array is None:
            checked.append(array)
            continue

        if ninstances(array) != shape_1:
            raise ValueError("Leading dimension mismatch (%d != %d)"
                             % (ninstances(array), shape_1))

        if sp.issparse(array):
            if not (sp.isspmatrix_csr(array) or sp.isspmatrix_csc(array)):
                array = array.tocsr()
            array.data = np.asarray(array.data)
            array = _dereferenced(array)
            has_inf = _check_inf(array.data)
        else:
            if dtype is not None:
                array = np.asarray(array, dtype=dtype)
            else:
                array = np.asarray(array)
            has_inf = _check_inf(array)

        if has_inf:
            array[np.isinf(array)] = np.nan
            warnings.warn("Array contains infinity.", RuntimeWarning)
        checked.append(array)

    return checked


def _check_inf(array):
    return array.dtype.char in np.typecodes['AllFloat'] and \
           np.isinf(array.data).any()


def _subarray(arr, rows, cols):
    rows = _optimize_indices(rows, arr.shape[0])
    if arr.ndim == 1:
        return arr[rows]
    cols = _optimize_indices(cols, arr.shape[1])
    return arr[_rxc_ix(rows, cols)]


def _optimize_indices(indices, maxlen):
    """
    Convert integer indices to slice if possible. It only converts increasing
    integer ranges with positive steps and valid starts and ends.
    Only convert valid ends so that invalid ranges will still raise
    an exception.

    Allows numpy to reuse the data array, because it defaults to copying
    if given indices.

    Parameters
    ----------
    indices : 1D sequence, slice or Ellipsis
    """
    if isinstance(indices, slice):
        return indices

    if indices is ...:
        return slice(None, None, 1)

    # a very common case for column selection
    if len(indices) == 1 and not isinstance(indices[0], bool):
        if indices[0] >= 0:
            return slice(indices[0], indices[0] + 1, 1)
        else:
            return slice(indices[0], indices[0] - 1, -1)

    if len(indices) >= 1:
        indices = np.asarray(indices)
        if indices.dtype != bool:
            begin = indices[0]
            end = indices[-1]
            steps = np.diff(indices) if len(indices) > 1 else np.array([1])
            step = steps[0]

            # continuous ranges with constant step and valid start and stop index can be slices
            if np.all(steps == step) and step > 0 and begin >= 0 and end < maxlen:
                return slice(begin, end + step, step)

    return indices


def _rxc_ix(rows, cols):
    """
    Construct an index object to index the `rows` x `cols` cross product.

    Rows and columns can be a 1d bool or int sequence, or a slice.
    The later is a convenience and is interpreted the same
    as `slice(None, None, -1)`

    Parameters
    ----------
    rows : 1D sequence, slice
        Row indices.
    cols : 1D sequence, slice
        Column indices.

    See Also
    --------
    numpy.ix_

    Examples
    --------
    >>> import numpy as np
    >>> a = np.arange(10).reshape(2, 5)
    >>> a[_rxc_ix([0, 1], [3, 4])]
    array([[3, 4],
           [8, 9]])
    >>> a[_rxc_ix([False, True], slice(None, None, 1))]
    array([[5, 6, 7, 8, 9]])

    """
    isslice = (isinstance(rows, slice), isinstance(cols, slice))
    if isslice == (True, True):
        return rows, cols
    elif isslice == (True, False):
        return rows, np.asarray(np.ix_(cols), int).ravel()
    elif isslice == (False, True):
        return np.asarray(np.ix_(rows), int).ravel(), cols
    else:
        r, c = np.ix_(rows, cols)
        return np.asarray(r, int), np.asarray(c, int)


def assure_domain_conversion_sparsity(target, source):
    """
    Assure that the table obeys the domain conversion's suggestions about sparsity.

    Args:
        target (Table): the target table.
        source (Table): the source table.

    Returns:
        Table: with fixed sparsity. The sparsity is set as it is recommended by domain conversion
            for transformation from source to the target domain.
    """
    conversion = DomainConversion(source.domain, target.domain)
    match_density = [assure_array_dense, assure_array_sparse]
    target.X = match_density[conversion.sparse_X](target.X)
    target.Y = match_density[conversion.sparse_Y](target.Y)
    target.metas = match_density[conversion.sparse_metas](target.metas)
    return target


class Role:
    Attribute = 0
    ClassAttribute = 1
    Meta = 2

    @staticmethod
    def get_arr(role, table):
        return table.X if role == Role.Attribute else \
               table.Y if role == Role.ClassAttribute else \
               table.metas

```
--- END FILE ---

Please first localize the bug based on the issue statement, and then generate *SEARCH/REPLACE* edits to fix the issue.

Every *SEARCH/REPLACE* edit must use this format:
1. The file path
2. The start of search block: <<<<<<< SEARCH
3. A contiguous chunk of lines to search for in the existing source code
4. The dividing line: =======
5. The lines to replace into the source code
6. The end of the replace block: >>>>>>> REPLACE

Here is an example:

```python
### mathweb/flask/app.py
<<<<<<< SEARCH
from flask import Flask
=======
import math
from flask import Flask
>>>>>>> REPLACE
```
</solution>

Please note that the *SEARCH/REPLACE* edit REQUIRES PROPER INDENTATION. If you would like to add the line '        print(x)', you must fully write that out, with all those spaces before the code!
Wrap each *SEARCH/REPLACE* edit in a code block as shown in the example above. If you have multiple *SEARCH/REPLACE* edits, use a separate code block for each one.
user