|
6 | 6 |
|
7 | 7 | if TYPE_CHECKING: |
8 | 8 | import datetime as dt |
9 | | - from collections.abc import Iterable, Sequence, Sized |
| 9 | + from collections.abc import Iterable, Mapping, Sequence, Sized |
10 | 10 | from decimal import Decimal |
11 | 11 | from types import ModuleType |
12 | 12 |
|
|
16 | 16 | from narwhals import dtypes |
17 | 17 | from narwhals.dataframe import DataFrame, LazyFrame |
18 | 18 | from narwhals.expr import Expr |
| 19 | + from narwhals.schema import Schema |
19 | 20 | from narwhals.series import Series |
20 | 21 |
|
21 | 22 | # All dataframes supported by Narwhals have a |
@@ -390,6 +391,36 @@ def Binary(self) -> type[dtypes.Binary]: ... |
390 | 391 | └──────────────────┘ |
391 | 392 | """ |
392 | 393 |
|
| 394 | +# TODO @dangotbanned: fix this? |
| 395 | +# Constructor allows tuples, but we don't support that *everywhere* yet |
| 396 | +IntoSchema: TypeAlias = "Mapping[str, dtypes.DType] | Schema" |
| 397 | +"""Anything that can be converted into a Narwhals Schema. |
| 398 | +
|
| 399 | +Defined by column names and their associated *instantiated* Narwhals DType. |
| 400 | +
|
| 401 | +Examples: |
| 402 | + >>> import narwhals as nw |
| 403 | + >>> import pyarrow as pa |
| 404 | + >>> data = {"a": [1, 2, 3], "b": [None, "hi", "howdy"], "c": [2.1, 2.0, None]} |
| 405 | + >>> nw.DataFrame.from_dict( |
| 406 | + ... data, |
| 407 | + ... schema={"a": nw.UInt8(), "b": nw.String(), "c": nw.Float32()}, |
| 408 | + ... backend="pyarrow", |
| 409 | + ... ) |
| 410 | + ┌────────────────────────┐ |
| 411 | + | Narwhals DataFrame | |
| 412 | + |------------------------| |
| 413 | + |pyarrow.Table | |
| 414 | + |a: uint8 | |
| 415 | + |b: string | |
| 416 | + |c: float | |
| 417 | + |---- | |
| 418 | + |a: [[1,2,3]] | |
| 419 | + |b: [[null,"hi","howdy"]]| |
| 420 | + |c: [[2.1,2,null]] | |
| 421 | + └────────────────────────┘ |
| 422 | +""" |
| 423 | + |
393 | 424 |
|
394 | 425 | # Annotations for `__getitem__` methods |
395 | 426 | _T = TypeVar("_T") |
|
0 commit comments