tabpfn-time-series 1.0.3__py3-none-any.whl → 1.0.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,8 +2,13 @@ import logging
2
2
  from enum import Enum
3
3
 
4
4
  from tabpfn_time_series.ts_dataframe import TimeSeriesDataFrame
5
- from tabpfn_time_series.tabpfn_worker import TabPFNClient, LocalTabPFN, MockTabPFN
5
+ from tabpfn_time_series.tabpfn_worker import (
6
+ TabPFNClient,
7
+ LocalTabPFN,
8
+ MockTabPFN,
9
+ )
6
10
  from tabpfn_time_series.defaults import TABPFN_TS_DEFAULT_CONFIG
11
+ from tabpfn_common_utils.telemetry import set_extension
7
12
 
8
13
  logger = logging.getLogger(__name__)
9
14
 
@@ -14,6 +19,7 @@ class TabPFNMode(Enum):
14
19
  MOCK = "tabpfn-mock"
15
20
 
16
21
 
22
+ @set_extension("time-series")
17
23
  class TabPFNTimeSeriesPredictor:
18
24
  """
19
25
  Given a TimeSeriesDataFrame (multiple time series), perform prediction on each time series individually.
@@ -29,6 +35,7 @@ class TabPFNTimeSeriesPredictor:
29
35
  TabPFNMode.LOCAL: lambda: LocalTabPFN(config),
30
36
  TabPFNMode.MOCK: lambda: MockTabPFN(config),
31
37
  }
38
+ self.tabpfn_mode = tabpfn_mode
32
39
  self.tabpfn_worker = worker_mapping[tabpfn_mode]()
33
40
 
34
41
  def predict(
@@ -1,6 +1,8 @@
1
+ import contextvars
1
2
  import logging
2
3
  from abc import ABC, abstractmethod
3
- from joblib import Parallel, delayed
4
+ from joblib import Parallel, delayed, parallel_config
5
+ import backoff
4
6
 
5
7
  from tqdm import tqdm
6
8
  import pandas as pd
@@ -14,6 +16,9 @@ from tabpfn_time_series.defaults import TABPFN_TS_DEFAULT_QUANTILE_CONFIG
14
16
 
15
17
  logger = logging.getLogger(__name__)
16
18
 
19
+ # Per-call attempt counter, isolated per thread & task
20
+ _retry_attempts = contextvars.ContextVar("predict_attempts", default=0)
21
+
17
22
 
18
23
  class TabPFNWorker(ABC):
19
24
  def __init__(
@@ -29,24 +34,7 @@ class TabPFNWorker(ABC):
29
34
  train_tsdf: TimeSeriesDataFrame,
30
35
  test_tsdf: TimeSeriesDataFrame,
31
36
  ):
32
- predictions = Parallel(
33
- n_jobs=self.num_workers,
34
- backend="loky",
35
- )(
36
- delayed(self._prediction_routine)(
37
- item_id,
38
- train_tsdf.loc[item_id],
39
- test_tsdf.loc[item_id],
40
- )
41
- for item_id in tqdm(train_tsdf.item_ids, desc="Predicting time series")
42
- )
43
-
44
- predictions = pd.concat(predictions)
45
-
46
- # Sort predictions according to original item_ids order (important for MASE and WQL calculation)
47
- predictions = predictions.loc[train_tsdf.item_ids]
48
-
49
- return TimeSeriesDataFrame(predictions)
37
+ raise NotImplementedError("Predict method must be implemented in subclass")
50
38
 
51
39
  def _prediction_routine(
52
40
  self,
@@ -54,8 +42,6 @@ class TabPFNWorker(ABC):
54
42
  single_train_tsdf: TimeSeriesDataFrame,
55
43
  single_test_tsdf: TimeSeriesDataFrame,
56
44
  ) -> pd.DataFrame:
57
- # logger.debug(f"Predicting on item_id: {item_id}")
58
-
59
45
  test_index = single_test_tsdf.index
60
46
  train_X, train_y = split_time_series_to_X_y(single_train_tsdf.copy())
61
47
  test_X, _ = split_time_series_to_X_y(single_test_tsdf.copy())
@@ -116,6 +102,39 @@ class TabPFNWorker(ABC):
116
102
  return result
117
103
 
118
104
 
105
+ def _reset_attempts(_details=None):
106
+ """Convenience function to reset the attempt counter."""
107
+ _retry_attempts.set(0)
108
+
109
+
110
+ def _predict_giveup_mixed(exc: Exception) -> bool:
111
+ """Determine whether to give up on a prediction call or not.
112
+
113
+ Returns:
114
+ True if the prediction call should be given up on, False otherwise.
115
+ """
116
+ if _is_tabpfn_gcs_429(exc):
117
+ return False
118
+
119
+ # Stop after first retry for non-429
120
+ return _retry_attempts.get() >= 2
121
+
122
+
123
+ def _is_tabpfn_gcs_429(err: Exception) -> bool:
124
+ """Determine if an error is a 429 error raised from TabPFN API
125
+ and relates to GCS 429 errors.
126
+
127
+ Returns:
128
+ True if the error is a 429 error raised from TabPFN API.
129
+ """
130
+ markers = (
131
+ "TooManyRequests: 429",
132
+ "rateLimitExceeded",
133
+ "cloud.google.com/storage/docs/gcs429",
134
+ )
135
+ return any(m in str(err) for m in markers)
136
+
137
+
119
138
  class TabPFNClient(TabPFNWorker):
120
139
  def __init__(
121
140
  self,
@@ -135,6 +154,53 @@ class TabPFNClient(TabPFNWorker):
135
154
 
136
155
  super().__init__(config, num_workers)
137
156
 
157
+ def predict(
158
+ self,
159
+ train_tsdf: TimeSeriesDataFrame,
160
+ test_tsdf: TimeSeriesDataFrame,
161
+ ):
162
+ # Run the predictions in parallel
163
+ with parallel_config(backend="threading"):
164
+ results = Parallel(
165
+ n_jobs=self.num_workers,
166
+ )(
167
+ delayed(self._prediction_routine)(
168
+ item_id,
169
+ train_tsdf.loc[item_id],
170
+ test_tsdf.loc[item_id],
171
+ )
172
+ for item_id in tqdm(train_tsdf.item_ids, desc="Predicting time series")
173
+ )
174
+
175
+ # Convert list to DataFrame
176
+ predictions = pd.concat(results)
177
+
178
+ # Sort predictions according to original item_ids order (important for MASE and WQL calculation)
179
+ predictions = predictions.loc[train_tsdf.item_ids]
180
+
181
+ return TimeSeriesDataFrame(predictions)
182
+
183
+ @backoff.on_exception(
184
+ backoff.expo,
185
+ Exception,
186
+ base=1,
187
+ factor=2,
188
+ max_tries=5,
189
+ jitter=backoff.full_jitter,
190
+ giveup=_predict_giveup_mixed,
191
+ on_success=_reset_attempts,
192
+ )
193
+ def _prediction_routine(
194
+ self,
195
+ item_id: str,
196
+ single_train_tsdf: TimeSeriesDataFrame,
197
+ single_test_tsdf: TimeSeriesDataFrame,
198
+ ) -> pd.DataFrame:
199
+ # Increment attempt count at start of each try
200
+ _retry_attempts.set(_retry_attempts.get() + 1)
201
+
202
+ return super()._prediction_routine(item_id, single_train_tsdf, single_test_tsdf)
203
+
138
204
  def _get_tabpfn_engine(self):
139
205
  from tabpfn_client import TabPFNRegressor
140
206
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tabpfn_time_series
3
- Version: 1.0.3
3
+ Version: 1.0.5
4
4
  Summary: Zero-shot time series forecasting with TabPFNv2
5
5
  Project-URL: Homepage, https://github.com/liam-sbhoo/tabpfn-time-series
6
6
  Project-URL: Bug Tracker, https://github.com/liam-sbhoo/tabpfn-time-series/issues
@@ -10,6 +10,7 @@ Classifier: License :: OSI Approved :: Apache Software License
10
10
  Classifier: Operating System :: OS Independent
11
11
  Classifier: Programming Language :: Python :: 3
12
12
  Requires-Python: >=3.10
13
+ Requires-Dist: backoff>=2.2.1
13
14
  Requires-Dist: datasets>=4.0
14
15
  Requires-Dist: gluonts>=0.16.0
15
16
  Requires-Dist: pandas<2.2.0,>=2.1.2
@@ -17,6 +18,7 @@ Requires-Dist: python-dotenv>=1.1.0
17
18
  Requires-Dist: pyyaml>=6.0.1
18
19
  Requires-Dist: statsmodels>=0.14.5
19
20
  Requires-Dist: tabpfn-client>=0.1.7
21
+ Requires-Dist: tabpfn-common-utils[telemetry-interactive]>=0.2.2
20
22
  Requires-Dist: tabpfn>=2.0.9
21
23
  Requires-Dist: tqdm
22
24
  Provides-Extra: dev
@@ -97,3 +99,33 @@ uv pip install -e ".[dev]"
97
99
  [![colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/PriorLabs/tabpfn-time-series/blob/main/demo.ipynb)
98
100
 
99
101
  The demo should explain it all. 😉
102
+
103
+ ## 📊 Anonymous Telemetry
104
+
105
+ This project collects **anonymous usage telemetry** by default.
106
+
107
+ The data is used exclusively to help us understand how the library is being used and to guide future improvements.
108
+
109
+ - **No personal data is collected**
110
+ - **No code, model inputs, or outputs are ever sent**
111
+ - **Data is strictly anonymous and cannot be linked to individuals**
112
+
113
+ ### What we collect
114
+ We only collect high-level, non-identifying information such as:
115
+ - Package version
116
+ - Python version
117
+ - How often fit and inference are called, including simple metadata like the dimensionality of the input and the type of task (e.g., classification vs. regression) (:warning: never the data itself)
118
+
119
+ See the [Telemetry documentation](https://github.com/priorlabs/tabpfn/blob/main/TELEMETRY.md) for the full details of events and metadata.
120
+
121
+ This data is processed in compliance with the **General Data Protection Regulation (GDPR)** principles of data minimization and purpose limitation.
122
+
123
+ For more details, please see our [Privacy Policy](https://priorlabs.ai/privacy_policy/).
124
+
125
+ ### How to opt out
126
+ If you prefer not to send telemetry, you can disable it by setting the following environment variable:
127
+
128
+ ```bash
129
+ export TABPFN_DISABLE_TELEMETRY=1
130
+ ```
131
+ ---
@@ -2,15 +2,15 @@ tabpfn_time_series/__init__.py,sha256=XJXSKqWp3AF9mAaWi-4KCgHQG7NzNTaBkLOYOMxvhS
2
2
  tabpfn_time_series/data_preparation.py,sha256=wWjSaKgV9KqKonMtSuDbYnW59ixflrScKIP_HSJ_MlA,5427
3
3
  tabpfn_time_series/defaults.py,sha256=ki1y38FR4zmbHWgRjcryA5T88GzNMwhlZC-sTRjuK2U,248
4
4
  tabpfn_time_series/plot.py,sha256=UXgLR2S94vi-vv1ArQKI6uYl_QwSAwAau5jFzGmQ7hw,6582
5
- tabpfn_time_series/predictor.py,sha256=UDhvH7reB3HAuxOyggE4yl2ntQXivvxgXCN_RhoddHc,1467
6
- tabpfn_time_series/tabpfn_worker.py,sha256=ZlJrU0O1dxfKh_As5Le4phm0P4RCDeXKpqp9X-h5bQs,9619
5
+ tabpfn_time_series/predictor.py,sha256=6R9Pb-8jD2jZp0nw1VOQFudJ7i676hwcUh96NRQRhOI,1609
6
+ tabpfn_time_series/tabpfn_worker.py,sha256=k6td4Ml0E3Xr1gERze-S0kyvBB6q_hbLMzvSurdaSp0,11589
7
7
  tabpfn_time_series/ts_dataframe.py,sha256=X94mssw_mSFedjplG55hjwTzKj8mM3VwWynveX3fegA,52834
8
8
  tabpfn_time_series/features/__init__.py,sha256=lzdZWkEfntfg3ZHqNNbfbg-3o_VIzju0tebdRu3AzF4,421
9
9
  tabpfn_time_series/features/auto_features.py,sha256=3OqqY2h7umcoLjLx4hOXypLTjwzrMtd6cQKTNi83vrU,11561
10
10
  tabpfn_time_series/features/basic_features.py,sha256=OV3B__S30-CX88vGjwYQDWqAbJajQw80PxcnvJVUbm4,2955
11
11
  tabpfn_time_series/features/feature_generator_base.py,sha256=jtySWLJyX4E31v6CbX44EHa8cdz7OMyauf4ltNEQeAQ,534
12
12
  tabpfn_time_series/features/feature_transformer.py,sha256=JzxswTGRGlt00QoYFyvAILlUVD68njdvoU3v-phnyi8,1774
13
- tabpfn_time_series-1.0.3.dist-info/METADATA,sha256=qp6gKaktKWsK3WiyyONpLI3r5pIoio2dEeFwWhYKjY8,4917
14
- tabpfn_time_series-1.0.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
15
- tabpfn_time_series-1.0.3.dist-info/licenses/LICENSE.txt,sha256=iwhPL7kIWQG6gyLZZwIMDItGrNgxMDIq9itxkUSMapY,11345
16
- tabpfn_time_series-1.0.3.dist-info/RECORD,,
13
+ tabpfn_time_series-1.0.5.dist-info/METADATA,sha256=tYxI37YfTs2irkka6-LmSNMOAvoyR6llSTNVcnbh_A8,6254
14
+ tabpfn_time_series-1.0.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
15
+ tabpfn_time_series-1.0.5.dist-info/licenses/LICENSE.txt,sha256=iwhPL7kIWQG6gyLZZwIMDItGrNgxMDIq9itxkUSMapY,11345
16
+ tabpfn_time_series-1.0.5.dist-info/RECORD,,