{"record":{"id":"75b05403fd4d637c","repo":"pandas-dev/pandas","slug":"not-supported-to-convert-periodarray-to-array-with","errorCode":null,"errorMessage":"Not supported to convert PeriodArray to array with different 'freq' ({self.freqstr} vs {type.freq})","messagePattern":"Not supported to convert PeriodArray to array with different 'freq' \\((.+?) vs (.+?)\\)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/period.py","lineNumber":486,"sourceCode":"\n        # This will raise TypeError for non-object dtypes\n        return np.array(list(self), dtype=object)\n\n    def __arrow_array__(self, type=None):\n        \"\"\"\n        Convert myself into a pyarrow Array.\n        \"\"\"\n        import pyarrow\n\n        from pandas.core.arrays.arrow.extension_types import ArrowPeriodType\n\n        if type is not None:\n            if pyarrow.types.is_integer(type):\n                return pyarrow.array(self._ndarray, mask=self.isna(), type=type)\n            elif isinstance(type, ArrowPeriodType):\n                # ensure we have the same freq\n                if self.freqstr != type.freq:\n                    raise TypeError(\n                        \"Not supported to convert PeriodArray to array with different \"\n                        f\"'freq' ({self.freqstr} vs {type.freq})\"\n                    )\n            else:\n                raise TypeError(\n                    f\"Not supported to convert PeriodArray to '{type}' type\"\n                )\n\n        period_type = ArrowPeriodType(self.freqstr)\n        storage_array = pyarrow.array(self._ndarray, mask=self.isna(), type=\"int64\")\n        return pyarrow.ExtensionArray.from_storage(period_type, storage_array)\n\n    # --------------------------------------------------------------------\n    # Vectorized analogues of Period properties\n\n    year = _field_accessor(\n        \"year\",\n        \"\"\"","sourceCodeStart":468,"sourceCodeEnd":504,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/period.py#L468-L504","documentation":"Raised by PeriodArray.__arrow_array__ when the target pyarrow type is an ArrowPeriodType whose freq string differs from the PeriodArray's freqstr. Arrow period values carry their frequency as part of the type, so a cross-freq conversion would silently change semantics; pandas rejects it. Both freqs are shown for diagnosis.","triggerScenarios":"pa.array(monthly_period_idx, type=ArrowPeriodType('D')) — monthly data into a daily-typed arrow array. pyarrow.Table.from_pandas(df) where the schema pins a different period freq than the source. Casting an Arrow-backed period array to a mismatched period type.","commonSituations":"Schema evolution where period freq changed; concatenating arrow tables with period columns of different freqs; user-supplied pyarrow schema that doesn't match the data.","solutions":["Match the freqs: convert the PeriodArray first with .asfreq(target_freq) before arrow export.","Drop the explicit type argument and let __arrow_array__ infer the correct ArrowPeriodType.","Export as int64 ordinals: pa.array(period_arr, type=pa.int64()) (the integer path is allowed)."],"exampleFix":"# before\npa.array(monthly_idx, type=ArrowPeriodType('D'))  # raises\n\n# after\npa.array(monthly_idx.asfreq('D'), type=ArrowPeriodType('D'))","handlingStrategy":"validation","validationCode":"import pandas as pd\n\ndef to_arrow_period(period_idx, target_type=None):\n    if target_type is not None and hasattr(target_type, 'freq'):\n        if period_idx.freqstr != target_type.freq:\n            period_idx = period_idx.asfreq(target_type.freq)\n    import pyarrow as pa\n    return pa.array(period_idx, type=target_type)","typeGuard":"def arrow_freq_matches(period_idx, target_type) -> bool:\n    return target_type is None or not hasattr(target_type, 'freq') or period_idx.freqstr == target_type.freq","tryCatchPattern":"try:\n    pa.array(period_idx, type=target_type)\nexcept TypeError as e:\n    if \"different 'freq'\" in str(e):\n        pa.array(period_idx.asfreq(target_type.freq), type=target_type)\n    else:\n        raise","preventionTips":["Match arrow period type freq to the source PeriodArray freqstr before export.","Omit the type argument to let pandas infer ArrowPeriodType.","Convert freq explicitly with .asfreq() when schemas disagree."],"tags":["pandas","period","pyarrow","interop","freq"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}