Skip to content

Commit

Permalink
chore: apply ruff isort rules in pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jhamman committed May 10, 2024
1 parent 5bb3375 commit 638b95e
Show file tree
Hide file tree
Showing 76 changed files with 578 additions and 493 deletions.
4 changes: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ repos:
rev: 'v0.4.3'
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
args: ["--fix", "--show-fixes", --select, I]
types_or: [ python, pyi, jupyter ]
- id: ruff-format
types_or: [ python, pyi, jupyter ]
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
Expand Down
3 changes: 1 addition & 2 deletions bench/compress_normal.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import sys
import timeit

import numpy as np

import line_profiler
import numpy as np
import zarr
from zarr import blosc

Expand Down
97 changes: 52 additions & 45 deletions notebooks/advanced_indexing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@
],
"source": [
"import sys\n",
"sys.path.insert(0, '..')\n",
"import zarr\n",
"\n",
"sys.path.insert(0, \"..\")\n",
"import numpy as np\n",
"import zarr\n",
"\n",
"np.random.seed(42)\n",
"import cProfile\n",
"\n",
"zarr.__version__"
]
},
Expand Down Expand Up @@ -57,7 +60,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 +550,7 @@
],
"source": [
"# combine with slice\n",
"za.oindex[[1, 3], :]"
"za.oindex[[1, 3], :]"
]
},
{
Expand Down Expand Up @@ -973,10 +976,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 +1002,7 @@
}
],
"source": [
"za['foo']"
"za[\"foo\"]"
]
},
{
Expand All @@ -1020,7 +1023,7 @@
}
],
"source": [
"za['foo', 'baz']"
"za[\"foo\", \"baz\"]"
]
},
{
Expand All @@ -1041,7 +1044,7 @@
}
],
"source": [
"za[:2, 'foo']"
"za[:2, \"foo\"]"
]
},
{
Expand All @@ -1062,7 +1065,7 @@
}
],
"source": [
"za[:2, 'foo', 'baz']"
"za[:2, \"foo\", \"baz\"]"
]
},
{
Expand All @@ -1083,7 +1086,7 @@
}
],
"source": [
"za.oindex[[0, 2], 'foo']"
"za.oindex[[0, 2], \"foo\"]"
]
},
{
Expand All @@ -1104,7 +1107,7 @@
}
],
"source": [
"za.vindex[[0, 2], 'foo']"
"za.vindex[[0, 2], \"foo\"]"
]
},
{
Expand All @@ -1125,7 +1128,7 @@
}
],
"source": [
"za['bar'] = 42\n",
"za[\"bar\"] = 42\n",
"za[:]"
]
},
Expand All @@ -1147,7 +1150,7 @@
}
],
"source": [
"za[:2, 'bar'] = 84\n",
"za[:2, \"bar\"] = 84\n",
"za[:]"
]
},
Expand Down Expand Up @@ -1176,7 +1179,7 @@
}
],
"source": [
"a['foo', 'baz']"
"a[\"foo\", \"baz\"]"
]
},
{
Expand All @@ -1197,7 +1200,7 @@
}
],
"source": [
"a[['foo', 'baz']]"
"a[[\"foo\", \"baz\"]]"
]
},
{
Expand All @@ -1218,7 +1221,7 @@
}
],
"source": [
"za['foo', 'baz']"
"za[\"foo\", \"baz\"]"
]
},
{
Expand All @@ -1243,7 +1246,7 @@
}
],
"source": [
"za[['foo', 'baz']]"
"za[[\"foo\", \"baz\"]]"
]
},
{
Expand Down Expand Up @@ -1437,14 +1440,15 @@
"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,9 @@
"metadata": {},
"outputs": [],
"source": [
"import h5py\n",
"import tempfile"
"import tempfile\n",
"\n",
"import h5py"
]
},
{
Expand All @@ -2647,7 +2652,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 +2672,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 +2740,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 638b95e

Please sign in to comment.