perspective-dev/perspective · error · TypeError

Cannot initialize PerspectiveWidget `index` or `limit`…

Error message

Cannot initialize PerspectiveWidget `index` or `limit` without a Table, data, or schema!

What it means

PerspectiveWidget.__init__ can only configure index/limit windows when it has something to load: a Table instance, raw data, or a schema. When all of these are absent (the deferred-load case where the user will call load() later), applying index/limit at construction has no target, so the constructor rejects the combination.

Solutions

  1. Pass a Table, data, or schema to PerspectiveWidget when using index or limit
  2. Defer the index/limit settings to the load() call instead of the constructor
  3. Construct the widget empty, then call widget.load(table, index=..., limit=...) once data is available
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at rust/perspective-python/perspective/widget/__init__.py:207 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of perspective-dev/perspective@11c8238c0c (2026-09-09). Data as JSON: /api/errors/bda812e1f6b5db4d. Report an issue: GitHub.

Appendix: source

Thrown at rust/perspective-python/perspective/widget/__init__.py:207

        #     if config.get("split_by", None) and "split_by" not in kwargs:
        #         kwargs.update({"split_by": config["split_by"]})

        #     if config.get("columns", None) and "columns" not in kwargs:
        #         kwargs.update({"columns": config["columns"]})

        # Initialize the viewer
        super(PerspectiveWidget, self).__init__(**kwargs)

        # Handle messages from the the front end
        self.on_msg(self.handle_message)
        self._sessions = {}

        # If an empty dataset is provided, don't call `load()` and wait
        # for the user to call `load()`.
        if data is None:
            if index is not None or limit is not None:
                raise TypeError(
                    "Cannot initialize PerspectiveWidget `index` or `limit` without a Table, data, or schema!"
                )
        else:
            if index is not None:
                self._options.update({"index": index})

            if limit is not None:
                self._options.update({"limit": limit})

            loading = self.load(data, **self._options)
            if inspect.isawaitable(loading):
                import asyncio

                asyncio.create_task(loading)

    def load(self, data, **options):
        """Load the widget with data."""
        # Viewer will ignore **options if `data` is a Table or View.

View on GitHub (pinned to 11c8238c0c)