def test_categorical_from_codes_registration_suite(self): """ Test register, is_registered, attach, unregister, unregister_categorical_by_name for Categorical made using .from_codes """ cleanup() # Make sure we start with a clean registry categories = ak.array(['a', 'b', 'c']) codes = ak.array([0, 1, 0, 2, 1]) cat = ak.Categorical.from_codes(codes, categories) self.assertFalse(cat.is_registered(), "test_me should be unregistered") self.assertTrue( cat.register("test_me").is_registered(), "test_me categorical should be registered") cat = None # Should trigger destructor, but survive server deletion because it is registered self.assertTrue(cat is None, "The reference to `c` should be None") cat = ak.Categorical.attach("test_me") self.assertTrue( cat.is_registered(), "test_me categorical should be registered after attach") cat.unregister() self.assertFalse(cat.is_registered(), "test_me should be unregistered") self.assertTrue( cat.register("another_name").name == "another_name" and cat.is_registered()) # Test static unregister_by_name ak.Categorical.unregister_categorical_by_name("another_name") self.assertFalse(cat.is_registered(), "another_name should be unregistered") # now mess with the subcomponents directly to test is_registered mis-match logic cat.register("another_name") unregister_pdarray_by_name("another_name.codes") with pytest.raises(RegistrationError): cat.is_registered()
def test_categorical_registration_suite(self): """ Test register, is_registered, attach, unregister, unregister_categorical_by_name """ cleanup() # Make sure we start with a clean registry c = ak.Categorical(ak.array([f"my_cat {i}" for i in range(1, 11)])) self.assertFalse(c.is_registered(), "test_me should be unregistered") self.assertTrue( c.register("test_me").is_registered(), "test_me categorical should be registered") c = None # Should trigger destructor, but survive server deletion because it is registered self.assertTrue(c is None, "The reference to `c` should be None") c = ak.Categorical.attach("test_me") self.assertTrue( c.is_registered(), "test_me categorical should be registered after attach") c.unregister() self.assertFalse(c.is_registered(), "test_me should be unregistered") self.assertTrue( c.register("another_name").name == "another_name" and c.is_registered()) # Test static unregister_by_name ak.Categorical.unregister_categorical_by_name("another_name") self.assertFalse(c.is_registered(), "another_name should be unregistered") # now mess with the subcomponents directly to test is_registered mis-match logic c.register("another_name") unregister_pdarray_by_name("another_name.codes") with pytest.raises(RegistrationError): c.is_registered()
def unregister_strings_by_name(user_defined_name: str) -> None: """ Unregister a Strings object in the arkouda server previously registered via register() Parameters ---------- user_defined_name : str The registered name of the Strings object See also -------- register, unregister, attach, is_registered """ unregister_pdarray_by_name(f"{user_defined_name}.bytes") unregister_pdarray_by_name(f"{user_defined_name}.offsets")
def unregister_categorical_by_name(user_defined_name: str) -> None: """ Function to unregister Categorical object by name which was registered with the arkouda server via register() Parameters ---------- user_defined_name : str Name under which the Categorical object was registered Raises ------- TypeError if user_defined_name is not a string RegistrationError if there is an issue attempting to unregister any underlying components See Also -------- register, unregister, attach, is_registered """ # We have 4 subcomponents, unregister each of them Strings.unregister_strings_by_name(f"{user_defined_name}.categories") unregister_pdarray_by_name(f"{user_defined_name}.codes") # Unregister optional pieces only if they are contained in the registry registry = list_registry() if f"{user_defined_name}.permutation" in registry: unregister_pdarray_by_name(f"{user_defined_name}.permutation") if f"{user_defined_name}.segments" in registry: unregister_pdarray_by_name(f"{user_defined_name}.segments")