Skip to content

Commit b4907df

Browse files
pitrouGeorgeAp
authored andcommitted
ARROW-12068: [Python] Stop using distutils
According to PEP 632, distutils will be deprecated in Python 3.10 and removed in 3.12. * switch to `setuptools` for general packaging * use the `Version` class from the `packaging` project instead of `distutils.LooseVersion` Closes apache#9849 from pitrou/ARROW-12068-remove-distutils Authored-by: Antoine Pitrou <antoine@python.org> Signed-off-by: Antoine Pitrou <antoine@python.org>
1 parent 335de95 commit b4907df

File tree

15 files changed

+636
-56
lines changed

15 files changed

+636
-56
lines changed

LICENSE.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,3 +2209,12 @@ The files in cpp/src/arrow/vendored/fast_float/ contain code from
22092209
https://github.com/lemire/fast_float
22102210

22112211
which is made available under the Apache License 2.0.
2212+
2213+
--------------------------------------------------------------------------------
2214+
2215+
The file python/pyarrow/vendored/version.py contains code from
2216+
2217+
https://github.com/pypa/packaging/
2218+
2219+
which is made available under both the Apache license v2.0 and the
2220+
BSD 2-clause license.

dev/release/rat_exclude_files.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ python/MANIFEST.in
136136
python/manylinux1/.dockerignore
137137
python/pyarrow/includes/__init__.pxd
138138
python/pyarrow/tests/__init__.py
139+
python/pyarrow/vendored/*
139140
python/requirements*.txt
140141
pax_global_header
141142
MANIFEST.in

dev/tasks/conda-recipes/azure.clean.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
displayName: Clone arrow
1414
1515
- script: |
16-
conda install -y -c conda-forge pandas anaconda-client
16+
conda install -y -c conda-forge pandas anaconda-client packaging
1717
displayName: Install requirements
1818
1919
- script: |

dev/tasks/conda-recipes/clean.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from distutils.version import LooseVersion
21
from subprocess import check_output, check_call
32
from typing import List
43

@@ -7,6 +6,8 @@
76
import pandas as pd
87
import sys
98

9+
from packaging.version import Version
10+
1011

1112
VERSIONS_TO_KEEP = 5
1213
PACKAGES = [
@@ -44,7 +45,7 @@ def packages_to_delete(package_name: str, platform: str) -> List[str]:
4445
env=env,
4546
)
4647
pkgs = pd.DataFrame(json.loads(pkgs_json)[package_name])
47-
pkgs["version"] = pkgs["version"].map(LooseVersion)
48+
pkgs["version"] = pkgs["version"].map(Version)
4849
pkgs["py_version"] = pkgs["build"].str.slice(0, 4)
4950

5051
to_delete = []

python/examples/plasma/sorting/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# under the License.
1717

1818
import numpy as np
19-
from distutils.core import setup
19+
from setuptools import setup
2020
from Cython.Build import cythonize
2121

2222
setup(

python/pyarrow/feather.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222
from pyarrow.lib import (Codec, FeatherError, Table, # noqa
2323
concat_tables, schema)
2424
import pyarrow.lib as ext
25+
from pyarrow.vendored.version import Version
2526

2627

2728
def _check_pandas_version():
28-
if _pandas_api.loose_version < '0.17.0':
29+
if _pandas_api.loose_version < Version('0.17.0'):
2930
raise ImportError("feather requires pandas >= 0.17.0")
3031

3132

python/pyarrow/pandas-shim.pxi

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ cdef class _PandasAPIShim(object):
5353
else:
5454
return
5555

56+
from pyarrow.vendored.version import Version
57+
5658
self._pd = pd
5759
self._version = pd.__version__
58-
from distutils.version import LooseVersion
59-
self._loose_version = LooseVersion(pd.__version__)
60+
self._loose_version = Version(pd.__version__)
6061

61-
if self._loose_version < LooseVersion('0.23.0'):
62+
if self._loose_version < Version('0.23.0'):
6263
self._have_pandas = False
6364
if raise_:
6465
raise ImportError(
@@ -82,7 +83,7 @@ cdef class _PandasAPIShim(object):
8283
self._series, self._index, self._categorical_type,
8384
self._extension_array)
8485
self._extension_dtype = pd.api.extensions.ExtensionDtype
85-
if self._loose_version >= LooseVersion('0.24.0'):
86+
if self._loose_version >= Version('0.24.0'):
8687
self._is_extension_array_dtype = \
8788
pd.api.types.is_extension_array_dtype
8889
else:
@@ -92,12 +93,12 @@ cdef class _PandasAPIShim(object):
9293
self._datetimetz_type = pd.api.types.DatetimeTZDtype
9394
self._have_pandas = True
9495

95-
if self._loose_version > LooseVersion('0.25'):
96+
if self._loose_version > Version('0.25'):
9697
self.has_sparse = False
9798
else:
9899
self.has_sparse = True
99100

100-
self._pd024 = self._loose_version >= LooseVersion('0.24')
101+
self._pd024 = self._loose_version >= Version('0.24')
101102

102103
cdef inline _check_import(self, bint raise_=True):
103104
if self._tried_importing_pandas:

python/pyarrow/tests/parquet/test_dataset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import datetime
1919
import os
20-
from distutils.version import LooseVersion
2120

2221
import numpy as np
2322
import pytest
@@ -30,6 +29,7 @@
3029
parametrize_legacy_dataset, parametrize_legacy_dataset_fixed,
3130
parametrize_legacy_dataset_not_supported)
3231
from pyarrow.util import guid
32+
from pyarrow.vendored.version import Version
3333

3434
try:
3535
import pyarrow.parquet as pq
@@ -633,7 +633,7 @@ def test_read_partitioned_directory_s3fs_wrapper(
633633

634634
from pyarrow.filesystem import S3FSWrapper
635635

636-
if s3fs.__version__ >= LooseVersion("0.5"):
636+
if Version(s3fs.__version__) >= Version("0.5"):
637637
pytest.skip("S3FSWrapper no longer working for s3fs 0.5+")
638638

639639
fs, path = s3_example_s3fs

python/pyarrow/tests/parquet/test_pandas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import io
1919
import json
20-
from distutils.version import LooseVersion
2120

2221
import numpy as np
2322
import pytest
@@ -26,6 +25,7 @@
2625
from pyarrow.tests.parquet.common import (
2726
parametrize_legacy_dataset, parametrize_legacy_dataset_not_supported)
2827
from pyarrow.util import guid
28+
from pyarrow.vendored.version import Version
2929

3030
try:
3131
import pyarrow.parquet as pq
@@ -559,7 +559,7 @@ def test_write_to_dataset_pandas_preserve_extensiondtypes(
559559
tempdir, use_legacy_dataset
560560
):
561561
# ARROW-8251 - preserve pandas extension dtypes in roundtrip
562-
if LooseVersion(pd.__version__) < "1.0.0":
562+
if Version(pd.__version__) < Version("1.0.0"):
563563
pytest.skip("__arrow_array__ added to pandas in 1.0.0")
564564

565565
df = pd.DataFrame({'part': 'a', "col": [1, 2, 3]})

python/pyarrow/tests/test_fs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
# under the License.
1717

1818
from datetime import datetime, timezone, timedelta
19-
from distutils.version import LooseVersion
2019
import gzip
2120
import os
2221
import pathlib
@@ -28,6 +27,8 @@
2827

2928
import pyarrow as pa
3029
from pyarrow.tests.test_io import assert_file_not_found
30+
from pyarrow.vendored.version import Version
31+
3132
from pyarrow.fs import (FileType, FileInfo, FileSelector, FileSystem,
3233
LocalFileSystem, SubTreeFileSystem, _MockFileSystem,
3334
FileSystemHandler, PyFileSystem, FSSpecHandler)
@@ -355,7 +356,8 @@ def py_fsspec_memoryfs(request, tempdir):
355356
@pytest.fixture
356357
def py_fsspec_s3fs(request, s3_connection, s3_server):
357358
s3fs = pytest.importorskip("s3fs")
358-
if sys.version_info < (3, 7) and s3fs.__version__ >= LooseVersion("0.5"):
359+
if (sys.version_info < (3, 7) and
360+
Version(s3fs.__version__) >= Version("0.5")):
359361
pytest.skip("s3fs>=0.5 version is async and requires Python >= 3.7")
360362

361363
host, port, access_key, secret_key = s3_connection

0 commit comments

Comments
 (0)