microsoft/qlib · error · ValueError

limit_type must be length or sizeof, your limit_type is {lim

Error message

limit_type must be length or sizeof, your limit_type is {limit_type}

What it means

Error "limit_type must be length or sizeof, your limit_type is {limit_type}" thrown in microsoft/qlib.

Source

Thrown at qlib/data/cache.py:159

        """

        Parameters
        ----------
        mem_cache_size_limit:
            cache max size.
        limit_type:
            length or sizeof; length(call fun: len), size(call fun: sys.getsizeof).
        """

        size_limit = C.mem_cache_size_limit if mem_cache_size_limit is None else mem_cache_size_limit
        limit_type = C.mem_cache_limit_type if limit_type is None else limit_type

        if limit_type == "length":
            klass = MemCacheLengthUnit
        elif limit_type == "sizeof":
            klass = MemCacheSizeofUnit
        else:
            raise ValueError(f"limit_type must be length or sizeof, your limit_type is {limit_type}")

        self.__calendar_mem_cache = klass(size_limit)
        self.__instrument_mem_cache = klass(size_limit)
        self.__feature_mem_cache = klass(size_limit)

    def __getitem__(self, key):
        if key == "c":
            return self.__calendar_mem_cache
        elif key == "i":
            return self.__instrument_mem_cache
        elif key == "f":
            return self.__feature_mem_cache
        else:
            raise KeyError("Unknown memcache unit")

    def clear(self):
        self.__calendar_mem_cache.clear()
        self.__instrument_mem_cache.clear()

View on GitHub (pinned to 79633dd950)

Solutions

  1. Set limit_type to either 'length' or 'sizeof' in your cache configuration.
  2. Fix the limit_type value in your qlib config: it must be the string 'length' or 'sizeof'.

When it happens

Trigger: This error is raised at qlib/data/cache.py:159 when the guard condition fails: "limit_type must be length or sizeof, your limit_type is {limit_type}". It triggers when the code path receives input or a state that violates the precondition checked at this point — e.g. an unimplemented abstract method being called, an unsupported argument type/value, or an invalid configuration. To avoid it, satisfy the documented precondition before this call: implement the required method in your subclass, or pass a supported value of the expected type as described by the message.

Common situations: See trigger scenarios.


AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15). Data as JSON: /api/errors/1caff0db2ce5c276. Report an issue: GitHub.