28 Commits
Author SHA1 Message Date
Rok Mihevc c48e81e4d0 GH-48593: [C++] C++20: use standard calendar / timezone APIs (#48601)
### Rationale for this change

Switch to std::chrono for MSVC to be able to use the system-provided timezone automatically on Windows.

### What changes are included in this PR?

This adds `chrono_internal.h` that uses C++20 std::chrono timezone/calendar APIs on compilers with support (MSVC only for now) and falls back to vendored `date.h` otherwise.

### Are these changes tested?

Partially tested locally and partially to be tested on CI.

### Are there any user-facing changes?

Yes, Windows users will no longer need to install the IANA tzdb (see [instructions here](https://arrow.apache.org/docs/cpp/build_system.html#runtime-dependencies) and [here](https://arrow.apache.org/docs/python/install.html#tzdata-on-windows)). We possibly have tzdb download set up in CI too and should update it appropriately.
* GitHub Issue: #48593

Authored-by: Rok Mihevc <rok@mihevc.org>
Signed-off-by: Raúl Cumplido <raulcumplido@gmail.com>
2026-03-03 14:19:25 +01:00
Rok Mihevc 86b860fc4e GH-49044: [CI][Python] Fix test_download_tzdata_on_windows by adding required user-agent on urllib request (#49052)
### Rationale for this change

See: #49044

### What changes are included in this PR?

Urllib now request with `"user-agent": "pyarrow"`

### Are these changes tested?

It's a CI fix.

### Are there any user-facing changes?

No, just a CI test fix.
* GitHub Issue: #49044

Authored-by: Rok Mihevc <rok@mihevc.org>
Signed-off-by: Raúl Cumplido <raulcumplido@gmail.com>
2026-01-29 12:41:41 +01:00
Bryce MecumandJoris Van den Bossche f6e2cbeca2 GH-45295: [Python][CI] Make download_tzdata_on_windows more robust and use tzdata package for tzinfo database on Windows for ORC (#45425)
### Rationale for this change

We have two Windows issues and this PR is addressing both:

1. PyArrow's `download_tzdata_on_windows` can fail due to TLS issues in certain CI environments.
2. The Python wheel test infrastructure needs a tzinfo database for ORC and the automation fetching that started failing because the URL was made invalid upstream.

These two issues are being solved in one PR simply because they appeared together during the 19.0.1 release process but they're separate.

### What changes are included in this PR?

1. Makes `download_tzdata_on_windows` more robust to TLS errors by attempting to use `requests` if it's available and falling back to urllib otherwise.
2. Switches our Windows wheel test infrastructure to grab a tzinfo database from the tzdata package on PyPi instead of from a mirror URL. This should be much more stable for us over time.

### Are these changes tested?

Yes.

### Are there any user-facing changes?

No.
* GitHub Issue: #45295

Lead-authored-by: Bryce Mecum <petridish@gmail.com>
Co-authored-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
Signed-off-by: Bryce Mecum <petridish@gmail.com>
2025-02-10 17:49:34 -08:00
Alenka FrimandJoris Van den Bossche e52017a727 GH-37328: [Python] Add a function to download and extract timezone database on Windows (#38179)
### Rationale for this change

There is a section in the [Arrow C++ documentation with the instructions](https://arrow.apache.org/docs/dev/cpp/build_system.html#runtime-dependencies) on how to download and extract text version of the IANA timezone database and on Windows. We should provide a function in PyArrow that a user would call to download and extract the timezone database from Python.

### What changes are included in this PR?

Function `download_tzdata_on_windows()` added to python/pyarrow/util.py that downloads and extracts timezone database to a standard location in `%USERPROFILE%\Downloads\tzdata` on Widnows.

### Are these changes tested?
Yes.

### Are there any user-facing changes?
No.
* Closes: #37328

Lead-authored-by: AlenkaF <frim.alenka@gmail.com>
Co-authored-by: Alenka Frim <AlenkaF@users.noreply.github.com>
Co-authored-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
Signed-off-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
2024-03-20 08:59:14 +01:00
Josh Soref 6101d12676 GH-38944: [Python] Fix spelling (#38945)
### Rationale for this change

### What changes are included in this PR?

Spelling fixes to python/

### Are these changes tested?

### Are there any user-facing changes?

* Closes: #38944

Authored-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
Signed-off-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
2023-12-01 09:30:13 +01:00
Dane Pitkin cd14e2019c GH-34868: [Python] Share docstrings between classes (#34894)
### Rationale for this change

Python classes sometimes duplicate docstrings, but change one word such as class name. Add a decorator function as a utility to help deduplicate docstring descriptions. Only works in Python. Does not work in Cython due to this CPython issue https://github.com/python/cpython/issues/91309.

### What changes are included in this PR?

Add a decorator `@ doc` that can copy, concatenate, and/or format docstrings between classes.

### Are these changes tested?

Tests added. 

```
>>> import pyarrow
>>> from pyarrow.filesystem import FileSystem, LocalFileSystem, DaskFileSystem, S3FSWrapper
>>> from pyarrow.hdfs import HadoopFileSystem
>>> for fs in [FileSystem, LocalFileSystem, DaskFileSystem, S3FSWrapper, HadoopFileSystem]:
...     print(fs.__name__)
...     print(fs.isdir.__doc__)
... 
FileSystem

        Return True if path is a directory.

        Parameters
        ----------
        path : str
            Path to check.
        
LocalFileSystem

Return True if path is a directory.

Parameters
----------
path : str
    Path to check.

DaskFileSystem

Return True if path is a directory.

Parameters
----------
path : str
    Path to check.

S3FSWrapper

Return True if path is a directory.

Parameters
----------
path : str
    Path to check.

HadoopFileSystem

Return True if path is a directory.

Parameters
----------
path : str
    Path to check.

```
Note that `FileSystem.isdir.__doc__` is not dedented because it does not use the `@ doc` decorator.

### Are there any user-facing changes?

No
* Closes: #34868

Authored-by: Dane Pitkin <dane@voltrondata.com>
Signed-off-by: Alenka Frim <frim.alenka@gmail.com>
2023-04-24 08:18:52 +02:00
Miles Granger 4d0fbffdf6 ARROW-17320: [Python] Refine pyarrow.parquet API exposure (#14096)
Fixes [ARROW-17320](https://issues.apache.org/jira/browse/ARROW-17320?page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel&focusedCommentId=17577330)

Added a deprecation for `_filters_to_expression` -> `filters_to_expression`, in https://github.com/apache/arrow/pull/14096/commits/c7fdff3b50ca0fe95ae4c771cee81d4d59aa98d0 let me know if that commit should be dropped. :) 

Authored-by: Miles Granger <miles59923@gmail.com>
Signed-off-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
2022-09-27 11:11:58 +02:00
Colin Jermain bdb5ab893e ARROW-15982: [Python] parquet.read_table fails to parse home directory path
This PR adds support for the home directory in paths. This fixes a problem where `pyarrow.parquet.read_table` fails to find files relative to the home directory.

I added `os.path.expanduser` to the `_stringify_path` function to have the widest effect with minimal changes. Happy to adjust that if there is a better place.

Closes #12675 from cjermain/ARROW-15982

Authored-by: Colin Jermain <cjermain@gmail.com>
Signed-off-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
2022-04-05 15:18:04 +02:00
Kian-Meng Ang ad073b7c0f MINOR: Fix typos in Python comments and docstrings
Closes #12295 from kianmeng/fix-typos-in-python

Authored-by: Kian-Meng Ang <kianmeng@cpan.org>
Signed-off-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
2022-01-31 12:29:58 +01:00
Antoine Pitrou 0f4d662ae5 ARROW-12706: [Python] Drop Python 3.6 support
Closes #12026 from pitrou/ARROW-12706-drop-py36

Authored-by: Antoine Pitrou <antoine@python.org>
Signed-off-by: Antoine Pitrou <antoine@python.org>
2021-12-29 13:40:52 +01:00
Antoine Pitrou fda6b27d81 ARROW-13187: [Python] Avoid creating reference cycle when reading CSV file
Some Python versions have a bug where `signal.getsignal` creates a reference cycle holding execution frames alive (https://bugs.python.org/issue42248).

This would cause excessive lifetimes of the PyArrow table returned by `read_csv`.

Closes #10609 from pitrou/ARROW-13187-signal-refcycle

Authored-by: Antoine Pitrou <antoine@python.org>
Signed-off-by: Antoine Pitrou <antoine@python.org>
2021-06-29 17:08:02 +02:00
David Li 3274d081e1 ARROW-10882: [Python] Allow writing dataset from iterator of batches
This binds InMemoryDataset to Python, allowing us to create and write back out datasets from iterables of record batches and various other objects.

Closes #9802 from lidavidm/arrow-10882

Authored-by: David Li <li.davidm96@gmail.com>
Signed-off-by: David Li <li.davidm96@gmail.com>
2021-04-06 08:00:48 -04:00
Joris Van den Bossche 25d131b3f1 ARROW-9645: [Python] Deprecate pyarrow.filesystem in favor of pyarrow.fs
Closes #8149 from jorisvandenbossche/ARROW-9645-deprecate-legacy-filesystems

Authored-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
Signed-off-by: Antoine Pitrou <antoine@python.org>
2020-10-07 19:33:27 +02:00
Krisztián Szűcs 98f10dce42 ARROW-9017: [C++][Python] Refactor scalar bindings
TODOs:
 - [x] split PRs into two, one with simplified python to arrow conversions with benchmarks
 - [x] implement union scalar on the C++ side
 - [x] store the index value for dictionary scalar
 - [x] more tests

Closes ARROW-9017, ARROW-9153

Closes #7519 from kszucs/ARROW-9153

Authored-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
Signed-off-by: Wes McKinney <wesm@apache.org>
2020-07-06 17:15:50 -05:00
Wes McKinney 124db17bcd ARROW-9030: [Python] Remove pyarrow/compat.py, move some oft-used utility functions to pyarrow.lib
This is some routine scrubbing that deals with some remnants of the prior dual py2/3 codebase.

Closes #7421 from wesm/ARROW-9030

Authored-by: Wes McKinney <wesm@apache.org>
Signed-off-by: Wes McKinney <wesm@apache.org>
2020-06-12 21:36:22 -05:00
Wes McKinney fc47dd035f ARROW-8232: [Python] Deprecate pyarrow.open_stream and pyarrow.open_file APIs in favor of accessing via pyarrow.ipc namespace
In my opinion, these APIs in the top level namespace are unclear and possibly misleading. We should encourage people to use the `pyarrow.ipc` namespace.

Closes #6757 from wesm/ARROW-8232

Authored-by: Wes McKinney <wesm+git@apache.org>
Signed-off-by: Antoine Pitrou <antoine@python.org>
2020-03-30 13:45:47 +02:00
Antoine Pitrou 412145b8a7 ARROW-5757: [Python] Remove Python 2.7 support
Part of the changes were done using [pyupgrade](https://github.com/asottile/pyupgrade).

Closes #6410 from pitrou/ARROW-5757-py2-goodbye and squashes the following commits:

f0f9f513b <Antoine Pitrou> Address review comments
561ac965c <Antoine Pitrou> ARROW-5757:  Remove Python 2.7 support

Authored-by: Antoine Pitrou <antoine@python.org>
Signed-off-by: Wes McKinney <wesm+git@apache.org>
2020-02-12 21:37:59 -06:00
Krisztián Szűcs 8bbb297b18 ARROW-6655: [Python] Filesystem bindings for S3
- Add support for S3FileSystem in the python bindings.
- Fixed issue with reading all the content of an S3 object
- Introduce `minio_server` fixture for parametrized testing of all filesystem implementations
- Fixed s3fs parquet test and updated it to use minio_server fixture

Closes #5423 from kszucs/s3 and squashes the following commits:

384c96052 <Krisztián Szűcs> Resolve review comments
73e6625f9 <Krisztián Szűcs> S3Options
98bd91ad1 <Krisztián Szűcs> remove commented tests
db89859ca <Krisztián Szűcs> rename to s3fs
44784582a <Krisztián Szűcs> fix read() issue
c1df10b92 <Krisztián Szűcs> initialization in first use
192ab6547 <Krisztián Szűcs> flake8
f70f9fbd8 <Krisztián Szűcs> remove minio-client dependency
d399643dc <Krisztián Szűcs> simplify test suite
fee57a9a4 <Krisztián Szűcs> remove accidentally committed files
751cfd429 <Krisztián Szűcs> resolve a couple of review comments; enum workaround
45436f7b3 <Krisztián Szűcs> cython flake8
38dcb88d0 <Krisztián Szűcs> rat
c541b3e15 <Krisztián Szűcs> comment left
098048a8a <Krisztián Szűcs> more compat
00340ed4c <Krisztián Szűcs> fixture error handling
2be25ce29 <Krisztián Szűcs> auto initialize s3 on import
88e0c9f79 <Krisztián Szűcs> py2 compat
8585a6085 <Krisztián Szűcs> py2 compat
d37228711 <Krisztián Szűcs> install minio in the conda-toolchain build
041cad42a <Krisztián Szűcs> executable flag
fb0f2813a <Krisztián Szűcs> travis minio install script
8cbe0eeef <Krisztián Szűcs> travis osx
72e56a68f <Krisztián Szűcs> enable S3 in travis python builds
7800c75d8 <Krisztián Szűcs> appveyor flag
7daf5668d <Krisztián Szűcs> fix syntax error in travis script
68eb59161 <Krisztián Szűcs> enable PYARROW_WITH_S3 on appveyor
2cb19d1ff <Krisztián Szűcs> conditional import of test dependencies
efa05d28e <Krisztián Szűcs> use minio for dask.s3fs test too
f25ae5aed <Krisztián Szűcs> travis
9042c7e4c <Krisztián Szűcs> use S3FS_DIR
9ce7180d1 <Krisztián Szűcs> cmake format; fix orc cimport
45a2a17ba <Krisztián Szűcs> docstrings
c0b91621e <Krisztián Szűcs> test requirements; flake8
44aedfd10 <Krisztián Szűcs> stat test
a343950e2 <Krisztián Szűcs> testing suite
1551b525c <Krisztián Szűcs> wip
dd41d21c2 <Krisztián Szűcs> imports
5200af16f <Krisztián Szűcs> s3 filesystem bindings

Authored-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
Signed-off-by: Antoine Pitrou <antoine@python.org>
2019-10-05 11:47:17 +02:00
Philipp Moritz 207b3507be ARROW-5027: [Python] Python bindings for JSON reader
This PR implements Python bindings for the JSON reader.

Author: Philipp Moritz <pcmoritz@gmail.com>

Closes #4044 from pcmoritz/cython-read-json and squashes the following commits:

1148f43ed <Philipp Moritz> update
465e9d416 <Philipp Moritz> fixes and docstring
d75b02d18 <Philipp Moritz> add tests
b630845a7 <Philipp Moritz> temp commit
aa0aa3f85 <Philipp Moritz> update
b1742b00e <Philipp Moritz> update
9dfc978cf <Philipp Moritz> add absolute imports
c776e0f5e <Philipp Moritz> linting
bb614282b <Philipp Moritz> comment in again
46a8561fe <Philipp Moritz> update
619064571 <Philipp Moritz> update
364971c86 <Philipp Moritz> update
90a3510a8 <Philipp Moritz> update
4edb201f6 <Philipp Moritz> initial work on JSON reader python wrapper
2019-05-27 18:01:27 +02:00
Pearu Peterson f0c464ea70 ARROW-4212: [C++][Python] CudaBuffer view of arbitrary device memory object
This PR implements the following new features:
1. `CudaContext::GetDeviceAddress` method
2. `pyarrow.cuda.Context.get_device_address` method
3. `pyarrow.cuda.Context.buffer_from_object` method to create a CudaBuffer view of arbitrary device memory object that implements `__cuda_array_interface__` attribute or that is `CudaBuffer` or `CudaHostBuffer` or numba `MemoryPointer` object.
4. Tests for `buffer_from_object` method

and the following improvements:
1. `pyarrow.cuda.Context.foreign_buffer` ensures that the used device memory address is valid for the given context.

Author: Pearu Peterson <pearu.peterson@gmail.com>

Closes #3439 from pearu/arrow-4212 and squashes the following commits:

ba905739 <Pearu Peterson> Add 2-D and 3-D tests. buffer_from_object requires contiguous memory input.
355fc035 <Pearu Peterson> Apply more feedback fixes.
22134da4 <Pearu Peterson> Refactor. Add tests for negative strides and reduce test cases.
dbd1cec6 <Pearu Peterson> Moved some buffer_from_objects tests under test_cuda.
562c1805 <Pearu Peterson> Change GetDeviceAddress API to use uint8_t, add C++ tests for it, update docs and apply feedback.
2726a91e <Pearu Peterson> Add buffer_from_object and get_device_address methods.
df8656f8 <Pearu Peterson> Add GetDeviceAddress method to CudaContext.
2019-01-24 14:22:29 +01:00
Wes McKinney e098651a12 ARROW-3971: [Python] Remove deprecations in 0.11 and prior
Author: Wes McKinney <wesm+git@apache.org>

Closes #3180 from wesm/ARROW-3971 and squashes the following commits:

2a367f5d <Wes McKinney> Remove Python deprecations in 0.11 and prior
2018-12-15 17:17:09 +01:00
Wes McKinney 9b4cd9c03e ARROW-3075: [C++] Incorporate parquet-cpp codebase into Arrow C++ build
system. Add unit test label granularity options, ability to add component group
targets like 'make parquet' that build libraries and tests

Change-Id: I250fd10da3a9505952115b3cec18cd7cb5589bdb
2018-09-07 01:56:08 -04:00
Krisztián Szűcs 21ef18bb6a ARROW-3160: [Python] Improve pathlib.Path support in parquet and filesystem modules
- organize parquet test files to be consistent with the recently added orc [subdir](https://github.com/apache/arrow/tree/master/python/pyarrow/tests/data)
- use pathlib paths in parquet and orc tests

I intend to consolidate parquet test suite a bit in followup PRs.

Author: Krisztián Szűcs <szucs.krisztian@gmail.com>

Closes #2506 from kszucs/ARROW-3160 and squashes the following commits:

bf1fe1f8 <Krisztián Szűcs> use _has_pathlib
8b023034 <Krisztián Szűcs> compatibility with py35
dc306003 <Krisztián Szűcs> reorganizte utility functions in parquet and filasystem modules; support pathlib.Path in Filesystem API
062ef56a <Krisztián Szűcs> global tempdir fixture returns pathlib object
7c4d72c7 <Krisztián Szűcs> fallback to pathlib2 for older python
c550e1ba <Krisztián Szűcs> update parquet and orc tests to use pathlib
ee494170 <Krisztián Szűcs> use pathlib in orc and parquet tests; move parquet test files to its own directory
2018-09-05 12:44:40 -04:00
Wes McKinney ad7e6c3d54 ARROW-2989: [C++/Python] Remove API deprecations in 0.10
I didn't remove the `nthreads` deprecations in Python yet. @pitrou do you support removing them in 0.11?

Author: Wes McKinney <wesm+git@apache.org>

Closes #2478 from wesm/ARROW-2989 and squashes the following commits:

8de36e6a <Wes McKinney> Test non-threaded conversion
bff138a0 <Wes McKinney> Make use_threads=True the default in pandas conversion tests
5ae97a96 <Wes McKinney> Remove nthreads argument where thread pool is being used. Set default for use_threads to True
279453c7 <Wes McKinney> Remove C++/Python API deprecations in 0.10, except for nthreads in Python
2018-09-04 17:24:23 -04:00
Antoine Pitrou 01202ccc84 ARROW-2568: [Python] Expose thread pool size setting to Python, and deprecate "nthreads" where possible
There are two areas where `nthreads` cannot be replaced immediately by the global thread pool:

1. when converting Pandas data to Arrow table or record batch, since it uses a Python `ThreadPoolExecutor` from pure Python code (see `dataframe_to_arrays` in `pandas_compat.py`)
2. when reading or writing Parquet data, since `parquet-cpp` relies on parallelization facilities in the stable version of Arrow (see https://github.com/apache/parquet-cpp/pull/467)

Elsewhere, we add a `use_threads` boolean argument and deprecate `nthreads`.

Author: Antoine Pitrou <antoine@python.org>

Closes #2078 from pitrou/ARROW-2568 and squashes the following commits:

91187bf6 <Antoine Pitrou> Move use_threads flag into PandasOptions
a7aeed0e <Antoine Pitrou> Factor out secession predicate
f601d4e9 <Antoine Pitrou> ThreadPool::State pointer is const
4567a2c3 <Antoine Pitrou> Add a two-argument variant of ParallelFor() that uses the global CPU thread pool
d0a527ab <Antoine Pitrou> Restore single-thread path in WriteTableToBlocks()
2171e6e2 <Antoine Pitrou> On Windows, avoid shutting down the global thread pool at process exit
934e5a11 <Antoine Pitrou> Add & operator between Statuses
96397076 <Antoine Pitrou> Factor out deprecation logic
6b685406 <Antoine Pitrou> Fix MSVC warning
6b6f64a1 <Antoine Pitrou> Make ThreadPool capacity an int, not a size_t
61669755 <Antoine Pitrou> Rename CPUThreadPool() to GetCpuThreadPool()
d4eb8d47 <Antoine Pitrou> Export ThreadPool and CPUThreadPool()
6985afe6 <Antoine Pitrou> Lint
fcca62f5 <Antoine Pitrou> Emit FutureWarning (which is visible by default) rather than DeprecationWarning
172fba37 <Antoine Pitrou> Use C++ API, rather than multiprocessing, in pyarrow.{cpu_count,set_cpu_count}
50310b88 <Antoine Pitrou> Add API function to get desired ThreadPool capacity
3417325c <Antoine Pitrou> ARROW-2568:  WIP
2018-05-24 21:28:15 -04:00
Antoine Pitrou 3917e85d4a ARROW-2292: [Python] Rename frombuffer() to py_buffer()
Author: Antoine Pitrou <antoine@python.org>

Closes #1736 from pitrou/ARROW-2292-py_buffer and squashes the following commits:

41bf5f8f <Antoine Pitrou> ARROW-2292:  Rename frombuffer() to py_buffer()
2018-03-12 14:10:29 -04:00
Wes McKinney af2aeafca6 ARROW-1213: [Python] Support s3fs filesystem for Amazon S3 in ParquetDataset
cc @yackoa

Author: Wes McKinney <wes.mckinney@twosigma.com>

Closes #916 from wesm/ARROW-1213 and squashes the following commits:

f8a0aff1 [Wes McKinney] Add HDFS section to API docs
c54302df [Wes McKinney] Add deprecation warning for HdfsClient
4d3e7222 [Wes McKinney] Auto-wrap s3fs filesystem when using ParquetDataset
0be33bb8 [Wes McKinney] Implement os.walk emulation layer for s3fs
719f806d [Wes McKinney] Progress toward supporting s3fs in Parquet reader
bbd664ed [Wes McKinney] Refactor HdfsClient into pyarrow/hdfs.py. Add connect factory method. Rename to HadoopFilesystem. Add walk implementation for HDFS, base Parquet directory walker on that
4984a9d4 [Wes McKinney] Refactoring slightly
4c0bcf4a [Wes McKinney] Start on Dask filesystem wrapper, S3-Parquet dataset test case
2017-07-31 18:46:54 -04:00
Wes McKinney 53a478dfb2 ARROW-475: [Python] Add support for reading multiple Parquet files as a single pyarrow.Table
Also fixes a serious bug in which the data source passed to the ParquetReader gets garbage collected prematurely

Also implements ARROW-470

Author: Wes McKinney <wes.mckinney@twosigma.com>

Closes #296 from wesm/ARROW-475 and squashes the following commits:

894d2a2 [Wes McKinney] Implement Filesystem abstraction, add Filesystem.read_parquet. Implement rudimentary shim on local filesystem
3927c2c [Wes McKinney] Test read multiple Parquet from HDFS, fix premature garbage collection error
4904b3b [Wes McKinney] Implement read_multiple_files function for multiple Parquet files as a single Arrow table
2017-01-23 06:41:35 -05:00