-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix: use `None` instead of `unset` We should accept `None` * Feat: add simple _like typetracer methods * Fix: support list-of-primitive in `TypeTracerArray.from_array` * Test: test new `_like` functions * Refactor: simplify `from_array` * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Refactor: be noisy about invalid types * Fix: test equality for object dtype * Refactor: cleanup test names * Test: ensure object dtypes are caught Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
3006f01
commit 0c6ae03
Showing
2 changed files
with
83 additions
and
21 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,48 @@ | ||
import awkward as ak | ||
import numpy as np | ||
import pytest | ||
|
||
|
||
typetracer = ak._v2._typetracer.TypeTracer.instance() | ||
|
||
|
||
@pytest.mark.parametrize("dtype", [np.float64, np.int64, np.uint8, None]) | ||
@pytest.mark.parametrize("like_dtype", [np.float64, np.int64, np.uint8, None]) | ||
def test_ones_like(dtype, like_dtype): | ||
array = ak._v2.contents.numpyarray.NumpyArray( | ||
np.array([99, 88, 77, 66, 66], dtype=dtype) | ||
) | ||
ones = ak._v2.ones_like(array.typetracer, dtype=like_dtype, highlevel=False) | ||
assert ones.typetracer.shape == array.shape | ||
assert ones.typetracer.dtype == like_dtype or array.dtype | ||
|
||
|
||
@pytest.mark.parametrize("dtype", [np.float64, np.int64, np.uint8, None]) | ||
@pytest.mark.parametrize("like_dtype", [np.float64, np.int64, np.uint8, None]) | ||
def test_zeros_like(dtype, like_dtype): | ||
array = ak._v2.contents.numpyarray.NumpyArray( | ||
np.array([99, 88, 77, 66, 66], dtype=dtype) | ||
) | ||
|
||
full = ak._v2.zeros_like(array.typetracer, dtype=like_dtype, highlevel=False) | ||
assert full.typetracer.shape == array.shape | ||
assert full.typetracer.dtype == like_dtype or array.dtype | ||
|
||
|
||
@pytest.mark.parametrize("dtype", [np.float64, np.int64, np.uint8, None]) | ||
@pytest.mark.parametrize("like_dtype", [np.float64, np.int64, np.uint8, None]) | ||
@pytest.mark.parametrize("value", [1.0, -20, np.iinfo(np.uint64).max]) | ||
def test_full_like(dtype, like_dtype, value): | ||
array = ak._v2.contents.numpyarray.NumpyArray( | ||
np.array([99, 88, 77, 66, 66], dtype=dtype) | ||
) | ||
full = ak._v2.full_like(array.typetracer, value, dtype=like_dtype, highlevel=False) | ||
assert full.typetracer.shape == array.shape | ||
assert full.typetracer.dtype == like_dtype or array.dtype | ||
|
||
|
||
def test_full_like_cast(): | ||
with pytest.raises(ValueError): | ||
ak._v2._typetracer.TypeTracerArray.from_array( | ||
[1, ak._v2._typetracer.UnknownScalar(np.uint8)] | ||
) |