Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Apr 20, 2022
1 parent e6ab1ae commit 971e6d7
Showing 1 changed file with 84 additions and 14 deletions.
98 changes: 84 additions & 14 deletions tests/v2/test_0401-add-categorical-type-for-arrow-dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@ def test_to_categorical_numbers():
assert to_list(categorical.layout.content) == [1.1, 2.2, 3.3]
not_categorical = ak._v2.behaviors.categorical.from_categorical(categorical)
assert not ak._v2.behaviors.categorical.is_categorical(not_categorical)
assert ak._v2.behaviors.categorical.categories(categorical).tolist() == [1.1, 2.2, 3.3]
assert ak._v2.behaviors.categorical.categories(categorical).tolist() == [
1.1,
2.2,
3.3,
]


def test_to_categorical_nested():
Expand All @@ -225,7 +229,11 @@ def test_to_categorical_nested():
assert to_list(array) == categorical.tolist()
not_categorical = ak._v2.behaviors.categorical.from_categorical(categorical)
assert not ak._v2.behaviors.categorical.is_categorical(not_categorical)
assert ak._v2.behaviors.categorical.categories(categorical).tolist() == ["one", "two", "three"]
assert ak._v2.behaviors.categorical.categories(categorical).tolist() == [
"one",
"two",
"three",
]


def test_to_categorical():
Expand All @@ -239,7 +247,11 @@ def test_to_categorical():
assert to_list(categorical.layout.content) == ["one", "two", "three"]
not_categorical = ak._v2.behaviors.categorical.from_categorical(categorical)
assert not ak._v2.behaviors.categorical.is_categorical(not_categorical)
assert ak._v2.behaviors.categorical.categories(categorical).tolist() == ["one", "two", "three"]
assert ak._v2.behaviors.categorical.categories(categorical).tolist() == [
"one",
"two",
"three",
]


def test_to_categorical_none():
Expand All @@ -266,7 +278,11 @@ def test_to_categorical_none():
assert to_list(categorical.layout.content) == ["one", "two", "three"]
not_categorical = ak._v2.behaviors.categorical.from_categorical(categorical)
assert not ak._v2.behaviors.categorical.is_categorical(not_categorical)
assert ak._v2.behaviors.categorical.categories(categorical).tolist() == ["one", "two", "three"]
assert ak._v2.behaviors.categorical.categories(categorical).tolist() == [
"one",
"two",
"three",
]


def test_to_categorical_masked():
Expand Down Expand Up @@ -304,15 +320,21 @@ def test_to_categorical_masked():
]
)
)
array = ak._v2.Array(ak._v2.contents.ByteMaskedArray(mask, content, valid_when=False))
array = ak._v2.Array(
ak._v2.contents.ByteMaskedArray(mask, content, valid_when=False)
)
assert not ak._v2.behaviors.categorical.is_categorical(array)
categorical = ak._v2.behaviors.categorical.to_categorical(array)
assert ak._v2.behaviors.categorical.is_categorical(categorical)
assert to_list(array) == categorical.tolist()
assert to_list(categorical.layout.content) == ["one", "two", "three"]
not_categorical = ak._v2.behaviors.categorical.from_categorical(categorical)
assert not ak._v2.behaviors.categorical.is_categorical(not_categorical)
assert ak._v2.behaviors.categorical.categories(categorical).tolist() == ["one", "two", "three"]
assert ak._v2.behaviors.categorical.categories(categorical).tolist() == [
"one",
"two",
"three",
]


def test_to_categorical_masked_again():
Expand Down Expand Up @@ -341,33 +363,63 @@ def test_to_categorical_masked_again():
]
)
)
array = ak._v2.Array(ak._v2.contents.ByteMaskedArray(mask, indexedarray, valid_when=False))
array = ak._v2.Array(
ak._v2.contents.ByteMaskedArray(mask, indexedarray, valid_when=False)
)
assert not ak._v2.behaviors.categorical.is_categorical(array)
categorical = ak._v2.behaviors.categorical.to_categorical(array)
assert ak._v2.behaviors.categorical.is_categorical(categorical)
assert to_list(array) == categorical.tolist()
assert to_list(categorical.layout.content) == ["one", "two", "three"]
not_categorical = ak._v2.behaviors.categorical.from_categorical(categorical)
assert not ak._v2.behaviors.categorical.is_categorical(not_categorical)
assert ak._v2.behaviors.categorical.categories(categorical).tolist() == ["one", "two", "three"]
assert ak._v2.behaviors.categorical.categories(categorical).tolist() == [
"one",
"two",
"three",
]


@pytest.mark.skip(reason="FIXME: ak._v2.operations.describe.type issues")
def test_typestr():
assert (
str(ak._v2.operations.describe.type(ak._v2.behaviors.categorical.to_categorical(ak._v2.Array([1.1, 2.2, 2.2, 3.3]))))
str(
ak._v2.operations.describe.type(
ak._v2.behaviors.categorical.to_categorical(
ak._v2.Array([1.1, 2.2, 2.2, 3.3])
)
)
)
== "4 * categorical[type=float64]"
)
assert (
str(ak._v2.operations.describe.type(ak._v2.behaviors.categorical.to_categorical(ak._v2.Array([1.1, 2.2, None, 2.2, 3.3]))))
str(
ak._v2.operations.describe.type(
ak._v2.behaviors.categorical.to_categorical(
ak._v2.Array([1.1, 2.2, None, 2.2, 3.3])
)
)
)
== "5 * categorical[type=?float64]"
)
assert (
str(ak._v2.operations.describe.type(ak._v2.behaviors.categorical.to_categorical(ak._v2.Array(["one", "two", "two", "three"]))))
str(
ak._v2.operations.describe.type(
ak._v2.behaviors.categorical.to_categorical(
ak._v2.Array(["one", "two", "two", "three"])
)
)
)
== "4 * categorical[type=string]"
)
assert (
str(ak._v2.operations.describe.type(ak._v2.behaviors.categorical.to_categorical(ak._v2.Array(["one", "two", None, "two", "three"]))))
str(
ak._v2.operations.describe.type(
ak._v2.behaviors.categorical.to_categorical(
ak._v2.Array(["one", "two", None, "two", "three"])
)
)
)
== "5 * categorical[type=option[string]]"
)

Expand All @@ -393,5 +445,23 @@ def test_zip():

def test_arrow_nomask():
array = ak._v2.Array([1.1, 2.2, 3.3, 4.4, None])
assert str(ak._v2.operations.describe.type(ak._v2.operations.convert.from_arrow(ak._v2.operations.convert.to_arrow(array)))) == "5 * ?float64"
assert str(ak._v2.operations.describe.type(ak._v2.operations.convert.from_arrow(ak._v2.operations.convert.to_arrow(array[:-1])))) == "4 * ?float64"
assert (
str(
ak._v2.operations.describe.type(
ak._v2.operations.convert.from_arrow(
ak._v2.operations.convert.to_arrow(array)
)
)
)
== "5 * ?float64"
)
assert (
str(
ak._v2.operations.describe.type(
ak._v2.operations.convert.from_arrow(
ak._v2.operations.convert.to_arrow(array[:-1])
)
)
)
== "4 * ?float64"
)

0 comments on commit 971e6d7

Please sign in to comment.