-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into ewm
- Loading branch information
Showing
5 changed files
with
133 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
from typing import Any | ||
|
||
import numpy as np | ||
import pandas as pd | ||
import polars as pl | ||
import pyarrow as pa | ||
|
||
import narwhals as nw | ||
from narwhals.dependencies import is_into_dataframe | ||
|
||
if TYPE_CHECKING: | ||
from typing_extensions import Self | ||
|
||
|
||
class DictDataFrame: | ||
def __init__(self, data: dict[str, list[Any]]) -> None: | ||
self._data = data | ||
|
||
def __len__(self) -> int: # pragma: no cover | ||
return len(next(iter(self._data.values()))) | ||
|
||
def __narwhals_dataframe__(self) -> Self: # pragma: no cover | ||
return self | ||
|
||
|
||
def test_is_into_dataframe() -> None: | ||
data = {"a": [1, 2, 3], "b": [4, 5, 6]} | ||
assert is_into_dataframe(pa.table(data)) | ||
assert is_into_dataframe(pl.DataFrame(data)) | ||
assert is_into_dataframe(pd.DataFrame(data)) | ||
assert is_into_dataframe(nw.from_native(pd.DataFrame(data))) | ||
assert is_into_dataframe(DictDataFrame(data)) | ||
assert not is_into_dataframe(np.array([[1, 4], [2, 5], [3, 6]])) | ||
assert not is_into_dataframe(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters