Skip to content

COMPAT: Add Pathlib, py.path support for read_hdf #12930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

quintusdias
Copy link
Contributor

  • [*] closes #xxxx
  • [*] tests added / passed
  • [*] passes git diff upstream/master | flake8 --diff
  • whatsnew entry

Closes #11773

Travis-ci test JOB_NAME=27_slow_nnet_LOCALE consistently fails due to locale issue... zh_CN.GB18030??

_PATHLIB_INSTALLED = True
except ImportError:
_PATHLIB_INSTALLED = False

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove all this

@jreback
Copy link
Contributor

jreback commented Apr 20, 2016

pls add a whatsnew note (you can put in Enhancements)

@jreback jreback added IO Data IO issues that don't fit into a more specific label IO HDF5 read_hdf, HDFStore Compat pandas objects compatability with Numpy or Python functions labels Apr 20, 2016
@quintusdias quintusdias force-pushed the issue11773 branch 3 times, most recently from 9cd0ef6 to e7f609c Compare April 24, 2016 16:05
@codecov-io
Copy link

codecov-io commented Apr 24, 2016

Current coverage is 83.91%

Merging #12930 into master will increase coverage by +<.01%

@@             master     #12930   diff @@
==========================================
  Files           136        136          
  Lines         49918      49927     +9   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          41885      41895    +10   
+ Misses         8033       8032     -1   
  Partials          0          0          
  1. File ...das/tseries/index.py (not in diff) was modified. more
    • Misses -1
    • Partials 0
    • Hits +1

Powered by Codecov. Last updated by f8173ed

@quintusdias
Copy link
Contributor Author

Ok, updates made. On the whatsnew item, there was already a pathlib item for read_csv down in the bugfixes section so I put the read_hdf item there.

@@ -270,7 +272,8 @@ def read_hdf(path_or_buf, key=None, **kwargs):

Parameters
----------
path_or_buf : path (string), or buffer to read from
path_or_buf : path (string), buffer, or path object (pathlib.Path or
py._path.local.LocalPath) to read from
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a versionadded tag here (for the last part)

@@ -4,3 +4,4 @@ numpy
cython
nose
flake8
pytables
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take this out

@quintusdias quintusdias force-pushed the issue11773 branch 3 times, most recently from 1c575ef to 7232661 Compare April 29, 2016 10:45
store = HDFStore(path_or_buf, **kwargs)
auto_close = True
else:
raise NotImplementedError('Support for generic buffers has not '
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a tests for this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_pytables.TestHDFStore.test_read_hdf_errors should be hitting the else-branch (NotImplementedError), as the path_or_buf object is a regular file pointer (io.TextWrapper) there.

pytables.TestHDFStore.test_read_from_pathlib_path should be hitting the if-branch on python3 (and on python2 if pathlib is installed).

I apologize for my tardiness in responding to these...

@jreback
Copy link
Contributor

jreback commented May 13, 2016

if you can rebase / update

@quintusdias quintusdias force-pushed the issue11773 branch 2 times, most recently from a9113cc to 3190fa2 Compare May 15, 2016 08:53
@quintusdias
Copy link
Contributor Author

Ok, rebased.

@@ -32,6 +32,8 @@ Other enhancements
- The ``.tz_localize()`` method of ``DatetimeIndex`` and ``Timestamp`` has gained the ``errors`` keyword, so you can potentially coerce nonexistent timestamps to ``NaT``. The default behaviour remains to raising a ``NonExistentTimeError`` (:issue:`13057`)

- ``Index`` now supports ``.str.extractall()`` which returns ``DataFrame``, see :ref:`Extract all matches in each subject (extractall) <text.extractall>` (:issue:`10008`, :issue:`13156`)
- ``pd.read_hdf()`` now accepts path objects (e.g. ``pathlib.Path``, ``py.path.local``) for the file path, in line with other ``read_*`` functions (:issue:`11773`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you an just make this a single line (the first one) and say .to_hdf()/from_hdf()

@jreback jreback added this to the 0.18.2 milestone May 15, 2016
@jreback
Copy link
Contributor

jreback commented May 15, 2016

@quintusdias lgtm. minor comments on docs. pls update / ping when green.

@quintusdias
Copy link
Contributor Author

Comments addressed

@@ -259,7 +261,13 @@ def to_hdf(path_or_buf, key, value, mode=None, complevel=None, complib=None,
complib=complib) as store:
f(store)
else:
f(path_or_buf)
path_or_buf = _stringify_path(path_or_buf)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think is redundant, just adding a path_or_buf = _stringify_path(path_or_buf) (before the if should allow this2 to work, rather than adding another test for if instance(path_or_buf, string_tyeps) (which is repeated).

@quintusdias
Copy link
Contributor Author

Changes made.

@jreback jreback closed this in 62bed0e May 16, 2016
@jreback
Copy link
Contributor

jreback commented May 16, 2016

thanks @quintusdias

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions IO Data IO issues that don't fit into a more specific label IO HDF5 read_hdf, HDFStore
Projects
None yet
Development

Successfully merging this pull request may close these issues.

read_hdf not supporting pathlib.Path
3 participants