Skip to content

Commit

Permalink
Merge pull request #9 from koaning/data_as_X_y
Browse files Browse the repository at this point in the history
`widget.data_as_X_y`
  • Loading branch information
koaning committed May 14, 2024
2 parents 0db53cd + c9a4b35 commit b0e1c65
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,5 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
esbuild
esbuild
.DS_Stores
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ install:
pypi:
python setup.py sdist
python setup.py bdist_wheel --universal
# twine upload dist/*
twine upload dist/*

js:
./esbuild --watch=forever --bundle --format=esm --outfile=drawdata/static/scatter_widget.js js/scatter_widget.js
13 changes: 13 additions & 0 deletions drawdata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,16 @@ def data_as_pandas(self):
def data_as_polars(self):
import polars as pl
return pl.DataFrame(self.data)

@property
def data_as_X_y(self, kind='classification'):
import numpy as np

colors = [_['label'] for _ in self.data]
if np.unique(colors).shape[0] == 1:
X = np.array([[_['x']] for _ in self.data])
y = np.array([_['y'] for _ in self.data])
return X, y
X = np.array([[_['x'], _['y']] for _ in self.data])
y = np.array([_['label'] for _ in self.data])
return X, y
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def read(fname):

setup(
name="drawdata",
version="0.3.0",
version="0.3.1",
description="draw a dataset from inside Jupyter",
author="Vincent D. Warmerdam",
packages=find_packages(exclude=["notebooks"]),
Expand Down

0 comments on commit b0e1c65

Please sign in to comment.