Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #100
This pull request focuses on refactoring and optimizing the
Enum
class in theenum.py
module. The main goals of this PR are to improve code clarity, performance, and maintainability.Key changes:
Added docstrings:
__init__
method to explain its purpose and how the index is assigned to each Enum item.encode
method to provide a clear explanation of its functionality, arguments, return value, and examples of usage.Simplified method assignments:
__eq__
and__hash__
method assignments by directly assigning them to the corresponding methods ofobject
.Optimized
encode
method:.astype(ENUM_ARRAY_DTYPE)
call at the end of the method, applying it to theindices
array before creating theEnumArray
.np.select()
instead of separate branches forbytes
and non-bytes
cases.ValueError
with a clear error message for unsupported array data types.Updated type hints:
array
parameter in theencode
method to usenp.ndarray
instead of specific data types likenp.int_
,np.float_
, andnp.object_
.Improved comments:
Removed unnecessary code:
warnings
import and thewarnings.simplefilter()
call since they are not directly related to the functionality of theEnum
class, and other changes should remove the warnings.These improvements aim to make the
Enum
class more readable, efficient, and maintainable. The added docstrings and comments provide better documentation and understanding of the code, while the optimized operations and simplified code structure enhance its performance and clarity.The consolidation of the
.astype(ENUM_ARRAY_DTYPE)
call at the end of theencode
method reduces code duplication and improves readability. The simplified code for handling enum items arrays usingnp.select()
makes the code more concise and easier to understand.Please review the changes and provide any feedback or suggestions for further improvements.