From e2ee3edb7c0c94ba2dcba9d7d177566af5455a9a Mon Sep 17 00:00:00 2001 From: Ethan-DeBandi99 <16845933+Ethan-DeBandi99@users.noreply.github.com> Date: Wed, 29 Jun 2022 10:53:59 -0400 Subject: [PATCH 1/5] Add .objType and .dtype to Categorical --- arkouda/categorical.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arkouda/categorical.py b/arkouda/categorical.py index ed90ee7860..3c362c79e8 100644 --- a/arkouda/categorical.py +++ b/arkouda/categorical.py @@ -137,6 +137,8 @@ def __init__(self, values, **kwargs) -> None: self.nlevels = self.categories.size self.ndim = self.codes.ndim self.shape = self.codes.shape + self.dtype = np.str_ + self.objType = "Categorical" self.name: Optional[str] = None @classmethod From bb6410c02e41f6ee3d505850fbd3c754d36a2092 Mon Sep 17 00:00:00 2001 From: Ethan-DeBandi99 <16845933+Ethan-DeBandi99@users.noreply.github.com> Date: Wed, 29 Jun 2022 11:29:39 -0400 Subject: [PATCH 2/5] Updating with changes requested by bill. --- arkouda/categorical.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arkouda/categorical.py b/arkouda/categorical.py index 3c362c79e8..4d74578731 100644 --- a/arkouda/categorical.py +++ b/arkouda/categorical.py @@ -19,7 +19,7 @@ from arkouda.dtypes import bool as akbool from arkouda.dtypes import int64 as akint64 -from arkouda.dtypes import int_scalars, resolve_scalar_dtype, str_scalars +from arkouda.dtypes import int_scalars, resolve_scalar_dtype, str_scalars, str_ from arkouda.groupbyclass import GroupBy, unique from arkouda.infoclass import information, list_registry from arkouda.logger import getArkoudaLogger @@ -137,8 +137,8 @@ def __init__(self, values, **kwargs) -> None: self.nlevels = self.categories.size self.ndim = self.codes.ndim self.shape = self.codes.shape - self.dtype = np.str_ - self.objType = "Categorical" + self.dtype = str_ + self.objType = self.__class__.__name__ self.name: Optional[str] = None @classmethod From 69613355b964f20ca6f04247318041c9b1264a20 Mon Sep 17 00:00:00 2001 From: Ethan-DeBandi99 <16845933+Ethan-DeBandi99@users.noreply.github.com> Date: Wed, 29 Jun 2022 12:21:59 -0400 Subject: [PATCH 3/5] Fixing camel case --- arkouda/categorical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arkouda/categorical.py b/arkouda/categorical.py index 4d74578731..29fb5110c1 100644 --- a/arkouda/categorical.py +++ b/arkouda/categorical.py @@ -138,7 +138,7 @@ def __init__(self, values, **kwargs) -> None: self.ndim = self.codes.ndim self.shape = self.codes.shape self.dtype = str_ - self.objType = self.__class__.__name__ + self.objtype = self.__class__.__name__ self.name: Optional[str] = None @classmethod From 1cc3d9b9c910767bd26f88b0d5143048628fc31f Mon Sep 17 00:00:00 2001 From: Ethan-DeBandi99 <16845933+Ethan-DeBandi99@users.noreply.github.com> Date: Wed, 29 Jun 2022 13:42:34 -0400 Subject: [PATCH 4/5] Added decorator for objType. Update category to Categorical for objtype references. --- arkouda/__init__.py | 1 + arkouda/categorical.py | 4 ++-- arkouda/decorators.py | 3 +++ src/AryUtil.chpl | 2 +- src/UniqueMsg.chpl | 4 ++-- tests/categorical_test.py | 6 +++--- 6 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 arkouda/decorators.py diff --git a/arkouda/__init__.py b/arkouda/__init__.py index a6659bf99e..c87dbc1581 100644 --- a/arkouda/__init__.py +++ b/arkouda/__init__.py @@ -9,6 +9,7 @@ from arkouda.client import * from arkouda.client_dtypes import * from arkouda.dtypes import * +from arkouda.decorators import * from arkouda.pdarrayclass import * from arkouda.sorting import * from arkouda.pdarraysetops import * diff --git a/arkouda/categorical.py b/arkouda/categorical.py index 29fb5110c1..14f3e2a5c1 100644 --- a/arkouda/categorical.py +++ b/arkouda/categorical.py @@ -16,6 +16,7 @@ import numpy as np # type: ignore from typeguard import typechecked +from arkouda.decorators import objtypedec from arkouda.dtypes import bool as akbool from arkouda.dtypes import int64 as akint64 @@ -39,6 +40,7 @@ __all__ = ["Categorical"] +@objtypedec class Categorical: """ Represents an array of values belonging to named categories. Converting a @@ -77,7 +79,6 @@ class Categorical: BinOps = frozenset(["==", "!="]) RegisterablePieces = frozenset(["categories", "codes", "permutation", "segments", "_akNAcode"]) RequiredPieces = frozenset(["categories", "codes", "_akNAcode"]) - objtype = "category" permutation = None segments = None @@ -138,7 +139,6 @@ def __init__(self, values, **kwargs) -> None: self.ndim = self.codes.ndim self.shape = self.codes.shape self.dtype = str_ - self.objtype = self.__class__.__name__ self.name: Optional[str] = None @classmethod diff --git a/arkouda/decorators.py b/arkouda/decorators.py new file mode 100644 index 0000000000..3fbdae7ffe --- /dev/null +++ b/arkouda/decorators.py @@ -0,0 +1,3 @@ +def objtypedec(orig_cls): + orig_cls.objtype = orig_cls.__name__ + return orig_cls \ No newline at end of file diff --git a/src/AryUtil.chpl b/src/AryUtil.chpl index fd8eca09d9..7b3101a6b4 100644 --- a/src/AryUtil.chpl +++ b/src/AryUtil.chpl @@ -170,7 +170,7 @@ module AryUtil thisSize = g.size; hasStr = true; } - when "category" { + when "Categorical" { // passed only Categorical.codes.name to be sorted on var g = getGenericTypedArrayEntry(name, st); thisSize = g.size; diff --git a/src/UniqueMsg.chpl b/src/UniqueMsg.chpl index e1110ff21f..fa85c03c27 100644 --- a/src/UniqueMsg.chpl +++ b/src/UniqueMsg.chpl @@ -118,7 +118,7 @@ module UniqueMsg for (name, objtype, i) in zip(names, types, 0..) { var newName = st.nextName(); select objtype { - when "pdarray", "category" { + when "pdarray", "Categorical" { var g = getGenericTypedArrayEntry(name, st); // Gathers unique values, stores in SymTab, and returns repMsg chunk proc gatherHelper(type t) throws { @@ -239,7 +239,7 @@ module UniqueMsg } for (name, objtype, i) in zip(names, types, 0..) { select objtype { - when "pdarray", "category" { + when "pdarray", "Categorical" { var g = getGenericTypedArrayEntry(name, st); select g.dtype { when DType.Int64 { diff --git a/tests/categorical_test.py b/tests/categorical_test.py index 1a73b85170..5a83834ce9 100644 --- a/tests/categorical_test.py +++ b/tests/categorical_test.py @@ -64,7 +64,7 @@ def testBaseCategorical(self): ).all() ) self.assertEqual(10, cat.size) - self.assertEqual("category", cat.objtype) + self.assertEqual("Categorical", cat.objtype) with self.assertRaises(ValueError): ak.Categorical(ak.arange(0, 5, 10)) @@ -229,7 +229,7 @@ def testConcatenate(self): catTwo = self._getCategorical("string-two", 51) resultCat = catOne.concatenate([catTwo]) - self.assertEqual("category", resultCat.objtype) + self.assertEqual("Categorical", resultCat.objtype) self.assertIsInstance(resultCat, ak.Categorical) self.assertEqual(100, resultCat.size) @@ -239,7 +239,7 @@ def testConcatenate(self): self.assertFalse(resultCat.segments) resultCat = ak.concatenate([catOne, catOne], ordered=False) - self.assertEqual("category", resultCat.objtype) + self.assertEqual("Categorical", resultCat.objtype) self.assertIsInstance(resultCat, ak.Categorical) self.assertEqual(100, resultCat.size) From 2d5409dc3c68387834f284f2daa10cb238a2be09 Mon Sep 17 00:00:00 2001 From: Ethan-DeBandi99 <16845933+Ethan-DeBandi99@users.noreply.github.com> Date: Wed, 29 Jun 2022 13:51:40 -0400 Subject: [PATCH 5/5] Added objtype property def for mypy. Ran formatting on decorators. --- arkouda/categorical.py | 4 ++++ arkouda/decorators.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/arkouda/categorical.py b/arkouda/categorical.py index 14f3e2a5c1..4d9f799450 100644 --- a/arkouda/categorical.py +++ b/arkouda/categorical.py @@ -141,6 +141,10 @@ def __init__(self, values, **kwargs) -> None: self.dtype = str_ self.name: Optional[str] = None + @property + def objtype(self): + return self.objtype + @classmethod @typechecked def from_codes( diff --git a/arkouda/decorators.py b/arkouda/decorators.py index 3fbdae7ffe..08a9cfec12 100644 --- a/arkouda/decorators.py +++ b/arkouda/decorators.py @@ -1,3 +1,3 @@ def objtypedec(orig_cls): orig_cls.objtype = orig_cls.__name__ - return orig_cls \ No newline at end of file + return orig_cls