Options¶
Process-global options (string keys, no symbol type) plus the per-frequency
holidays_map. option_scope is a contextlib-style context manager for
scoped overrides.
tsecon._options ¶
Global package options.
Mirrors TimeSeriesEcon.jl/src/options.jl. A small dictionary of
process-global settings consulted by other modules at call time. Public API:
- :func:
getoption/ :func:setoption— generic accessors. - :func:
set_holidays_map— install a BDaily Boolean :class:TSeries(True= business day,False= holiday) under"bdaily_holidays_map". Accepts either a pre-built TSeries (set_holidays_map(t)) or a country / subdivision code (set_holidays_map("CA", "ON")); the country form requires the optionalholidaysextra (pip install 'TimeSeriesEconPy[holidays]') and delegates to the upstreampython-holidayspackage for the calendar data — single source of truth, no vendored CSVs. - :func:
get_holidays_options— list supported country codes (no arg) or subdivisions of a country (with a country code arg). Mirrors Julia'sget_holidays_options. - :func:
clear_holidays_map— setbdaily_holidays_mapback toNone.
Recognised option names and their types:
========================== =========================== =================================
Name Type Default
========================== =========================== =================================
bdaily_holidays_map TSeries[BDaily, bool] None
or None
bdaily_creation_bias "strict" / "previous" / "strict"
"next" / "nearest"
x13path str ""
========================== =========================== =================================
Setting an unknown option raises :class:KeyError; passing an invalid value
for a known option raises :class:ValueError (for the enum-like bias) or
:class:TypeError (for the wrong Python type).
The options dictionary is process-global. Tests that mutate it must restore
the previous value in a teardown — there is a context-manager helper
:func:option_scope for that pattern.
getoption ¶
Return the current value of a recognised option.
Raises :class:KeyError for unknown names.
Source code in src/tsecon/_options.py
setoption ¶
Set the value of a recognised option, validating its type.
bdaily_creation_bias— must be one of"strict","previous","next","nearest".bdaily_holidays_map— must beNoneor a Boolean BDaily :class:~tsecon.tseries.TSeries.x13path— must be a string.
Source code in src/tsecon/_options.py
set_holidays_map ¶
Install a BDaily Boolean holidays map under bdaily_holidays_map.
Two call forms:
set_holidays_map(t)— install a pre-built BDaily Boolean :class:~tsecon.tseries.TSeries(True= business day,False= holiday).set_holidays_map("CA", "ON")— fetch the calendar for the given country / subdivision from theholidaysPyPI package, build a BDaily Boolean TSeries spanningbdaily("1970-01-01")tobdaily("2049-12-31")(matches the Julia upstream's default range), and install it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
Any
|
Either a pre-built BDaily Boolean :class: |
required |
subdivision
|
str | None
|
Optional subdivision code (ISO 3166-2 short form, e.g. |
None
|
Raises:
| Type | Description |
|---|---|
ImportError
|
|
ValueError
|
|
TypeError
|
|
Notes
The country / subdivision codes follow the python-holidays
package's conventions (ISO 3166), which differ in minor cases from
the Julia upstream's CSV-derived names (e.g. the Julia CSVs spell
a few subdivisions with spaces that the package replaces with
underscores or drops). The package is the single source of truth;
discover the supported codes with :func:get_holidays_options.
Examples:
>>> set_holidays_map("DK") # Denmark, federal holidays
>>> set_holidays_map("CA", "ON") # Ontario, Canada
>>> from tsecon import bdaily, TSeries, MITRange
>>> cal = TSeries.trues(MITRange(bdaily("2022-01-03"), bdaily("2022-12-30")))
>>> set_holidays_map(cal) # pre-built TSeries
Source code in src/tsecon/_options.py
get_holidays_options ¶
List supported country codes (or subdivisions of a given country).
Mirrors Julia's get_holidays_options(country=nothing). Both no-arg
and country-arg forms return a sorted tuple. Subdivisions are reported
using the country's native code (ISO 3166-2 short form), exactly as
the holidays package exposes them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
country
|
str | None
|
Optional country code accepted by
:func: |
None
|
Returns:
| Type | Description |
|---|---|
tuple of str
|
Sorted country codes (no arg) or sorted subdivision codes (one arg). A country with no subdivisions returns an empty tuple. |
Raises:
| Type | Description |
|---|---|
ImportError
|
The |
ValueError
|
|
Source code in src/tsecon/_options.py
clear_holidays_map ¶
get_holidays_map ¶
option_scope ¶
Context manager that temporarily overrides one or more options.
On exit, every overridden option is restored to its prior value.
Convenient for tests; the wrapper goes through :func:setoption so the
same validation applies.