GH-33377: [Python] Table.drop should support passing a single column#33810
Conversation
|
|
|
This is my first Arrow PR. I am very open to any feedback or suggestions you might have! I followed the instructions as stated in the original GH issue, but there is now some redundancy between |
742b5bc to
8510b16
Compare
Welcome @danepitkin! Thanks for opening the PR!
I would slightly prefer |
|
Thanks, Rok!
I like this plan. Also, I think this is what the original issue was requesting and I just misread it! I'll update the ticket with |
Indeed. I think it also depends a bit on the capability evolution - if we ever introduce |
8510b16 to
b4d4c03
Compare
|
I decided to name it Also, instead of a wrapper with a warning, what if we alias it directly with |
b4d4c03 to
9f9ebae
Compare
I don't have a strong opinion, but if we don't actually plan to remove it in a few releases, we can indeed also just alias it as you said without warning. |
There was a problem hiding this comment.
Either way if we just keep it as alias or actively deprecate it, I think it's also fine to only keep the docstring up to here, saying it is an alias, and then refer to the docstring of drop_columns for more details. That avoids duplicating the rest of the content.
There was a problem hiding this comment.
Thanks! I tried this at first, but thought I was getting a document build error. I probably was just building it wrong 😬 haha. I'll do this because I very much dislike duplication.
There was a problem hiding this comment.
| "Table.drop is deprecated, use Table.drop_columns.", | |
| DeprecationWarning) | |
| "Table.drop is deprecated, use Table.drop_columns.", | |
| DeprecationWarning, stacklevel=2) |
(to ensure the warning points to where the method is actually used and not to this location)
There was a problem hiding this comment.
If we keep the warning, we can assert that this raises a warning (pytest.raises), which at the same time also suppresses the warning (we don't want that running our test suite prints this expected warning)
There was a problem hiding this comment.
Thank you! I'm going to remove the warning since there is no plan for deprecation. Good to know for the future though!
90b2649 to
bf7be35
Compare
There was a problem hiding this comment.
Is this docstring for sphinx? (interactively checking the docstring in a terminal/notebook, that still gives the drop_columns one)
There was a problem hiding this comment.
Great catch!! Will fix this.
There was a problem hiding this comment.
I'm going to remove the alias and use a wrapper. I'm not sure if it's possible to update the docstring of an alias without affecting the original method's docstring.
I tried this:
drop = drop_columns
drop.__doc__ = """Alias of Table.drop_columns, kept for backwards compatibility."""
..but got an error:
Traceback (most recent call last):
...
File "pyarrow/table.pxi", line 4729, in init pyarrow.lib
AttributeError: attribute '__doc__' of 'method_descriptor' objects is not writable
There was a problem hiding this comment.
I suppose that's because it's implemented in cython, and then that attribute is not writeable as it would be in python (just a guess, didn't actually verify)
But anyway, the wrapper looks good!
bf7be35 to
7d06ba2
Compare
|
Thanks! |
|
Congrats @danepitkin ! |
|
Benchmark runs are scheduled for baseline = 177a0d4 and contender = 36d3394. 36d3394 is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
|
['Python', 'R'] benchmarks have high level of regressions. |
Rationale for this change
Provide a better user experience in pyarrow when working with
Table.What changes are included in this PR?
Allow
Table.drop()to accept a single column name as astrargument.Provide a wrapper
Table.drop_column(str), which callsTable.drop(), to match similar APIs such asadd_column(),append_column().Are these changes tested?
Updated the pytest for
Table.drop()and added a pytest forTable.drop_column(). Verified both test cases ran successfully locally.Are there any user-facing changes?
Yes, a new pyarrow API is added. The existing pyarrow API is backwards compatible, but does support additional types of input now (str). The doc strings are updated so I assume the python API reference will be auto-updated somehow? Let me know if this is not the case.