GithubHelp home page GithubHelp logo

Comments (5)

jorisvandenbossche avatar jorisvandenbossche commented on June 14, 2024

A reproducer just with pyarrow as well (using your registered ext type example):

class DummyArray:
    def __init__(self):
        self._field = pa.field("", pa.null(), metadata={"ARROW:extension:name": "arrow.test"})
        self._array = pa.array([None, None], pa.null())

    def __arrow_c_array__(self, requested_schema=None):
        return self._field.__arrow_c_schema__(), self._array.__arrow_c_array__()[1]

pa.array(DummyArray())

which crashes, and when adding "ARROW:extension:metadata": "" to the dict, it works.

Now, apart from your fix (thanks for that!), I realize from the example that it is right now actually impossible to register an extension type without metadata (at least from Python).

I don't know it we should fix that (e.g. allow __arrow_ext_serialize__ to return None in addition to bytes?), or whether this is OK as long as we ensure this still works when actually receiving data with extension types without metadata (i.e. your fix for this issue)

from arrow.

jorisvandenbossche avatar jorisvandenbossche commented on June 14, 2024

We should probably also check that this works in other places that imports extension types, like reading IPC.

from arrow.

jorisvandenbossche avatar jorisvandenbossche commented on June 14, 2024

For IPC it seems to work:

table = pa.Table.from_arrays(
   [pa.array([None, None], pa.null())],
   schema=pa.schema([pa.field("a", pa.null(), metadata={"ARROW:extension:name": "arrow.test"})])
)
with pa.ipc.new_file("/tmp/test_ext_no_meta.arrow", table.schema) as f:
    f.write(table)

with pa.ipc.open_file("/tmp/test_ext_no_meta.arrow") as f:
    result = f.read_all()
print(result.schema)

pa.register_extension_type(DummyExtType())

with pa.ipc.open_file("/tmp/test_ext_no_meta.arrow") as f:
    result = f.read_all()
print(result.schema)

And the same for write/read Parquet (where we get the extension type from the ARROW:schema)

from arrow.

paleolimbot avatar paleolimbot commented on June 14, 2024

Good call! It looks like the version of this that IPC and Parquet (which I believe uses the IPC Schema encoding) use is here and has more or less the same logic.

if (metadata != nullptr) {
// Look for extension metadata in custom_metadata field
int name_index = metadata->FindKey(kExtensionTypeKeyName);
if (name_index != -1) {
std::shared_ptr<ExtensionType> ext_type =
GetExtensionType(metadata->value(name_index));
if (ext_type != nullptr) {
int data_index = metadata->FindKey(kExtensionMetadataKeyName);
std::string type_data = data_index == -1 ? "" : metadata->value(data_index);
ARROW_ASSIGN_OR_RAISE(type, ext_type->Deserialize(type, type_data));
// Remove the metadata, for faithful roundtripping
if (data_index != -1) {
RETURN_NOT_OK(metadata->DeleteMany({name_index, data_index}));
} else {
RETURN_NOT_OK(metadata->Delete(name_index));
}
}
// NOTE: if extension type is unknown, we do not raise here and
// simply return the storage type.
}
}

(Also good call on the registration not mattering!)

from arrow.

paleolimbot avatar paleolimbot commented on June 14, 2024

Issue resolved by pull request 41763
#41763

from arrow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.