core_query_functions module¶
- active_no_duplicates_refnr_list(conn, skjema=None, filters=None)¶
Takes an Ibis connection and optionally a skjema-ra-number and returns the latest refnr for each unit that is still marked as active.
If there are more than one active refnr the latest one is returned.
- Parameters:
conn (
BaseBackend) – An ibis connection.skjema (
str|None) – If not None filters based on a string referring to a specific form RA-number.filters (
dict[str,Any] |None) – Dict with filters to filter which subset of refnr to return.
- Return type:
list[str]- Returns:
A list of unique refnr values to select in order to get most recent and currently active response from each respondent in the filtered data.
Examples
result = active_no_duplicates_refnr_list(conn) result = active_no_duplicates_refnr_list(conn, filters={“aar”: “2023”}) result = active_no_duplicates_refnr_list(conn, skjema = “RA-9999”) result = active_no_duplicates_refnr_list(conn, skjema = “RA-9999”, filters={“aar”: “2023”})
- conn_is_ibis(conn)¶
Function to check if a supplied object is an Ibis connection.
Used to select which ‘path’ to take for preparing data in modules.
- Parameters:
conn (
Any) – Object to check.- Return type:
bool- Returns:
A bool that is True if the supplied object is an Ibis connection.
- connect_periods_by_ident(conn, current_filter, previous_filter)¶
Helper function to find form from previous period by connecting through ident using the ‘skjemamottak’ table.
See “Examples” for specific usage.
- Parameters:
conn (
BaseBackend) – Ibis connection object.current_filter (
dict[str,Any]) – Filter to find the current period.previous_filter (
dict[str,Any]) – Filter to find the previous period.
- Return type:
DataFrame- Returns:
Dataframe with columns current and previous containing current refnr and refnr from previous period from same ident.
Examples
- connect_periods_by_ident(
conn, current_filter={“aar”: “2024”}, previous_filter={“aar”: “2023”}
)
- connect_periods_by_ident(
conn, current_filter={“aar”: “2024”, , “kvartal”: “3”}, previous_filter={“aar”: “2024”, “kvartal”: “2”}
)
- connect_periods_by_ident(
conn, current_filter={“aar”: “2024”, , “kvartal”: “3”}, previous_filter={“aar”: “2023”, “kvartal”: “3”}
)
Note
Finds refnrs for given period using the ‘active_no_duplicates_refnr_list’ function.
- Raises:
ValueError – if joined dataframe has rows where current and previous ident are not identical or previous ident is None. The latter is accepted as it shows that there is no previous form.
- Parameters:
conn (BaseBackend)
current_filter (dict[str, Any])
previous_filter (dict[str, Any])
- Return type:
DataFrame
- create_filter_dict(variables, values)¶
Creates a filter dict for use in ibis_filter_with_dict.
- Return type:
dict[str,Any]- Parameters:
variables (list[str])
values (list[Any] | tuple[Any])
- ibis_filter_with_dict(periods_dict)¶
Creates a filter expression for Ibis.
- Parameters:
periods_dict (
dict[str,Any]) – A dictionary of column names and values to filter by.- Return type:
list[Any]- Returns:
A list of filter expressions for Ibis.
Example
filter_dict = {“year”: “2025”, “quarter”: [“3”, “4”]} t.filter(ibis_filter_with_dict(filter_dict))
- logger = <Logger ssb_dash_framework.utils.core_query_functions (WARNING)>¶
From here and down Ibis lives.