diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 35ee63e63..4badb6245 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ ci: repos: - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: "v0.1.9" + rev: "v0.3.5" hooks: - id: ruff args: ["--fix", "--show-fixes"] @@ -23,7 +23,7 @@ repos: - id: check-docstring-first - repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.12.1 + rev: 24.3.0 hooks: - id: black @@ -36,14 +36,14 @@ repos: - mdformat-myst - repo: https://github.com/nbQA-dev/nbQA - rev: 1.7.1 + rev: 1.8.5 hooks: - id: nbqa-black - id: nbqa-ruff args: [--fix] - repo: https://github.com/kynan/nbstripout - rev: 0.6.1 + rev: 0.7.1 hooks: - id: nbstripout args: [--extra-keys=metadata.kernelspec metadata.language_info.version] @@ -56,12 +56,12 @@ repos: - tomli - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.15 + rev: v0.16 hooks: - id: validate-pyproject - repo: https://github.com/rhysd/actionlint - rev: v1.6.26 + rev: v1.6.27 hooks: - id: actionlint files: ".github/workflows/" diff --git a/docs/source/user-stories/climatology-hourly.ipynb b/docs/source/user-stories/climatology-hourly.ipynb index b17cdc1aa..d264ac102 100644 --- a/docs/source/user-stories/climatology-hourly.ipynb +++ b/docs/source/user-stories/climatology-hourly.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "84e8bbee-90cc-4e6a-bf89-c56dc19c11ca", + "id": "0", "metadata": {}, "source": [ "# More climatology reductions\n", @@ -26,7 +26,7 @@ { "cell_type": "code", "execution_count": null, - "id": "727f490e-906a-4537-ac5e-3c67985cd6d5", + "id": "1", "metadata": {}, "outputs": [ { @@ -73,7 +73,7 @@ { "cell_type": "code", "execution_count": null, - "id": "6085684f-cafa-450c-8448-d5c9c1cbb55f", + "id": "2", "metadata": {}, "outputs": [ { @@ -98,7 +98,7 @@ }, { "cell_type": "markdown", - "id": "5380714a-b35f-4fb0-8b3d-7528ef7a7595", + "id": "3", "metadata": {}, "source": [ "## Create data\n" @@ -107,7 +107,7 @@ { "cell_type": "code", "execution_count": null, - "id": "2aa66559-b2dd-4b46-b32b-f1ce2270c3de", + "id": "4", "metadata": {}, "outputs": [ { @@ -636,7 +636,7 @@ }, { "cell_type": "markdown", - "id": "3a350782-b747-4e5e-8b8b-15fab72c0d2c", + "id": "5", "metadata": {}, "source": [ "Here's just plain xarray: 10000 tasks and one chunk per hour in the output\n" @@ -645,7 +645,7 @@ { "cell_type": "code", "execution_count": null, - "id": "ecc77698-5879-4b7c-ad97-891fb104d295", + "id": "6", "metadata": {}, "outputs": [ { @@ -1173,7 +1173,7 @@ }, { "cell_type": "markdown", - "id": "beccd9f8-ad62-4cd8-86cc-acfe14f13023", + "id": "7", "metadata": {}, "source": [ "And flox: 600 tasks and all hours in a single chunk\n" @@ -1182,7 +1182,7 @@ { "cell_type": "code", "execution_count": null, - "id": "0a3da8e5-863a-4602-9176-0a9adc689563", + "id": "8", "metadata": {}, "outputs": [ { @@ -1676,7 +1676,7 @@ { "cell_type": "code", "execution_count": null, - "id": "8aa1a641-1ce1-4264-96dc-d11bb1d4ab57", + "id": "9", "metadata": {}, "outputs": [], "source": [] @@ -1684,7 +1684,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e37c5aa2-c77a-4d87-8db4-5052c675c42d", + "id": "10", "metadata": {}, "outputs": [], "source": [ @@ -1694,7 +1694,7 @@ }, { "cell_type": "markdown", - "id": "494766c2-305a-4518-b2b7-a85bcc7fd5b2", + "id": "11", "metadata": {}, "source": [ "View the performance report\n", diff --git a/docs/source/user-stories/climatology.ipynb b/docs/source/user-stories/climatology.ipynb index 6ba8593fd..30bf38b75 100644 --- a/docs/source/user-stories/climatology.ipynb +++ b/docs/source/user-stories/climatology.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "4e9bf3f9-0952-493c-a8df-4a1d851c37a9", + "id": "0", "metadata": {}, "source": [ "# Strategies for climatology calculations\n", @@ -15,7 +15,7 @@ { "cell_type": "code", "execution_count": null, - "id": "85ac0588-ff00-43cc-b952-7ab775b24e4a", + "id": "1", "metadata": { "tags": [] }, @@ -31,7 +31,7 @@ }, { "cell_type": "markdown", - "id": "82f46621-1b6c-4a14-ac0f-3aa5121dad54", + "id": "2", "metadata": {}, "source": [ "Let's first create an example Xarray Dataset representing the OISST dataset,\n", @@ -41,7 +41,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9a91d2e2-bd6d-4b35-8002-5fac76c4c5b3", + "id": "3", "metadata": {}, "outputs": [], "source": [ @@ -56,7 +56,7 @@ }, { "cell_type": "markdown", - "id": "b7f519ee-e575-492c-a70b-8dad63a8c222", + "id": "4", "metadata": {}, "source": [ "To account for Feb-29 being present in some years, we'll construct a time vector to group by as \"mmm-dd\" string.\n", @@ -67,7 +67,7 @@ { "cell_type": "code", "execution_count": null, - "id": "3c42a618-47bc-4c83-a902-ec4cf3420180", + "id": "5", "metadata": {}, "outputs": [], "source": [ @@ -77,7 +77,7 @@ }, { "cell_type": "markdown", - "id": "6d913e7f-25bd-43c4-98b6-93bcb420c524", + "id": "6", "metadata": {}, "source": [ "## map-reduce\n", @@ -93,7 +93,7 @@ { "cell_type": "code", "execution_count": null, - "id": "ef2a14de-7526-40e3-8a97-28e84d6d6f20", + "id": "7", "metadata": {}, "outputs": [], "source": [ @@ -107,7 +107,7 @@ }, { "cell_type": "markdown", - "id": "442ad701-ea45-4555-9550-ec9daecfbea3", + "id": "8", "metadata": {}, "source": [ "## Rechunking for map-reduce\n", @@ -119,7 +119,7 @@ { "cell_type": "code", "execution_count": null, - "id": "322c7776-9a21-4115-8ac9-9c7c6c6e2c91", + "id": "9", "metadata": {}, "outputs": [], "source": [ @@ -133,7 +133,7 @@ }, { "cell_type": "markdown", - "id": "833f72eb-1501-4362-ae55-ec419c9f0ac1", + "id": "10", "metadata": {}, "source": [ "But what if we didn't want to rechunk the dataset so drastically (note the 10x\n", @@ -156,7 +156,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a3bafc32-7e13-41b8-90eb-b27955393392", + "id": "11", "metadata": {}, "outputs": [], "source": [ @@ -170,7 +170,7 @@ }, { "cell_type": "markdown", - "id": "b4e1ba0b-20e5-466a-9199-38b47029a0ed", + "id": "12", "metadata": {}, "source": [ "By default cohorts doesn't work so well for this problem because the period\n", @@ -185,7 +185,7 @@ { "cell_type": "code", "execution_count": null, - "id": "13ce5531-0d6c-4c89-bc44-dc2c24fa4e47", + "id": "13", "metadata": {}, "outputs": [], "source": [ @@ -200,7 +200,7 @@ }, { "cell_type": "markdown", - "id": "068b4109-b7f4-4c16-918d-9a18ff2ed183", + "id": "14", "metadata": {}, "source": [ "Looking more closely, we can see many cohorts with a single entry. " @@ -209,7 +209,7 @@ { "cell_type": "code", "execution_count": null, - "id": "57983cd0-a2e0-4d16-abe6-9572f6f252bf", + "id": "15", "metadata": {}, "outputs": [], "source": [ @@ -218,7 +218,7 @@ }, { "cell_type": "markdown", - "id": "bcbdbb3b-2aed-4f3f-ad20-efabb52b5e68", + "id": "16", "metadata": {}, "source": [ "## Rechunking data for cohorts\n", @@ -231,7 +231,7 @@ { "cell_type": "code", "execution_count": null, - "id": "40d393a5-7a4e-4d33-997b-4c422a0b8100", + "id": "17", "metadata": {}, "outputs": [], "source": [ @@ -240,7 +240,7 @@ }, { "cell_type": "markdown", - "id": "cd0033a3-d211-4aef-a284-c9fd3f75f6e4", + "id": "18", "metadata": {}, "source": [ "We'll choose to rechunk such that a single month in is a chunk. This is not too different from the current chunking but will help your periodicity problem" @@ -249,7 +249,7 @@ { "cell_type": "code", "execution_count": null, - "id": "5914a350-a7db-49b3-9504-6d63ff874f5e", + "id": "19", "metadata": {}, "outputs": [], "source": [ @@ -259,7 +259,7 @@ { "cell_type": "code", "execution_count": null, - "id": "90a884bc-1b71-4874-8143-73b3b5c41458", + "id": "20", "metadata": {}, "outputs": [], "source": [ @@ -268,7 +268,7 @@ }, { "cell_type": "markdown", - "id": "12b7a27f-ebab-4673-bb9f-80620389994b", + "id": "21", "metadata": {}, "source": [ "And now our cohorts contain more than one group\n" @@ -277,7 +277,7 @@ { "cell_type": "code", "execution_count": null, - "id": "f522fb82-764d-4e4e-8337-a5123e3088f8", + "id": "22", "metadata": {}, "outputs": [], "source": [ @@ -292,7 +292,7 @@ { "cell_type": "code", "execution_count": null, - "id": "4e2b6f70-c057-4783-ad55-21b20ff27e7f", + "id": "23", "metadata": {}, "outputs": [], "source": [ @@ -301,7 +301,7 @@ }, { "cell_type": "markdown", - "id": "949ac39c-dd84-4375-a884-0c1c3c382a8f", + "id": "24", "metadata": {}, "source": [ "Now the groupby reduction **looks OK** in terms of number of tasks but remember\n", @@ -311,7 +311,7 @@ { "cell_type": "code", "execution_count": null, - "id": "8f1e45f9-5b18-482a-8c76-66f81ff5710f", + "id": "25", "metadata": {}, "outputs": [], "source": [ @@ -320,7 +320,7 @@ }, { "cell_type": "markdown", - "id": "93c58969-5c99-4bc0-90ee-9cef468bf78b", + "id": "26", "metadata": {}, "source": [ "## How about other climatologies?\n", @@ -331,7 +331,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e559ea33-5499-48ff-9a2e-5141c3a69fea", + "id": "27", "metadata": {}, "outputs": [], "source": [ @@ -340,7 +340,7 @@ }, { "cell_type": "markdown", - "id": "a00de8eb-e414-4920-8dcd-b64afbf91b62", + "id": "28", "metadata": {}, "source": [ "This looks great. Why?\n", diff --git a/docs/source/user-stories/custom-aggregations.ipynb b/docs/source/user-stories/custom-aggregations.ipynb index 8b9be09e9..b452287e9 100644 --- a/docs/source/user-stories/custom-aggregations.ipynb +++ b/docs/source/user-stories/custom-aggregations.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "190a42b0-e1df-40dd-bb68-0f8ebacdc6f3", + "id": "0", "metadata": {}, "source": [ "# Custom Aggregations\n", @@ -27,7 +27,7 @@ { "cell_type": "code", "execution_count": null, - "id": "8c6fcc42-b081-44fa-acf7-a95ec4ed75d2", + "id": "1", "metadata": {}, "outputs": [], "source": [ @@ -68,7 +68,7 @@ }, { "cell_type": "markdown", - "id": "4bf0f68a-cefc-454c-80cd-e60688958a87", + "id": "2", "metadata": {}, "source": [ "## A built-in reduction\n", @@ -79,7 +79,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c0a7f29f-311c-41fd-b03b-33ba7ffccfc6", + "id": "3", "metadata": {}, "outputs": [], "source": [ @@ -96,7 +96,7 @@ }, { "cell_type": "markdown", - "id": "d58c2984-0589-4730-848f-bb92817a4bd1", + "id": "4", "metadata": {}, "source": [ "## Aggregations\n", @@ -112,7 +112,7 @@ { "cell_type": "code", "execution_count": null, - "id": "574b93ef-dd73-4a98-bd53-69119d5d97c0", + "id": "5", "metadata": {}, "outputs": [], "source": [ @@ -122,7 +122,7 @@ }, { "cell_type": "markdown", - "id": "8750f32d-9d77-4197-88bb-b7c1388cdcfe", + "id": "6", "metadata": {}, "source": [ "Here's how the mean Aggregation is created\n", @@ -152,7 +152,7 @@ }, { "cell_type": "markdown", - "id": "ddb4663c-16bc-4f78-899d-490d0ec01452", + "id": "7", "metadata": {}, "source": [ "## Defining a custom aggregation\n", @@ -202,7 +202,7 @@ { "cell_type": "code", "execution_count": null, - "id": "05b8a1e5-e865-4b25-8540-df5aa6c218e9", + "id": "8", "metadata": {}, "outputs": [], "source": [ @@ -220,7 +220,7 @@ }, { "cell_type": "markdown", - "id": "b356f4f2-ae22-4f56-89ec-50646136e2eb", + "id": "9", "metadata": {}, "source": [ "Now we create the `Aggregation`\n" @@ -229,7 +229,7 @@ { "cell_type": "code", "execution_count": null, - "id": "07c0fc82-c77b-4472-9de7-3c4a7cf3e07e", + "id": "10", "metadata": {}, "outputs": [], "source": [ @@ -245,7 +245,7 @@ }, { "cell_type": "markdown", - "id": "899ece52-ebd4-47b4-8090-cbbb63f504a4", + "id": "11", "metadata": {}, "source": [ "And apply it!\n" @@ -254,7 +254,7 @@ { "cell_type": "code", "execution_count": null, - "id": "df85a390-99dd-432f-b248-6160935deb52", + "id": "12", "metadata": {}, "outputs": [], "source": [ diff --git a/docs/source/user-stories/nD-bins.ipynb b/docs/source/user-stories/nD-bins.ipynb index 87ef942bf..25fcee822 100644 --- a/docs/source/user-stories/nD-bins.ipynb +++ b/docs/source/user-stories/nD-bins.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "e970d800-c612-482a-bb3a-b1eb7ad53d88", + "id": "0", "metadata": { "tags": [], "user_expressions": [] @@ -28,7 +28,7 @@ { "cell_type": "code", "execution_count": null, - "id": "01f1a2ef-de62-45d0-a04e-343cd78debc5", + "id": "1", "metadata": { "tags": [] }, @@ -46,7 +46,7 @@ }, { "cell_type": "markdown", - "id": "0be3e214-0cf0-426f-8ebb-669cc5322310", + "id": "2", "metadata": { "user_expressions": [] }, @@ -56,7 +56,7 @@ }, { "cell_type": "markdown", - "id": "ce239000-e053-4fc3-ad14-e9e0160da869", + "id": "3", "metadata": { "user_expressions": [] }, @@ -67,7 +67,7 @@ { "cell_type": "code", "execution_count": null, - "id": "7659c24e-f5a1-4e59-84c0-5ec965ef92d2", + "id": "4", "metadata": { "tags": [] }, @@ -83,7 +83,7 @@ }, { "cell_type": "markdown", - "id": "da0c0ac9-ad75-42cd-a1ea-99069f5bef00", + "id": "5", "metadata": { "user_expressions": [] }, @@ -94,7 +94,7 @@ { "cell_type": "code", "execution_count": null, - "id": "4601e744-5d22-447e-97ce-9644198d485e", + "id": "6", "metadata": { "tags": [] }, @@ -110,7 +110,7 @@ }, { "cell_type": "markdown", - "id": "61c21c94-7b6e-46a6-b9c2-59d7b2d40c81", + "id": "7", "metadata": { "tags": [], "user_expressions": [] @@ -122,7 +122,7 @@ { "cell_type": "code", "execution_count": null, - "id": "863a1991-ab8d-47c0-aa48-22b422fcea8c", + "id": "8", "metadata": { "tags": [] }, @@ -139,7 +139,7 @@ }, { "cell_type": "markdown", - "id": "e65ecaba-d1cc-4485-ae58-c390cb2ebfab", + "id": "9", "metadata": { "user_expressions": [] }, @@ -174,7 +174,7 @@ { "cell_type": "code", "execution_count": null, - "id": "aa33ab2c-0ecf-4198-a033-2a77f5d83c99", + "id": "10", "metadata": { "tags": [] }, @@ -186,7 +186,7 @@ { "cell_type": "code", "execution_count": null, - "id": "afcddcc1-dd57-461e-a649-1f8bcd30342f", + "id": "11", "metadata": { "tags": [] }, @@ -217,7 +217,7 @@ }, { "cell_type": "markdown", - "id": "1661312a-dc61-4a26-bfd8-12c2dc01eb15", + "id": "12", "metadata": { "user_expressions": [] }, @@ -234,7 +234,7 @@ { "cell_type": "code", "execution_count": null, - "id": "0e5801cb-a79c-4670-ad10-36bb19f1a6ff", + "id": "13", "metadata": { "tags": [] }, @@ -250,7 +250,7 @@ }, { "cell_type": "markdown", - "id": "6c06c48b-316b-4a33-9bc3-921acd10bcba", + "id": "14", "metadata": { "user_expressions": [] }, @@ -263,7 +263,7 @@ { "cell_type": "code", "execution_count": null, - "id": "2cf1295e-4585-48b9-ac2b-9e00d03b2b9a", + "id": "15", "metadata": { "tags": [] }, @@ -283,7 +283,7 @@ }, { "cell_type": "markdown", - "id": "3539509b-d9b4-4342-a679-6ada6f285dfb", + "id": "16", "metadata": { "user_expressions": [] }, @@ -296,7 +296,7 @@ { "cell_type": "code", "execution_count": null, - "id": "b1389d37-d76d-4a50-9dfb-8710258de3fd", + "id": "17", "metadata": { "tags": [] }, @@ -316,7 +316,7 @@ }, { "cell_type": "markdown", - "id": "a98b5e60-94af-45ae-be1b-4cb47e2d77ba", + "id": "18", "metadata": { "user_expressions": [] }, @@ -327,7 +327,7 @@ { "cell_type": "code", "execution_count": null, - "id": "053a8643-f6d9-4fd1-b014-230fa716449c", + "id": "19", "metadata": { "tags": [] }, @@ -338,7 +338,7 @@ }, { "cell_type": "markdown", - "id": "619ba4c4-7c87-459a-ab86-c187d3a86c67", + "id": "20", "metadata": { "tags": [], "user_expressions": [] diff --git a/flox/aggregations.py b/flox/aggregations.py index 86b0f5f2e..deaccd4e0 100644 --- a/flox/aggregations.py +++ b/flox/aggregations.py @@ -623,9 +623,11 @@ def _initialize_aggregation( "final": final_dtype, "numpy": (final_dtype,), "intermediate": tuple( - _normalize_dtype(int_dtype, np.result_type(array_dtype, final_dtype), int_fv) - if int_dtype is None - else np.dtype(int_dtype) + ( + _normalize_dtype(int_dtype, np.result_type(array_dtype, final_dtype), int_fv) + if int_dtype is None + else np.dtype(int_dtype) + ) for int_dtype, int_fv in zip( agg.dtype_init["intermediate"], agg.fill_value["intermediate"] ) diff --git a/flox/core.py b/flox/core.py index 30589c25a..7d82b6f44 100644 --- a/flox/core.py +++ b/flox/core.py @@ -657,8 +657,7 @@ def factorize_( expected_groups: T_ExpectIndexOptTuple | None = None, reindex: bool = False, sort: bool = True, -) -> tuple[np.ndarray, tuple[np.ndarray, ...], tuple[int, ...], int, int, None]: - ... +) -> tuple[np.ndarray, tuple[np.ndarray, ...], tuple[int, ...], int, int, None]: ... @overload @@ -670,8 +669,7 @@ def factorize_( reindex: bool = False, sort: bool = True, fastpath: Literal[False] = False, -) -> tuple[np.ndarray, tuple[np.ndarray, ...], tuple[int, ...], int, int, FactorProps]: - ... +) -> tuple[np.ndarray, tuple[np.ndarray, ...], tuple[int, ...], int, int, FactorProps]: ... @overload @@ -683,8 +681,7 @@ def factorize_( reindex: bool = False, sort: bool = True, fastpath: bool = False, -) -> tuple[np.ndarray, tuple[np.ndarray, ...], tuple[int, ...], int, int, FactorProps | None]: - ... +) -> tuple[np.ndarray, tuple[np.ndarray, ...], tuple[int, ...], int, int, FactorProps | None]: ... def factorize_( @@ -1929,15 +1926,13 @@ def _assert_by_is_aligned(shape: tuple[int, ...], by: T_Bys) -> None: @overload def _convert_expected_groups_to_index( expected_groups: tuple[None, ...], isbin: Sequence[bool], sort: bool -) -> tuple[None, ...]: - ... +) -> tuple[None, ...]: ... @overload def _convert_expected_groups_to_index( expected_groups: T_ExpectTuple, isbin: Sequence[bool], sort: bool -) -> T_ExpectIndexTuple: - ... +) -> T_ExpectIndexTuple: ... def _convert_expected_groups_to_index( @@ -2025,13 +2020,11 @@ def _factorize_multiple( @overload -def _validate_expected_groups(nby: int, expected_groups: None) -> tuple[None, ...]: - ... +def _validate_expected_groups(nby: int, expected_groups: None) -> tuple[None, ...]: ... @overload -def _validate_expected_groups(nby: int, expected_groups: T_ExpectedGroups) -> T_ExpectTuple: - ... +def _validate_expected_groups(nby: int, expected_groups: T_ExpectedGroups) -> T_ExpectTuple: ... def _validate_expected_groups(nby: int, expected_groups: T_ExpectedGroupsOpt) -> T_ExpectOptTuple: