{"record":{"id":"0b82835b28030b85","repo":"microsoft/qlib","slug":"cut-operator-l-shoud-0-and-r-should-0","errorCode":null,"errorMessage":"Cut operator l shoud > 0 and r should < 0","messagePattern":"Cut operator l shoud > 0 and r should < 0","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/contrib/ops/high_freq.py","lineNumber":263,"sourceCode":"    ----------\n    feature : Expression\n        feature instance\n    l : int\n        l > 0, delete the first l elements of feature (default is None, which means 0)\n    r : int\n        r < 0, delete the last -r elements of feature (default is None, which means 0)\n    Returns\n    ----------\n    feature:\n        A series with the first l and last -r elements deleted from the feature.\n        Note: It is deleted from the raw data, not the sliced data\n    \"\"\"\n\n    def __init__(self, feature, left=None, right=None):\n        self.left = left\n        self.right = right\n        if (self.left is not None and self.left <= 0) or (self.right is not None and self.right >= 0):\n            raise ValueError(\"Cut operator l shoud > 0 and r should < 0\")\n\n        super(Cut, self).__init__(feature)\n\n    def _load_internal(self, instrument, start_index, end_index, freq):\n        series = self.feature.load(instrument, start_index, end_index, freq)\n        return series.iloc[self.left : self.right]\n\n    def get_extended_window_size(self):\n        ll = 0 if self.left is None else self.left\n        rr = 0 if self.right is None else abs(self.right)\n        lft_etd, rght_etd = self.feature.get_extended_window_size()\n        lft_etd = lft_etd + ll\n        rght_etd = rght_etd + rr\n        return lft_etd, rght_etd\n","sourceCodeStart":245,"sourceCodeEnd":278,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/contrib/ops/high_freq.py#L245-L278","documentation":"Raised by qlib's Cut operator (qlib/contrib/ops/high_freq.py) when the constructor receives invalid cut bounds. Cut deletes the first `left` and last `-right` elements of a feature series, so `left` must be a strictly positive integer (or None) and `right` a strictly negative integer (or None). Any other sign or zero value fails fast in __init__ before any data is loaded.","triggerScenarios":"Calling Cut(feature, left=0, right=-5), Cut(feature, left=2, right=0), Cut(feature, left=-1, ...), or Cut(feature, ..., right=3). The check `self.left <= 0` (when left is not None) or `self.right >= 0` (when right is not None) fires immediately at construction time.","commonSituations":"Developers porting pandas iloc slicing habits (where 0 is a valid bound) into Cut's semantic where the counts are one-based and sign-encoded; passing right as a positive count of tail elements instead of a negative iloc-style bound; using Cut in high-frequency expression strings with wrong literals.","solutions":["Pass left as a positive int > 0 (number of head elements to drop) or leave it as None","Pass right as a negative int < 0 (iloc-style end, e.g. -5 drops the last 5 rows) or leave it as None","If you intended no cut on one side, explicitly use None instead of 0","Double-check the docstring: the operator wraps series.iloc[left:right], so use iloc semantics"],"exampleFix":"# before\nCut(feature, left=0, right=5)\n\n# after\nCut(feature, left=None, right=-5)  # drop last 5 elements only","handlingStrategy":"validation","validationCode":"def valid_cut_params(left, right):\n    return (left is None or (isinstance(left, int) and left > 0)) and \\\n           (right is None or (isinstance(right, int) and right < 0))\n\nassert valid_cut_params(left, right), 'left must be >0 or None; right must be <0 or None'","typeGuard":"def is_valid_cut(left, right) -> bool:\n    return (left is None or left > 0) and (right is None or right < 0)","tryCatchPattern":null,"preventionTips":["Remember Cut uses iloc semantics: left is a positive head count, right is a negative tail bound","Use None (not 0) to disable cutting on one side","Wrap parameterized Cut construction in a small config validator before building the expression"],"tags":["qlib","validation","operator","high-frequency"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}