-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ddefccc
commit 90d6c2f
Showing
2 changed files
with
81 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from __future__ import annotations | ||
|
||
import pandas as pd | ||
import pytest | ||
|
||
import narwhals.stable.v1 as nw | ||
|
||
|
||
def test_repr() -> None: | ||
duckdb = pytest.importorskip("duckdb") | ||
df = pd.DataFrame({"a": [1, 2, 3], "b": ["fdaf", "fda", "cf"]}) | ||
result = nw.from_native(df).__repr__() | ||
expected = ( | ||
"┌──────────────────┐\n" | ||
"|Narwhals DataFrame|\n" | ||
"|------------------|\n" | ||
"| a b |\n" | ||
"| 0 1 fdaf |\n" | ||
"| 1 2 fda |\n" | ||
"| 2 3 cf |\n" | ||
"└──────────────────┘" | ||
) | ||
assert result == expected | ||
result = nw.from_native(df).lazy().__repr__() | ||
expected = ( | ||
"┌──────────────────┐\n" | ||
"|Narwhals LazyFrame|\n" | ||
"|------------------|\n" | ||
"| a b |\n" | ||
"| 0 1 fdaf |\n" | ||
"| 1 2 fda |\n" | ||
"| 2 3 cf |\n" | ||
"└──────────────────┘" | ||
) | ||
assert result == expected | ||
result = nw.from_native(df)["a"].__repr__() | ||
expected = ( | ||
"┌─────────────────────┐\n" | ||
"| Narwhals Series |\n" | ||
"|---------------------|\n" | ||
"|0 1 |\n" | ||
"|1 2 |\n" | ||
"|2 3 |\n" | ||
"|Name: a, dtype: int64|\n" | ||
"└─────────────────────┘" | ||
) | ||
assert result == expected | ||
result = nw.from_native(duckdb.table("df")).__repr__() | ||
expected = ( | ||
"┌───────────────────┐\n" | ||
"|Narwhals DataFrame |\n" | ||
"|-------------------|\n" | ||
"|┌───────┬─────────┐|\n" | ||
"|│ a │ b │|\n" | ||
"|│ int64 │ varchar │|\n" | ||
"|├───────┼─────────┤|\n" | ||
"|│ 1 │ fdaf │|\n" | ||
"|│ 2 │ fda │|\n" | ||
"|│ 3 │ cf │|\n" | ||
"|└───────┴─────────┘|\n" | ||
"└───────────────────┘" | ||
) | ||
assert result == expected | ||
# Make something wider than the terminal size | ||
df = pd.DataFrame({"a": [1, 2, 3], "b": ["fdaf" * 100, "fda", "cf"]}) | ||
result = nw.from_native(duckdb.table("df")).__repr__() | ||
expected = ( | ||
"┌───────────────────────────────────────┐\n" | ||
"| Narwhals DataFrame |\n" | ||
"| Use `.to_native` to see native output |\n" | ||
"└───────────────────────────────────────┘" | ||
) | ||
assert result == expected |