ordered-set


Nameordered-set JSON
Version 4.1.0 PyPI version JSON
download
home_page
SummaryAn OrderedSet is a custom MutableSet that remembers its order, so that every
upload_time2022-01-26 14:38:56
maintainer
docs_urlNone
author
requires_python>=3.7
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            [![Pypi](https://img.shields.io/pypi/v/ordered-set.svg)](https://pypi.python.org/pypi/ordered-set)

An OrderedSet is a mutable data structure that is a hybrid of a list and a set.
It remembers the order of its entries, and every entry has an index number that
can be looked up.

## Installation

`ordered_set` is available on PyPI and packaged as a wheel. You can list it
as a dependency of your project, in whatever form that takes.

To install it into your current Python environment:

    pip install ordered-set

To install the code for development, after checking out the repository:

    pip install flit
    flit install

## Usage examples

An OrderedSet is created and used like a set:

    >>> from ordered_set import OrderedSet

    >>> letters = OrderedSet('abracadabra')

    >>> letters
    OrderedSet(['a', 'b', 'r', 'c', 'd'])

    >>> 'r' in letters
    True

It is efficient to find the index of an entry in an OrderedSet, or find an
entry by its index. To help with this use case, the `.add()` method returns
the index of the added item, whether it was already in the set or not.

    >>> letters.index('r')
    2

    >>> letters[2]
    'r'

    >>> letters.add('r')
    2

    >>> letters.add('x')
    5

OrderedSets implement the union (`|`), intersection (`&`), and difference (`-`)
operators like sets do.

    >>> letters |= OrderedSet('shazam')

    >>> letters
    OrderedSet(['a', 'b', 'r', 'c', 'd', 'x', 's', 'h', 'z', 'm'])

    >>> letters & set('aeiou')
    OrderedSet(['a'])

    >>> letters -= 'abcd'

    >>> letters
    OrderedSet(['r', 'x', 's', 'h', 'z', 'm'])

The `__getitem__()` and `index()` methods have been extended to accept any
iterable except a string, returning a list, to perform NumPy-like "fancy
indexing".

    >>> letters = OrderedSet('abracadabra')

    >>> letters[[0, 2, 3]]
    ['a', 'r', 'c']

    >>> letters.index(['a', 'r', 'c'])
    [0, 2, 3]

OrderedSet implements `__getstate__` and `__setstate__` so it can be pickled,
and implements the abstract base classes `collections.MutableSet` and
`collections.Sequence`.

OrderedSet can be used as a generic collection type, similar to the collections
in the `typing` module like List, Dict, and Set. For example, you can annotate
a variable as having the type `OrderedSet[str]` or `OrderedSet[Tuple[int,
str]]`.


## OrderedSet in data science applications

An OrderedSet can be used as a bi-directional mapping between a sparse
vocabulary and dense index numbers. As of version 3.1, it accepts NumPy arrays
of index numbers as well as lists.

This combination of features makes OrderedSet a simple implementation of many
of the things that `pandas.Index` is used for, and many of its operations are
faster than the equivalent pandas operations.

For further compatibility with pandas.Index, `get_loc` (the pandas method for
looking up a single index) and `get_indexer` (the pandas method for fancy
indexing in reverse) are both aliases for `index` (which handles both cases
in OrderedSet).


## Authors

OrderedSet was implemented by Elia Robyn Lake (maiden name: Robyn Speer).
Jon Crall contributed changes and tests to make it fit the Python set API.
Roman Inflianskas added the original type annotations.


## Comparisons

The original implementation of OrderedSet was a [recipe posted to ActiveState
Recipes][recipe] by Raymond Hettiger, released under the MIT license.

[recipe]: https://code.activestate.com/recipes/576694-orderedset/

Hettiger's implementation kept its content in a doubly-linked list referenced by a
dict. As a result, looking up an item by its index was an O(N) operation, while
deletion was O(1).

This version makes different trade-offs for the sake of efficient lookups. Its
content is a standard Python list instead of a doubly-linked list. This
provides O(1) lookups by index at the expense of O(N) deletion, as well as
slightly faster iteration.

In Python 3.6 and later, the built-in `dict` type is inherently ordered. If you
ignore the dictionary values, that also gives you a simple ordered set, with
fast O(1) insertion, deletion, iteration and membership testing. However, `dict`
does not provide the list-like random access features of OrderedSet. You
would have to convert it to a list in O(N) to look up the index of an entry or
look up an entry by its index.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "ordered-set",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "",
    "author_email": "Elia Robyn Lake <gh@arborelia.net>",
    "download_url": "https://files.pythonhosted.org/packages/4c/ca/bfac8bc689799bcca4157e0e0ced07e70ce125193fc2e166d2e685b7e2fe/ordered-set-4.1.0.tar.gz",
    "platform": "",
    "description": "[![Pypi](https://img.shields.io/pypi/v/ordered-set.svg)](https://pypi.python.org/pypi/ordered-set)\n\nAn OrderedSet is a mutable data structure that is a hybrid of a list and a set.\nIt remembers the order of its entries, and every entry has an index number that\ncan be looked up.\n\n## Installation\n\n`ordered_set` is available on PyPI and packaged as a wheel. You can list it\nas a dependency of your project, in whatever form that takes.\n\nTo install it into your current Python environment:\n\n    pip install ordered-set\n\nTo install the code for development, after checking out the repository:\n\n    pip install flit\n    flit install\n\n## Usage examples\n\nAn OrderedSet is created and used like a set:\n\n    >>> from ordered_set import OrderedSet\n\n    >>> letters = OrderedSet('abracadabra')\n\n    >>> letters\n    OrderedSet(['a', 'b', 'r', 'c', 'd'])\n\n    >>> 'r' in letters\n    True\n\nIt is efficient to find the index of an entry in an OrderedSet, or find an\nentry by its index. To help with this use case, the `.add()` method returns\nthe index of the added item, whether it was already in the set or not.\n\n    >>> letters.index('r')\n    2\n\n    >>> letters[2]\n    'r'\n\n    >>> letters.add('r')\n    2\n\n    >>> letters.add('x')\n    5\n\nOrderedSets implement the union (`|`), intersection (`&`), and difference (`-`)\noperators like sets do.\n\n    >>> letters |= OrderedSet('shazam')\n\n    >>> letters\n    OrderedSet(['a', 'b', 'r', 'c', 'd', 'x', 's', 'h', 'z', 'm'])\n\n    >>> letters & set('aeiou')\n    OrderedSet(['a'])\n\n    >>> letters -= 'abcd'\n\n    >>> letters\n    OrderedSet(['r', 'x', 's', 'h', 'z', 'm'])\n\nThe `__getitem__()` and `index()` methods have been extended to accept any\niterable except a string, returning a list, to perform NumPy-like \"fancy\nindexing\".\n\n    >>> letters = OrderedSet('abracadabra')\n\n    >>> letters[[0, 2, 3]]\n    ['a', 'r', 'c']\n\n    >>> letters.index(['a', 'r', 'c'])\n    [0, 2, 3]\n\nOrderedSet implements `__getstate__` and `__setstate__` so it can be pickled,\nand implements the abstract base classes `collections.MutableSet` and\n`collections.Sequence`.\n\nOrderedSet can be used as a generic collection type, similar to the collections\nin the `typing` module like List, Dict, and Set. For example, you can annotate\na variable as having the type `OrderedSet[str]` or `OrderedSet[Tuple[int,\nstr]]`.\n\n\n## OrderedSet in data science applications\n\nAn OrderedSet can be used as a bi-directional mapping between a sparse\nvocabulary and dense index numbers. As of version 3.1, it accepts NumPy arrays\nof index numbers as well as lists.\n\nThis combination of features makes OrderedSet a simple implementation of many\nof the things that `pandas.Index` is used for, and many of its operations are\nfaster than the equivalent pandas operations.\n\nFor further compatibility with pandas.Index, `get_loc` (the pandas method for\nlooking up a single index) and `get_indexer` (the pandas method for fancy\nindexing in reverse) are both aliases for `index` (which handles both cases\nin OrderedSet).\n\n\n## Authors\n\nOrderedSet was implemented by Elia Robyn Lake (maiden name: Robyn Speer).\nJon Crall contributed changes and tests to make it fit the Python set API.\nRoman Inflianskas added the original type annotations.\n\n\n## Comparisons\n\nThe original implementation of OrderedSet was a [recipe posted to ActiveState\nRecipes][recipe] by Raymond Hettiger, released under the MIT license.\n\n[recipe]: https://code.activestate.com/recipes/576694-orderedset/\n\nHettiger's implementation kept its content in a doubly-linked list referenced by a\ndict. As a result, looking up an item by its index was an O(N) operation, while\ndeletion was O(1).\n\nThis version makes different trade-offs for the sake of efficient lookups. Its\ncontent is a standard Python list instead of a doubly-linked list. This\nprovides O(1) lookups by index at the expense of O(N) deletion, as well as\nslightly faster iteration.\n\nIn Python 3.6 and later, the built-in `dict` type is inherently ordered. If you\nignore the dictionary values, that also gives you a simple ordered set, with\nfast O(1) insertion, deletion, iteration and membership testing. However, `dict`\ndoes not provide the list-like random access features of OrderedSet. You\nwould have to convert it to a list in O(N) to look up the index of an entry or\nlook up an entry by its index.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "An OrderedSet is a custom MutableSet that remembers its order, so that every",
    "version": "4.1.0",
    "project_urls": {
        "Home": "https://github.com/rspeer/ordered-set"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3355af02708f230eb77084a299d7b08175cff006dea4f2721074b92cdb0296c0",
                "md5": "6db93c545cdb9548e7a1130ebbf80da7",
                "sha256": "046e1132c71fcf3330438a539928932caf51ddbc582496833e23de611de14562"
            },
            "downloads": -1,
            "filename": "ordered_set-4.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6db93c545cdb9548e7a1130ebbf80da7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 7634,
            "upload_time": "2022-01-26T14:38:48",
            "upload_time_iso_8601": "2022-01-26T14:38:48.677482Z",
            "url": "https://files.pythonhosted.org/packages/33/55/af02708f230eb77084a299d7b08175cff006dea4f2721074b92cdb0296c0/ordered_set-4.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4ccabfac8bc689799bcca4157e0e0ced07e70ce125193fc2e166d2e685b7e2fe",
                "md5": "2a9ba8d1a962c26f9a4fbe246b62ee77",
                "sha256": "694a8e44c87657c59292ede72891eb91d34131f6531463aab3009191c77364a8"
            },
            "downloads": -1,
            "filename": "ordered-set-4.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "2a9ba8d1a962c26f9a4fbe246b62ee77",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 12826,
            "upload_time": "2022-01-26T14:38:56",
            "upload_time_iso_8601": "2022-01-26T14:38:56.600833Z",
            "url": "https://files.pythonhosted.org/packages/4c/ca/bfac8bc689799bcca4157e0e0ced07e70ce125193fc2e166d2e685b7e2fe/ordered-set-4.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-01-26 14:38:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rspeer",
    "github_project": "ordered-set",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": false,
    "tox": true,
    "lcname": "ordered-set"
}
        
Elapsed time: 0.43142s