pytups


Namepytups JSON
Version 0.88.1 PyPI version JSON
download
home_pagehttps://github.com/pchtsp/pytups
Summarydata wrangling for lists of tuples and dictionaries
upload_time2024-05-15 15:31:13
maintainerFranco Peschiera
docs_urlNone
authorFranco Peschiera
requires_pythonNone
licenseNone
keywords super dict dictionary tuple list math pulp
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            Pytups
**************************
.. image:: https://img.shields.io/pypi/v/pytups.svg
    :target: https://pypi.org/project/pytups/
.. image:: https://img.shields.io/pypi/l/pytups.svg
    :target: https://pypi.org/project/pytups/
.. image:: https://img.shields.io/pypi/pyversions/pytups.svg
    :target: https://pypi.org/project/pytups/
.. image:: https://travis-ci.org/pchtsp/pytups.svg?branch=master
    :target: https://travis-ci.org/pchtsp/pytups

What and why
================

The idea is to allow sparse operations to be executed in matrix data.

I grew used to the chained operations in R's `tidyverse <https://www.tidyverse.org/>`_  packages or, although not a great fan myself, python's `pandas <https://pandas.pydata.org/>`_ . I find myself using dictionary and list comprehensions all the time to pass from one data format to the other efficiently. But after doing it for the Nth time, I thought of automaticing it.

In my case, it helps me construct optimisation models with  `PuLP <https://github.com/coin-or/pulp>`_. I see other possible uses not related to OR.

I've implemented some additional methods to regular dictionaries, lists and sets to come up with interesting methods that somewhat quickly pass from one to the other and help with data wrangling.

In order for the operations to make any sense, the assumption that is done is that whatever you are using has the same 'structure'. For example, if you a have a list of tuples: every element of the list is a tuple with the same size and the Nth element of the tuple has the same type, e.g. ``[(1, 'red', 'b', '2018-01'), (10, 'ccc', 'ttt', 'ff')]``. Note that both tuples have four elements and the first one is a number, not a string. We do not check that this is consistent.

They're made to always return a new object, so no "in-place" editing, hopefully.

Right now there are three classes to use: dictionaries, tuple lists and ordered sets.

Python versions
================

Python 3.8 and up.


Quick example
================

We index a tuple list according to some index positions.::

    import pytups as pt
    some_list_of_tuples = [('a', 'b', 'c', 1), ('a', 'b', 'c', 2), ('a', 'b', 'c', 45)]
    tp_list = pt.TupList(some_list_of_tuples)
    tp_list.to_dict(result_col=3)
    # {('a', 'b', 'c'): [1, 2, 45]}
    tp_list.to_dict(result_col=3).to_dictdict()
    # {'a': {'b': {'c': [1, 2, 45]}}}
    tp_list.to_dict(result_col=[2, 3])
    # {('a', 'b'): [('c', 1), ('c', 2), ('c', 45)]}

We do some operations on dictionaries with common keys.::

    import pytups as pt
    some_dict = pt.SuperDict(a=1, b=2, c=3, d=5)
    some_other_dict = pt.SuperDict(a=5, b=7, c=1)
    some_other_dict + some_dict
    # {'a': 6, 'b': 9, 'c': 4}
    some_other_dict.vapply(lambda v: v**2)
    # {'a': 25, 'b': 49, 'c': 1}
    some_other_dict.kvapply(lambda k, v: v/some_dict[k])
    # {'a': 5.0, 'b': 3.5, 'c': 0.3333333333333333}

Installing
================

::

    pip install pytups

or, for the development version::

    pip install https://github.com/pchtsp/pytups/archive/master.zip

Testing
================

Run the command::
    
    python -m unittest discover -s tests

if the output says OK, all tests were passed.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pchtsp/pytups",
    "name": "pytups",
    "maintainer": "Franco Peschiera",
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": "pchtsp@gmail.com",
    "keywords": "super dict dictionary tuple list math pulp",
    "author": "Franco Peschiera",
    "author_email": "pchtsp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c6/ac/5c4dfd8c2a2c72903df8b4a677b27a7cb59d4919bb9290fc6ca17f7b93cd/pytups-0.88.1.tar.gz",
    "platform": null,
    "description": "Pytups\n**************************\n.. image:: https://img.shields.io/pypi/v/pytups.svg\n    :target: https://pypi.org/project/pytups/\n.. image:: https://img.shields.io/pypi/l/pytups.svg\n    :target: https://pypi.org/project/pytups/\n.. image:: https://img.shields.io/pypi/pyversions/pytups.svg\n    :target: https://pypi.org/project/pytups/\n.. image:: https://travis-ci.org/pchtsp/pytups.svg?branch=master\n    :target: https://travis-ci.org/pchtsp/pytups\n\nWhat and why\n================\n\nThe idea is to allow sparse operations to be executed in matrix data.\n\nI grew used to the chained operations in R's `tidyverse <https://www.tidyverse.org/>`_  packages or, although not a great fan myself, python's `pandas <https://pandas.pydata.org/>`_ . I find myself using dictionary and list comprehensions all the time to pass from one data format to the other efficiently. But after doing it for the Nth time, I thought of automaticing it.\n\nIn my case, it helps me construct optimisation models with  `PuLP <https://github.com/coin-or/pulp>`_. I see other possible uses not related to OR.\n\nI've implemented some additional methods to regular dictionaries, lists and sets to come up with interesting methods that somewhat quickly pass from one to the other and help with data wrangling.\n\nIn order for the operations to make any sense, the assumption that is done is that whatever you are using has the same 'structure'. For example, if you a have a list of tuples: every element of the list is a tuple with the same size and the Nth element of the tuple has the same type, e.g. ``[(1, 'red', 'b', '2018-01'), (10, 'ccc', 'ttt', 'ff')]``. Note that both tuples have four elements and the first one is a number, not a string. We do not check that this is consistent.\n\nThey're made to always return a new object, so no \"in-place\" editing, hopefully.\n\nRight now there are three classes to use: dictionaries, tuple lists and ordered sets.\n\nPython versions\n================\n\nPython 3.8 and up.\n\n\nQuick example\n================\n\nWe index a tuple list according to some index positions.::\n\n    import pytups as pt\n    some_list_of_tuples = [('a', 'b', 'c', 1), ('a', 'b', 'c', 2), ('a', 'b', 'c', 45)]\n    tp_list = pt.TupList(some_list_of_tuples)\n    tp_list.to_dict(result_col=3)\n    # {('a', 'b', 'c'): [1, 2, 45]}\n    tp_list.to_dict(result_col=3).to_dictdict()\n    # {'a': {'b': {'c': [1, 2, 45]}}}\n    tp_list.to_dict(result_col=[2, 3])\n    # {('a', 'b'): [('c', 1), ('c', 2), ('c', 45)]}\n\nWe do some operations on dictionaries with common keys.::\n\n    import pytups as pt\n    some_dict = pt.SuperDict(a=1, b=2, c=3, d=5)\n    some_other_dict = pt.SuperDict(a=5, b=7, c=1)\n    some_other_dict + some_dict\n    # {'a': 6, 'b': 9, 'c': 4}\n    some_other_dict.vapply(lambda v: v**2)\n    # {'a': 25, 'b': 49, 'c': 1}\n    some_other_dict.kvapply(lambda k, v: v/some_dict[k])\n    # {'a': 5.0, 'b': 3.5, 'c': 0.3333333333333333}\n\nInstalling\n================\n\n::\n\n    pip install pytups\n\nor, for the development version::\n\n    pip install https://github.com/pchtsp/pytups/archive/master.zip\n\nTesting\n================\n\nRun the command::\n    \n    python -m unittest discover -s tests\n\nif the output says OK, all tests were passed.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "data wrangling for lists of tuples and dictionaries",
    "version": "0.88.1",
    "project_urls": {
        "Download": "https://github.com/pchtsp/pytups/archive/master.zip",
        "Homepage": "https://github.com/pchtsp/pytups"
    },
    "split_keywords": [
        "super",
        "dict",
        "dictionary",
        "tuple",
        "list",
        "math",
        "pulp"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1238b82dd0b5b57e559b4a6268d6c6000ab2a9a7135bb2d19885e7720c898cad",
                "md5": "1759ef61954d936adc67b257c32419b5",
                "sha256": "6b45969212c4c58d6511419c45e2a217abde978f77d4b9aae78b60d2e1958ee5"
            },
            "downloads": -1,
            "filename": "pytups-0.88.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1759ef61954d936adc67b257c32419b5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 14617,
            "upload_time": "2024-05-15T15:31:12",
            "upload_time_iso_8601": "2024-05-15T15:31:12.390931Z",
            "url": "https://files.pythonhosted.org/packages/12/38/b82dd0b5b57e559b4a6268d6c6000ab2a9a7135bb2d19885e7720c898cad/pytups-0.88.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c6ac5c4dfd8c2a2c72903df8b4a677b27a7cb59d4919bb9290fc6ca17f7b93cd",
                "md5": "49d38187ef9ff1280d78411c5fdce5ca",
                "sha256": "b1f96fe41337ee65250e71f973fe3b91495a55dab42feebc0ff66ae00af1004a"
            },
            "downloads": -1,
            "filename": "pytups-0.88.1.tar.gz",
            "has_sig": false,
            "md5_digest": "49d38187ef9ff1280d78411c5fdce5ca",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 19466,
            "upload_time": "2024-05-15T15:31:13",
            "upload_time_iso_8601": "2024-05-15T15:31:13.618366Z",
            "url": "https://files.pythonhosted.org/packages/c6/ac/5c4dfd8c2a2c72903df8b4a677b27a7cb59d4919bb9290fc6ca17f7b93cd/pytups-0.88.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-15 15:31:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pchtsp",
    "github_project": "pytups",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pytups"
}
        
Elapsed time: 0.69115s