Skip to content

[C++] Improve error message when reading Streaming file with File reader and vice versa #33823

Closed

Description

@domoritz

Describe the bug, including details regarding any error messages, version, and platform.

I am trying to loan an arrow file

with pa.memory_map('flights-200k.arrow', 'r') as source:
    my_arrow = pa.ipc.open_file(source).read_all()

but get this error

  File "/opt/homebrew/Caskroom/miniforge/base/envs/ramsch/lib/python3.10/site-packages/pyarrow/ipc.py", line 228, in open_file
    return RecordBatchFileReader(
  File "/opt/homebrew/Caskroom/miniforge/base/envs/ramsch/lib/python3.10/site-packages/pyarrow/ipc.py", line 110, in __init__
    self._open(source, footer_offset=footer_offset,
  File "pyarrow/ipc.pxi", line 862, in pyarrow.lib._RecordBatchFileReader._open
  File "pyarrow/error.pxi", line 144, in pyarrow.lib.pyarrow_internal_check_status
  File "pyarrow/error.pxi", line 100, in pyarrow.lib.check_status
pyarrow.lib.ArrowInvalid: Not an Arrow file

The arrow file is https://github.com/uwdata/flights-arrow/blob/master/flights-200k.arrow and loads fine in the arrow js library.

Component(s)

Python

Activity

  1. domoritz commented on Jan 21, 2023

    @domoritz
    MemberAuthor

    The issue is that I need to use open_stream. The error message should be better.

  2. changed the title [-]pyarrow.lib.ArrowInvalid: Not an Arrow file[/-] [+][Python] pyarrow.lib.ArrowInvalid: Not an Arrow file[/+] on Jan 21, 2023
  3. vibhatha commented on Jan 24, 2023

    @vibhatha
    Contributor

    I am not sure if this is related. I had a similar experience when I have mistakenly written files but haven't closed the file writer. In your case since it is loaded in JS properly, this could be an entirely different scenario. But thought it is worth mentioning here.

  4. jorisvandenbossche commented on Jan 24, 2023

    @jorisvandenbossche
    Member

    Small reproducer without having to download a file:

    import pyarrow as pa
    
    batch = pa.record_batch([pa.array([1, 2, 3])], ['a'])
    
    # Create an Arrow Stream file
    with pa.ipc.new_stream("test.arrows", batch.schema) as writer:
        writer.write(batch)
    
    # Read as Arrow File
    pa.ipc.open_file("test.arrows")
    # -> ... ArrowInvalid: Not an Arrow file

    I agree it would be nice we can give a more informative error message and hint the user they are reading a Arrow Streaming format file and not a Arrow File format file.

  5. changed the title [-][Python] pyarrow.lib.ArrowInvalid: Not an Arrow file[/-] [+][C++] Improve error message when reading Streaming file with File reader and vice versa[/+] on Jan 24, 2023
  6. jorisvandenbossche commented on Jan 24, 2023

    @jorisvandenbossche
    Member

    Similarly, reading a File with a Streaming reader also gives a non-informative error message:

    with pa.ipc.new_file("test.arrow", batch.schema) as writer:
        writer.write(batch)
    
    pa.ipc.open_stream("test.arrow")
    # ... ArrowInvalid: Expected to read 1330795073 metadata bytes, but only read 486
  7. westonpace commented on Jan 24, 2023

    @westonpace
    Member

    Files written in the file format have a magic number on both sides of the data. The error message "Not an Arrow file" is thrown when that magic number is wrong. So we already detect this situation, we just need to be proactive about suggesting solutions / alternatives (e.g. "Not an Arrow file, perhaps this is in the streaming format?") so this should be very doable.

  8. domoritz commented on Jan 25, 2023

    @domoritz
    MemberAuthor

    I am an arrow committer and got totally thrown off by the error message and thought my file was corrupt. So yes, your suggested error message sounds great.

  9. jalajk24 commented on Jan 27, 2023

    @jalajk24

    @domoritz i would like to contribute in this project can you assign this project to me

  10. domoritz commented on Jan 27, 2023

    @domoritz
    MemberAuthor

    I assigned it to you. Please send a pull request soon.

  11. pbaner16 commented on Dec 8, 2023

    @pbaner16

    Hello @domoritz -- has this issue been fixed? If not, i can contribute!

  12. RobertLD commented on Apr 15, 2026

    @RobertLD
    Contributor

    This looks to be very easy change and I've been trolling the issue board to find a good first contribution to arrow.

    I'd love to post a PR if @jalajk24 is no longer working on this (I assume so it's been some years

  13. kou commented on Apr 15, 2026

    @kou
    Member

    You can work on this!

  14. assigned and unassigned on Apr 15, 2026
  15. added 2 commits that reference this issue on Apr 16, 2026
  16. RobertLD commented on Apr 19, 2026

    @RobertLD
    Contributor

    @kou PR is posted for your review!

  17. added a commit that references this issue on Oct 29, 2026
  18. added this to the 27.0.0 milestone on Oct 29, 2026
  19. pitrou commented on Oct 29, 2026

    @pitrou
    Member

    Issue resolved by pull request 49771
    #49771

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions