Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] - Raise error when payload is too large and suggest number of partitions #456

Merged
merged 13 commits into from
Sep 3, 2024
18 changes: 18 additions & 0 deletions nbs/src/nixtla_client.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,9 @@
"\n",
" ensure_contiguous_arrays(payload)\n",
" content = orjson.dumps(payload, option=orjson.OPT_SERIALIZE_NUMPY)\n",
" content_size_mb = len(content) / (1024*1024)\n",
" if content_size_mb > 200:\n",
" raise ValueError(f'The payload is too large. Set num_partitions={math.ceil(content_size_mb / 200)}')\n",
" resp = client.post(url=endpoint, content=content)\n",
" try:\n",
" resp_body = orjson.loads(resp.content)\n",
Expand Down Expand Up @@ -2489,6 +2492,21 @@
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#| hide\n",
"# Test large requests raise error and suggest partition number\n",
"df = generate_series(20_000, min_length=1_000, max_length=1_000, freq='min')\n",
"test_fail(\n",
" lambda: nixtla_client.forecast(df=df, h=1, freq='min', finetune_steps=2),\n",
" contains=\"num_partitions\"\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
7 changes: 6 additions & 1 deletion nixtla/nixtla_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,11 @@ def ensure_contiguous_arrays(d: Dict[str, Any]) -> None:

ensure_contiguous_arrays(payload)
content = orjson.dumps(payload, option=orjson.OPT_SERIALIZE_NUMPY)
content_size_mb = len(content) / (1024 * 1024)
if content_size_mb > 200:
raise ValueError(
f"The payload is too large. Set num_partitions={math.ceil(content_size_mb / 200)}"
)
resp = client.post(url=endpoint, content=content)
try:
resp_body = orjson.loads(resp.content)
Expand Down Expand Up @@ -1531,7 +1536,7 @@ def plot(
ax=ax,
)

# %% ../nbs/src/nixtla_client.ipynb 51
# %% ../nbs/src/nixtla_client.ipynb 52
def _forecast_wrapper(
df: pd.DataFrame,
client: NixtlaClient,
Expand Down