# slicer [alpha]
![License](https://img.shields.io/github/license/interpretml/slicer.svg?style=flat-square)
![Python Version](https://img.shields.io/pypi/pyversions/slicer.svg?style=flat-square)
![Package Version](https://img.shields.io/pypi/v/slicer.svg?style=flat-square)
![Build Status](https://img.shields.io/azure-devops/build/ms/interpret/405/master?style=flat-square)
![Coverage](https://img.shields.io/azure-devops/coverage/ms/interpret/405/master.svg?style=flat-square)
![Maintenance](https://img.shields.io/maintenance/yes/2021.svg?style=flat-square)
*(Equal Contribution) Samuel Jenkins & Harsha Nori & Scott Lundberg*
**slicer** wraps tensor-like objects and provides a uniform slicing interface via `__getitem__`.
<br/>
It supports many data types including:
[numpy](https://github.com/numpy/numpy) |
[pandas](https://github.com/pandas-dev/pandas) |
[scipy](https://docs.scipy.org/doc/scipy/reference/sparse.html) |
[pytorch](https://github.com/pytorch/pytorch) |
[list](https://github.com/python/cpython) |
[tuple](https://github.com/python/cpython) |
[dict](https://github.com/python/cpython)
And enables upgraded slicing functionality on its objects:
```python
# Handles non-integer indexes for slicing.
S(df)[:, ["Age", "Income"]]
# Handles nested slicing in one call.
S(nested_list)[..., :5]
```
It can also simultaneously slice many objects at once:
```python
# Gets first elements of both objects.
S(first=df, second=ar)[0, :]
```
This package has **0** dependencies. Not even one.
## Installation
Python 3.6+ | Linux, Mac, Windows
```sh
pip install slicer
```
## Getting Started
Basic anonymous slicing:
```python
from slicer import Slicer as S
li = [[1, 2, 3], [4, 5, 6]]
S(li)[:, 0:2].o
# [[1, 2], [4, 5]]
di = {'x': [1, 2, 3], 'y': [4, 5, 6]}
S(di)[:, 0:2].o
# {'x': [1, 2], 'y': [4, 5]}
```
Basic named slicing:
```python
import pandas as pd
import numpy as np
df = pd.DataFrame({'A': [1, 3], 'B': [2, 4]})
ar = np.array([[5, 6], [7, 8]])
sliced = S(first=df, second=ar)[0, :]
sliced.first
# A 1
# B 2
# Name: 0, dtype: int64
sliced.second
# array([5, 6])
```
Real example:
```python
from slicer import Slicer as S
from slicer import Alias as A
data = [[1, 2], [3, 4]]
values = [[5, 6], [7, 8]]
identifiers = ["id1", "id1"]
instance_names = ["r1", "r2"]
feature_names = ["f1", "f2"]
full_name = "A"
slicer = S(
data=data,
values=values,
# Aliases are objects that also function as slicing keys.
# A(obj, dim) where dim informs what dimension it can be sliced on.
identifiers=A(identifiers, 0),
instance_names=A(instance_names, 0),
feature_names=A(feature_names, 1),
full_name=full_name,
)
sliced = slicer[:, 1] # Tensor-like parallel slicing on all objects
assert sliced.data == [2, 4]
assert sliced.instance_names == ["r1", "r2"]
assert sliced.feature_names == "f2"
assert sliced.values == [6, 8]
sliced = slicer["r1", "f2"] # Example use of aliasing
assert sliced.data == 2
assert sliced.feature_names == "f2"
assert sliced.instance_names == "r1"
assert sliced.values == 6
```
## Contact us
Raise an issue on GitHub, or contact us at interpret@microsoft.com
Raw data
{
"_id": null,
"home_page": "https://github.com/interpretml/slicer",
"name": "slicer",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "",
"author": "InterpretML",
"author_email": "interpret@microsoft.com",
"download_url": "",
"platform": null,
"description": "# slicer [alpha]\r\n![License](https://img.shields.io/github/license/interpretml/slicer.svg?style=flat-square)\r\n![Python Version](https://img.shields.io/pypi/pyversions/slicer.svg?style=flat-square)\r\n![Package Version](https://img.shields.io/pypi/v/slicer.svg?style=flat-square)\r\n![Build Status](https://img.shields.io/azure-devops/build/ms/interpret/405/master?style=flat-square)\r\n![Coverage](https://img.shields.io/azure-devops/coverage/ms/interpret/405/master.svg?style=flat-square)\r\n![Maintenance](https://img.shields.io/maintenance/yes/2021.svg?style=flat-square)\r\n\r\n*(Equal Contribution) Samuel Jenkins & Harsha Nori & Scott Lundberg*\r\n\r\n**slicer** wraps tensor-like objects and provides a uniform slicing interface via `__getitem__`.\r\n\r\n<br/>\r\nIt supports many data types including:\r\n\r\n \r\n[numpy](https://github.com/numpy/numpy) |\r\n[pandas](https://github.com/pandas-dev/pandas) |\r\n[scipy](https://docs.scipy.org/doc/scipy/reference/sparse.html) |\r\n[pytorch](https://github.com/pytorch/pytorch) |\r\n[list](https://github.com/python/cpython) |\r\n[tuple](https://github.com/python/cpython) |\r\n[dict](https://github.com/python/cpython)\r\n\r\nAnd enables upgraded slicing functionality on its objects:\r\n```python\r\n# Handles non-integer indexes for slicing.\r\nS(df)[:, [\"Age\", \"Income\"]]\r\n\r\n# Handles nested slicing in one call.\r\nS(nested_list)[..., :5]\r\n```\r\n\r\nIt can also simultaneously slice many objects at once:\r\n```python\r\n# Gets first elements of both objects.\r\nS(first=df, second=ar)[0, :]\r\n```\r\n\r\nThis package has **0** dependencies. Not even one.\r\n\r\n## Installation\r\n\r\nPython 3.6+ | Linux, Mac, Windows\r\n```sh\r\npip install slicer\r\n```\r\n\r\n## Getting Started\r\n\r\nBasic anonymous slicing:\r\n```python\r\nfrom slicer import Slicer as S\r\nli = [[1, 2, 3], [4, 5, 6]]\r\nS(li)[:, 0:2].o\r\n# [[1, 2], [4, 5]]\r\ndi = {'x': [1, 2, 3], 'y': [4, 5, 6]}\r\nS(di)[:, 0:2].o\r\n# {'x': [1, 2], 'y': [4, 5]}\r\n```\r\n\r\nBasic named slicing:\r\n```python\r\nimport pandas as pd\r\nimport numpy as np\r\ndf = pd.DataFrame({'A': [1, 3], 'B': [2, 4]})\r\nar = np.array([[5, 6], [7, 8]])\r\nsliced = S(first=df, second=ar)[0, :]\r\nsliced.first\r\n# A 1\r\n# B 2\r\n# Name: 0, dtype: int64\r\nsliced.second\r\n# array([5, 6])\r\n```\r\n\r\nReal example:\r\n```python\r\nfrom slicer import Slicer as S\r\nfrom slicer import Alias as A\r\n\r\ndata = [[1, 2], [3, 4]]\r\nvalues = [[5, 6], [7, 8]]\r\nidentifiers = [\"id1\", \"id1\"]\r\ninstance_names = [\"r1\", \"r2\"]\r\nfeature_names = [\"f1\", \"f2\"]\r\nfull_name = \"A\"\r\n\r\nslicer = S(\r\n data=data,\r\n values=values,\r\n # Aliases are objects that also function as slicing keys.\r\n # A(obj, dim) where dim informs what dimension it can be sliced on.\r\n identifiers=A(identifiers, 0),\r\n instance_names=A(instance_names, 0),\r\n feature_names=A(feature_names, 1),\r\n full_name=full_name,\r\n)\r\n\r\nsliced = slicer[:, 1] # Tensor-like parallel slicing on all objects\r\nassert sliced.data == [2, 4]\r\nassert sliced.instance_names == [\"r1\", \"r2\"]\r\nassert sliced.feature_names == \"f2\"\r\nassert sliced.values == [6, 8]\r\n\r\nsliced = slicer[\"r1\", \"f2\"] # Example use of aliasing\r\nassert sliced.data == 2\r\nassert sliced.feature_names == \"f2\"\r\nassert sliced.instance_names == \"r1\"\r\nassert sliced.values == 6\r\n```\r\n\r\n## Contact us\r\nRaise an issue on GitHub, or contact us at interpret@microsoft.com\r\n",
"bugtrack_url": null,
"license": "",
"summary": "A small package for big slicing.",
"version": "0.0.8",
"project_urls": {
"Homepage": "https://github.com/interpretml/slicer"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "63819ef641ff4e12cbcca30e54e72fb0951a2ba195d0cda0ba4100e532d929db",
"md5": "73ebeb05ff885e4b72e216667146a015",
"sha256": "6c206258543aecd010d497dc2eca9d2805860a0b3758673903456b7df7934dc3"
},
"downloads": -1,
"filename": "slicer-0.0.8-py3-none-any.whl",
"has_sig": false,
"md5_digest": "73ebeb05ff885e4b72e216667146a015",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 15251,
"upload_time": "2024-03-09T07:03:07",
"upload_time_iso_8601": "2024-03-09T07:03:07.708440Z",
"url": "https://files.pythonhosted.org/packages/63/81/9ef641ff4e12cbcca30e54e72fb0951a2ba195d0cda0ba4100e532d929db/slicer-0.0.8-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-09 07:03:07",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "interpretml",
"github_project": "slicer",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"lcname": "slicer"
}