{"id":19505269,"url":"https://github.com/interpretml/slicer","last_synced_at":"2025-04-04T16:13:03.540Z","repository":{"id":57468363,"uuid":"296451189","full_name":"interpretml/slicer","owner":"interpretml","description":"Unified slicing for all Python data structures.","archived":false,"fork":false,"pushed_at":"2025-02-13T19:35:59.000Z","size":41,"stargazers_count":35,"open_issues_count":3,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-28T15:07:21.901Z","etag":null,"topics":["python","slicing"],"latest_commit_sha":null,"homepage":"","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/interpretml.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-17T21:59:09.000Z","updated_at":"2025-02-13T19:36:03.000Z","dependencies_parsed_at":"2025-03-13T08:11:14.299Z","dependency_job_id":"f5720cda-6b8c-411b-9d19-f2e5b095054a","html_url":"https://github.com/interpretml/slicer","commit_stats":{"total_commits":30,"total_committers":6,"mean_commits":5.0,"dds":0.6,"last_synced_commit":"d40d0358a501d6dc84dbfe942854c82d4182c152"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interpretml%2Fslicer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interpretml%2Fslicer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interpretml%2Fslicer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interpretml%2Fslicer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/interpretml","download_url":"https://codeload.github.com/interpretml/slicer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247208139,"owners_count":20901570,"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":["python","slicing"],"created_at":"2024-11-10T22:29:26.087Z","updated_at":"2025-04-04T16:13:03.523Z","avatar_url":"https://github.com/interpretml.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# slicer [alpha]\n![License](https://img.shields.io/github/license/interpretml/slicer.svg?style=flat-square)\n![Python Version](https://img.shields.io/pypi/pyversions/slicer.svg?style=flat-square)\n![Package Version](https://img.shields.io/pypi/v/slicer.svg?style=flat-square)\n![Maintenance](https://img.shields.io/maintenance/yes/2025.svg?style=flat-square)\n\n*(Equal Contribution) Samuel Jenkins \u0026 Harsha Nori \u0026 Scott Lundberg*\n\n**slicer** wraps tensor-like objects and provides a uniform slicing interface via `__getitem__`.\n\n\u003cbr/\u003e\nIt supports many data types including:\n\n\u0026nbsp;\u0026nbsp;\n[numpy](https://github.com/numpy/numpy) |\n[pandas](https://github.com/pandas-dev/pandas) |\n[scipy](https://docs.scipy.org/doc/scipy/reference/sparse.html) |\n[pytorch](https://github.com/pytorch/pytorch) |\n[list](https://github.com/python/cpython) |\n[tuple](https://github.com/python/cpython) |\n[dict](https://github.com/python/cpython)\n\nAnd enables upgraded slicing functionality on its objects:\n```python\n# Handles non-integer indexes for slicing.\nS(df)[:, [\"Age\", \"Income\"]]\n\n# Handles nested slicing in one call.\nS(nested_list)[..., :5]\n```\n\nIt can also simultaneously slice many objects at once:\n```python\n# Gets first elements of both objects.\nS(first=df, second=ar)[0, :]\n```\n\nThis package has **0** dependencies. Not even one.\n\n## Installation\n\nPython 3.6+ | Linux, Mac, Windows\n```sh\npip install slicer\n```\n\n## Getting Started\n\nBasic anonymous slicing:\n```python\nfrom slicer import Slicer as S\nli = [[1, 2, 3], [4, 5, 6]]\nS(li)[:, 0:2].o\n# [[1, 2], [4, 5]]\ndi = {'x': [1, 2, 3], 'y': [4, 5, 6]}\nS(di)[:, 0:2].o\n# {'x': [1, 2], 'y': [4, 5]}\n```\n\nBasic named slicing:\n```python\nimport pandas as pd\nimport numpy as np\ndf = pd.DataFrame({'A': [1, 3], 'B': [2, 4]})\nar = np.array([[5, 6], [7, 8]])\nsliced = S(first=df, second=ar)[0, :]\nsliced.first\n# A    1\n# B    2\n# Name: 0, dtype: int64\nsliced.second\n# array([5, 6])\n```\n\nReal example:\n```python\nfrom slicer import Slicer as S\nfrom slicer import Alias as A\n\ndata = [[1, 2], [3, 4]]\nvalues = [[5, 6], [7, 8]]\nidentifiers = [\"id1\", \"id1\"]\ninstance_names = [\"r1\", \"r2\"]\nfeature_names = [\"f1\", \"f2\"]\nfull_name = \"A\"\n\nslicer = S(\n    data=data,\n    values=values,\n    # Aliases are objects that also function as slicing keys.\n    # A(obj, dim) where dim informs what dimension it can be sliced on.\n    identifiers=A(identifiers, 0),\n    instance_names=A(instance_names, 0),\n    feature_names=A(feature_names, 1),\n    full_name=full_name,\n)\n\nsliced = slicer[:, 1]  # Tensor-like parallel slicing on all objects\nassert sliced.data == [2, 4]\nassert sliced.instance_names == [\"r1\", \"r2\"]\nassert sliced.feature_names == \"f2\"\nassert sliced.values == [6, 8]\n\nsliced = slicer[\"r1\", \"f2\"]  # Example use of aliasing\nassert sliced.data == 2\nassert sliced.feature_names == \"f2\"\nassert sliced.instance_names == \"r1\"\nassert sliced.values == 6\n```\n\n## Contact us\nRaise an issue on GitHub, or contact us at interpret@microsoft.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finterpretml%2Fslicer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finterpretml%2Fslicer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finterpretml%2Fslicer/lists"}