Skip to content

Commit

Permalink
Merge 340ffbd into f4d0ca7
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestoarbitrio committed Sep 24, 2019
2 parents f4d0ca7 + 340ffbd commit 529134e
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ celerybeat-schedule
venv/
venv3/
ENV/
Pipenv
Pipenv.lock

# Spyder project settings
.spyderproject
Expand Down
108 changes: 86 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ or
To setup and run tests, you will need to install `cr.cube` as well as testing
dependencies. To do this, from the root directory, simply run:

pip install -e .[testing]
pip install -e ".[testing]"

And then tests can be run using `py.test` in the root directory:

Expand All @@ -65,45 +65,109 @@ After the `cr.cube` package has been successfully installed, the usage is as
simple as:


from cr.cube.crunch_cube import CrunchCube
from cr.cube.cube import Cube

### Obtain the crunch cube JSON from the Crunch.io
### And store it in the 'cube_JSON_response' variable

cube = CrunchCube(cube_JSON_response)
cube.as_array()
cube = Cube(cube_JSON_response)
slice_ = cube.partitions[0]
print(slice_.column_proportions)

### Outputs:
### Output (2D Cube):
#
# np.array([
# [5, 2],
# [5, 3]
# np.ndarray([
# [0.38227848 0.33855186 0.39252336 0.44117647]
# [0.09620253 0.10665362 0.18691589 0.08823529]
# [0.47848101 0.44520548 0.57943925 0.52941176]
# [0. 0. 0. 0. ]
# [0.09113924 0.09099804 0.14018692 0.17647059]
# [0.25316456 0.23091977 0.08411215 0.05882353]
# [0.09113924 0.13111546 0.13084112 0.14705882]
# [0.07594937 0.07632094 0.05607477 0.08823529]
# [0.01012658 0.02544031 0.00934579 0. ]
# ])


print(slice_.row_proportions)

### Output (2D Cube:
#
# np.ndarray([
# [0.27256318 0.62454874 0.07581227 0.02707581]
# [0.22352941 0.64117647 0.11764706 0.01764706]
# [0.26104972 0.62845304 0.08563536 0.02486188]
# [ nan nan nan nan]
# [0.24 0.62 0.1 0.04 ]
# [0.28818444 0.68011527 0.0259366 0.00576369]
# [0.19047619 0.70899471 0.07407407 0.02645503]
# [0.25641026 0.66666667 0.05128205 0.02564103]
# [0.12903226 0.83870968 0.03225806 0. ]
# ])

# How to get the data values (%) from the cube

print(slice_.column_percentages)

### Output:
#
# np.ndarray([
# [38.2278481 , 33.85518591, 39.25233645, 44.11764706],
# [ 9.62025316, 10.66536204, 18.69158879, 8.82352941],
# [47.84810127, 44.52054795, 57.94392523, 52.94117647],
# [ 0. , 0. , 0. , 0. ],
# [ 9.11392405, 9.09980431, 14.01869159, 17.64705882],
# [25.3164557 , 23.09197652, 8.41121495, 5.88235294],
# [ 9.11392405, 13.11154599, 13.08411215, 14.70588235],
# [ 7.59493671, 7.63209393, 5.60747664, 8.82352941],
# [ 1.01265823, 2.54403131, 0.93457944, 0. ]
# ])

print(cube.base_counts)

### Output:
#
# np.ndarray([
# [151 346 42 15]
# [ 38 109 20 3]
# [ 0 0 0 0]
# [ 36 93 15 6]
# [100 236 9 2]
# [ 36 134 14 5]
# [ 30 78 6 3]
# [ 4 26 1 0]
# ])

## API

### `as_array`
### `base_counts` or `counts`

Tabular, or matrix, representation of the _cube_. The detailed description can
be found
[here](http://crunch-cube.readthedocs.io/en/latest/cr.cube.html#cr-cube-crunch-cube-module).
`cube.counts` `cube.base_counts`

### `margin`
Tabular, or matrix, representation of the _cube_.

Calculates margins of the _cube_. The detailed description can be found
[here](http://crunch-cube.readthedocs.io/en/latest/cr.cube.html#cr-cube-crunch-cube-module).
[^Comment]: [here](http://crunch-cube.readthedocs.io/en/latest/cr.cube.html#cr-cube-crunch-cube-module).

### `proportions`
### `rows_margin`
`slice_.rows_margin`

Calculates rows margin of the _slice_.

[^Comment]: [here](http://crunch-cube.readthedocs.io/en/latest/cr.cube.html#cr-cube-crunch-cube-module).

### `row_proportions` and `column_proportions`
`slice_.row_proportions` `slice_.column_proportions`

Calculates proportions of single variable elements to the whole sample size.
The detailed description can be found
[here](http://crunch-cube.readthedocs.io/en/latest/cr.cube.html#cr-cube-crunch-cube-module).

### `percentages`
[^Comment]: [here](http://crunch-cube.readthedocs.io/en/latest/cr.cube.html#cr-cube-crunch-cube-module).

### `row_percentages` and `column_percentages`

`slice_.row_percentages` `slice_.column_percentages`

Calculates percentages of single variable elements to the whole sample size.
The detailed description can be found
[here](http://crunch-cube.readthedocs.io/en/latest/cr.cube.html#cr-cube-crunch-cube-module).

[^Comment]: [here](http://crunch-cube.readthedocs.io/en/latest/cr.cube.html#cr-cube-crunch-cube-module).

[![Build Status](https://travis-ci.org/Crunch-io/crunch-cube.png?branch=master)](https://travis-ci.org/Crunch-io/crunch-cube)
[![Coverage Status](https://coveralls.io/repos/github/Crunch-io/crunch-cube/badge.svg?branch=master)](https://coveralls.io/github/Crunch-io/crunch-cube?branch=master)
Expand Down
4 changes: 4 additions & 0 deletions src/cr/cube/crunch_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ def as_array(
if prune:
array = self._prune_body(array, transforms=include_transforms_for_dims)

warnings.warn(
"Deprecated. Use `cr.cube.cube.base_counts or cr.cube.cube.counts` instead.",
DeprecationWarning,
)
return self._drop_mr_cat_dims(array)

@lazyproperty
Expand Down

0 comments on commit 529134e

Please sign in to comment.