|
92 | 92 |
|
93 | 93 |
|
94 | 94 | class DataFrame(NwDataFrame[IntoDataFrameT]):
|
95 |
| - """Narwhals DataFrame, backed by a native dataframe. |
96 |
| -
|
97 |
| - The native dataframe might be pandas.DataFrame, polars.DataFrame, ... |
98 |
| -
|
99 |
| - This class is not meant to be instantiated directly - instead, use |
100 |
| - `narwhals.from_native`. |
| 95 | + """Narwhals DataFrame, backed by a native eager dataframe. |
| 96 | +
|
| 97 | + !!! warning |
| 98 | + This class is not meant to be instantiated directly - instead: |
| 99 | +
|
| 100 | + - If the native object is a eager dataframe from one of the supported |
| 101 | + backend (e.g. pandas.DataFrame, polars.DataFrame, pyarrow.Table), |
| 102 | + you can use [`narwhals.from_native`](../narwhals/#narwhals.from_native): |
| 103 | + ```py |
| 104 | + narwhals.from_native(native_dataframe) |
| 105 | + narwhals.from_native(native_dataframe, eager_only=True) |
| 106 | + ``` |
| 107 | +
|
| 108 | + - If the object is a dictionary of column names and generic sequences mapping |
| 109 | + (e.g. `dict[str, list]`), you can create a DataFrame via |
| 110 | + [`narwhals.from_dict`](../narwhals/#narwhals.from_dict): |
| 111 | + ```py |
| 112 | + narwhals.from_dict( |
| 113 | + data={"a": [1, 2, 3]}, |
| 114 | + native_namespace=narwhals.get_native_namespace(another_object), |
| 115 | + ) |
| 116 | + ``` |
101 | 117 | """
|
102 | 118 |
|
103 | 119 | # We need to override any method which don't return Self so that type
|
@@ -364,12 +380,16 @@ def _l1_norm(self: Self) -> Self:
|
364 | 380 |
|
365 | 381 |
|
366 | 382 | class LazyFrame(NwLazyFrame[IntoFrameT]):
|
367 |
| - """Narwhals DataFrame, backed by a native dataframe. |
368 |
| -
|
369 |
| - The native dataframe might be pandas.DataFrame, polars.LazyFrame, ... |
370 |
| -
|
371 |
| - This class is not meant to be instantiated directly - instead, use |
372 |
| - `narwhals.from_native`. |
| 383 | + """Narwhals LazyFrame, backed by a native lazyframe. |
| 384 | +
|
| 385 | + !!! warning |
| 386 | + This class is not meant to be instantiated directly - instead use |
| 387 | + [`narwhals.from_native`](../narwhals/#narwhals.from_native) with a native |
| 388 | + object that is a lazy dataframe from one of the supported |
| 389 | + backend (e.g. polars.LazyFrame, dask_expr._collection.DataFrame): |
| 390 | + ```py |
| 391 | + narwhals.from_native(native_lazyframe) |
| 392 | + ``` |
373 | 393 | """
|
374 | 394 |
|
375 | 395 | @property
|
@@ -425,11 +445,26 @@ def _l1_norm(self: Self) -> Self:
|
425 | 445 | class Series(NwSeries[Any]):
|
426 | 446 | """Narwhals Series, backed by a native series.
|
427 | 447 |
|
428 |
| - The native series might be pandas.Series, polars.Series, ... |
429 |
| -
|
430 |
| - This class is not meant to be instantiated directly - instead, use |
431 |
| - `narwhals.from_native`, making sure to pass `allow_series=True` or |
432 |
| - `series_only=True`. |
| 448 | + !!! warning |
| 449 | + This class is not meant to be instantiated directly - instead: |
| 450 | +
|
| 451 | + - If the native object is a series from one of the supported backend (e.g. |
| 452 | + pandas.Series, polars.Series, pyarrow.ChunkedArray), you can use |
| 453 | + [`narwhals.from_native`](../narwhals/#narwhals.from_native): |
| 454 | + ```py |
| 455 | + narwhals.from_native(native_series, allow_series=True) |
| 456 | + narwhals.from_native(native_series, series_only=True) |
| 457 | + ``` |
| 458 | +
|
| 459 | + - If the object is a generic sequence (e.g. a list or a tuple of values), you can |
| 460 | + create a series via [`narwhals.new_series`](../narwhals/#narwhals.new_series): |
| 461 | + ```py |
| 462 | + narwhals.new_series( |
| 463 | + name=name, |
| 464 | + values=values, |
| 465 | + native_namespace=narwhals.get_native_namespace(another_object), |
| 466 | + ) |
| 467 | + ``` |
433 | 468 | """
|
434 | 469 |
|
435 | 470 | # We need to override any method which don't return Self so that type
|
@@ -2334,7 +2369,8 @@ def nth(*indices: int | Sequence[int]) -> Expr:
|
2334 | 2369 | """Creates an expression that references one or more columns by their index(es).
|
2335 | 2370 |
|
2336 | 2371 | Notes:
|
2337 |
| - `nth` is not supported for Polars version<1.0.0. Please use [`col`](/api-reference/narwhals/#narwhals.col) instead. |
| 2372 | + `nth` is not supported for Polars version<1.0.0. Please use |
| 2373 | + [`col`](../narwhals/#narwhals.col) instead. |
2338 | 2374 |
|
2339 | 2375 | Arguments:
|
2340 | 2376 | indices: One or more indices representing the columns to retrieve.
|
|
0 commit comments