@@ -919,8 +919,15 @@ def direct_Content_subclass_name(node):
919
919
return out .__name__
920
920
921
921
922
+ def is_revertable (akarray ):
923
+ return hasattr (akarray , "__pyarrow_original" )
924
+
925
+
922
926
def remove_optiontype (akarray ):
923
- return akarray .__pyarrow_original
927
+ if callable (akarray .__pyarrow_original ):
928
+ return akarray .__pyarrow_original ()
929
+ else :
930
+ return akarray .__pyarrow_original
924
931
925
932
926
933
def form_remove_optiontype (akform ):
@@ -944,6 +951,17 @@ def handle_arrow(obj, generate_bitmasks=False, pass_empty_field=False):
944
951
945
952
if len (layouts ) == 1 :
946
953
return layouts [0 ]
954
+ elif any (is_revertable (arr ) for arr in layouts ):
955
+ assert all (is_revertable (arr ) for arr in layouts )
956
+ # TODO: the callable argument to revertable is a premature(?) optimisation.
957
+ # it would be better to obviate the need to compute both revertable and non revertable branches
958
+ # e.g. by requesting a particular layout kind from the next `frombuffers` operation
959
+ return revertable (
960
+ ak .operations .concatenate (layouts , highlevel = False ),
961
+ lambda : ak .operations .concatenate (
962
+ [remove_optiontype (x ) for x in layouts ], highlevel = False
963
+ ),
964
+ )
947
965
else :
948
966
return ak .operations .concatenate (layouts , highlevel = False )
949
967
@@ -1044,7 +1062,19 @@ def handle_arrow(obj, generate_bitmasks=False, pass_empty_field=False):
1044
1062
for batch in batches
1045
1063
if len (batch ) > 0
1046
1064
]
1047
- return ak .operations .concatenate (arrays , highlevel = False )
1065
+ if any (is_revertable (arr ) for arr in arrays ):
1066
+ assert all (is_revertable (arr ) for arr in arrays )
1067
+ # TODO: the callable argument to revertable is a premature(?) optimisation.
1068
+ # it would be better to obviate the need to compute both revertable and non revertable branches
1069
+ # e.g. by requesting a particular layout kind from the next `frombuffers` operation
1070
+ return revertable (
1071
+ ak .operations .concatenate (arrays , highlevel = False ),
1072
+ lambda : ak .operations .concatenate (
1073
+ [remove_optiontype (x ) for x in arrays ], highlevel = False
1074
+ ),
1075
+ )
1076
+ else :
1077
+ return ak .operations .concatenate (arrays , highlevel = False )
1048
1078
1049
1079
elif (
1050
1080
isinstance (obj , Iterable )
0 commit comments