ENH: Add columns argument to read_feather() (#24025)
State: closed

- [x] closes #24025
- [x] tests added / ~~passed~~
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

I have added test case but when running 
```
pytest pandas/tests/io/test_feather.py
```
test cases (including some of already existing test cases) fails with error 
```
NotImplementedError: > 1 ndim Categorical are not supported at this time
```

let me know if this is expected or I'm missing something

Labels:
name: IO Data
description: IO issues that don't fit into a more specific label

Comments:
Hello @nixphix! Thanks for submitting the PR.

 - There are no PEP8 issues in the file [`pandas/io/feather_format.py`](https://github.com/nixphix/pandas/blob/43afb8d4b9d930db37d47b741cd7edc16fbf0e28/pandas/io/feather_format.py) !

 - There are no PEP8 issues in the file [`pandas/tests/io/test_feather.py`](https://github.com/nixphix/pandas/blob/43afb8d4b9d930db37d47b741cd7edc16fbf0e28/pandas/tests/io/test_feather.py) !


# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24034?src=pr&el=h1) Report
> Merging [#24034](https://codecov.io/gh/pandas-dev/pandas/pull/24034?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/5b6b346b9db57b610df2965f60753473ef16e16f?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `66.66%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/24034/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/24034?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master   #24034   +/-   ##
=======================================
  Coverage   42.46%   42.46%           
=======================================
  Files         161      161           
  Lines       51557    51557           
=======================================
  Hits        21892    21892           
  Misses      29665    29665
```

| Flag | Coverage Δ | |
|---|---|---|
| #single | `42.46% <66.66%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24034?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/feather\_format.py](https://codecov.io/gh/pandas-dev/pandas/pull/24034/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2ZlYXRoZXJfZm9ybWF0LnB5) | `89.74% <66.66%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24034?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24034?src=pr&el=footer). Last update [5b6b346...43afb8d](https://codecov.io/gh/pandas-dev/pandas/pull/24034?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24034?src=pr&el=h1) Report
> Merging [#24034](https://codecov.io/gh/pandas-dev/pandas/pull/24034?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/08395af43b813b69b1cf038d260104cfeeb3e787?src=pr&el=desc) will **increase** coverage by `49.86%`.
> The diff coverage is `66.66%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/24034/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/24034?src=pr&el=tree)

```diff
@@             Coverage Diff             @@
##           master   #24034       +/-   ##
===========================================
+ Coverage   42.38%   92.25%   +49.86%     
===========================================
  Files         161      161               
  Lines       51701    51701               
===========================================
+ Hits        21914    47696    +25782     
+ Misses      29787     4005    -25782
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.65% <33.33%> (?)` | |
| #single | `42.38% <66.66%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24034?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/feather\_format.py](https://codecov.io/gh/pandas-dev/pandas/pull/24034/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2ZlYXRoZXJfZm9ybWF0LnB5) | `89.74% <66.66%> (ø)` | :arrow_up: |
| [pandas/core/computation/pytables.py](https://codecov.io/gh/pandas-dev/pandas/pull/24034/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vcHl0YWJsZXMucHk=) | `92.37% <0%> (+0.3%)` | :arrow_up: |
| [pandas/io/pytables.py](https://codecov.io/gh/pandas-dev/pandas/pull/24034/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3B5dGFibGVzLnB5) | `92.3% <0%> (+0.92%)` | :arrow_up: |
| [pandas/util/\_test\_decorators.py](https://codecov.io/gh/pandas-dev/pandas/pull/24034/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvX3Rlc3RfZGVjb3JhdG9ycy5weQ==) | `93.24% <0%> (+4.05%)` | :arrow_up: |
| [pandas/compat/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/24034/diff?src=pr&el=tree#diff-cGFuZGFzL2NvbXBhdC9fX2luaXRfXy5weQ==) | `58.36% <0%> (+8.17%)` | :arrow_up: |
| [pandas/core/config\_init.py](https://codecov.io/gh/pandas-dev/pandas/pull/24034/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29uZmlnX2luaXQucHk=) | `99.24% <0%> (+9.84%)` | :arrow_up: |
| [pandas/core/reshape/util.py](https://codecov.io/gh/pandas-dev/pandas/pull/24034/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS91dGlsLnB5) | `100% <0%> (+11.53%)` | :arrow_up: |
| [pandas/compat/numpy/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/24034/diff?src=pr&el=tree#diff-cGFuZGFzL2NvbXBhdC9udW1weS9fX2luaXRfXy5weQ==) | `92.85% <0%> (+14.28%)` | :arrow_up: |
| [pandas/core/computation/common.py](https://codecov.io/gh/pandas-dev/pandas/pull/24034/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vY29tbW9uLnB5) | `85.71% <0%> (+14.28%)` | :arrow_up: |
| [pandas/core/api.py](https://codecov.io/gh/pandas-dev/pandas/pull/24034/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXBpLnB5) | `100% <0%> (+14.81%)` | :arrow_up: |
| ... and [120 more](https://codecov.io/gh/pandas-dev/pandas/pull/24034/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24034?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24034?src=pr&el=footer). Last update [08395af...8a997fc](https://codecov.io/gh/pandas-dev/pandas/pull/24034?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Any reason to not just specify the columns as a list? It’d make the test easier to read.


________________________________
From: Prabakaran Kumaresshan <notifications@github.com>
Sent: Saturday, December 1, 2018 11:43 AM
To: pandas-dev/pandas
Cc: Tom Augspurger; Mention
Subject: Re: [pandas-dev/pandas] ENH: Add columns argument to read_feather() (#24025) (#24034)


@nixphix commented on this pull request.

________________________________

In pandas/tests/io/test_feather.py<https://github.com/pandas-dev/pandas/pull/24034#discussion_r238070955>:

> @@ -74,6 +77,18 @@ def test_stringify_columns(self):
         df = pd.DataFrame(np.arange(12).reshape(4, 3)).copy()
         self.check_error_on_write(df, ValueError)

+    def test_read_columns(self):
+
+        df = pd.DataFrame({'col1': list('abc'),
+                           'col2': list(range(1, 4)),
+                           'col3': list('xyz'),
+                           'col4': list(range(4, 7))})
+        self.check_round_trip(df, columns=None)
+        self.check_round_trip(df, columns=df.columns)
+        random_cols = np.random.choice(df.columns, 2)


@TomAugspurger<https://github.com/TomAugspurger> I missed replace=Flase argument that will ensure we are getting unique columns, this should work

        random_cols = np.random.choice(df.columns, 2, replace=False)


—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<https://github.com/pandas-dev/pandas/pull/24034#discussion_r238070955>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ABQHIq2LF0wkf9uXwQ5c22CFCGQfVx8gks5u0r-_gaJpZM4Y803h>.

@TomAugspurger It's just that I'm not a fan of hard coded values, thought it might make the test case more dynamic and robust. I will change it to list for better readability.
lgtm. @TomAugspurger 
Thanks @nixphix!