Skip to content

Commit 8d08247

Browse files
committed
[pandas 2.0] Share low level C++ utility code (memory allocation, error reporting, bit manipulation) with libarrow
Closes wesm#44. This will spare us developing similar functionality in two places for the time being -- we can keep an eye on the relationship between the libraries in case it does make sense to split in the future (but it may not, particularly if we use Arrow to implement nested data natively in pandas). Author: Wes McKinney <[email protected]> Closes wesm#49 from wesm/link-libarrow and squashes the following commits: 1d176b1 [Wes McKinney] Refactor libpandas to use common constructs and utility code from libarrow: Status, MemoryPool, Buffer, etc. Change-Id: I3140a3ed8dd17db376be21241fc259523a16cc88
1 parent 5fbf982 commit 8d08247

33 files changed

+167
-885
lines changed

CMakeLists.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,17 @@ include_directories(SYSTEM
467467
thirdparty/
468468
src)
469469

470+
## Arrow
471+
find_package(Arrow REQUIRED)
472+
include_directories(SYSTEM ${ARROW_INCLUDE_DIR})
473+
ADD_THIRDPARTY_LIB(arrow
474+
SHARED_LIB ${ARROW_SHARED_LIB}
475+
STATIC_LIB ${ARROW_STATIC_LIB})
476+
ADD_THIRDPARTY_LIB(arrow_io
477+
SHARED_LIB ${ARROW_IO_SHARED_LIB})
478+
ADD_THIRDPARTY_LIB(arrow_ipc
479+
SHARED_LIB ${ARROW_IPC_SHARED_LIB})
480+
470481
############################################################
471482
# Testing
472483
############################################################
@@ -631,13 +642,11 @@ add_subdirectory(src/pandas/util)
631642

632643
set(PANDAS_SRCS
633644
src/pandas/array.cc
634-
src/pandas/buffer.cc
635645
src/pandas/dispatch.cc
636646
src/pandas/init.cc
637647
src/pandas/memory.cc
638648
src/pandas/numpy_interop.cc
639649
src/pandas/pytypes.cc
640-
src/pandas/status.cc
641650
src/pandas/type.cc
642651

643652
src/pandas/types/boolean.cc
@@ -649,11 +658,12 @@ set(PANDAS_SRCS
649658
add_library(pandas SHARED
650659
${PANDAS_SRCS})
651660
target_link_libraries(pandas
652-
pandas_util)
661+
arrow
662+
pandas_util)
653663
set_target_properties(pandas PROPERTIES LINKER_LANGUAGE CXX)
654664

655665
if(APPLE)
656-
set_target_properties(pandas PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
666+
set_target_properties(pandas PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
657667
endif()
658668

659669
############################################################

cmake_modules/FindArrow.cmake

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
# - Find ARROW (arrow/api.h, libarrow.a, libarrow.so)
19+
# This module defines
20+
# ARROW_INCLUDE_DIR, directory containing headers
21+
# ARROW_LIBS, directory containing arrow libraries
22+
# ARROW_STATIC_LIB, path to libarrow.a
23+
# ARROW_SHARED_LIB, path to libarrow's shared library
24+
# ARROW_FOUND, whether arrow has been found
25+
26+
set(ARROW_SEARCH_HEADER_PATHS
27+
$ENV{ARROW_HOME}/include
28+
)
29+
30+
set(ARROW_SEARCH_LIB_PATH
31+
$ENV{ARROW_HOME}/lib
32+
)
33+
34+
find_path(ARROW_INCLUDE_DIR arrow/array.h PATHS
35+
${ARROW_SEARCH_HEADER_PATHS}
36+
# make sure we don't accidentally pick up a different version
37+
NO_DEFAULT_PATH
38+
)
39+
40+
find_library(ARROW_LIB_PATH NAMES arrow
41+
PATHS
42+
${ARROW_SEARCH_LIB_PATH}
43+
NO_DEFAULT_PATH)
44+
45+
find_library(ARROW_IO_LIB_PATH NAMES arrow_io
46+
PATHS
47+
${ARROW_SEARCH_LIB_PATH}
48+
NO_DEFAULT_PATH)
49+
50+
find_library(ARROW_IPC_LIB_PATH NAMES arrow_ipc
51+
PATHS
52+
${ARROW_SEARCH_LIB_PATH}
53+
NO_DEFAULT_PATH)
54+
55+
if (ARROW_INCLUDE_DIR AND ARROW_LIB_PATH)
56+
set(ARROW_FOUND TRUE)
57+
set(ARROW_LIB_NAME libarrow)
58+
set(ARROW_IO_LIB_NAME libarrow_io)
59+
set(ARROW_IPC_LIB_NAME libarrow_ipc)
60+
61+
set(ARROW_LIBS ${ARROW_SEARCH_LIB_PATH})
62+
set(ARROW_STATIC_LIB ${ARROW_SEARCH_LIB_PATH}/${ARROW_LIB_NAME}.a)
63+
set(ARROW_SHARED_LIB ${ARROW_LIBS}/${ARROW_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX})
64+
65+
set(ARROW_IO_STATIC_LIB ${ARROW_SEARCH_LIB_PATH}/${ARROW_IO_LIB_NAME}.a)
66+
set(ARROW_IO_SHARED_LIB ${ARROW_LIBS}/${ARROW_IO_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX})
67+
68+
set(ARROW_IPC_STATIC_LIB ${ARROW_SEARCH_LIB_PATH}/${ARROW_IPC_LIB_NAME}.a)
69+
set(ARROW_IPC_SHARED_LIB ${ARROW_LIBS}/${ARROW_IPC_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX})
70+
71+
if (NOT Arrow_FIND_QUIETLY)
72+
message(STATUS "Found the Arrow core library: ${ARROW_LIB_PATH}")
73+
message(STATUS "Found the Arrow IO library: ${ARROW_IO_LIB_PATH}")
74+
message(STATUS "Found the Arrow IPC library: ${ARROW_IPC_LIB_PATH}")
75+
endif ()
76+
else ()
77+
if (NOT Arrow_FIND_QUIETLY)
78+
set(ARROW_ERR_MSG "Could not find the Arrow library. Looked for headers")
79+
set(ARROW_ERR_MSG "${ARROW_ERR_MSG} in ${ARROW_SEARCH_HEADER_PATHS}, and for libs")
80+
set(ARROW_ERR_MSG "${ARROW_ERR_MSG} in ${ARROW_SEARCH_LIB_PATH}")
81+
if (Arrow_FIND_REQUIRED)
82+
message(FATAL_ERROR "${ARROW_ERR_MSG}")
83+
else (Arrow_FIND_REQUIRED)
84+
message(STATUS "${ARROW_ERR_MSG}")
85+
endif (Arrow_FIND_REQUIRED)
86+
endif ()
87+
set(ARROW_FOUND FALSE)
88+
endif ()
89+
90+
mark_as_advanced(
91+
ARROW_INCLUDE_DIR
92+
ARROW_LIBS
93+
ARROW_STATIC_LIB
94+
ARROW_SHARED_LIB
95+
ARROW_IO_STATIC_LIB
96+
ARROW_IO_SHARED_LIB
97+
)

src/pandas/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,4 @@ install(FILES
1212
set(PANDAS_TEST_LINK_LIBS pandas_test_util ${PANDAS_MIN_TEST_LIBS})
1313

1414
ADD_PANDAS_TEST(array-test)
15-
ADD_PANDAS_TEST(buffer-test)
16-
ADD_PANDAS_TEST(memory-test)
1715
ADD_PANDAS_TEST(util-test)

src/pandas/api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#define PANDAS_API_H
66

77
#include "pandas/array.h"
8+
#include "pandas/common.h"
89
#include "pandas/dispatch.h"
9-
#include "pandas/status.h"
1010
#include "pandas/type.h"
1111

1212
#include "pandas/types/boolean.h"

src/pandas/array-test.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
#include "gtest/gtest.h"
1111

1212
#include "pandas/array.h"
13-
#include "pandas/buffer.h"
13+
#include "pandas/common.h"
1414
#include "pandas/memory.h"
15-
#include "pandas/status.h"
1615
#include "pandas/test-util.h"
1716
#include "pandas/type.h"
1817
#include "pandas/types/numeric.h"

src/pandas/array.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// copyright holders
33

44
#include "pandas/array.h"
5-
#include "pandas/status.h"
5+
#include "pandas/common.h"
66
#include "pandas/type.h"
77
#include "pandas/util/logging.h"
88

src/pandas/array.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99
#include <string>
1010
#include <vector>
1111

12+
#include "pandas/common.h"
1213
#include "pandas/type.h"
1314
#include "pandas/util.h"
1415

1516
namespace pandas {
1617

17-
// Forward declarations
18-
class Status;
19-
2018
// Base class for physical array data structures.
2119
class Array {
2220
public:

src/pandas/buffer-test.cc

Lines changed: 0 additions & 117 deletions
This file was deleted.

0 commit comments

Comments
 (0)