{"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":372,"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":354,"sourceCodeEnd":390,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/period.py#L354-L390","documentation":"Raised by PeriodArray._generate_range (used by period_range) when both start and end are None. A period range needs at least one bound to anchor it; specifying only periods (count) without start or end is insufficient. freq is optional only when start/end are datetime-like with inferable frequency.","triggerScenarios":"pd.period_range(periods=5, freq='D') — no start/end. pd.period_range(None, None, 5). Internal calls to _generate_range that drop both bounds.","commonSituations":"Building a generic 'N periods' range without a starting anchor; misreading the API and assuming periods alone suffices; refactoring that nulls out start/end conditionally.","solutions":["Provide a start: pd.period_range(start='2023-01-01', periods=5, freq='D').","Provide an end: pd.period_range(end='2023-12-31', periods=5, freq='D').","If you need a list of N anonymous ordinals, construct PeriodArray directly with a dtype."],"exampleFix":"# before\npd.period_range(periods=5, freq='D')  # raises\n\n# after\npd.period_range(start='2023-01-01', periods=5, freq='D')","handlingStrategy":"validation","validationCode":"import pandas as pd\n\ndef build_period_range(start=None, end=None, periods=None, freq=None):\n    if start is None and end is None:\n        raise ValueError('period_range requires at least one of start or end')\n    return pd.period_range(start=start, end=end, periods=periods, freq=freq)","typeGuard":"def has_range_anchor(start, end) -> bool:\n    return start is not None or end is not None","tryCatchPattern":"try:\n    pd.period_range(periods=periods, freq=freq)\nexcept ValueError as e:\n    if 'Not enough parameters' in str(e):\n        pd.period_range(start='2023-01-01', periods=periods, freq=freq)\n    else:\n        raise","preventionTips":["Always provide start or end to period_range; periods alone is insufficient.","Default start to a known epoch (e.g. today) when only 'count' is configured.","Validate that at least one bound is non-None in your range-building helpers."],"tags":["pandas","period","period-range","constructor","validation"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}