[
https://issues.apache.org/jira/browse/ARROW-1865?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16276105#comment-16276105
]
ASF GitHub Bot commented on ARROW-1865:
---------------------------------------
wesm closed pull request #1373: ARROW-1865: [C++] Do not alter number of rows
attribute when removing last column from Table
URL: https://github.com/apache/arrow/pull/1373
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/cpp/src/arrow/table-test.cc b/cpp/src/arrow/table-test.cc
index 8a2288710..3f1c6be3a 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 129524b7e..2cf6c2652 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 ab012340c..e72761d32 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)),
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> [C++] Adding a column to an empty Table fails
> ---------------------------------------------
>
> Key: ARROW-1865
> URL: https://issues.apache.org/jira/browse/ARROW-1865
> Project: Apache Arrow
> Issue Type: Bug
> Components: C++
> Reporter: Uwe L. Korn
> Assignee: Wes McKinney
> Labels: pull-request-available
> Fix For: 0.8.0
>
>
> If we remove a column from a table and add new column (probably a casted
> version of it), it is rejected as the Table {{num_rows}} was reset to 0:
> {code}
> Invalid: Added column's length must match table's length. Expected length 0
> but got length 1
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)