Skip to content

Commit

Permalink
style: pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Aug 19, 2024
1 parent b688cc6 commit 5113045
Show file tree
Hide file tree
Showing 11 changed files with 337 additions and 275 deletions.
97 changes: 51 additions & 46 deletions notebooks/advanced_indexing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@
],
"source": [
"import sys\n",
"sys.path.insert(0, '..')\n",
"import zarr\n",
"\n",
"sys.path.insert(0, \"..\")\n",
"import numpy as np\n",
"\n",
"import zarr\n",
"\n",
"np.random.seed(42)\n",
"import cProfile\n",
"\n",
"zarr.__version__"
]
},
Expand Down Expand Up @@ -57,7 +61,7 @@
"source": [
"a = np.arange(10)\n",
"za = zarr.array(a, chunks=2)\n",
"ix = [False, True, False, True, False, True, False, True, False, True]"
"ix = [False, True, False, True, False, True, False, True, False, True]"
]
},
{
Expand Down Expand Up @@ -547,7 +551,7 @@
],
"source": [
"# combine with slice\n",
"za.oindex[[1, 3], :]"
"za.oindex[[1, 3], :]"
]
},
{
Expand Down Expand Up @@ -973,10 +977,10 @@
}
],
"source": [
"a = np.array([(b'aaa', 1, 4.2),\n",
" (b'bbb', 2, 8.4),\n",
" (b'ccc', 3, 12.6)], \n",
" dtype=[('foo', 'S3'), ('bar', 'i4'), ('baz', 'f8')])\n",
"a = np.array(\n",
" [(b\"aaa\", 1, 4.2), (b\"bbb\", 2, 8.4), (b\"ccc\", 3, 12.6)],\n",
" dtype=[(\"foo\", \"S3\"), (\"bar\", \"i4\"), (\"baz\", \"f8\")],\n",
")\n",
"za = zarr.array(a, chunks=2, fill_value=None)\n",
"za[:]"
]
Expand All @@ -999,7 +1003,7 @@
}
],
"source": [
"za['foo']"
"za[\"foo\"]"
]
},
{
Expand All @@ -1020,7 +1024,7 @@
}
],
"source": [
"za['foo', 'baz']"
"za[\"foo\", \"baz\"]"
]
},
{
Expand All @@ -1041,7 +1045,7 @@
}
],
"source": [
"za[:2, 'foo']"
"za[:2, \"foo\"]"
]
},
{
Expand All @@ -1062,7 +1066,7 @@
}
],
"source": [
"za[:2, 'foo', 'baz']"
"za[:2, \"foo\", \"baz\"]"
]
},
{
Expand All @@ -1083,7 +1087,7 @@
}
],
"source": [
"za.oindex[[0, 2], 'foo']"
"za.oindex[[0, 2], \"foo\"]"
]
},
{
Expand All @@ -1104,7 +1108,7 @@
}
],
"source": [
"za.vindex[[0, 2], 'foo']"
"za.vindex[[0, 2], \"foo\"]"
]
},
{
Expand All @@ -1125,7 +1129,7 @@
}
],
"source": [
"za['bar'] = 42\n",
"za[\"bar\"] = 42\n",
"za[:]"
]
},
Expand All @@ -1147,7 +1151,7 @@
}
],
"source": [
"za[:2, 'bar'] = 84\n",
"za[:2, \"bar\"] = 84\n",
"za[:]"
]
},
Expand Down Expand Up @@ -1176,7 +1180,7 @@
}
],
"source": [
"a['foo', 'baz']"
"a[\"foo\", \"baz\"]"
]
},
{
Expand All @@ -1197,7 +1201,7 @@
}
],
"source": [
"a[['foo', 'baz']]"
"a[[\"foo\", \"baz\"]]"
]
},
{
Expand All @@ -1218,7 +1222,7 @@
}
],
"source": [
"za['foo', 'baz']"
"za[\"foo\", \"baz\"]"
]
},
{
Expand All @@ -1243,7 +1247,7 @@
}
],
"source": [
"za[['foo', 'baz']]"
"za[[\"foo\", \"baz\"]]"
]
},
{
Expand Down Expand Up @@ -1437,14 +1441,14 @@
"metadata": {},
"outputs": [],
"source": [
"import tempfile\n",
"import cProfile\n",
"import pstats\n",
"import tempfile\n",
"\n",
"\n",
"def profile(statement, sort='time', restrictions=(7,)):\n",
"def profile(statement, sort=\"time\", restrictions=(7,)):\n",
" with tempfile.NamedTemporaryFile() as f:\n",
" cProfile.run(statement, filename=f.name)\n",
" pstats.Stats(f.name).sort_stats(sort).print_stats(*restrictions)\n"
" pstats.Stats(f.name).sort_stats(sort).print_stats(*restrictions)"
]
},
{
Expand Down Expand Up @@ -1477,7 +1481,7 @@
}
],
"source": [
"profile('zc.oindex[ix_dense_bool]')"
"profile(\"zc.oindex[ix_dense_bool]\")"
]
},
{
Expand Down Expand Up @@ -1517,7 +1521,7 @@
}
],
"source": [
"profile('zc.vindex[ix_dense_bool]')"
"profile(\"zc.vindex[ix_dense_bool]\")"
]
},
{
Expand Down Expand Up @@ -1551,7 +1555,7 @@
}
],
"source": [
"ix_dense_int = np.random.choice(c.shape[0], size=c.shape[0]//10, replace=True)\n",
"ix_dense_int = np.random.choice(c.shape[0], size=c.shape[0] // 10, replace=True)\n",
"ix_dense_int_sorted = ix_dense_int.copy()\n",
"ix_dense_int_sorted.sort()\n",
"len(ix_dense_int)"
Expand Down Expand Up @@ -1689,7 +1693,7 @@
}
],
"source": [
"profile('zc.oindex[ix_dense_int_sorted]')"
"profile(\"zc.oindex[ix_dense_int_sorted]\")"
]
},
{
Expand Down Expand Up @@ -1722,7 +1726,7 @@
}
],
"source": [
"profile('zc.vindex[ix_dense_int_sorted]')"
"profile(\"zc.vindex[ix_dense_int_sorted]\")"
]
},
{
Expand Down Expand Up @@ -1755,7 +1759,7 @@
}
],
"source": [
"profile('zc.oindex[ix_dense_int]')"
"profile(\"zc.oindex[ix_dense_int]\")"
]
},
{
Expand Down Expand Up @@ -1788,7 +1792,7 @@
}
],
"source": [
"profile('zc.vindex[ix_dense_int]')"
"profile(\"zc.vindex[ix_dense_int]\")"
]
},
{
Expand Down Expand Up @@ -1908,7 +1912,7 @@
}
],
"source": [
"profile('zc.oindex[ix_sparse_bool]')"
"profile(\"zc.oindex[ix_sparse_bool]\")"
]
},
{
Expand Down Expand Up @@ -1941,7 +1945,7 @@
}
],
"source": [
"profile('zc.vindex[ix_sparse_bool]')"
"profile(\"zc.vindex[ix_sparse_bool]\")"
]
},
{
Expand All @@ -1968,7 +1972,7 @@
}
],
"source": [
"ix_sparse_int = np.random.choice(c.shape[0], size=c.shape[0]//10000, replace=True)\n",
"ix_sparse_int = np.random.choice(c.shape[0], size=c.shape[0] // 10000, replace=True)\n",
"ix_sparse_int_sorted = ix_sparse_int.copy()\n",
"ix_sparse_int_sorted.sort()\n",
"len(ix_sparse_int)"
Expand Down Expand Up @@ -2106,7 +2110,7 @@
}
],
"source": [
"profile('zc.oindex[ix_sparse_int]')"
"profile(\"zc.oindex[ix_sparse_int]\")"
]
},
{
Expand Down Expand Up @@ -2139,7 +2143,7 @@
}
],
"source": [
"profile('zc.vindex[ix_sparse_int]')"
"profile(\"zc.vindex[ix_sparse_int]\")"
]
},
{
Expand Down Expand Up @@ -2330,7 +2334,7 @@
}
],
"source": [
"profile('zc[::2]')"
"profile(\"zc[::2]\")"
]
},
{
Expand Down Expand Up @@ -2480,8 +2484,8 @@
"metadata": {},
"outputs": [],
"source": [
"ix0 = np.random.choice(d.shape[0], size=int(d.shape[0] * .5), replace=True)\n",
"ix1 = np.random.choice(d.shape[1], size=int(d.shape[1] * .5), replace=True)"
"ix0 = np.random.choice(d.shape[0], size=int(d.shape[0] * 0.5), replace=True)\n",
"ix1 = np.random.choice(d.shape[1], size=int(d.shape[1] * 0.5), replace=True)"
]
},
{
Expand Down Expand Up @@ -2542,7 +2546,7 @@
}
],
"source": [
"n = int(d.size * .1)\n",
"n = int(d.size * 0.1)\n",
"ix0 = np.random.choice(d.shape[0], size=n, replace=True)\n",
"ix1 = np.random.choice(d.shape[1], size=n, replace=True)\n",
"n"
Expand Down Expand Up @@ -2612,7 +2616,7 @@
}
],
"source": [
"profile('zd.vindex[ix0, ix1]')"
"profile(\"zd.vindex[ix0, ix1]\")"
]
},
{
Expand All @@ -2637,8 +2641,7 @@
"metadata": {},
"outputs": [],
"source": [
"import h5py\n",
"import tempfile"
"import h5py"
]
},
{
Expand All @@ -2647,7 +2650,7 @@
"metadata": {},
"outputs": [],
"source": [
"h5f = h5py.File(tempfile.mktemp(), driver='core', backing_store=False)"
"h5f = h5py.File(tempfile.mktemp(), driver=\"core\", backing_store=False)"
]
},
{
Expand All @@ -2667,7 +2670,9 @@
}
],
"source": [
"hc = h5f.create_dataset('c', data=c, compression='gzip', compression_opts=1, chunks=zc.chunks, shuffle=True)\n",
"hc = h5f.create_dataset(\n",
" \"c\", data=c, compression=\"gzip\", compression_opts=1, chunks=zc.chunks, shuffle=True\n",
")\n",
"hc"
]
},
Expand Down Expand Up @@ -2733,7 +2738,7 @@
"metadata": {},
"outputs": [],
"source": [
"# # this is pathological, takes minutes \n",
"# # this is pathological, takes minutes\n",
"# %time hc[ix_dense_bool]"
]
},
Expand Down
Loading

0 comments on commit 5113045

Please sign in to comment.