Skip to content

Commit

Permalink
Merge pull request #7 from alanmarazzi/dev
Browse files Browse the repository at this point in the history
Finalize docs & tests
  • Loading branch information
alanmarazzi authored Jan 29, 2020
2 parents 7fffda6 + 47a2774 commit 36dbecf
Show file tree
Hide file tree
Showing 15 changed files with 2,827 additions and 1,351 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ examples/.ipynb_checkpoints
*.log
.classpath
.project
.settings
.settings
resources/docs.md
87 changes: 9 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,68 +12,25 @@ Dataframes in Clojure. Through [pandas](https://github.com/pandas-dev/pandas). O

## Disclaimer

This is very alpha, things will change fast, will break and the API is neither complete, nor settled. Since a few people have started playing with this there's a Clojars project available. Please give feedback if you're using this, every kind of contribution is appreciated (for more info check the [Contributing](#contributing) section). At the moment everything is mostly undocumented and untested, I'm currently adding them.
This is alpha, things will change fast, will break and the API is neither complete, nor settled. Since a few people have started playing with this there's a Clojars project available. Please give feedback if you're using this, every kind of contribution is appreciated (for more info check the [Contributing](#contributing) section). At the moment everything is mostly undocumented and untested, I'm currently adding them.

[![Clojars Project](https://img.shields.io/clojars/v/panthera.svg)](https://clojars.org/panthera)

## Get started

**Panthera** uses the great [libpython-clj](https://github.com/cnuernber/libpython-clj) as a backend to access Python and get [pandas](https://github.com/pandas-dev/pandas) and [numpy](https://github.com/numpy/numpy) functionality.

### System level

If you usually don't develop in Python then a system level install might be a good solution (though always discouraged), if this is your case then follow the subsequent steps.

To get started you need python, pandas and numpy (the latter comes with the former) on your path. Usually a:

```bash
sudo apt install libpython3.6-dev
pip3 install numpy pandas xlrd # the latter is for Excel files, if you don't care you can do without
```

### Environments

If you want to have different Python environments, then getting **panthera** to work correctly is a bit more tricky.

First create your new environment with at least python=3.6, numpy and pandas. (This was tested both on GNU/Linux and WSL with [conda](https://docs.conda.io/projects/conda/en/latest/), but there's no reason why it shouldn't work with other env management tools. On other systems, [Docker is your best bet](https://github.com/scicloj/docker-hub/tree/master/panthera)):

```bash
conda create -n panthera python=3.6 numpy pandas
```

Then check the path to the newly created environment:

```bash
conda activate panthera
which python
```

Now you just have to add to one of your profiles the path to the wanted python executable:

```bash
{:dev {:resource-paths ["/home/user/miniconda3/envs/panthera"]}}
```

You can create different profiles with different paths according to what you need. Now if you want to make it possible to work with **panthera** without having to activate your environments you have 2 choices:

- assign `PYTHONHOME` env variable to your environment

```bash
PYTHONHOME="/home/user/miniconda3/envs/panthera" lein whatever
```

- assign `PYTHONHOME` env variable before requiring **panthera**

```bash
(System/setProperty "PYTHONHOME" "/home/user/miniconda3/envs/panthera")
```
### N.B.: check [libpython-clj](https://github.com/cnuernber/libpython-clj) repo on how to install and start a Clojure/Python session.

### The actual code

After this you can start playing around with **panthera**

```clojure
(require '[panthera.panthera :as pt])
(require '[[panthera.panthera :as pt]
[libpython-clj.python :refer [initialize!]])

(initialize!)

(-> (pt/read-csv "mycsv.csv")
(pt/subset-cols "Col1" "Col2" "Col3")
Expand All @@ -86,33 +43,7 @@ The above chain will read your csv file as a DataFrame, select only the given co

## Numpy

All of Numpy is wrapped and accessible through a single interface from `panthera.numpy`.

```clojure
(require '[panthera.numpy :refer [npy doc]])

(npy :power {:args [[1 2 3] 3]})
;=> [1 8 27]

(npy :power)
; This arity returns the actual numpy object that can be passed around to other functions as an argument
```

To access functions inside submodules pass to `npy` a sequence of keys leading to the wanted function:

```clojure
(npy [:linalg :svd] {:args [[1 2 3] [4 5 6]]})
```

You can check the original docstring for every module and function with the `doc` helper

```clojure
(doc :power)

(doc [:linalg :eigh])
```

To see what is available and how everything works check the [official docs](https://docs.scipy.org/doc/numpy/reference/) online.
All of Numpy is accessible through [libpython-clj](https://github.com/cnuernber/libpython-clj) interop, check the repo for more info.

## Contributing

Expand Down Expand Up @@ -142,8 +73,8 @@ Panthera doesn't pretend to be a clever wordplay because it doesn't need to. Fir

## License

Copyright © 2019 Alan Marazzi
Copyright © 2020 Alan Marazzi

This program and the accompanying materials are made available under the
terms of the Eclipse Public License 2.0 which is available at
http://www.eclipse.org/legal/epl-2.0.
http://www.eclipse.org/legal/epl-2.0.
19 changes: 4 additions & 15 deletions examples/panthera-intro.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,9 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"nil"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"(require '[panthera.panthera :as pt])"
]
Expand Down Expand Up @@ -3913,9 +3902,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Clojure (clojupyter-v0.2.2)",
"display_name": "Lein-Clojure",
"language": "clojure",
"name": "clojupyter"
"name": "lein-clojure"
},
"language_info": {
"file_extension": ".clj",
Expand Down
22 changes: 11 additions & 11 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
(defproject panthera "0.1-alpha.16"
:description "Data Frames in Clojure (with Pandas) + NumPy"
:url "https://github.com/alanmarazzi/panthera"
:scm {:name "git" :url "https://github.com/alanmarazzi/panthera"}
:license {:name "EPL-2.0"
:url "https://www.eclipse.org/legal/epl-2.0/"}
:dependencies [[cnuernber/libpython-clj "1.0"]
[org.clojure/core.memoize "0.7.2"]]
:profiles {:dev {:dependencies [[org.clojure/clojure "1.10.1"]]
:plugins [[refactor-nrepl "2.4.0"]
[cider/cider-nrepl "0.18.0"]]}})
(defproject panthera "0.1-alpha.17"
:description "Data Frames in Clojure (with Pandas) + NumPy"
:url "https://github.com/alanmarazzi/panthera"
:scm {:name "git" :url "https://github.com/alanmarazzi/panthera"}
:license {:name "EPL-2.0"
:url "https://www.eclipse.org/legal/epl-2.0/"}
:dependencies [[cnuernber/libpython-clj "1.32"]
[org.clojure/core.memoize "0.7.2"]]
:profiles {:dev {:dependencies [[org.clojure/clojure "1.10.1"]]
:plugins [[lein-jupyter "0.1.16"]]}})

Loading

0 comments on commit 36dbecf

Please sign in to comment.