You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by uw...@apache.org on 2018/07/03 08:41:15 UTC
[arrow] branch master updated: ARROW-1954: [Python] Add metadata
accessor to pyarrow.Field
This is an automated email from the ASF dual-hosted git repository.
uwe pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 7deb141 ARROW-1954: [Python] Add metadata accessor to pyarrow.Field
7deb141 is described below
commit 7deb141060de02c0529305c2a792cc4b25346d22
Author: Krisztián Szűcs <sz...@gmail.com>
AuthorDate: Tue Jul 3 10:41:08 2018 +0200
ARROW-1954: [Python] Add metadata accessor to pyarrow.Field
Already implemented.
Author: Krisztián Szűcs <sz...@gmail.com>
Closes #2191 from kszucs/ARROW-1954 and squashes the following commits:
265539e3 <Krisztián Szűcs> move field tests from test_schema to test_types
2986e73f <Krisztián Szűcs> test field metadata accessor
---
python/pyarrow/tests/test_schema.py | 35 -----------------------------
python/pyarrow/tests/test_types.py | 45 +++++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 35 deletions(-)
diff --git a/python/pyarrow/tests/test_schema.py b/python/pyarrow/tests/test_schema.py
index 9b00021..6a4b80f 100644
--- a/python/pyarrow/tests/test_schema.py
+++ b/python/pyarrow/tests/test_schema.py
@@ -197,19 +197,6 @@ def test_from_numpy_dtype():
pa.from_numpy_dtype('not_convertible_to_dtype')
-def test_field():
- t = pa.string()
- f = pa.field('foo', t)
-
- assert f.name == 'foo'
- assert f.nullable
- assert f.type is t
- assert repr(f) == "pyarrow.Field<foo: string>"
-
- f = pa.field('foo', t, False)
- assert not f.nullable
-
-
def test_schema():
fields = [
pa.field('foo', pa.int32()),
@@ -233,28 +220,6 @@ baz: list<item: int8>
child 0, item: int8"""
-def test_field_add_remove_metadata():
- f0 = pa.field('foo', pa.int32())
-
- assert f0.metadata is None
-
- metadata = {b'foo': b'bar', b'pandas': b'badger'}
-
- f1 = f0.add_metadata(metadata)
- assert f1.metadata == metadata
-
- f3 = f1.remove_metadata()
- assert f3.metadata is None
-
- # idempotent
- f4 = f3.remove_metadata()
- assert f4.metadata is None
-
- f5 = pa.field('foo', pa.int32(), True, metadata)
- f6 = f0.add_metadata(metadata)
- assert f5.equals(f6)
-
-
def test_field_flatten():
f0 = pa.field('foo', pa.int32()).add_metadata({b'foo': b'bar'})
assert f0.flatten() == [f0]
diff --git a/python/pyarrow/tests/test_types.py b/python/pyarrow/tests/test_types.py
index fabda08..4408859 100644
--- a/python/pyarrow/tests/test_types.py
+++ b/python/pyarrow/tests/test_types.py
@@ -297,6 +297,19 @@ def test_type_equality_operators(index, ty):
assert ty != other
+def test_field_basic():
+ t = pa.string()
+ f = pa.field('foo', t)
+
+ assert f.name == 'foo'
+ assert f.nullable
+ assert f.type is t
+ assert repr(f) == "pyarrow.Field<foo: string>"
+
+ f = pa.field('foo', t, False)
+ assert not f.nullable
+
+
def test_field_equals():
meta1 = {b'foo': b'bar'}
meta2 = {b'bizz': b'bazz'}
@@ -330,3 +343,35 @@ def test_field_equality_operators():
assert f1 != f3
assert f3 != f4
assert f1 != 'foo'
+
+
+def test_field_metadata():
+ f1 = pa.field('a', pa.int8())
+ f2 = pa.field('a', pa.int8(), metadata={})
+ f3 = pa.field('a', pa.int8(), metadata={b'bizz': b'bazz'})
+
+ assert f1.metadata is None
+ assert f2.metadata == {}
+ assert f3.metadata[b'bizz'] == b'bazz'
+
+
+def test_field_add_remove_metadata():
+ f0 = pa.field('foo', pa.int32())
+
+ assert f0.metadata is None
+
+ metadata = {b'foo': b'bar', b'pandas': b'badger'}
+
+ f1 = f0.add_metadata(metadata)
+ assert f1.metadata == metadata
+
+ f3 = f1.remove_metadata()
+ assert f3.metadata is None
+
+ # idempotent
+ f4 = f3.remove_metadata()
+ assert f4.metadata is None
+
+ f5 = pa.field('foo', pa.int32(), True, metadata)
+ f6 = f0.add_metadata(metadata)
+ assert f5.equals(f6)