Skip to content

Commit 532801f

Browse files
committed
future annotations
1 parent ce34c1c commit 532801f

File tree

120 files changed

+253
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+253
-0
lines changed

.pre-commit-config.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,21 @@ repos:
156156
|(pd|pandas)\.api\.types\.
157157
files: ^pandas/tests/
158158
types_or: [python, cython, rst]
159+
- id: future-annotations
160+
name: Use from __future__ import annotations in source code
161+
language: pygrep
162+
entry: from __future__ import annotations
163+
files: ^pandas/
164+
exclude: |
165+
(?x)
166+
__init__\.py$
167+
|^pandas/tests/
168+
|^pandas/testing\.py
169+
|api\.py$
170+
|pandas/io/formats/_color_data\.py
171+
|pandas/io/sas/sas_constants\.py
172+
args: [--negate]
173+
types: [python]
159174
- id: pip-to-conda
160175
name: Generate pip dependency from conda
161176
description: This hook checks if the conda environment.yml and requirements-dev.txt are equal

pandas/_config/config.py

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
4949
"""
5050

51+
from __future__ import annotations
52+
5153
from collections import namedtuple
5254
from contextlib import (
5355
ContextDecorator,

pandas/_config/dates.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""
22
config for datetime formatting
33
"""
4+
from __future__ import annotations
5+
46
from pandas._config import config as cf
57

68
pc_date_dayfirst_doc = """

pandas/_config/display.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Unopinionated display configuration.
33
"""
44

5+
from __future__ import annotations
6+
57
import locale
68
import sys
79
from typing import Optional

pandas/_config/localization.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
44
Name `localization` is chosen to avoid overlap with builtin `locale` module.
55
"""
6+
from __future__ import annotations
7+
68
from contextlib import contextmanager
79
import locale
810
import re

pandas/_testing/_io.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import bz2
24
from functools import wraps
35
import gzip

pandas/_testing/_random.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import string
24

35
import numpy as np

pandas/_testing/_warnings.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from contextlib import contextmanager
24
import re
35
from typing import (

pandas/_testing/asserters.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import (
24
Union,
35
cast,

pandas/_testing/compat.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Helpers for sharing tests between DataFrame/Series
33
"""
44

5+
from __future__ import annotations
6+
57
from pandas import DataFrame
68

79

pandas/_testing/contexts.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from contextlib import contextmanager
24
import os
35
from pathlib import Path

pandas/_typing.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from datetime import (
24
datetime,
35
timedelta,

pandas/_version.py

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
"""Git implementation of _version.py."""
1111

12+
from __future__ import annotations
13+
1214
import errno
1315
import os
1416
import re

pandas/compat/_optional.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import distutils.version
24
import importlib
35
import sys

pandas/compat/chainmap.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import (
24
ChainMap,
35
MutableMapping,

pandas/compat/numpy/function.py

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
methods that are spread throughout the codebase. This module will make it
1616
easier to adjust to future upstream changes in the analogous numpy signatures.
1717
"""
18+
from __future__ import annotations
19+
1820
from distutils.version import LooseVersion
1921
from typing import (
2022
Any,

pandas/conftest.py

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- Misc
1919
"""
2020

21+
from __future__ import annotations
22+
2123
from collections import abc
2224
from datetime import (
2325
date,

pandas/core/accessor.py

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
that can be mixed into or pinned onto other pandas classes.
55
66
"""
7+
from __future__ import annotations
8+
79
from typing import (
810
FrozenSet,
911
List,

pandas/core/array_algos/masked_reductions.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
for missing values.
44
"""
55

6+
from __future__ import annotations
7+
68
from typing import Callable
79

810
import numpy as np

pandas/core/array_algos/putmask.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""
22
EA-compatible analogue to to np.putmask
33
"""
4+
from __future__ import annotations
5+
46
from typing import (
57
Any,
68
Tuple,

pandas/core/array_algos/replace.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""
22
Methods used by Block.replace and related methods.
33
"""
4+
from __future__ import annotations
5+
46
import operator
57
import re
68
from typing import (

pandas/core/array_algos/transforms.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
transforms.py is for shape-preserving functions.
33
"""
44

5+
from __future__ import annotations
6+
57
import numpy as np
68

79
from pandas.core.dtypes.common import ensure_platform_int

pandas/core/arraylike.py

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
Index
55
ExtensionArray
66
"""
7+
from __future__ import annotations
8+
79
import operator
810
from typing import Any
911
import warnings

pandas/core/arrays/_arrow_utils.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from distutils.version import LooseVersion
24
import json
35

pandas/core/arrays/_ranges.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
(and possibly TimedeltaArray/PeriodArray)
44
"""
55

6+
from __future__ import annotations
7+
68
from typing import Union
79

810
import numpy as np

pandas/core/arrays/sparse/accessor.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Sparse accessor"""
22

3+
from __future__ import annotations
4+
35
import numpy as np
46

57
from pandas.compat._optional import import_optional_dependency

pandas/core/arrays/sparse/scipy_sparse.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
44
Currently only includes to_coo helpers.
55
"""
6+
from __future__ import annotations
7+
68
from pandas.core.indexes.api import (
79
Index,
810
MultiIndex,

pandas/core/base.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Base and utility classes for pandas objects.
33
"""
44

5+
from __future__ import annotations
6+
57
import builtins
68
import textwrap
79
from typing import (

pandas/core/computation/check.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from pandas.compat._optional import import_optional_dependency
24

35
ne = import_optional_dependency("numexpr", errors="warn")

pandas/core/computation/common.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from functools import reduce
24

35
import numpy as np

pandas/core/computation/engines.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Engine classes for :func:`~pandas.eval`
33
"""
44

5+
from __future__ import annotations
6+
57
import abc
68
from typing import (
79
Dict,

pandas/core/computation/eval.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Top level ``eval`` module.
33
"""
44

5+
from __future__ import annotations
6+
57
import tokenize
68
from typing import Optional
79
import warnings

pandas/core/computation/expr.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
:func:`~pandas.eval` parsers.
33
"""
44

5+
from __future__ import annotations
6+
57
import ast
68
from functools import (
79
partial,

pandas/core/computation/expressions.py

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
Offer fast expression evaluation through numexpr
66
77
"""
8+
from __future__ import annotations
9+
810
import operator
911
from typing import (
1012
List,

pandas/core/computation/parsing.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
:func:`~pandas.eval` source string parsing functions
33
"""
44

5+
from __future__ import annotations
6+
57
from io import StringIO
68
from keyword import iskeyword
79
import token

pandas/core/config_init.py

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
module is imported, register them here rather than in the module.
1010
1111
"""
12+
from __future__ import annotations
13+
1214
import os
1315
import warnings
1416

pandas/core/dtypes/common.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Common type operations.
33
"""
44

5+
from __future__ import annotations
6+
57
from typing import (
68
Any,
79
Callable,

pandas/core/dtypes/concat.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""
22
Utility functions related to concat.
33
"""
4+
from __future__ import annotations
5+
46
from typing import cast
57

68
import numpy as np

pandas/core/dtypes/inference.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
""" basic inference routines """
22

3+
from __future__ import annotations
4+
35
from collections import abc
46
from numbers import Number
57
import re

pandas/core/dtypes/missing.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""
22
missing types & inference
33
"""
4+
from __future__ import annotations
5+
46
from decimal import Decimal
57
from functools import partial
68

pandas/core/flags.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import weakref
24

35

pandas/core/groupby/base.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
hold the allowlist of methods that are exposed on the
44
SeriesGroupBy and the DataFrameGroupBy objects.
55
"""
6+
from __future__ import annotations
7+
68
import collections
79
from typing import List
810

pandas/core/groupby/categorical.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import (
24
Optional,
35
Tuple,

pandas/core/groupby/numba_.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Common utilities for Numba operations with groupby ops"""
2+
from __future__ import annotations
3+
24
import inspect
35
from typing import (
46
Any,

pandas/core/index.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import warnings
24

35
from pandas.core.indexes.api import ( # noqa:F401

pandas/core/indexes/category.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import (
24
Any,
35
Hashable,

pandas/core/indexes/datetimelike.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""
22
Base and utility classes for tseries type pandas objects.
33
"""
4+
from __future__ import annotations
5+
46
from datetime import datetime
57
from typing import (
68
TYPE_CHECKING,

pandas/core/indexes/extension.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""
22
Shared methods for Index subclasses backed by ExtensionArray.
33
"""
4+
from __future__ import annotations
5+
46
from typing import (
57
Hashable,
68
List,

0 commit comments

Comments
 (0)