Tags¶
You can start using the Tags entity by running the following import statement:
Below we have the most common attributes used in the Tags entity:
min_size: The minimum size of each individual tag. Default is 1.
max_size: The maximum size of each individual tag. Default is 252.
Creating a Tag instance¶
For creating a new Tag instance and starting using, we can use the following piece of code:
Min Size¶
The min_size attribute is used to set the minimum size of each individual tag. By default, the minimum size is 1. If we want to change it, we can do it as follows:
Let's try to add a tag with less than 2 characters:
Max Size¶
The max_size attribute is used to set the maximum size of each individual tag. By default, the maximum size is 252. If we want to change it, we can do it as follows:
Let's try to add a tag with more than 5 characters:
Now, let's understand below the append() method along with a few other methods that can be used to manipulate the tags.
Adding new tags¶
The append() method is used in order to add new tags to our tag instance:
Keep in mind that the append() method only accepts a single tag as an argument, which can be a string, integer, or float. If you want to add multiple tags at once, you can use the extend() method.
Extending tags¶
There is also the possibility of adding multiple tags at once on a list format by using the extend method:
Inserting a tag at some index¶
To add a specific tag at a certain index, we can make use of the insert method:
Lets continue with our previous tag instance, now let's say that we want to add a new tag at the beginning of our tags list:
Unifying Tags¶
The unify() static method merges two tag sources — typically an overwrite value and an existing entity's tags — into a single Tags instance. If the overwrite is provided it takes precedence; otherwise the existing tags are kept:
existing_tags = Tags(['equity', 'risk'])
overwrite_tags = Tags(['bond'])
Tags.unify(overwrite_tags, existing_tags)
# Tags(['bond'])
# When overwrite is empty, existing tags are preserved
Tags.unify(Tags(), existing_tags)
# Tags(['equity', 'risk'])
This is the standard pattern used by modifier workers when applying partial updates to an entity's tags.