-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
BUG: disallow 'w' mode in pd.read_hdf (#13623) #13858
Conversation
@@ -303,6 +303,8 @@ def read_hdf(path_or_buf, key=None, **kwargs): | |||
|
|||
""" | |||
|
|||
if 'mode' in kwargs and kwargs['mode'] == 'w': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use kwargs.get()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
needs tests |
Current coverage is 85.25% (diff: 100%)@@ master #13858 diff @@
==========================================
Files 140 140
Lines 50455 50457 +2
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 43014 43017 +3
+ Misses 7441 7440 -1
Partials 0 0
|
a324cb7
to
785f386
Compare
The existing test cases check for r, r+, a and w modes. I have added a new test case to check read_hdf for default mode (i.e without mode argument given). |
@@ -303,6 +303,9 @@ def read_hdf(path_or_buf, key=None, **kwargs): | |||
|
|||
""" | |||
|
|||
if kwargs.get('mode') == 'w': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should raise other invalid mode here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Now instead of checking for invalid modes, I check only for valid modes and raise a ValueError if any invalid modes are passed.
785f386
to
8359d0b
Compare
@@ -303,6 +303,9 @@ def read_hdf(path_or_buf, key=None, **kwargs): | |||
|
|||
""" | |||
|
|||
if kwargs.get('mode', 'a') not in ['r', 'r+', 'a']: | |||
raise ValueError('mode %s is not allowed while performing a read. ' | |||
'Allowed modes are r, r+ and a.' % kwargs.get('mode')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use .format()
formatting
@iamsimha minor changes. ping when green. |
8359d0b
to
b03d90b
Compare
@jreback I have made the changes. |
thanks @iamsimha |
closes ERR: disallow read_hdf mode='w' #13623
tests added / passed
passes
git diff upstream/master | flake8 --diff
whatsnew entry
Passing mode='w' to read_hdf raises ValueError.