arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject [arrow] branch master updated: ARROW-1865: [C++] Do not alter number of rows attribute when removing last column from Table
Date Sun, 03 Dec 2017 21:37:26 GMT
This is an automated email from the ASF dual-hosted git repository.

wesm 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 3bed4eb  ARROW-1865: [C++] Do not alter number of rows attribute when removing last
column from Table
3bed4eb is described below

commit 3bed4ebfb344d83e3c09a33aac51f6917fc787fe
Author: Wes McKinney <wes.mckinney@twosigma.com>
AuthorDate: Sun Dec 3 16:37:22 2017 -0500

    ARROW-1865: [C++] Do not alter number of rows attribute when removing last column from
Table
    
    Author: Wes McKinney <wes.mckinney@twosigma.com>
    
    Closes #1373 from wesm/ARROW-1865 and squashes the following commits:
    
    bc7cd336 [Wes McKinney] Removing last column from a Table does not alter number of rows.
Test in C++ and Python
---
 cpp/src/arrow/table-test.cc        | 20 ++++++++++++++++++++
 cpp/src/arrow/table.cc             |  3 ++-
 python/pyarrow/tests/test_table.py | 14 ++++++++++++++
 3 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/cpp/src/arrow/table-test.cc b/cpp/src/arrow/table-test.cc
index 8a22887..3f1c6be 100644
--- a/cpp/src/arrow/table-test.cc
+++ b/cpp/src/arrow/table-test.cc
@@ -404,6 +404,26 @@ TEST_F(TestTable, RemoveColumn) {
   ASSERT_TRUE(result->Equals(*expected));
 }
 
+TEST_F(TestTable, RemoveColumnEmpty) {
+  // ARROW-1865
+  const int64_t length = 10;
+
+  auto f0 = field("f0", int32());
+  auto schema = ::arrow::schema({f0});
+  auto a0 = MakeRandomArray<Int32Array>(length);
+
+  auto table = Table::Make(schema, {std::make_shared<Column>(f0, a0)});
+
+  std::shared_ptr<Table> empty;
+  ASSERT_OK(table->RemoveColumn(0, &empty));
+
+  ASSERT_EQ(table->num_rows(), empty->num_rows());
+
+  std::shared_ptr<Table> added;
+  ASSERT_OK(empty->AddColumn(0, table->column(0), &added));
+  ASSERT_EQ(table->num_rows(), added->num_rows());
+}
+
 TEST_F(TestTable, AddColumn) {
   const int64_t length = 10;
   MakeExample1(length);
diff --git a/cpp/src/arrow/table.cc b/cpp/src/arrow/table.cc
index 129524b..2cf6c26 100644
--- a/cpp/src/arrow/table.cc
+++ b/cpp/src/arrow/table.cc
@@ -202,7 +202,8 @@ class SimpleTable : public Table {
     std::shared_ptr<Schema> new_schema;
     RETURN_NOT_OK(schema_->RemoveField(i, &new_schema));
 
-    *out = Table::Make(new_schema, internal::DeleteVectorElement(columns_, i));
+    *out = Table::Make(new_schema, internal::DeleteVectorElement(columns_, i),
+                       this->num_rows());
     return Status::OK();
   }
 
diff --git a/python/pyarrow/tests/test_table.py b/python/pyarrow/tests/test_table.py
index ab01234..e72761d 100644
--- a/python/pyarrow/tests/test_table.py
+++ b/python/pyarrow/tests/test_table.py
@@ -312,6 +312,20 @@ def test_table_remove_column():
     assert t2.equals(expected)
 
 
+def test_table_remove_column_empty():
+    # ARROW-1865
+    data = [
+        pa.array(range(5)),
+    ]
+    table = pa.Table.from_arrays(data, names=['a'])
+
+    t2 = table.remove_column(0)
+    assert len(t2) == len(table)
+
+    t3 = t2.add_column(0, table[0])
+    assert t3.equals(table)
+
+
 def test_concat_tables():
     data = [
         list(range(5)),

-- 
To stop receiving notification emails like this one, please contact
['"commits@arrow.apache.org" <commits@arrow.apache.org>'].

Mime
View raw message