{"record":{"id":"bb557a69b80b746c","repo":"pandas-dev/pandas","slug":"not-enough-parameters-to-construct-period-range","errorCode":null,"errorMessage":"Not enough parameters to construct Period range","messagePattern":"Not enough parameters to construct Period range","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/period.py","lineNumber":362,"sourceCode":"        PeriodArray[freq]\n        \"\"\"\n        if isinstance(freq, BaseOffset):\n            freq = PeriodDtype(freq)._freqstr\n        data, freq = dt64arr_to_periodarr(data, freq, tz)\n        dtype = PeriodDtype(freq)\n        return cls(data, dtype=dtype)\n\n    @classmethod\n    def _generate_range(cls, start, end, periods, freq):\n        periods = dtl.validate_periods(periods)\n\n        if freq is not None:\n            freq = Period._maybe_convert_freq(freq)\n\n        if start is not None or end is not None:\n            subarr, freq = _get_ordinal_range(start, end, periods, freq)\n        else:\n            raise ValueError(\"Not enough parameters to construct Period range\")\n\n        return subarr, freq\n\n    @classmethod\n    def _from_fields(cls, *, fields: dict, freq) -> Self:\n        subarr, freq = _range_from_fields(freq=freq, **fields)\n        dtype = PeriodDtype(freq)\n        return cls._simple_new(subarr, dtype=dtype)\n\n    # -----------------------------------------------------------------\n    # DatetimeLike Interface\n\n    def _unbox_scalar(\n        self,\n        # error: Argument 1 of \"_unbox_scalar\" is incompatible with supertype\n        # \"pandas.core.arrays.datetimelike.DatetimeLikeArrayMixin\"; supertype\n        #  defines the argument type as \"Period | Timestamp | Timedelta | NaTType\"\n        value: Period | NaTType,  # type: ignore[override]","sourceCodeStart":344,"sourceCodeEnd":380,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/period.py#L344-L380","documentation":"Raised by PeriodArray._generate_range when both `start` and `end` are None. A period range needs at least one anchor (start or end); with neither, plus only `periods`/`freq`, there is no way to fix the actual dates. (Note this is distinct from the start/end/periods count check at _get_ordinal_range.)","triggerScenarios":"Calling period_range/PeriodIndex with periods=N and freq=... but neither start nor end. Internal _generate_range invocations where both anchors were filtered out as None.","commonSituations":"Building a range dynamically where start/end come from optional config and both end up unset. Refactoring that drops the start argument by mistake.","solutions":["Provide a start (or end): pd.period_range(start='2020-01-01', periods=N, freq='D').","If you have end, pass it: pd.period_range(end='2020-12-31', periods=N, freq='D').","Validate that at least one of start/end is non-None before calling."],"exampleFix":"# before\npd.period_range(periods=5, freq='D')\n# after\npd.period_range(start='2020-01-01', periods=5, freq='D')","handlingStrategy":"validation","validationCode":"import pandas as pd\n\ndef safe_period_range(start=None, end=None, periods=None, freq=None):\n    if start is None and end is None:\n        raise ValueError('Either start or end must be provided for a period range')\n    return pd.period_range(start=start, end=end, periods=periods, freq=freq)","typeGuard":"def has_anchor(start, end) -> bool:\n    return start is not None or end is not None","tryCatchPattern":"try:\n    rng = pd.period_range(start=start, end=end, periods=periods, freq=freq)\nexcept ValueError:\n    rng = pd.period_range(start='2020-01-01', periods=periods, freq=freq)","preventionTips":["Treat start/end as required-one-of in calling code.","Default start to a sensible epoch when config omits it.","Unit-test range builders with None anchors."],"tags":["period","range","constructor","pandas-arrays"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}