call_report.fca.convert_long_format_to_code_grain_format#
- call_report.fca.convert_long_format_to_code_grain_format(*, long: NativeDataFrame, dataframe_type: None = None) NativeDataFrame[source]#
- call_report.fca.convert_long_format_to_code_grain_format(*, long: NativeDataFrame, dataframe_type: Literal['pandas']) pandas.DataFrame
- call_report.fca.convert_long_format_to_code_grain_format(*, long: NativeDataFrame, dataframe_type: Literal['pyarrow_table']) pyarrow.Table
- call_report.fca.convert_long_format_to_code_grain_format(*, long: NativeDataFrame, dataframe_type: Literal['polars_dataframe']) polars.DataFrame
- call_report.fca.convert_long_format_to_code_grain_format(*, long: NativeDataFrame, dataframe_type: Literal['polars_lazyframe']) polars.LazyFrame
Convert an already-built long-format frame to the code grain.
This function is self-contained. The long format already carries code_column and code_value as first-class columns, so the code grain is the pivot that keeps them as row keys instead of folding them into the column name. It needs no FCACallReport instance, layout lookups, or other external metadata.
Only multiple-occurrence rows survive. A single-occurrence variable has no code to key on, so it is dropped rather than carried with null code keys. Pivoting requires the CODE_GRAIN_INDEX plus
{schedule}__{variable}grain to be unique, and pivot enforces that and raises ReshapeError if it is not, so no separate check is needed here.- Parameters:
- longNativeDataFrame
A long-format frame, e.g. from FCACallReport.to_long_format.
- dataframe_type{“pandas”, “pyarrow_table”, “polars_lazyframe”, “polars_dataframe”}, optional
The dataframe type to convert the result to as a final step. Leave this
None(the default) to get back whatever backend call_report.config.get_config currently has configured.
- Returns:
- NativeDataFrame
The code-grain frame (see FCACallReport.to_code_grain_format), of the configured backend, or of dataframe_type if it was supplied.
- Raises:
- ReshapeError
If long has no multiple-occurrence rows, or if
(UNINUM, period, code_column, code_value, schedule, variable_name)is not a unique grain.
Examples
>>> from call_report.fca.transport import PackagedArchiveTransport >>> from call_report.fca.report import FCACallReport >>> report = FCACallReport( ... start="2026-03-31", ... end="2026-03-31", ... transport=PackagedArchiveTransport(), ... ) >>> long = report.to_long_format(schedules=["RC", "RCB"]) >>> code_grain = convert_long_format_to_code_grain_format(long=long) >>> list(code_grain.columns)[:5] ['UNINUM', 'period', 'code_column', 'code_value', 'RCB__BKVAL']