faninsar.Pair#
- class faninsar.Pair(pair: Sequence[datetime, datetime])[source]#
Bases:
objectPair class for one pair.
- __init__(pair: Sequence[datetime, datetime]) None[source]#
Initialize the Pair class.
- Parameters:
pair (Sequence[datetime, datetime]) – Sequence object of two dates. Each date is a datetime object. For example, (date1, date2).
Methods
__init__(pair)Initialize the Pair class.
from_name(name[, parse_function, date_args])Initialize the pair class from a pair name.
primary_string([date_format])Return the primary dates of all pairs in string format.
secondary_string([date_format])Return the secondary dates of all pairs in string format.
to_numpy([dtype])Return the pair as a numpy array.
Attributes
The time span of the pair in days.
String of the pair with format of '%Y%m%d_%Y%m%d'.
The primary dates of all pairs.
The secondary dates of all pairs.
The values of the pair with format of datetime.
- classmethod from_name(name: str, parse_function: Callable | None = None, date_args: dict | None = None) Pair[source]#
Initialize the pair class from a pair name.
- Parameters:
name (str) – Pair name.
parse_function (Callable, optional) – Function to parse the date strings from the pair name. If None, the pair name will be split by ‘_’ and the last 2 items will be used. Default is None.
date_args (dict, optional) – Keyword arguments for pd.to_datetime() to convert the date strings to datetime objects. For example, {‘format’: ‘%Y%m%d’}. Default is {}.
- Returns:
pair – Pair class.
- Return type:
- primary_string(date_format: str = '%Y%m%d') str[source]#
Return the primary dates of all pairs in string format.
- Parameters:
date_format (str) – Format of the date string. Default is ‘%Y%m%d’. See more at strftime Format Codes.
- secondary_string(date_format: str = '%Y%m%d') str[source]#
Return the secondary dates of all pairs in string format.
- Parameters:
date_format (str) –
Format of the date string. Default is ‘%Y%m%d’. See more at strftime Format Codes.
- property values: NDArray[np.datetime64]#
The values of the pair with format of datetime.