Skip to content

Dataloaders

Shape the source data for modelling.

BaseDataLoader(param_grid=None)

Bases: ABC

Read and validate source snapshots and extract moment-aware modelling data.

A dataloader reads long stats and odds event snapshots and validates them. It derives the available providers, markets and per-column metadata from the data. It then extracts moment-aware training and fixtures data. This base class does everything except read the data source. A concrete dataloader implements the abstract _load_snapshots method. It overrides the optional _list_all_params hook when its data is downloadable.

Parameters:

Name Type Description Default
param_grid ParamGrid | None

Selects the data to include. Keys are parameters like 'league', 'division' or 'year' and values are sequences of allowed values, mirroring scikit-learn's ParameterGrid. The default None selects all available parameters.

None

Attributes:

Name Type Description
param_grid_ list[dict]

The league/division/year combinations of the loaded data.

stats_ DataFrame

The validated long stats snapshots.

odds_ DataFrame

The validated long odds snapshots of the selected provider.

drop_na_thres_ float

The checked value of drop_na_thres.

odds_type_ str | None

The checked value of odds_type.

input_cols_ Index

The columns of X for training and fixtures data.

output_cols_ Index | None

The columns of Y for training data.

odds_cols_ Index

The columns of O for training and fixtures data.

stats_schema_ Schema

The validated schema of the stats snapshots.

odds_schema_ Schema

The validated schema of the odds snapshots.

targets_ list[str]

The market columns the targets are built from.

target_event_status_ str

The resolved status of the target moment.

target_event_time_ Timedelta

The resolved time of the target moment.

input_event_status_ str | None

The resolved status of the input horizon.

input_event_time_ Timedelta

The resolved time of the input horizon.

Examples:

>>> import pandas as pd
>>> from sportsbet.dataloaders import BaseDataLoader
>>>
>>> identity = {'date': pd.Timestamp('2024-08-16', tz='UTC'), 'league': 'England', 'division': 1,
...             'year': 2025, 'home_team': 'A', 'away_team': 'B'}
>>>
>>> class MyDataLoader(BaseDataLoader):
...     'A dataloader of data that is already on your machine.'
...
...     def _load_snapshots(self):
...         stats = pd.DataFrame([
...             {**identity, 'event_status': 'preplay', 'event_time': pd.Timedelta(0), 'home_form': 1.0},
...             {**identity, 'event_status': 'postplay', 'event_time': pd.Timedelta(0), 'home_win': 1},
...         ])
...         odds = pd.DataFrame([
...             {**identity, 'event_status': 'preplay', 'event_time': pd.Timedelta(0),
...              'provider': 'acme', 'home_win': 2.5},
...         ])
...         return stats, odds
>>>
>>> dataloader = MyDataLoader()
>>> # The providers and the markets are derived from the data.
>>> dataloader.get_odds_types()
['acme']
>>> X, Y, O = dataloader.extract_train_data(odds_type='acme')
>>> list(Y.columns)
['home_win__postplay__0min']
>>> list(O.columns)
['acme__home_win__preplay__0min']
Source code in src/sportsbet/dataloaders/_base.py
202
203
def __init__(self: Self, param_grid: ParamGrid | None = None) -> None:
    self.param_grid = param_grid

sources_ property

The data sources, empty for a dataloader carrying its own data.

extract_exploration_data(*, drop_na_thres=0.0, target_event_status=None, target_event_time=None, input_event_status=None, input_event_time=None)

Extract the moment-aware features on their own, for exploration.

Read more in the user guide.

It downloads the selected seasons. It returns the features X, with no targets and no odds. Use it to look at a sport before you choose a param_grid or a model. Use it too when the source carries no odds and has nothing to predict. The features follow the target moment and input horizon you pass.

Parameters:

Name Type Description Default
drop_na_thres float

Threshold in [0.0, 1.0] controlling how aggressively feature columns with missing values are dropped. 0.0 keeps all columns.

0.0
target_event_status str | None

'inplay' or 'postplay' (default 'postplay').

None
target_event_time Timedelta | None

In-play target time (e.g. pd.Timedelta('60min')). Defaults to 0.

None
input_event_status str | None

Latest snapshot status to keep as a feature, one of 'preplay', 'inplay', 'postplay'. None (default) keeps every snapshot before the target. For example, 'preplay' keeps only pre-match features.

None
input_event_time Timedelta | None

Time of the input horizon (e.g. pd.Timedelta('45min')), used together with input_event_status. Defaults to 0.

None

Returns:

Name Type Description
X DataFrame

The moment-aware features of the selected matches.

Source code in src/sportsbet/dataloaders/_base.py
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
def extract_exploration_data(
    self: Self,
    *,
    drop_na_thres: float = 0.0,
    target_event_status: str | None = None,
    target_event_time: pd.Timedelta | None = None,
    input_event_status: str | None = None,
    input_event_time: pd.Timedelta | None = None,
) -> pd.DataFrame:
    """Extract the moment-aware features on their own, for exploration.

    Read more in the [user guide][user-guide].

    It downloads the selected seasons. It returns the features `X`, with no targets and no odds. Use it to look at
    a sport before you choose a `param_grid` or a model. Use it too when the source carries no odds and has nothing
    to predict. The features follow the target moment and input horizon you pass.

    Args:
        drop_na_thres:
            Threshold in `[0.0, 1.0]` controlling how aggressively feature
            columns with missing values are dropped. `0.0` keeps all columns.
        target_event_status:
            `'inplay'` or `'postplay'` (default `'postplay'`).
        target_event_time:
            In-play target time (e.g. `pd.Timedelta('60min')`). Defaults to 0.
        input_event_status:
            Latest snapshot status to keep as a feature, one of `'preplay'`,
            `'inplay'`, `'postplay'`. `None` (default) keeps every snapshot
            before the target. For example, `'preplay'` keeps only pre-match features.
        input_event_time:
            Time of the input horizon (e.g. `pd.Timedelta('45min')`), used
            together with `input_event_status`. Defaults to 0.

    Returns:
        X:
            The moment-aware features of the selected matches.
    """
    X, _, _, _ = self._extract_inputs(
        None,
        drop_na_thres,
        target_event_status,
        target_event_time,
        input_event_status,
        input_event_time,
    )
    self.output_cols_ = None
    return X

extract_fixtures_data()

Extract the fixtures data.

Read more in the user guide.

A fixture is a match that has not been played yet. This downloads the upcoming matches of the selected leagues. It returns them shaped exactly like the training data, so a model trained on the history can bet on the fixtures. The two share their columns, not their contents. param_grid chose the seasons to train on, and a match still to be played is in none of them.

Call extract_train_data first, because it fixes those columns. The multi-output targets Y are always None.

Returns:

Type Description
(X, None, O)

The fixtures input data X, Y equal to None, and the corresponding odds O, matching the training columns.

Raises:

Type Description
ValueError

If it is called before extract_train_data, which fixes the columns the fixtures data must match.

Source code in src/sportsbet/dataloaders/_base.py
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
def extract_fixtures_data(self: Self) -> FixturesData:
    """Extract the fixtures data.

    Read more in the [user guide][user-guide].

    A fixture is a match that has not been played yet. This downloads the upcoming matches of the selected leagues.
    It returns them shaped exactly like the training data, so a model trained on the history can bet on the
    fixtures. The two share their columns, not their contents. `param_grid` chose the seasons to train on, and a
    match still to be played is in none of them.

    Call `extract_train_data` first, because it fixes those columns. The multi-output targets `Y` are always
    `None`.

    Returns:
        (X, None, O):
            The fixtures input data `X`, `Y` equal to `None`, and the
            corresponding odds `O`, matching the training columns.

    Raises:
        ValueError:
            If it is called before `extract_train_data`, which fixes the
            columns the fixtures data must match.
    """
    if not hasattr(self, 'input_cols_'):
        msg = 'Call `extract_train_data` before `extract_fixtures_data`, since it fixes the columns to match.'
        raise ValueError(msg)
    stats, odds = self._load_fixtures_snapshots()
    stats = self._finalize(stats)
    odds = self._finalize(odds)
    odds = odds[odds['provider'] == self.odds_type_] if self.odds_type_ is not None else odds.iloc[0:0]

    index_cols = self._list_identity_cols()
    played = pd.MultiIndex.from_frame(
        stats.loc[
            (stats['event_status'] == self.target_event_status_) & (stats['event_time'] == self.target_event_time_),
            index_cols,
        ],
    )
    fixtures_mask = ~pd.MultiIndex.from_frame(stats[index_cols]).isin(played) & self._is_upcoming(stats)
    fixtures_odds_mask = ~pd.MultiIndex.from_frame(odds[index_cols]).isin(played) & self._is_upcoming(odds)
    if not fixtures_mask.any():
        X = pd.DataFrame(columns=self.input_cols_, index=pd.DatetimeIndex([], name='date'))
        O = pd.DataFrame(columns=self.odds_cols_, index=pd.DatetimeIndex([], name='date'))
        return X, None, O
    X, O = self._extract(
        stats[fixtures_mask],
        odds[fixtures_odds_mask],
        self.target_event_status_,
        self.target_event_time_,
        self.input_event_status_,
        self.input_event_time_,
    )
    X = X.reindex(columns=self.input_cols_)
    O = O.reindex(columns=self.odds_cols_)
    return X, None, O

extract_train_data(*, drop_na_thres=None, odds_type=None, target_event_status=None, target_event_time=None, input_event_status=None, input_event_time=None)

Extract the moment-aware training data.

Read more in the user guide.

It downloads the selected seasons. It returns the historical data you build and backtest a betting strategy on. Every snapshot before the target moment (target_event_status, target_event_time) becomes a feature in X. An input horizon can cap which snapshots become features. The target-moment outcomes become the labels Y. The odds become O. A dataloader that already downloaded reuses the snapshots it holds instead of fetching again. A bare call on a reloaded dataloader rebuilds the same data offline. Save one with save. When the odds source carries no markets, there is nothing to predict. Use extract_exploration_data to get the features on their own.

Parameters:

Name Type Description Default
drop_na_thres float | None

Threshold in [0.0, 1.0] controlling how aggressively feature columns with missing values are dropped. None keeps all columns.

None
odds_type str | None

One of get_odds_types(). None returns no odds.

None
target_event_status str | None

'inplay' or 'postplay' (default 'postplay').

None
target_event_time Timedelta | None

In-play target time (e.g. pd.Timedelta('60min')). Defaults to 0.

None
input_event_status str | None

Latest snapshot status to keep as a feature, one of 'preplay', 'inplay', 'postplay'. None (default) keeps every snapshot before the target. For example, 'preplay' keeps only pre-match features.

None
input_event_time Timedelta | None

Time of the input horizon (e.g. pd.Timedelta('45min')), used together with input_event_status. Defaults to 0.

None

Returns:

Type Description
(X, Y, O)

Moment-aware features X, target outcomes Y and odds O. The three components share the same date index and rows.

Raises:

Type Description
ValueError

If the selection yields no betting markets, so there is nothing to predict. Pass an odds source, or call extract_exploration_data for the features on their own.

Source code in src/sportsbet/dataloaders/_base.py
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
def extract_train_data(
    self: Self,
    *,
    drop_na_thres: float | None = None,
    odds_type: str | None = None,
    target_event_status: str | None = None,
    target_event_time: pd.Timedelta | None = None,
    input_event_status: str | None = None,
    input_event_time: pd.Timedelta | None = None,
) -> TrainData:
    """Extract the moment-aware training data.

    Read more in the [user guide][user-guide].

    It downloads the selected seasons. It returns the historical data you build and backtest a betting strategy
    on. Every snapshot before the target moment (`target_event_status`, `target_event_time`) becomes a feature in
    `X`. An input horizon can cap which snapshots become features. The target-moment outcomes become the labels
    `Y`. The odds become `O`. A dataloader that already downloaded reuses the snapshots it holds instead of
    fetching again. A bare call on a reloaded dataloader rebuilds the same data offline. Save one with `save`.
    When the odds source carries no markets, there is nothing to predict. Use `extract_exploration_data` to get
    the features on their own.

    Args:
        drop_na_thres:
            Threshold in `[0.0, 1.0]` controlling how aggressively feature
            columns with missing values are dropped. `None` keeps all columns.
        odds_type:
            One of `get_odds_types()`. `None` returns no odds.
        target_event_status:
            `'inplay'` or `'postplay'` (default `'postplay'`).
        target_event_time:
            In-play target time (e.g. `pd.Timedelta('60min')`). Defaults to 0.
        input_event_status:
            Latest snapshot status to keep as a feature, one of `'preplay'`,
            `'inplay'`, `'postplay'`. `None` (default) keeps every snapshot
            before the target. For example, `'preplay'` keeps only pre-match features.
        input_event_time:
            Time of the input horizon (e.g. `pd.Timedelta('45min')`), used
            together with `input_event_status`. Defaults to 0.

    Returns:
        (X, Y, O):
            Moment-aware features `X`, target outcomes `Y` and odds `O`. The
            three components share the same date index and rows.

    Raises:
        ValueError:
            If the selection yields no betting markets, so there is nothing
            to predict. Pass an `odds` source, or call
            `extract_exploration_data` for the features on their own.
    """
    arguments = (
        drop_na_thres,
        odds_type,
        target_event_status,
        target_event_time,
        input_event_status,
        input_event_time,
    )
    if all(argument is None for argument in arguments) and hasattr(self, 'odds_type_'):
        odds_type = self.odds_type_
        drop_na_thres = self.drop_na_thres_
        target_event_status = self.target_event_status_
        target_event_time = self.target_event_time_
        input_event_status = self.input_event_status_
        input_event_time = self.input_event_time_
    X, O, target_event_status, target_event_time = self._extract_inputs(
        odds_type,
        0.0 if drop_na_thres is None else drop_na_thres,
        target_event_status,
        target_event_time,
        input_event_status,
        input_event_time,
    )
    if not self.targets_:
        msg = (
            'There are no odds, so there are no markets to predict: the markets a model learns are the ones its '
            'odds price. Pass an `odds` source, or call `extract_exploration_data` to get the features on their '
            'own.'
        )
        raise ValueError(msg)
    index_cols = self._list_identity_cols()
    train_mask = pd.MultiIndex.from_frame(self.stats_[index_cols]).isin(self._train_ids)
    Y = self._extract_targets(
        self.stats_[train_mask],
        pd.MultiIndex.from_frame(X.reset_index()[index_cols]),
        target_event_status,
        target_event_time,
    )
    Y.index = X.index
    self.output_cols_ = Y.columns

    labelled = Y.notna().all(axis=1)
    return X[labelled], Y[labelled], O[labelled]

get_odds_types()

Return the available odds types (providers) derived from the data.

Returns:

Type Description
list[str]

The provider names the odds data carries, sorted.

Source code in src/sportsbet/dataloaders/_base.py
262
263
264
265
266
267
268
269
def get_odds_types(self: Self) -> list[str]:
    """Return the available odds types (providers) derived from the data.

    Returns:
        The provider names the odds data carries, sorted.
    """
    _, odds = self._load_snapshots()
    return sorted(odds['provider'].dropna().unique().tolist())

save(path)

Save the dataloader object.

Parameters:

Name Type Description Default
path str

The path to save the object.

required

Returns:

Name Type Description
self Self

The dataloader object.

Source code in src/sportsbet/dataloaders/_base.py
758
759
760
761
762
763
764
765
766
767
768
769
770
771
def save(self: Self, path: str) -> Self:
    """Save the dataloader object.

    Args:
        path:
            The path to save the object.

    Returns:
        self:
            The dataloader object.
    """
    with Path(path).open('wb') as file:
        cloudpickle.dump(self, file)
    return self

DataLoader(param_grid=None, stats=None, odds=None, aliases=None)

Bases: BaseDataLoader

Download source data and shape it into moment-aware modelling data.

There is one dataloader for every sport. The loader reads the sport off the statistics source and pairs it only with odds about the same sport.

It downloads the data into memory when you extract, and holds it on the object. Extract again and it downloads again. Keep what you have with save, and read it back with load_dataloader.

Parameters:

Name Type Description Default
param_grid ParamGrid | None

Selects the seasons to train on. Keys are 'league', 'division' and 'year', and values are the allowed values, mirroring scikit-learn's ParameterGrid. The default None selects everything the sources publish. It bounds only the training data. The fixtures are whatever is upcoming in the selected leagues.

None
stats BaseStatsSource | None

The source of the statistics.

None
odds BaseOddsSource | None

The source of the odds, which may differ from the statistics source. The default None gives a dataloader with no markets, for extract_exploration_data.

None
aliases dict[str, str] | None

The team names of the odds source, mapped to the names of the statistics source, for the clubs the two feeds name differently. They are added to the ones the library already knows.

None

Attributes:

Name Type Description
stats_ DataFrame

The downloaded statistics snapshots: the selected seasons, plus each selected league's season in progress.

odds_ DataFrame

The downloaded odds snapshots of the selected provider.

Examples:

>>> from sportsbet.dataloaders import DataLoader
>>> from sportsbet.sources import FootballDataOdds, FootballDataStats
>>> dataloader = DataLoader(
...     param_grid={'league': ['Italy'], 'division': [1], 'year': [2024]},
...     stats=FootballDataStats(),
...     odds=FootballDataOdds(),
... )
>>> # The sources say what sport it is.
>>> dataloader.sport_
'soccer'
>>> # X, Y, O = dataloader.extract_train_data(odds_type='market_maximum')
Source code in src/sportsbet/dataloaders/_sourced.py
68
69
70
71
72
73
74
75
76
77
78
def __init__(
    self: Self,
    param_grid: ParamGrid | None = None,
    stats: BaseStatsSource | None = None,
    odds: BaseOddsSource | None = None,
    aliases: dict[str, str] | None = None,
) -> None:
    super().__init__(param_grid)
    self.stats = stats
    self.odds = odds
    self.aliases = aliases

sources_ property

The statistics and odds sources.

sport_ property

The sport the sources carry.

build_dataloader(stats, odds=None, leagues=None, divisions=None, years=None, odds_key_env=DEFAULT_KEY_ENV, odds_markets=None, odds_regions=None, odds_moments=None, aliases=None)

Build a dataloader from the names of its sources and the seasons to select.

Parameters:

Name Type Description Default
stats str

The statistics source to read, one of the ready-made names (football-data, euroleague, nba).

required
odds str | None

The odds source to pair with the statistics, or None for a dataloader with no odds.

None
leagues list[str] | None

The leagues to select, or None for every league the sources publish.

None
divisions list[int] | None

The divisions to select, or None for every division.

None
years list[int] | None

The years to select, or None for every year.

None
odds_key_env str

The name of the environment variable holding the odds source's API key, read when the source needs one.

DEFAULT_KEY_ENV
odds_markets list[str] | None

The markets the odds source should price, or None for its own default.

None
odds_regions list[str] | None

The regions the odds source should price, or None for its own default.

None
odds_moments list[str] | None

The moments the odds source should price, each as status:minute, or None for its default.

None
aliases list[str] | None

The teams the sources spell differently, each as stats name=odds name.

None

Returns:

Name Type Description
dataloader DataLoader

The dataloader that downloads and shapes the selected data.

Raises:

Type Description
BuildError

If a source name is unknown, or an argument is malformed.

Source code in src/sportsbet/dataloaders/_factory.py
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
def build_dataloader(
    stats: str,
    odds: str | None = None,
    leagues: list[str] | None = None,
    divisions: list[int] | None = None,
    years: list[int] | None = None,
    odds_key_env: str = DEFAULT_KEY_ENV,
    odds_markets: list[str] | None = None,
    odds_regions: list[str] | None = None,
    odds_moments: list[str] | None = None,
    aliases: list[str] | None = None,
) -> DataLoader:
    """Build a dataloader from the names of its sources and the seasons to select.

    Args:
        stats:
            The statistics source to read, one of the ready-made names (`football-data`, `euroleague`, `nba`).
        odds:
            The odds source to pair with the statistics, or `None` for a dataloader with no odds.
        leagues:
            The leagues to select, or `None` for every league the sources publish.
        divisions:
            The divisions to select, or `None` for every division.
        years:
            The years to select, or `None` for every year.
        odds_key_env:
            The name of the environment variable holding the odds source's API key, read when the source needs one.
        odds_markets:
            The markets the odds source should price, or `None` for its own default.
        odds_regions:
            The regions the odds source should price, or `None` for its own default.
        odds_moments:
            The moments the odds source should price, each as `status:minute`, or `None` for its default.
        aliases:
            The teams the sources spell differently, each as `stats name=odds name`.

    Returns:
        dataloader:
            The dataloader that downloads and shapes the selected data.

    Raises:
        BuildError:
            If a source name is unknown, or an argument is malformed.
    """
    if stats not in STATS_SOURCES:
        msg = f'`{stats}` is not a statistics source. Available: {", ".join(sorted(STATS_SOURCES))}.'
        raise BuildError(msg)
    selected: ParamGrid = {
        name: values for name, values in (('league', leagues), ('division', divisions), ('year', years)) if values
    }
    return DataLoader(
        param_grid=selected or None,
        stats=STATS_SOURCES[stats](),
        odds=_build_odds_source(odds, odds_key_env, odds_markets, odds_regions, odds_moments) if odds else None,
        aliases=_parse_aliases(aliases),
    )

build_extraction_settings(odds_type=None, drop_na_thres=None, target_event_status=None, target_event_time=None, input_event_status=None, input_event_time=None)

Turn the extraction arguments into keyword arguments for extract_train_data.

Parameters:

Name Type Description Default
odds_type str | None

The odds to extract, or None to leave it to the method.

None
drop_na_thres float | None

The threshold to drop missing columns, or None to leave it to the method.

None
target_event_status str | None

Where the targets are taken from, or None to leave it to the method.

None
target_event_time str | None

The moment of the targets when they are in-play, as 45min, or None.

None
input_event_status str | None

The latest snapshot kept as a feature, or None to keep every one before the target.

None
input_event_time str | None

The moment of the input horizon, as 45min, or None.

None

Returns:

Name Type Description
settings dict[str, Any]

The keyword arguments, with the times as Timedelta and the None values dropped.

Examples:

>>> from sportsbet.dataloaders import build_extraction_settings
>>> build_extraction_settings(odds_type='market_average', target_event_time='45min')
{'odds_type': 'market_average', 'target_event_time': Timedelta('0 days 00:45:00')}
Source code in src/sportsbet/dataloaders/_extraction.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def build_extraction_settings(
    odds_type: str | None = None,
    drop_na_thres: float | None = None,
    target_event_status: str | None = None,
    target_event_time: str | None = None,
    input_event_status: str | None = None,
    input_event_time: str | None = None,
) -> dict[str, Any]:
    """Turn the extraction arguments into keyword arguments for `extract_train_data`.

    Args:
        odds_type:
            The odds to extract, or `None` to leave it to the method.
        drop_na_thres:
            The threshold to drop missing columns, or `None` to leave it to the method.
        target_event_status:
            Where the targets are taken from, or `None` to leave it to the method.
        target_event_time:
            The moment of the targets when they are in-play, as `45min`, or `None`.
        input_event_status:
            The latest snapshot kept as a feature, or `None` to keep every one before the target.
        input_event_time:
            The moment of the input horizon, as `45min`, or `None`.

    Returns:
        settings:
            The keyword arguments, with the times as `Timedelta` and the `None` values dropped.

    Examples:
        >>> from sportsbet.dataloaders import build_extraction_settings
        >>> build_extraction_settings(odds_type='market_average', target_event_time='45min')
        {'odds_type': 'market_average', 'target_event_time': Timedelta('0 days 00:45:00')}
    """
    settings: dict[str, Any] = {
        'odds_type': odds_type,
        'drop_na_thres': drop_na_thres,
        'target_event_status': target_event_status,
        'input_event_status': input_event_status,
        'target_event_time': target_event_time,
        'input_event_time': input_event_time,
    }
    for name in ('target_event_time', 'input_event_time'):
        if settings.get(name) is not None:
            settings[name] = pd.Timedelta(settings[name])
    return {name: value for name, value in settings.items() if value is not None}

load_dataloader(path)

Load the dataloader object.

Parameters:

Name Type Description Default
path str

The path of the dataloader pickled file.

required

Returns:

Name Type Description
dataloader BaseDataLoader

The dataloader object.

Examples:

>>> import tempfile
>>> from pathlib import Path
>>> from sportsbet.dataloaders import DataLoader, load_dataloader
>>> from sportsbet.sources import SampleSoccerOdds, SampleSoccerStats
>>> path = str(Path(tempfile.mkdtemp()) / 'dataloader.pkl')
>>> dataloader = DataLoader(
...     param_grid={'league': ['England']}, stats=SampleSoccerStats(), odds=SampleSoccerOdds()
... )
>>> X, Y, O = dataloader.extract_train_data(odds_type='market_average')
>>> _ = dataloader.save(path)
>>> # It comes back knowing what it was told, so the fixtures take the shape the training data took.
>>> loaded = load_dataloader(path)
>>> loaded.param_grid_ == dataloader.param_grid_
True
>>> X_fix, _, O_fix = loaded.extract_fixtures_data()
>>> list(X_fix.columns) == list(X.columns)
True
Source code in src/sportsbet/dataloaders/_base.py
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
def load_dataloader(path: str) -> BaseDataLoader:
    """Load the dataloader object.

    Args:
        path:
            The path of the dataloader pickled file.

    Returns:
        dataloader:
            The dataloader object.

    Examples:
        >>> import tempfile
        >>> from pathlib import Path
        >>> from sportsbet.dataloaders import DataLoader, load_dataloader
        >>> from sportsbet.sources import SampleSoccerOdds, SampleSoccerStats
        >>> path = str(Path(tempfile.mkdtemp()) / 'dataloader.pkl')
        >>> dataloader = DataLoader(
        ...     param_grid={'league': ['England']}, stats=SampleSoccerStats(), odds=SampleSoccerOdds()
        ... )
        >>> X, Y, O = dataloader.extract_train_data(odds_type='market_average')
        >>> _ = dataloader.save(path)
        >>> # It comes back knowing what it was told, so the fixtures take the shape the training data took.
        >>> loaded = load_dataloader(path)
        >>> loaded.param_grid_ == dataloader.param_grid_
        True
        >>> X_fix, _, O_fix = loaded.extract_fixtures_data()
        >>> list(X_fix.columns) == list(X.columns)
        True
    """
    with Path(path).open('rb') as file:
        dataloader = cloudpickle.load(file)
    return dataloader