Skip to content

Commit

Permalink
Adds arkouda.testing module (#3186)
Browse files Browse the repository at this point in the history
Co-authored-by: Amanda Potts <ajpotts@users.noreply.github.com>
  • Loading branch information
ajpotts and ajpotts authored Jun 26, 2024
1 parent 2ac5a23 commit dd9524f
Show file tree
Hide file tree
Showing 8 changed files with 1,847 additions and 42 deletions.
607 changes: 607 additions & 0 deletions PROTO_tests/tests/testing/asserters_test.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions arkouda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@
from arkouda.scipy.special import *
from arkouda.scipy import *
from arkouda.random import *
from arkouda.testing import *
84 changes: 51 additions & 33 deletions arkouda/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2922,19 +2922,27 @@ def _to_hdf_snapshot(self, path, dataset="DataFrame", mode="truncate", file_type
from arkouda.io import _file_type_to_int, _mode_str_to_int

column_data = [
obj.name
if not isinstance(obj, (Categorical_, SegArray))
else json.dumps(
{
"codes": obj.codes.name,
"categories": obj.categories.name,
"NA_codes": obj._akNAcode.name,
**({"permutation": obj.permutation.name} if obj.permutation is not None else {}),
**({"segments": obj.segments.name} if obj.segments is not None else {}),
}
(
obj.name
if not isinstance(obj, (Categorical_, SegArray))
else (
json.dumps(
{
"codes": obj.codes.name,
"categories": obj.categories.name,
"NA_codes": obj._akNAcode.name,
**(
{"permutation": obj.permutation.name}
if obj.permutation is not None
else {}
),
**({"segments": obj.segments.name} if obj.segments is not None else {}),
}
)
if isinstance(obj, Categorical_)
else json.dumps({"segments": obj.segments.name, "values": obj.values.name})
)
)
if isinstance(obj, Categorical_)
else json.dumps({"segments": obj.segments.name, "values": obj.values.name})
for k, obj in self.items()
]
dtypes = [
Expand Down Expand Up @@ -3900,7 +3908,7 @@ def copy(self, deep=True):
"""

if deep:
if deep is True:
res = DataFrame()
res._size = self._nrows
res._bytes = self._bytes
Expand Down Expand Up @@ -5015,26 +5023,36 @@ def register(self, user_defined_name: str) -> DataFrame:
if self.registered_name is not None and self.is_registered():
raise RegistrationError(f"This object is already registered as {self.registered_name}")
column_data = [
obj.name
if not isinstance(obj, (Categorical_, SegArray, BitVector))
else json.dumps(
{
"codes": obj.codes.name,
"categories": obj.categories.name,
"NA_codes": obj._akNAcode.name,
**({"permutation": obj.permutation.name} if obj.permutation is not None else {}),
**({"segments": obj.segments.name} if obj.segments is not None else {}),
}
)
if isinstance(obj, Categorical_)
else json.dumps({"segments": obj.segments.name, "values": obj.values.name})
if isinstance(obj, SegArray)
else json.dumps(
{
"name": obj.name,
"width": obj.width,
"reverse": obj.reverse,
} # BitVector Case
(
obj.name
if not isinstance(obj, (Categorical_, SegArray, BitVector))
else (
json.dumps(
{
"codes": obj.codes.name,
"categories": obj.categories.name,
"NA_codes": obj._akNAcode.name,
**(
{"permutation": obj.permutation.name}
if obj.permutation is not None
else {}
),
**({"segments": obj.segments.name} if obj.segments is not None else {}),
}
)
if isinstance(obj, Categorical_)
else (
json.dumps({"segments": obj.segments.name, "values": obj.values.name})
if isinstance(obj, SegArray)
else json.dumps(
{
"name": obj.name,
"width": obj.width,
"reverse": obj.reverse,
} # BitVector Case
)
)
)
)
for obj in self.values()
]
Expand Down
15 changes: 8 additions & 7 deletions arkouda/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,7 @@ def index(self):
def nlevels(self) -> int:
"""
Integer number of levels in this MultiIndex.
See Also
--------
Index.nlevels
Expand All @@ -1131,6 +1132,13 @@ def ndim(self):
def inferred_type(self) -> str:
return "mixed"

@property
def dtype(self) -> npdtype:
"""
Return the dtype object of the underlying data.
"""
return npdtype("O")

def get_level_values(self, level: Union[str, int]):
if isinstance(level, str):
if self.names is None:
Expand All @@ -1153,13 +1161,6 @@ def get_level_values(self, level: Union[str, int]):
"an integer with absolute value less than the number of levels."
)

@property
def dtype(self) -> npdtype:
"""
Return the dtype object of the underlying data.
"""
return npdtype("O")

def equal_levels(self, other: MultiIndex) -> builtins.bool:
"""
Return True if the levels of both MultiIndex objects are the same
Expand Down
37 changes: 37 additions & 0 deletions arkouda/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from ._asserters import (
assert_almost_equal,
assert_arkouda_array_equal,
assert_arkouda_pdarray_equal,
assert_arkouda_segarray_equal,
assert_arkouda_strings_equal,
assert_attr_equal,
assert_categorical_equal,
assert_class_equal,
assert_contains_all,
assert_copy,
assert_dict_equal,
assert_equal,
assert_frame_equal,
assert_index_equal,
assert_is_sorted,
assert_series_equal,
)

__all__ = [
"assert_almost_equal",
"assert_arkouda_array_equal",
"assert_arkouda_pdarray_equal",
"assert_arkouda_segarray_equal",
"assert_arkouda_strings_equal",
"assert_attr_equal",
"assert_categorical_equal",
"assert_class_equal",
"assert_contains_all",
"assert_copy",
"assert_dict_equal",
"assert_equal",
"assert_frame_equal",
"assert_index_equal",
"assert_is_sorted",
"assert_series_equal",
]
Loading

0 comments on commit dd9524f

Please sign in to comment.