Skip to content

feat: add ak.enforce_type #2365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 62 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
ee71a63
feat: add `ak.enforce_type`
agoose77 Apr 5, 2023
36b4096
test: add tests
agoose77 Apr 5, 2023
de75076
test: fix argument order
agoose77 Apr 6, 2023
9f78323
feat: add removal of option!
agoose77 Apr 6, 2023
cec1b0b
feat: add option to keep type parameters
agoose77 Apr 6, 2023
6250dac
refactor: use independent `recurse_` functions
agoose77 Apr 24, 2023
ec5e442
test: add more test cases
agoose77 Apr 25, 2023
aff262c
feat!: don't permute for recordarrays
agoose77 Apr 25, 2023
5052110
feat!: make union conversions stricter
agoose77 Apr 25, 2023
ef13fa8
refactor: drop closure abstraction
agoose77 Apr 25, 2023
1246880
fix: check metadata in layout equality
agoose77 Apr 25, 2023
f91ead1
fix: allow unions to be unconverted
agoose77 Apr 25, 2023
63f73df
fix: Python 3.7's sum doesn't accept kwargs
agoose77 Apr 25, 2023
b8d606e
style: pre-commit fixes
pre-commit-ci[bot] Apr 25, 2023
65fd2f2
feat: don't project indexed types if type matches
agoose77 Apr 25, 2023
79a6747
misc fixes
agoose77 Apr 26, 2023
6ad56a7
feat: convert between strings and char arrays
agoose77 Apr 27, 2023
fac894b
feat: support changing record lengths
agoose77 Apr 27, 2023
fd8f0c8
refactor: rename `layout_equal_type`
agoose77 Apr 27, 2023
108aa2c
refactor: change error types
agoose77 Apr 28, 2023
7f87d36
refactor: simplify record handling
agoose77 Apr 28, 2023
eb444bb
fix: recurse into all contents, even if same type!
agoose77 Apr 28, 2023
93723e3
fix: pack option only for one level
agoose77 Apr 28, 2023
7bab81d
fix: only project option if content type changes
agoose77 Apr 28, 2023
f4552bd
fix: more packing work!
agoose77 Apr 28, 2023
537ae8d
refactor: make all functions private
agoose77 Apr 28, 2023
2e17d17
refactor: rename function
agoose77 Apr 28, 2023
9ce138a
Fix: invert condition
agoose77 May 3, 2023
038646b
refactor: cleanups
agoose77 May 3, 2023
1e27ae9
wip: work on documentation
agoose77 May 3, 2023
8dc7a86
docs: add to toctree
agoose77 May 3, 2023
d930499
Merge branch 'main' into agoose77/feat-enforce-type
agoose77 May 3, 2023
c8c1b63
docs: clean-up docstring
agoose77 May 3, 2023
96042c8
docs: small change
agoose77 May 3, 2023
ff13277
fix: correct record (todo: add test with different fields)
agoose77 May 3, 2023
652926c
fix: regular is also list!
agoose77 May 3, 2023
3be994c
feat: add projection mode
agoose77 May 3, 2023
fc02b12
docs: update docstrings
agoose77 May 3, 2023
06f9edd
test: add tests for new behavior
agoose77 May 3, 2023
41d2512
docs: fix docstring formatting
agoose77 May 3, 2023
434bdda
docs: fix formatting
agoose77 May 3, 2023
4bb9346
docs: small formatting change
agoose77 May 3, 2023
e812fda
docs: small internal notice
agoose77 May 3, 2023
b8c2dc6
fix: support converting 0-length lists to sized regular
agoose77 May 4, 2023
e122a99
refactor: pull out index_nplike
agoose77 May 4, 2023
3354ff2
feat: detect projection automatically
agoose77 May 4, 2023
fe99aca
refactor: drop single-use helper functions
agoose77 May 4, 2023
737ded3
refactor: simplify branches
agoose77 May 4, 2023
1fd2914
test: ensure indexing works properly
agoose77 May 4, 2023
b54e1cb
docs: clarify when projection vs conversion is used
agoose77 May 4, 2023
8b4895f
fix: add note about high level types
agoose77 May 4, 2023
44fef06
test: add scalar test
agoose77 May 4, 2023
e887810
refactor: move functions around
agoose77 May 4, 2023
5980afc
fix: only operate on part of array used for records
agoose77 May 4, 2023
b1c1917
fix: take parameters from `_parameters`
agoose77 May 4, 2023
72cf08c
fix: take parameters from `_parameters`
agoose77 May 4, 2023
1a32ee7
docs: expand on docstrings
agoose77 May 4, 2023
09a1b04
fix: catch bug with packing
agoose77 May 5, 2023
fec5950
test: check packing of indexed
agoose77 May 5, 2023
ff5fa81
fix: preserve field order
agoose77 May 5, 2023
bb768d8
test: check _exact_ layouts
agoose77 May 5, 2023
f8dd513
docs: fix docstring
agoose77 May 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/reference/toctree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
.. toctree::
:caption: Value and type conversions

generated/ak.enforce_type
generated/ak.nan_to_none
generated/ak.nan_to_num
generated/ak.values_astype
Expand Down
21 changes: 12 additions & 9 deletions src/awkward/forms/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,11 @@ def from_type(type_: ak.types.Type) -> Form:
# Categorical types are reintroduced into forms using metadata
if type_.parameter("__categorical__"):
# Drop categorical placeholder parameter
next_parameters = type_.parameters.copy()
next_parameters.pop("__categorical__")
if type_._parameters is None:
next_parameters = None
else:
next_parameters = type_._parameters.copy()
next_parameters.pop("__categorical__")

if isinstance(type_, ak.types.OptionType):
next_content = from_type(type_.content)
Expand All @@ -206,38 +209,38 @@ def from_type(type_: ak.types.Type) -> Form:
)

if isinstance(type_, ak.types.NumpyType):
return ak.forms.NumpyForm(type_.primitive, parameters=type_.parameters)
return ak.forms.NumpyForm(type_.primitive, parameters=type_._parameters)
elif isinstance(type_, ak.types.ListType):
return ak.forms.ListOffsetForm(
"i64", from_type(type_.content), parameters=type_.parameters
"i64", from_type(type_.content), parameters=type_._parameters
)
elif isinstance(type_, ak.types.RegularType):
return ak.forms.RegularForm(
from_type(type_.content),
size=type_.size,
parameters=type_.parameters,
parameters=type_._parameters,
)
elif isinstance(type_, ak.types.OptionType):
return ak.forms.IndexedOptionForm(
"i64",
from_type(type_.content),
parameters=type_.parameters,
parameters=type_._parameters,
)
elif isinstance(type_, ak.types.RecordType):
return ak.forms.RecordForm(
[from_type(c) for c in type_.contents],
type_.fields,
parameters=type_.parameters,
parameters=type_._parameters,
)
elif isinstance(type_, ak.types.UnionType):
return ak.forms.UnionForm(
"i8",
"i64",
[from_type(c) for c in type_.contents],
parameters=type_.parameters,
parameters=type_._parameters,
)
elif isinstance(type_, ak.types.UnknownType):
return ak.forms.EmptyForm(parameters=type_.parameters)
return ak.forms.EmptyForm(parameters=type_._parameters)
elif isinstance(type_, (ak.types.ArrayType, ak.types.ScalarType)):
raise TypeError(
"High-level types (ak.types.ArrayType, ak.types.ScalarType) do not have representations as Awkward forms. "
Expand Down
1 change: 1 addition & 0 deletions src/awkward/operations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from awkward.operations.ak_count_nonzero import *
from awkward.operations.ak_covar import *
from awkward.operations.ak_drop_none import *
from awkward.operations.ak_enforce_type import *
from awkward.operations.ak_fields import *
from awkward.operations.ak_fill_none import *
from awkward.operations.ak_firsts import *
Expand Down
Loading