-
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.
feat: add is_ordered_categorical (#377)
- Loading branch information
1 parent
d77db26
commit c1f1a01
Showing
11 changed files
with
155 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
- Float32 | ||
- Boolean | ||
- Categorical | ||
- Enum | ||
- String | ||
- Datetime | ||
- Duration | ||
|
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
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
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,41 @@ | ||
from typing import Any | ||
|
||
import pandas as pd | ||
import polars as pl | ||
import pyarrow as pa | ||
import pytest | ||
|
||
import narwhals as nw | ||
|
||
|
||
def test_is_ordered_categorical() -> None: | ||
s = pl.Series(["a", "b"], dtype=pl.Categorical) | ||
assert nw.is_ordered_categorical(nw.from_native(s, series_only=True)) | ||
s = pl.Series(["a", "b"], dtype=pl.Categorical(ordering="lexical")) | ||
assert not nw.is_ordered_categorical(nw.from_native(s, series_only=True)) | ||
s = pl.Series(["a", "b"], dtype=pl.Enum(["a", "b"])) | ||
assert nw.is_ordered_categorical(nw.from_native(s, series_only=True)) | ||
s = pd.Series(["a", "b"], dtype=pd.CategoricalDtype(ordered=True)) | ||
assert nw.is_ordered_categorical(nw.from_native(s, series_only=True)) | ||
s = pd.Series(["a", "b"], dtype=pd.CategoricalDtype(ordered=False)) | ||
assert not nw.is_ordered_categorical(nw.from_native(s, series_only=True)) | ||
s = pa.chunked_array( | ||
[pa.array(["a", "b"], type=pa.dictionary(pa.int32(), pa.string()))] | ||
) | ||
assert not nw.is_ordered_categorical(nw.from_native(s, series_only=True)) | ||
|
||
|
||
def test_is_definitely_not_ordered_categorical( | ||
constructor_series_with_pyarrow: Any, | ||
) -> None: | ||
assert not nw.is_ordered_categorical( | ||
nw.from_native(constructor_series_with_pyarrow([1, 2, 3]), series_only=True) | ||
) | ||
|
||
|
||
@pytest.mark.xfail(reason="https://github.com/apache/arrow/issues/41017") | ||
def test_is_ordered_categorical_pyarrow() -> None: | ||
s = pa.chunked_array( | ||
[pa.array(["a", "b"], type=pa.dictionary(pa.int32(), pa.string(), ordered=True))] | ||
) | ||
assert nw.is_ordered_categorical(nw.from_native(s, series_only=True)) |