coldp.IdentifierPolicy¶
Class¶
- IdentifierPolicy.__init__(existing, default_prefix, required=True, volatile=False)¶
Internal class to manage ID values in COLDP dataframes.
- Parameters:
existing¶ – Pandas series containing current ID values for table - may be empty or None
default_prefix¶ – String prefix to use before numeric ID values if existing ID values are not consistently positive integer values
required¶ – Flag to indicate whether the table must have ID values - if False, the
IdentifierPolicy
will return None unlessexisting
already contains ID valuesvolatile¶ – Flag to indicate if external code may modify ID values while the current COLDP instance is active - if False, the policy and future values will be determined on initialisation, otherwise the policy will be reviewed for each new ID value
Checks any existing values in the series. If none are present, the next ID value will be 1. If all values are integer strings, the next value will be the integer string with a value one higher than the current maximum value. Otherwise ID values will be the concatenation of the prefix (defaulting to the empty string) and the current length of the ID series. Subsequent values will increment by one.
If
required
is False and no current valus exist in the series, the policy will always return None.If
volatile
is True, the policy will be revised on every invocation of next. Otherwise, the series will only be scanned on initialisation and all policy values will then be fixed.
Methods¶
- IdentifierPolicy.initialise(existing)¶
Internal method to set or refresh policy
- Parameters:
existing¶ – Pandas series containing current ID values for table - may be empty or None
- Returns:
Tuple comprising the next integer value for the policy and a prefix for use if ID values should not be plain integer strings - one or both values will be None
Provides the variables to determine the next ID value, if any
- IdentifierPolicy.next(existing=None)¶
Return next ID value for series
- Parameters:
existing¶ – Pandas series containing current ID values for table - may be empty or None - only required if
volatile
is True- Returns:
Next string ID value for policy or None if no ID is required
Returns the next ID value for use in the Series associated with this IdentifierPolicy. Recalculates policy if paramref:~coldp.IdentifierPolicy.__init__.volatile is True.