Skip to content

Commit

Permalink
Refactory to nbdev-less
Browse files Browse the repository at this point in the history
  • Loading branch information
raynardj committed Apr 27, 2022
1 parent d044e2d commit 88591c9
Show file tree
Hide file tree
Showing 177 changed files with 443 additions and 48,104 deletions.
199 changes: 9 additions & 190 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# ForgeBox
> Data science comprehensive toolbox 🛠⚔️📦

![forgebox logo](https://raw.githubusercontent.com/raynardj/forgebox/new_feature/docs/logo.jpg)
> Data science comprehensive toolbox
## Installation

Expand All @@ -25,90 +22,14 @@ The following command will import many frequent tools for data science, like **p
from frogebox.imports import *
```

No more🚫 following typings
No more following verbosity
```python
import pandas as pd
import numpy as np
import os
import json
...
```

### Categorical converter

> Mapping and converting categorical infomation
```python
from forgebox.category import Category
```

```python
az = list(map(chr,range(ord("A"), ord("z")+1)))
print(az)
```

['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']


```python
cate_az = Category(az)
cate_az
```




Category Manager with 58



```python
cate_az.c2i["R"], cate_az.i2c[17]
```




(17, 'R')



```python
cate_az.c2i[list("ForgeBox")]
```




array([ 5, 46, 49, 38, 36, 1, 46, 55])



```python
cate_az.i2c[[ 5, 46, 49, 38, 36, 1, 46, 55]]
```




array(['F', 'o', 'r', 'g', 'e', 'B', 'o', 'x'], dtype='<U1')



Padding missing token

```python
cate_az = Category(az, pad_mst=True)
cate_az.c2i[list("Forge⚡️Box")]
```




array([ 6, 47, 50, 39, 37, 0, 0, 2, 47, 56])



### Get a dataframe of file details under a directory

```python
Expand All @@ -119,23 +40,7 @@ from forgebox.files import file_detail
file_detail("/Users/xiaochen.zhang/.cache/").sample(5)
```




<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}

.dataframe tbody tr th {
vertical-align: top;
}

.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
Expand Down Expand Up @@ -187,37 +92,6 @@ file_detail("/Users/xiaochen.zhang/.cache/").sample(5)
</div>



### JS style async

```python
from forgebox.asyncing import Async
from time import sleep
```

```python
def something_time_costing_but_you_dont_want_to_wait(x):
sleep(x)
return f"slept for {x} seconds"

def task2_you_will_perfrom_after_the_time_costing_one(x):
print(f"[result]:\t{x}")
return 1

print("1111111111")

Async(something_time_costing_but_you_dont_want_to_wait)(2)\
.then(task2_you_will_perfrom_after_the_time_costing_one)\
.catch(print)

print("22222222222")
```

1111111111
22222222222
[result]: slept for 2 seconds


### HTML in notebook

```python
Expand All @@ -231,26 +105,6 @@ bands = ["police", "headpin", {"ac":"dc"}]
list_group(bands)()
```


<ul class="list-group"><li class="list-group-item">police</li><li class="list-group-item">headpin</li><li class="list-group-item"><ul class="list-group"><li class="list-group-item"><div class="row"><strong class="col-sm-5">ac</strong><span class="col-sm-7">dc</span></div></li></ul></li></ul>


```python
questions = {
"question":"answer",
"another":{
"deeper question": "answer again"},
"final":{
"questions": ["what","is","the","answer", "to",
["life", "universe","everything"]]}
}
list_group_kv(questions)()
```


<ul class="list-group"><li class="list-group-item"><div class="row"><strong class="col-sm-5">question</strong><span class="col-sm-7">answer</span></div></li><li class="list-group-item"><div class="row"><strong class="col-sm-5">another</strong><span class="col-sm-7"><ul class="list-group"><li class="list-group-item"><div class="row"><strong class="col-sm-5">deeper question</strong><span class="col-sm-7">answer again</span></div></li></ul></span></div></li><li class="list-group-item"><div class="row"><strong class="col-sm-5">final</strong><span class="col-sm-7"><ul class="list-group"><li class="list-group-item"><div class="row"><strong class="col-sm-5">questions</strong><span class="col-sm-7"><ul class="list-group"><li class="list-group-item">what</li><li class="list-group-item">is</li><li class="list-group-item">the</li><li class="list-group-item">answer</li><li class="list-group-item">to</li><li class="list-group-item"><ul class="list-group"><li class="list-group-item">life</li><li class="list-group-item">universe</li><li class="list-group-item">everything</li></ul></li></ul></span></div></li></ul></span></div></li></ul>


#### Coding html in python

```python
Expand All @@ -271,23 +125,6 @@ ul()
<ul><li style="color:#EE33DD">Line 0</li><li style="color:#EE33DD">Line 1</li><li style="color:#EE33DD">Line 2</li><li style="color:#EE33DD">Line 3</li><li style="color:#EE33DD">Line 4</li></ul>


### Free style mapping

Works on every value of a complicated dictionary structure (eg. list in dict in list in dict, etc,. 😳)

```python
from forgebox.freemap import FreeMap

# flatten decides if we want to flatten the strucuture
freemap_tool = FreeMap(
<function/callable applying to every value>,
<function/callable that filters every value>,
flatten=True
)

data2 = freemap_tool(data1)
```

### Interactive Widgets
> Interactive widgets work with in jupyter notebooks
Expand All @@ -306,32 +143,14 @@ search_box(data_df, columns=["col1","col2"], manual=False)
You can browse through a pandas dataframe like fliping pages 📄.

```python
from forgebox.widgets import paginate

paginate(your_dataframe, page_len=10)
# this will import many things like enhanced pandas
from forgebox.imports import *
df = pd.read_csv("xxxx.csv")
df.paginate()
```

#### Single button callback
> a fully functional page with a single button, this single button is bonded to a function
This is as much code as you need, to build a fully functional interactive page shows sql table from jupyter, that you can:* choose which table to visit* choose how many lines you want to show, (with a slider)
* configure the where condition with a text box on front end

```python
tablename_list = ["pubmed", "patient", "users", "drugs"]

from forgebox.html import DOM
def show_sql_table(sql_input:str) -> str:
with engine.connect() as conn:
df=pd.read_sql(sql_input, con=conn)
# display the table as html
DOM(df.to_html(),"div")()

@SingleButton(callback=show_sql_table)
def abc(
limit:{"typing":int, "default":10, "min":5, "max":20},
where_condition:{"typing":str, "default": "where 1=1", },
table:{"typing":list, "options":tablename_list}
):
return f"SELECT * FROM {table} {where_condition} LIMIT {limit}"
from forgebox.widgets import paginate

paginate(your_dataframe, page_len=10)
```
Binary file removed docs/.DS_Store
Binary file not shown.
1 change: 0 additions & 1 deletion docs/.gitignore

This file was deleted.

Loading

0 comments on commit 88591c9

Please sign in to comment.