Skip to content
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

feat: rename toXXX methods #1919

Merged
merged 2 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions src/awkward/_broadcasting.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,15 +346,15 @@ def apply_step(
isinstance(x, NumpyArray) and x.data.ndim != 1 for x in inputs
):
inputs = [
x.toRegularArray() if isinstance(x, NumpyArray) else x for x in inputs
x.to_RegularArray() if isinstance(x, NumpyArray) else x for x in inputs
]

# Rare that any function would want this, but some do.
if options["regular_to_jagged"] and any(
isinstance(x, RegularArray) for x in inputs
):
inputs = [
x.toListOffsetArray64(False) if isinstance(x, RegularArray) else x
x.to_ListOffsetArray64(False) if isinstance(x, RegularArray) else x
for x in inputs
]

Expand Down Expand Up @@ -405,7 +405,7 @@ def continuation():
# Any EmptyArrays?
if any(isinstance(x, EmptyArray) for x in inputs):
nextinputs = [
x.toNumpyArray(np.float64, nplike) if isinstance(x, EmptyArray) else x
x.to_NumpyArray(np.float64, nplike) if isinstance(x, EmptyArray) else x
for x in inputs
]
return apply_step(
Expand All @@ -422,7 +422,7 @@ def continuation():
# Any NumpyArrays with ndim != 1?
elif any(isinstance(x, NumpyArray) and x.data.ndim != 1 for x in inputs):
nextinputs = [
x.toRegularArray() if isinstance(x, NumpyArray) else x for x in inputs
x.to_RegularArray() if isinstance(x, NumpyArray) else x for x in inputs
]
return apply_step(
nplike,
Expand Down Expand Up @@ -807,14 +807,14 @@ def continuation():

if isinstance(offsets, Index):
return tuple(
ListOffsetArray(offsets, x, parameters=p).toListOffsetArray64(
ListOffsetArray(offsets, x, parameters=p).to_ListOffsetArray64(
False
)
for x, p in zip(outcontent, parameters)
)
elif isinstance(starts, Index) and isinstance(stops, Index):
return tuple(
ListArray(starts, stops, x, parameters=p).toListOffsetArray64(
ListArray(starts, stops, x, parameters=p).to_ListOffsetArray64(
False
)
for x, p in zip(outcontent, parameters)
Expand Down
4 changes: 2 additions & 2 deletions src/awkward/_connect/cling.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,13 @@ class ArrayBuilder {{

def togenerator(form, flatlist_as_rvec):
if isinstance(form, ak.forms.EmptyForm):
return togenerator(form.toNumpyForm(np.dtype(np.float64)), flatlist_as_rvec)
return togenerator(form.to_NumpyForm(np.dtype(np.float64)), flatlist_as_rvec)

elif isinstance(form, ak.forms.NumpyForm):
if len(form.inner_shape) == 0:
return NumpyArrayGenerator.from_form(form, flatlist_as_rvec)
else:
return togenerator(form.toRegularForm(), flatlist_as_rvec)
return togenerator(form.to_RegularForm(), flatlist_as_rvec)

elif isinstance(form, ak.forms.RegularForm):
return RegularArrayGenerator.from_form(form, flatlist_as_rvec)
Expand Down
4 changes: 2 additions & 2 deletions src/awkward/_connect/numba/arrayview.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ def code_to_function(code, function_name, externals=None, debug=False):

def tonumbatype(form):
if isinstance(form, ak.forms.EmptyForm):
return tonumbatype(form.toNumpyForm(np.dtype(np.float64)))
return tonumbatype(form.to_NumpyForm(np.dtype(np.float64)))

elif isinstance(form, ak.forms.NumpyForm):
if len(form.inner_shape) == 0:
return ak._connect.numba.layout.NumpyArrayType.from_form(form)
else:
return tonumbatype(form.toRegularForm())
return tonumbatype(form.to_RegularForm())

elif isinstance(form, ak.forms.RegularForm):
return ak._connect.numba.layout.RegularArrayType.from_form(form)
Expand Down
4 changes: 2 additions & 2 deletions src/awkward/_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ def arrayptr(x):

def tolookup(layout, positions):
if isinstance(layout, ak.contents.EmptyArray):
return tolookup(layout.toNumpyArray(np.dtype(np.float64)), positions)
return tolookup(layout.to_NumpyArray(np.dtype(np.float64)), positions)

elif isinstance(layout, ak.contents.NumpyArray):
if len(layout.shape) == 1:
return NumpyLookup.tolookup(layout, positions)
else:
return tolookup(layout.toRegularArray(), positions)
return tolookup(layout.to_RegularArray(), positions)

elif isinstance(layout, ak.contents.RegularArray):
return RegularLookup.tolookup(layout, positions)
Expand Down
16 changes: 8 additions & 8 deletions src/awkward/_slicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def normalise_item(item, nplike):
return normalise_item(item.layout, nplike)

elif isinstance(item, ak.contents.EmptyArray):
return normalise_item(item.toNumpyArray(np.int64), nplike)
return normalise_item(item.to_NumpyArray(np.int64), nplike)

elif isinstance(item, ak.contents.NumpyArray):
return item.data
Expand Down Expand Up @@ -188,13 +188,13 @@ def normalise_items(where, nplike):
return [normalise_item(x, nplike) for x in where]


def normalise_item_RegularArray_toListOffsetArray64(item):
def normalise_item_RegularArray_to_ListOffsetArray64(item):
if isinstance(item, ak.contents.RegularArray):

next = item.toListOffsetArray64()
next = item.to_ListOffsetArray64()
return ak.contents.ListOffsetArray(
next.offsets,
normalise_item_RegularArray_toListOffsetArray64(next.content),
normalise_item_RegularArray_to_ListOffsetArray64(next.content),
parameters=item.parameters,
)

Expand All @@ -208,7 +208,7 @@ def normalise_item_RegularArray_toListOffsetArray64(item):
def normalise_item_nested(item):
if isinstance(item, ak.contents.EmptyArray):
# policy: unknown -> int
return normalise_item_nested(item.toNumpyArray(np.int64))
return normalise_item_nested(item.to_NumpyArray(np.int64))

elif isinstance(item, ak.contents.NumpyArray) and issubclass(
item.dtype.type, (bool, np.bool_, np.integer)
Expand All @@ -221,8 +221,8 @@ def normalise_item_nested(item):
parameters=item.parameters,
nplike=item.nplike,
)
next = next.toRegularArray()
next = normalise_item_RegularArray_toListOffsetArray64(next)
next = next.to_RegularArray()
next = normalise_item_RegularArray_to_ListOffsetArray64(next)
return next

elif isinstance(
Expand All @@ -243,7 +243,7 @@ def normalise_item_nested(item):
ak.contents.RegularArray,
),
):
next = item.toListOffsetArray64(False)
next = item.to_ListOffsetArray64(False)
return normalise_item_nested(next)

elif isinstance(
Expand Down
4 changes: 2 additions & 2 deletions src/awkward/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ def attach(x):
attach(x.content), x.size, len(x)
)

return attach(data.toRegularArray())
return attach(data.to_RegularArray())

else:
# NumPy's MaskedArray is a ByteMaskedArray with valid_when=False
Expand Down Expand Up @@ -776,7 +776,7 @@ def _impl(array):
return out[: shape[0] * array.size].reshape(shape)

elif isinstance(array, (ak.contents.ListArray, ak.contents.ListOffsetArray)):
return _impl(array.toRegularArray())
return _impl(array.to_RegularArray())

elif isinstance(array, ak.contents.RecordArray):
raise ak._errors.wrap_error(
Expand Down
56 changes: 29 additions & 27 deletions src/awkward/contents/bitmaskedarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def merge_parameters(self, parameters):
self._nplike,
)

def toIndexedOptionArray64(self):
def to_IndexedOptionArray64(self):
index = ak.index.Index64.empty(self._mask.length * 8, self._nplike)
assert index.nplike is self._nplike and self._mask.nplike is self._nplike
self._handle_error(
Expand All @@ -242,7 +242,7 @@ def toIndexedOptionArray64(self):
self._nplike,
)

def toByteMaskedArray(self):
def to_ByteMaskedArray(self):
bytemask = ak.index.Index8.empty(self._mask.length * 8, self._nplike)
assert bytemask.nplike is self._nplike and self._mask.nplike is self._nplike
self._handle_error(
Expand All @@ -266,7 +266,7 @@ def toByteMaskedArray(self):
self._nplike,
)

def toBitMaskedArray(self, valid_when, lsb_order):
def to_BitMaskedArray(self, valid_when, lsb_order):
if lsb_order == self._lsb_order:
if valid_when == self._valid_when:
return self
Expand Down Expand Up @@ -346,7 +346,7 @@ def _getitem_at(self, where):
return None

def _getitem_range(self, where):
return self.toByteMaskedArray()._getitem_range(where)
return self.to_ByteMaskedArray()._getitem_range(where)

def _getitem_field(self, where, only_fields=()):
return BitMaskedArray(
Expand All @@ -372,10 +372,10 @@ def _getitem_fields(self, where, only_fields=()):

def _carry(self, carry, allow_lazy):
assert isinstance(carry, ak.index.Index)
return self.toByteMaskedArray()._carry(carry, allow_lazy)
return self.to_ByteMaskedArray()._carry(carry, allow_lazy)

def _getitem_next_jagged(self, slicestarts, slicestops, slicecontent, tail):
return self.toByteMaskedArray()._getitem_next_jagged(
return self.to_ByteMaskedArray()._getitem_next_jagged(
slicestarts, slicestops, slicecontent, tail
)

Expand All @@ -386,7 +386,7 @@ def _getitem_next(self, head, tail, advanced):
elif isinstance(
head, (int, slice, ak.index.Index64, ak.contents.ListOffsetArray)
):
return self.toByteMaskedArray()._getitem_next(head, tail, advanced)
return self.to_ByteMaskedArray()._getitem_next(head, tail, advanced)

elif isinstance(head, str):
return self._getitem_next_field(head, tail, advanced)
Expand All @@ -407,7 +407,7 @@ def _getitem_next(self, head, tail, advanced):
raise ak._errors.wrap_error(AssertionError(repr(head)))

def project(self, mask=None):
return self.toByteMaskedArray().project(mask)
return self.to_ByteMaskedArray().project(mask)

def simplify_optiontype(self):
if isinstance(
Expand All @@ -420,15 +420,15 @@ def simplify_optiontype(self):
ak.contents.UnmaskedArray,
),
):
return self.toIndexedOptionArray64().simplify_optiontype()
return self.to_IndexedOptionArray64().simplify_optiontype()
else:
return self

def num(self, axis, depth=0):
return self.toByteMaskedArray().num(axis, depth)
return self.to_ByteMaskedArray().num(axis, depth)

def _offsets_and_flattened(self, axis, depth):
return self.toByteMaskedArray._offsets_and_flattened(axis, depth)
return self.to_ByteMaskedArray._offsets_and_flattened(axis, depth)

def _mergeable(self, other, mergebool):
if isinstance(
Expand All @@ -447,44 +447,46 @@ def _mergeable(self, other, mergebool):
return self._content.mergeable(other, mergebool)

def _reverse_merge(self, other):
return self.toIndexedOptionArray64()._reverse_merge(other)
return self.to_IndexedOptionArray64()._reverse_merge(other)

def mergemany(self, others):
if len(others) == 0:
return self

out = self.toIndexedOptionArray64().mergemany(others)
out = self.to_IndexedOptionArray64().mergemany(others)

if all(
isinstance(x, BitMaskedArray)
and x._valid_when == self._valid_when
and x._lsb_order == self._lsb_order
for x in others
):
return out.toBitMaskedArray(self._valid_when, self._lsb_order)
return out.to_BitMaskedArray(self._valid_when, self._lsb_order)
else:
return out

def fill_none(self, value):
return self.toIndexedOptionArray64().fill_none(value)
return self.to_IndexedOptionArray64().fill_none(value)

def _local_index(self, axis, depth):
return self.toByteMaskedArray()._local_index(axis, depth)
return self.to_ByteMaskedArray()._local_index(axis, depth)

def numbers_to_type(self, name):
return self.toByteMaskedArray().numbers_to_type(name)
return self.to_ByteMaskedArray().numbers_to_type(name)

def _is_unique(self, negaxis, starts, parents, outlength):
if self._mask.length == 0:
return True
return self.toIndexedOptionArray64()._is_unique(
return self.to_IndexedOptionArray64()._is_unique(
negaxis, starts, parents, outlength
)

def _unique(self, negaxis, starts, parents, outlength):
if self._mask.length == 0:
return self
out = self.toIndexedOptionArray64()._unique(negaxis, starts, parents, outlength)
out = self.to_IndexedOptionArray64()._unique(
negaxis, starts, parents, outlength
)
if negaxis is None:
return out
else:
Expand All @@ -502,7 +504,7 @@ def _argsort_next(
kind,
order,
):
return self.toIndexedOptionArray64()._argsort_next(
return self.to_IndexedOptionArray64()._argsort_next(
negaxis,
starts,
shifts,
Expand All @@ -517,7 +519,7 @@ def _argsort_next(
def _sort_next(
self, negaxis, starts, parents, outlength, ascending, stable, kind, order
):
return self.toIndexedOptionArray64()._sort_next(
return self.to_IndexedOptionArray64()._sort_next(
negaxis,
starts,
parents,
Expand All @@ -529,7 +531,7 @@ def _sort_next(
)

def _combinations(self, n, replacement, recordlookup, parameters, axis, depth):
return self.toByteMaskedArray()._combinations(
return self.to_ByteMaskedArray()._combinations(
n, replacement, recordlookup, parameters, axis, depth
)

Expand All @@ -545,7 +547,7 @@ def _reduce_next(
keepdims,
behavior,
):
return self.toByteMaskedArray()._reduce_next(
return self.to_ByteMaskedArray()._reduce_next(
reducer,
negaxis,
starts,
Expand Down Expand Up @@ -580,15 +582,15 @@ def _nbytes_part(self):
return self.mask._nbytes_part() + self.content._nbytes_part()

def _pad_none(self, target, axis, depth, clip):
return self.toByteMaskedArray()._pad_none(target, axis, depth, clip)
return self.to_ByteMaskedArray()._pad_none(target, axis, depth, clip)

def _to_arrow(self, pyarrow, mask_node, validbytes, length, options):
return self.toByteMaskedArray()._to_arrow(
return self.to_ByteMaskedArray()._to_arrow(
pyarrow, mask_node, validbytes, length, options
)

def _to_numpy(self, allow_missing):
return self.toByteMaskedArray()._to_numpy(allow_missing)
return self.to_ByteMaskedArray()._to_numpy(allow_missing)

def _completely_flatten(self, nplike, options):
branch, depth = self.branch_depth
Expand Down Expand Up @@ -657,7 +659,7 @@ def continuation():

def packed(self):
if self._content.is_record:
next = self.toIndexedOptionArray64()
next = self.to_IndexedOptionArray64()

content = next._content.packed()
if content.length > self._length:
Expand Down
Loading