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# LINQto 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)whereqisQueryableandXis 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
hintoq,q.feedmethod 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.DataFramefor futher analysismetrics: computes lots of metrics for predicted/actual values and returns them aspd.DataFrame.keras: wrapper overkerasgenerators.
Metadata
Release files for yo-ds 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| yo_ds-0.2.0.tar.gz | 37.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| yo_ds-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 92.4 kB
Release files / yo_ds-0.2.0.tar.gz
| Download URL | yo_ds-0.2.0.tar.gz |
|---|---|
| Size | 37.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a98135d9a500356f625365b94ef52bbcb433dc35ad44a4c0d278c646680cf3ce
|
|
BLAKE2b-256 checksum How to use checksums |
b675b33c6eda74709272e55634a479c05c35ef608278b8f7cd2b0471d1a51a44
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / yo_ds-0.2.0-py3-none-any.whl
| Download URL | yo_ds-0.2.0-py3-none-any.whl |
|---|---|
| Size | 55.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e63eba0e6bbbc472b4ab90e74a68a025601c6287f673050711a2d80bc5dcaaad
|
|
BLAKE2b-256 checksum How to use checksums |
07a848f8c5562e05cd89f84bdd7803b4a620e4f96cbb0e81edf0469ef1119688
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|