{"record":{"id":"eff81327dbd244db","repo":"pandas-dev/pandas","slug":"not-supported-to-convert-periodarray-to-type-t","errorCode":null,"errorMessage":"Not supported to convert PeriodArray to '{type}' type","messagePattern":"Not supported to convert PeriodArray to '(.+?)' type","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/period.py","lineNumber":491,"sourceCode":"        \"\"\"\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        \"\"\"\n        The year of the period.\n\n        Returns the year component for each period in the index.\n\n        See Also","sourceCodeStart":473,"sourceCodeEnd":509,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/period.py#L473-L509","documentation":"Raised by PeriodArray.__arrow_array__ when the target pyarrow type is neither an integer type nor an ArrowPeriodType. Period data can only be exported to arrow as raw int64 ordinals or as a proper period extension type; other types (string, timestamp, float, list, etc.) are not supported and would lose semantics.","triggerScenarios":"pa.array(period_idx, type=pa.string()). pa.array(period_idx, type=pa.timestamp('ns')). pyarrow.Table.from_pandas with a schema that declares the period column as a non-integer/period type.","commonSituations":"Schema mismatches in from_pandas/to_pandas round-trips; assuming period maps to arrow timestamp; user-built pyarrow schemas.","solutions":["Omit the type argument and let pandas infer ArrowPeriodType.","Specify an integer type if you want raw ordinals: pa.array(period_idx, type=pa.int64()).","If a timestamp/string representation is required, convert in pandas first (.to_timestamp() or .astype(str)) then export."],"exampleFix":"# before\npa.array(period_idx, type=pa.timestamp('ns'))  # raises\n\n# after\npa.array(period_idx.to_timestamp())","handlingStrategy":"validation","validationCode":"import pyarrow as pa\nfrom pandas.core.arrays.arrow.extension_types import ArrowPeriodType\n\ndef supported_arrow_type_for_period(target_type):\n    if target_type is None:\n        return True\n    if pa.types.is_integer(target_type):\n        return True\n    return isinstance(target_type, ArrowPeriodType)","typeGuard":"def is_supported_period_arrow_type(target_type) -> bool:\n    import pyarrow as pa\n    from pandas.core.arrays.arrow.extension_types import ArrowPeriodType\n    return (target_type is None or pa.types.is_integer(target_type)\n            or isinstance(target_type, ArrowPeriodType))","tryCatchPattern":"try:\n    pa.array(period_idx, type=target_type)\nexcept TypeError as e:\n    if 'Not supported to convert' in str(e):\n        pa.array(period_idx.to_timestamp())  # or omit type\n    else:\n        raise","preventionTips":["Omit the pyarrow type argument to let pandas pick ArrowPeriodType automatically.","For raw ordinals, use pa.int64(); for timestamps, convert via .to_timestamp() first.","Validate the schema's period-column type in from_pandas pipelines."],"tags":["pandas","period","pyarrow","interop","type-conversion"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}