{"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":476,"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":458,"sourceCodeEnd":494,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/period.py#L458-L494","documentation":"Raised by PeriodArray.__arrow_array__ when the target pyarrow type is an ArrowPeriodType whose freq string differs from the array's freq. Period data is frequency-tagged, so exporting to a pyarrow period extension type with a mismatched freq would silently relabel the ordinals; pandas refuses.","triggerScenarios":"pa.__arrow_array__(type=ArrowPeriodType('M')) on a period[D] array. pd.array(...).to_arrow() with an explicit schema carrying a different period freq. pyarrow.Table.from_pandas with a schema mismatch.","commonSituations":"Schema evolution where the stored freq changed. Joining DataFrames whose period columns were declared with different freqs. Arrow-based ETL pipelines with hardcoded period schemas.","solutions":["Align the target schema freq to the data: use ArrowPeriodType(pa.freqstr).","Convert the array's freq first: pa.asfreq('M') then export.","Drop the explicit type and let __arrow_array__ infer the matching ArrowPeriodType."],"exampleFix":"# before\nimport pyarrow as pa_par\nfrom pandas.core.arrays.arrow.extension_types import ArrowPeriodType\npa = pd.period_array(['2020-01-01'], dtype=pd.PeriodDtype('D'))\nstorage = pa.__arrow_array__(type=ArrowPeriodType('M'))\n# after\nstorage = pa.__arrow_array__(type=ArrowPeriodType(pa.freqstr))\n# or convert freq first\nstorage = pa.asfreq('M').__arrow_array__(type=ArrowPeriodType('M'))","handlingStrategy":"validation","validationCode":"from pandas.core.arrays.arrow.extension_types import ArrowPeriodType\n\ndef arrow_period_type_for(pa):\n    return ArrowPeriodType(pa.freqstr)","typeGuard":"def freq_matches(pa, arrow_type) -> bool:\n    return getattr(arrow_type, 'freq', None) == pa.freqstr","tryCatchPattern":"try:\n    out = pa.__arrow_array__(type=target_type)\nexcept TypeError:\n    out = pa.__arrow_array__()  # let pandas infer the matching type","preventionTips":["Do not pin a period freq in pyarrow schemas; let pandas infer.","Document the source freq when persisting to Arrow.","Use asfreq() to normalize period columns before cross-system export."],"tags":["period","arrow","freq","conversion","pandas-arrays"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}