Skip to main content

A small package for big slicing.

Project description

slicer [alpha]

License Python Version Package Version Build Status Coverage Maintenance

(Equal Contribution) Samuel Jenkins & Harsha Nori & Scott Lundberg

slicer wraps tensor-like objects and provides a uniform slicing interface via __getitem__.


It supports many data types including:

   numpy | pandas | scipy | pytorch | list | tuple | dict

And enables upgraded slicing functionality on its objects:

# 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:

# 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

pip install slicer

Getting Started

Basic anonymous slicing:

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:

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:

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

slicer-0.0.7.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

slicer-0.0.7-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file slicer-0.0.7.tar.gz.

File metadata

  • Download URL: slicer-0.0.7.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

File hashes

Hashes for slicer-0.0.7.tar.gz
Algorithm Hash digest
SHA256 f5d5f7b45f98d155b9c0ba6554fa9770c6b26d5793a3e77a1030fb56910ebeec
MD5 113c3d9f3820dd50313c2b68a087591e
BLAKE2b-256 5f1a0388801c10441b1060f7e9dbb540544e602e6fe774359c6fa5c17df9679e

See more details on using hashes here.

File details

Details for the file slicer-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: slicer-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

File hashes

Hashes for slicer-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 0b94faa5251c0f23782c03f7b7eedda91d80144059645f452c4bc80fab875976
MD5 cb21350dba25ac8c82e8a6452857a6a2
BLAKE2b-256 78c2b3f55dfdb8af9812fdb9baf70cacf3b9e82e505b2bd4324d588888b81202

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page