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 isasq
. 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)
whereq
isQueryable
andX
is a tuple of additional argument. - Lets Curry
q
, introducingh(X)
such thath(X)
returnsg(q)
and soh(X)(q)=g(q)=f(q,X)
- To inject
h
intoq
,q.feed
method acceptsg
, soq.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 aspd.DataFrame
for futher analysismetrics
: computes lots of metrics for predicted/actual values and returns them aspd.DataFrame
.keras
: wrapper overkeras
generators.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file yo_ds-0.2.0.tar.gz
.
File metadata
- Download URL: yo_ds-0.2.0.tar.gz
- Upload date:
- Size: 37.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
a98135d9a500356f625365b94ef52bbcb433dc35ad44a4c0d278c646680cf3ce
|
|
MD5 |
f43ce30701733453bdcec4f42847e063
|
|
BLAKE2b-256 |
b675b33c6eda74709272e55634a479c05c35ef608278b8f7cd2b0471d1a51a44
|
File details
Details for the file yo_ds-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: yo_ds-0.2.0-py3-none-any.whl
- Upload date:
- Size: 55.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
e63eba0e6bbbc472b4ab90e74a68a025601c6287f673050711a2d80bc5dcaaad
|
|
MD5 |
6c662976a23d5ae4edf2a4bcd5b52fe7
|
|
BLAKE2b-256 |
07a848f8c5562e05cd89f84bdd7803b4a620e4f96cbb0e81edf0469ef1119688
|