Skip to main content

The toolkit for data science projects with a focus on functional programming

Project description

yo_ds

This is a personal library, allowing more functional programming in Python data-science. Mostly, it's focused on writing code like this:

from yo_extensions import *
import json

(Query
.file.text('data.jsonlines')                # read file and create a 'stream' of lines
.select(json.loads)                         # parse each line with JSON
.where(lambda z: maybe(z,'status')=='OK')   # only items with status equals OK, maybe is Elvis operator
.select(lambda z: (z['id'],z['message']))
.to_dataframe(columns=['id','message'])     # seamless integration with pandas
.groupby('message')
.size()
.feed(plots.series.pie())                   # extension method, draws a pie chart with custom settings
)

The key principles are:

  • Fluent interface
  • Type annotations
  • Extendability

Contents:

  • Yet another port of C# LINQ to Python. The closest analogue is asq. The key differences are: type annotation support and different extendability mechanism
  • Extension methods for better data-science: plotting, status reporting, algorithms on pandas
  • A few useful classes for machine-learning
  • Wide test coverage for most of the implemented funcionality

fluq

The port of C# LINQ to Python with type annotations. The usual methods (select, where) are implemented as methods of Queryable class.

The extension methods are challenging due to Python restrictions. I couldn't use monkey-patching, because it does not preserve type-annotations, and injected methods are not seen by IDE. Thus, the following mechanism is employed:

  • Consider the function f(q,X) where q is Queryable and X is a tuple of additional argument.
  • Lets Curry q, introducing h(X) such that h(X) returns g(q) and so h(X)(q)=g(q)=f(q,X)
  • To inject h into q, q.feed method accepts g, so q.feed(h(X)) = h(X)(q) = f(q,X)

This mechanism preserves the type annotation, allows to add any functionality to Queryable and almost preserves Fluent interface: you need to add feed instead of just chaining methods.

To avoid coding of both g and h function for any functionality, the suggested way of implementation for h is a class, X is provided in __init__, and also h is Callable so it can accept q.

The same mechanism employed for pd.DataFrame, pd.Series, pd.DataFrameGroupBy and pd.SeriesGroupBy. For these classes, feed is monkey-patced and does not preserve the type annotation.

feed-compatible extensions

  • Several extensions for fluq: input/output to various file types, partitioning, etc.
  • Few extensions for pandas: adding ordering inside groups, stratifying order for Dataframes, etc
  • Plots: several plots I like to use in research, implemented in feed-compatible mode.

yo_extensions/__init__.py provides the demonstration on how better include fluq with extensions into the side project.

ml

Small utilities:

  • kraken: Executes method with the various arguments (plan) and returns the result as pd.DataFrame for futher analysis
  • metrics: computes lots of metrics for predicted/actual values and returns them as pd.DataFrame.
  • keras: wrapper over keras generators.

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

yo_ds-0.4.0.tar.gz (38.2 kB view details)

Uploaded Source

Built Distribution

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

yo_ds-0.4.0-py3-none-any.whl (66.0 kB view details)

Uploaded Python 3

File details

Details for the file yo_ds-0.4.0.tar.gz.

File metadata

  • Download URL: yo_ds-0.4.0.tar.gz
  • Upload date:
  • Size: 38.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.5.0.1 requests/2.13.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for yo_ds-0.4.0.tar.gz
Algorithm Hash digest
SHA256 2d2660301f2dfc1b7dba7198340805789bf4e3380ee3623579fdb0b25fd95a34
MD5 740b135f4edef29b2a7eb199b794775c
BLAKE2b-256 84c85ce07fbaf242d2dcf2f15bea5d7856eef2d00f72a85e4b9c406ff061f6d9

See more details on using hashes here.

File details

Details for the file yo_ds-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: yo_ds-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 66.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.5.0.1 requests/2.13.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for yo_ds-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c1f75240717c913fb08591604da193b87066b0be8e3a4c211ad893ec0fbf6d0
MD5 b446f87ed688f38703c616e0ca0ba273
BLAKE2b-256 0fb4b97466268ee0066bcea306fe23ad4171efb3b292f6c95bb7b4c5b935265f

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