{"id":17307047,"url":"https://github.com/pchtsp/pytups","last_synced_at":"2025-04-14T13:42:55.440Z","repository":{"id":45239800,"uuid":"182603334","full_name":"pchtsp/pytups","owner":"pchtsp","description":"Powerful dictionaries and tuple lists for data wrangling","archived":false,"fork":false,"pushed_at":"2025-04-01T14:21:38.000Z","size":431,"stargazers_count":6,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T15:33:21.263Z","etag":null,"topics":["data","data-science","dictionaries","optimization","tuples"],"latest_commit_sha":null,"homepage":"https://pchtsp.github.io/pytups","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pchtsp.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.md","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-22T01:38:52.000Z","updated_at":"2025-04-01T14:21:22.000Z","dependencies_parsed_at":"2025-04-01T15:26:41.670Z","dependency_job_id":"f75da2ad-4920-4dfd-8b79-1e2d8a365cf6","html_url":"https://github.com/pchtsp/pytups","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pchtsp%2Fpytups","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pchtsp%2Fpytups/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pchtsp%2Fpytups/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pchtsp%2Fpytups/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pchtsp","download_url":"https://codeload.github.com/pchtsp/pytups/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248890158,"owners_count":21178377,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data","data-science","dictionaries","optimization","tuples"],"created_at":"2024-10-15T12:00:28.060Z","updated_at":"2025-04-14T13:42:55.413Z","avatar_url":"https://github.com/pchtsp.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"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\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 \u003chttps://www.tidyverse.org/\u003e`_  packages or, although not a great fan myself, python's `pandas \u003chttps://pandas.pydata.org/\u003e`_ . 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 \u003chttps://github.com/coin-or/pulp\u003e`_. 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.9 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.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpchtsp%2Fpytups","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpchtsp%2Fpytups","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpchtsp%2Fpytups/lists"}