METADATA 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. Metadata-Version: 2.1
  2. Name: ordered-set
  3. Version: 4.1.0
  4. Summary: An OrderedSet is a custom MutableSet that remembers its order, so that every
  5. Author-email: Elia Robyn Lake <gh@arborelia.net>
  6. Requires-Python: >=3.7
  7. Description-Content-Type: text/markdown
  8. Classifier: Development Status :: 5 - Production/Stable
  9. Classifier: Intended Audience :: Developers
  10. Classifier: License :: OSI Approved :: MIT License
  11. Classifier: Programming Language :: Python
  12. Classifier: Programming Language :: Python :: 3
  13. Classifier: Programming Language :: Python :: 3.7
  14. Classifier: Programming Language :: Python :: 3.8
  15. Classifier: Programming Language :: Python :: 3.9
  16. Classifier: Programming Language :: Python :: 3.10
  17. Classifier: Programming Language :: Python :: Implementation :: CPython
  18. Classifier: Programming Language :: Python :: Implementation :: PyPy
  19. Requires-Dist: pytest ; extra == "dev"
  20. Requires-Dist: black ; extra == "dev"
  21. Requires-Dist: mypy ; extra == "dev"
  22. Project-URL: Home, https://github.com/rspeer/ordered-set
  23. Provides-Extra: dev
  24. [![Pypi](https://img.shields.io/pypi/v/ordered-set.svg)](https://pypi.python.org/pypi/ordered-set)
  25. An OrderedSet is a mutable data structure that is a hybrid of a list and a set.
  26. It remembers the order of its entries, and every entry has an index number that
  27. can be looked up.
  28. ## Installation
  29. `ordered_set` is available on PyPI and packaged as a wheel. You can list it
  30. as a dependency of your project, in whatever form that takes.
  31. To install it into your current Python environment:
  32. pip install ordered-set
  33. To install the code for development, after checking out the repository:
  34. pip install flit
  35. flit install
  36. ## Usage examples
  37. An OrderedSet is created and used like a set:
  38. >>> from ordered_set import OrderedSet
  39. >>> letters = OrderedSet('abracadabra')
  40. >>> letters
  41. OrderedSet(['a', 'b', 'r', 'c', 'd'])
  42. >>> 'r' in letters
  43. True
  44. It is efficient to find the index of an entry in an OrderedSet, or find an
  45. entry by its index. To help with this use case, the `.add()` method returns
  46. the index of the added item, whether it was already in the set or not.
  47. >>> letters.index('r')
  48. 2
  49. >>> letters[2]
  50. 'r'
  51. >>> letters.add('r')
  52. 2
  53. >>> letters.add('x')
  54. 5
  55. OrderedSets implement the union (`|`), intersection (`&`), and difference (`-`)
  56. operators like sets do.
  57. >>> letters |= OrderedSet('shazam')
  58. >>> letters
  59. OrderedSet(['a', 'b', 'r', 'c', 'd', 'x', 's', 'h', 'z', 'm'])
  60. >>> letters & set('aeiou')
  61. OrderedSet(['a'])
  62. >>> letters -= 'abcd'
  63. >>> letters
  64. OrderedSet(['r', 'x', 's', 'h', 'z', 'm'])
  65. The `__getitem__()` and `index()` methods have been extended to accept any
  66. iterable except a string, returning a list, to perform NumPy-like "fancy
  67. indexing".
  68. >>> letters = OrderedSet('abracadabra')
  69. >>> letters[[0, 2, 3]]
  70. ['a', 'r', 'c']
  71. >>> letters.index(['a', 'r', 'c'])
  72. [0, 2, 3]
  73. OrderedSet implements `__getstate__` and `__setstate__` so it can be pickled,
  74. and implements the abstract base classes `collections.MutableSet` and
  75. `collections.Sequence`.
  76. OrderedSet can be used as a generic collection type, similar to the collections
  77. in the `typing` module like List, Dict, and Set. For example, you can annotate
  78. a variable as having the type `OrderedSet[str]` or `OrderedSet[Tuple[int,
  79. str]]`.
  80. ## OrderedSet in data science applications
  81. An OrderedSet can be used as a bi-directional mapping between a sparse
  82. vocabulary and dense index numbers. As of version 3.1, it accepts NumPy arrays
  83. of index numbers as well as lists.
  84. This combination of features makes OrderedSet a simple implementation of many
  85. of the things that `pandas.Index` is used for, and many of its operations are
  86. faster than the equivalent pandas operations.
  87. For further compatibility with pandas.Index, `get_loc` (the pandas method for
  88. looking up a single index) and `get_indexer` (the pandas method for fancy
  89. indexing in reverse) are both aliases for `index` (which handles both cases
  90. in OrderedSet).
  91. ## Authors
  92. OrderedSet was implemented by Elia Robyn Lake (maiden name: Robyn Speer).
  93. Jon Crall contributed changes and tests to make it fit the Python set API.
  94. Roman Inflianskas added the original type annotations.
  95. ## Comparisons
  96. The original implementation of OrderedSet was a [recipe posted to ActiveState
  97. Recipes][recipe] by Raymond Hettiger, released under the MIT license.
  98. [recipe]: https://code.activestate.com/recipes/576694-orderedset/
  99. Hettiger's implementation kept its content in a doubly-linked list referenced by a
  100. dict. As a result, looking up an item by its index was an O(N) operation, while
  101. deletion was O(1).
  102. This version makes different trade-offs for the sake of efficient lookups. Its
  103. content is a standard Python list instead of a doubly-linked list. This
  104. provides O(1) lookups by index at the expense of O(N) deletion, as well as
  105. slightly faster iteration.
  106. In Python 3.6 and later, the built-in `dict` type is inherently ordered. If you
  107. ignore the dictionary values, that also gives you a simple ordered set, with
  108. fast O(1) insertion, deletion, iteration and membership testing. However, `dict`
  109. does not provide the list-like random access features of OrderedSet. You
  110. would have to convert it to a list in O(N) to look up the index of an entry or
  111. look up an entry by its index.