|
254 | 254 | }, |
255 | 255 | { |
256 | 256 | "cell_type": "markdown", |
257 | | - "id": "a46e377e-729a-4f99-b5d3-83b0736cb8a3", |
| 257 | + "id": "7474a792-2cfd-4139-a1cd-872f913fa07b", |
258 | 258 | "metadata": {}, |
259 | 259 | "source": [ |
260 | 260 | ":::{note}\n", |
261 | 261 | "Added in version `0.9.0`.\n", |
262 | | - ":::" |
263 | | - ] |
264 | | - }, |
265 | | - { |
266 | | - "cell_type": "markdown", |
267 | | - "id": "7474a792-2cfd-4139-a1cd-872f913fa07b", |
268 | | - "metadata": {}, |
269 | | - "source": [ |
| 262 | + ":::\n", |
| 263 | + "\n", |
270 | 264 | ":::{important}\n", |
271 | 265 | "While other data sources like `Pandas` or `Dask` have built-in support in HoloViews, as of version 1.17.1 this is not yet the case for `Polars`. You can track this [issue](https://github.com/holoviz/holoviews/issues/5939) to follow the evolution of this feature in HoloViews. Internally hvPlot simply selects the columns that contribute to the plot and casts them to a Pandas object using Polars' `.to_pandas()` method.\n", |
272 | 266 | ":::" |
|
327 | 321 | "df_polars['A'].hvplot.line(height=150)" |
328 | 322 | ] |
329 | 323 | }, |
| 324 | + { |
| 325 | + "cell_type": "markdown", |
| 326 | + "id": "efc2f45e", |
| 327 | + "metadata": {}, |
| 328 | + "source": [ |
| 329 | + "#### DuckDB" |
| 330 | + ] |
| 331 | + }, |
| 332 | + { |
| 333 | + "cell_type": "markdown", |
| 334 | + "id": "db91860c", |
| 335 | + "metadata": {}, |
| 336 | + "source": [ |
| 337 | + ":::{note}\n", |
| 338 | + "Added in version `0.11.0`.\n", |
| 339 | + ":::" |
| 340 | + ] |
| 341 | + }, |
| 342 | + { |
| 343 | + "cell_type": "code", |
| 344 | + "execution_count": null, |
| 345 | + "id": "0d6460d0", |
| 346 | + "metadata": {}, |
| 347 | + "outputs": [], |
| 348 | + "source": [ |
| 349 | + "import numpy as np\n", |
| 350 | + "import pandas as pd\n", |
| 351 | + "\n", |
| 352 | + "df_pandas = pd.DataFrame(np.random.randn(1000, 4), columns=list('ABCD')).cumsum()\n", |
| 353 | + "df_pandas.head(2)" |
| 354 | + ] |
| 355 | + }, |
| 356 | + { |
| 357 | + "cell_type": "code", |
| 358 | + "execution_count": null, |
| 359 | + "id": "21638d45", |
| 360 | + "metadata": {}, |
| 361 | + "outputs": [], |
| 362 | + "source": [ |
| 363 | + "import hvplot.duckdb # noqa \n", |
| 364 | + "import duckdb\n", |
| 365 | + "\n", |
| 366 | + "connection = duckdb.connect(':memory:')\n", |
| 367 | + "relation = duckdb.from_df(df_pandas, connection=connection)\n", |
| 368 | + "relation.to_view(\"example_view\");" |
| 369 | + ] |
| 370 | + }, |
| 371 | + { |
| 372 | + "cell_type": "markdown", |
| 373 | + "id": "40b56f16", |
| 374 | + "metadata": {}, |
| 375 | + "source": [ |
| 376 | + "`.hvplot()` supports [DuckDB](https://duckdb.org/docs/api/python/overview.html) `DuckDBPyRelation` and `DuckDBConnection` objects." |
| 377 | + ] |
| 378 | + }, |
| 379 | + { |
| 380 | + "cell_type": "code", |
| 381 | + "execution_count": null, |
| 382 | + "id": "f588e3fe", |
| 383 | + "metadata": {}, |
| 384 | + "outputs": [], |
| 385 | + "source": [ |
| 386 | + "relation.hvplot.line(y=['A', 'B', 'C', 'D'], height=150)" |
| 387 | + ] |
| 388 | + }, |
| 389 | + { |
| 390 | + "cell_type": "markdown", |
| 391 | + "id": "68a47856", |
| 392 | + "metadata": {}, |
| 393 | + "source": [ |
| 394 | + "`DuckDBPyRelation` is a bit more optimized because it handles column subsetting directly within DuckDB before the data is converted to a `pd.DataFrame`.\n", |
| 395 | + "\n", |
| 396 | + "So, it's a good idea to use the `connection.sql()` method when possible, which gives you a `DuckDBPyRelation`, instead of `connection.execute()`, which returns a `DuckDBPyConnection`." |
| 397 | + ] |
| 398 | + }, |
| 399 | + { |
| 400 | + "cell_type": "code", |
| 401 | + "execution_count": null, |
| 402 | + "id": "214c60ee", |
| 403 | + "metadata": {}, |
| 404 | + "outputs": [], |
| 405 | + "source": [ |
| 406 | + "sql_expr = \"SELECT * FROM example_view WHERE A > 0 AND B > 0\"\n", |
| 407 | + "connection.sql(sql_expr).hvplot.line(y=['A', 'B'], hover_cols=[\"C\"], height=150) # subsets A, B, C" |
| 408 | + ] |
| 409 | + }, |
| 410 | + { |
| 411 | + "cell_type": "markdown", |
| 412 | + "id": "2a2f61d4", |
| 413 | + "metadata": {}, |
| 414 | + "source": [ |
| 415 | + "Alternatively, you can directly subset the desired columns in the SQL expression." |
| 416 | + ] |
| 417 | + }, |
| 418 | + { |
| 419 | + "cell_type": "code", |
| 420 | + "execution_count": null, |
| 421 | + "id": "5ce25c3d", |
| 422 | + "metadata": {}, |
| 423 | + "outputs": [], |
| 424 | + "source": [ |
| 425 | + "sql_expr = \"SELECT A, B, C FROM example_view WHERE A > 0 AND B > 0\"\n", |
| 426 | + "connection.execute(sql_expr).hvplot.line(y=['A', 'B'], hover_cols=[\"C\"], height=150)" |
| 427 | + ] |
| 428 | + }, |
330 | 429 | { |
331 | 430 | "cell_type": "markdown", |
332 | 431 | "id": "25a6e724-6a84-4bff-9108-ac71dcfa9116", |
|
0 commit comments