mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-25 05:38:11 +08:00
Makefile modularity, test targets, and auto-formatting (#1070)
* Fix Makefile whitespace and .PHONY use
* Fix Makefile filename
* Modularize Makefile into client and server Makefiles
Part of the reason that the Makefile in the root directory is a bit
complicated is that it tries to handle tasks that can be handled
separately in the client and server modules.
This commit pushes some of the make logic specific to each module into
their own makefiles and calls out to those makefiles from that in the
project root.
* Add auto-formatting to client and server modules
One thing that can make linting faster is auto-formatting. This commit
adds the yapf auto-formatting tool to the server module and uses
eslint's "fix" functionality to speed up the linting/formatting process.
* Add yapf for automatic code formatting
* Add a root test target that calls sub-tests
* Apply yapf to python files
* Do not duplicate npm commands, simply pass through
* Update documentation
* Do not shadow reserved word len
* Add general test target
* Fix make call in dev-env
* Use black instead of yapf
* Run flake8 from the root directory
* Revert "Apply yapf to python files"
This reverts commit cdca128a01.
* Apply black to python code
* Resolve lint errors resulting from black format
* Add explanation of server unit tests in dev guidelines
This commit is contained in:
@@ -7,9 +7,10 @@ class NdArrayProxyView(MatrixProxyView):
|
||||
"""
|
||||
Fake test class for matrix proxy - wraps ndarray
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def __supports__(cls):
|
||||
return ('numpy.ndarray', )
|
||||
return ("numpy.ndarray",)
|
||||
|
||||
|
||||
class MatrixProxyViewTest(unittest.TestCase):
|
||||
@@ -41,18 +42,17 @@ class MatrixProxyViewTest(unittest.TestCase):
|
||||
def test_toarray(self):
|
||||
n = np.arange(15, dtype=np.float32).reshape((3, 5))
|
||||
mp = MatrixProxy.create(n)
|
||||
self.assertTrue(np.all(mp.toarray() == [
|
||||
[0., 1., 2., 3., 4.],
|
||||
[5., 6., 7., 8., 9.],
|
||||
[10., 11., 12., 13., 14.]
|
||||
]))
|
||||
self.assertTrue(np.all(mp.T.toarray() == [
|
||||
[0., 5., 10.],
|
||||
[1., 6., 11.],
|
||||
[2., 7., 12.],
|
||||
[3., 8., 13.],
|
||||
[4., 9., 14.]
|
||||
]))
|
||||
self.assertTrue(
|
||||
np.all(
|
||||
mp.toarray() == [[0.0, 1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0, 9.0], [10.0, 11.0, 12.0, 13.0, 14.0]]
|
||||
)
|
||||
)
|
||||
self.assertTrue(
|
||||
np.all(
|
||||
mp.T.toarray()
|
||||
== [[0.0, 5.0, 10.0], [1.0, 6.0, 11.0], [2.0, 7.0, 12.0], [3.0, 8.0, 13.0], [4.0, 9.0, 14.0]]
|
||||
)
|
||||
)
|
||||
|
||||
def test_indexing(self):
|
||||
"""
|
||||
@@ -95,47 +95,19 @@ class MatrixProxyViewTest(unittest.TestCase):
|
||||
|
||||
# slice, slice
|
||||
|
||||
self.assertTrue(np.all(mp[1:3, 2:4].toarray() == [
|
||||
[7, 8],
|
||||
[12, 13]
|
||||
]))
|
||||
self.assertTrue(np.all(mp[:3, :4].toarray() == [
|
||||
[0., 1., 2., 3.],
|
||||
[5., 6., 7., 8.],
|
||||
[10., 11., 12., 13.]
|
||||
]))
|
||||
self.assertTrue(np.all(mp[::-1, ::-1].toarray() == [
|
||||
[14, 13, 12, 11, 10],
|
||||
[9, 8, 7, 6, 5],
|
||||
[4, 3, 2, 1, 0]
|
||||
]))
|
||||
self.assertTrue(np.all(mp[::-2, ::-2].toarray() == [
|
||||
[14, 12, 10],
|
||||
[4, 2, 0]
|
||||
]))
|
||||
self.assertTrue(np.all(mp[1:3, 2:4].toarray() == [[7, 8], [12, 13]]))
|
||||
self.assertTrue(
|
||||
np.all(mp[:3, :4].toarray() == [[0.0, 1.0, 2.0, 3.0], [5.0, 6.0, 7.0, 8.0], [10.0, 11.0, 12.0, 13.0]])
|
||||
)
|
||||
self.assertTrue(np.all(mp[::-1, ::-1].toarray() == [[14, 13, 12, 11, 10], [9, 8, 7, 6, 5], [4, 3, 2, 1, 0]]))
|
||||
self.assertTrue(np.all(mp[::-2, ::-2].toarray() == [[14, 12, 10], [4, 2, 0]]))
|
||||
|
||||
self.assertTrue(np.all(mp.T[2:4, 1:3].toarray() == [
|
||||
[7, 12],
|
||||
[8, 13]
|
||||
]))
|
||||
self.assertTrue(np.all(mp.T[:4, :3].toarray() == [
|
||||
[0, 5, 10],
|
||||
[1, 6, 11],
|
||||
[2, 7, 12],
|
||||
[3, 8, 13]
|
||||
]))
|
||||
self.assertTrue(np.all(mp.T[::-1, ::-1].toarray() == [
|
||||
[14, 9, 4],
|
||||
[13, 8, 3],
|
||||
[12, 7, 2],
|
||||
[11, 6, 1],
|
||||
[10, 5, 0]
|
||||
]))
|
||||
self.assertTrue(np.all(mp.T[::-2, ::-2].toarray() == [
|
||||
[14, 4],
|
||||
[12, 2],
|
||||
[10, 0]
|
||||
]))
|
||||
self.assertTrue(np.all(mp.T[2:4, 1:3].toarray() == [[7, 12], [8, 13]]))
|
||||
self.assertTrue(np.all(mp.T[:4, :3].toarray() == [[0, 5, 10], [1, 6, 11], [2, 7, 12], [3, 8, 13]]))
|
||||
self.assertTrue(
|
||||
np.all(mp.T[::-1, ::-1].toarray() == [[14, 9, 4], [13, 8, 3], [12, 7, 2], [11, 6, 1], [10, 5, 0]])
|
||||
)
|
||||
self.assertTrue(np.all(mp.T[::-2, ::-2].toarray() == [[14, 4], [12, 2], [10, 0]]))
|
||||
|
||||
def test_repeated_indexing(self):
|
||||
"""
|
||||
@@ -149,31 +121,15 @@ class MatrixProxyViewTest(unittest.TestCase):
|
||||
self.assertEqual(mp[0][1], 1)
|
||||
self.assertEqual(mp.T[0][1], 5)
|
||||
|
||||
self.assertTrue(np.all(mp[0::-1, ::-1][0, 2:4].toarray() == [
|
||||
2, 1
|
||||
]))
|
||||
self.assertTrue(np.all(mp[0::-1, 1:5:1][0, 1:3:1].toarray() == [
|
||||
2, 3
|
||||
]))
|
||||
self.assertTrue(np.all(mp[0::-1, 1:5:1][0, 2:0:-1].toarray() == [
|
||||
3, 2
|
||||
]))
|
||||
self.assertTrue(np.all(mp[0::-1, 5:1:-1][0, 1:3:1].toarray() == [
|
||||
3, 2
|
||||
]))
|
||||
self.assertTrue(np.all(mp[0::-1, 5:1:-1][0, 2:0:-1].toarray() == [
|
||||
2, 3
|
||||
]))
|
||||
self.assertTrue(np.all(mp[0::-1, ::-1][0, 2:4].toarray() == [2, 1]))
|
||||
self.assertTrue(np.all(mp[0::-1, 1:5:1][0, 1:3:1].toarray() == [2, 3]))
|
||||
self.assertTrue(np.all(mp[0::-1, 1:5:1][0, 2:0:-1].toarray() == [3, 2]))
|
||||
self.assertTrue(np.all(mp[0::-1, 5:1:-1][0, 1:3:1].toarray() == [3, 2]))
|
||||
self.assertTrue(np.all(mp[0::-1, 5:1:-1][0, 2:0:-1].toarray() == [2, 3]))
|
||||
|
||||
self.assertTrue(np.all(mp.T[::-1, 0::-1][2:4, 0].toarray() == [
|
||||
2, 1
|
||||
]))
|
||||
self.assertTrue(np.all(mp.T[0::-1, 1:5:1][0, 1:3:1].toarray() == [
|
||||
10
|
||||
]))
|
||||
self.assertTrue(np.all(mp.T[0::-1, 1:5:1][0, 2:0:-1].toarray() == [
|
||||
10
|
||||
]))
|
||||
self.assertTrue(np.all(mp.T[::-1, 0::-1][2:4, 0].toarray() == [2, 1]))
|
||||
self.assertTrue(np.all(mp.T[0::-1, 1:5:1][0, 1:3:1].toarray() == [10]))
|
||||
self.assertTrue(np.all(mp.T[0::-1, 1:5:1][0, 2:0:-1].toarray() == [10]))
|
||||
self.assertTrue(np.all(mp.T[0::-1, 5:1:-1][0, 1:3:1].toarray() == []))
|
||||
self.assertTrue(np.all(mp.T[0::-1, 5:1:-1][0, 2:0:-1].toarray() == []))
|
||||
|
||||
@@ -190,20 +146,12 @@ class MatrixProxyViewTest(unittest.TestCase):
|
||||
self.assertEqual(mp[0, 0], 0)
|
||||
|
||||
# drop 1 dimension, to an array
|
||||
self.assertTrue(np.all(mp[0, :].toarray() == [
|
||||
0, 1, 2, 3, 4
|
||||
]))
|
||||
self.assertTrue(np.all(mp[:, 0].toarray() == [
|
||||
0, 5, 10
|
||||
]))
|
||||
self.assertTrue(np.all(mp[0, :].toarray() == [0, 1, 2, 3, 4]))
|
||||
self.assertTrue(np.all(mp[:, 0].toarray() == [0, 5, 10]))
|
||||
|
||||
# with .T
|
||||
self.assertTrue(np.all(mp[0:2].T[-1:].toarray() == [
|
||||
[4, 9]
|
||||
]))
|
||||
self.assertTrue(np.all(mp[0:2].T[-1].toarray() == [
|
||||
4, 9
|
||||
]))
|
||||
self.assertTrue(np.all(mp[0:2].T[-1:].toarray() == [[4, 9]]))
|
||||
self.assertTrue(np.all(mp[0:2].T[-1].toarray() == [4, 9]))
|
||||
|
||||
def test_iter(self):
|
||||
"""
|
||||
@@ -214,17 +162,13 @@ class MatrixProxyViewTest(unittest.TestCase):
|
||||
|
||||
rows = [r for r in mp]
|
||||
self.assertEqual(len(rows), 3)
|
||||
self.assertTrue(np.all(rows[0].toarray() == [
|
||||
0, 1, 2, 3, 4
|
||||
]))
|
||||
self.assertTrue(np.all(rows[0].toarray() == [0, 1, 2, 3, 4]))
|
||||
for i, r in enumerate(rows):
|
||||
self.assertTrue(np.all(mp[i].toarray() == r.toarray()))
|
||||
|
||||
cols = [c for c in mp.T]
|
||||
self.assertEqual(len(cols), 5)
|
||||
self.assertTrue(np.all(cols[0].toarray() == [
|
||||
0, 5, 10
|
||||
]))
|
||||
self.assertTrue(np.all(cols[0].toarray() == [0, 5, 10]))
|
||||
for i, c in enumerate(cols):
|
||||
self.assertTrue(np.all(mp.T[i].toarray() == c.toarray()))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user