-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Make kwargs explicit in put, append #29957
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
Changes from 1 commit
a19e8d0
e9e90e7
65b0611
e3acb53
47ec657
9954d20
5852f9b
5be4945
5d464cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2412,6 +2412,8 @@ def to_hdf( | |
complib: Optional[str] = None, | ||
append: bool_t = False, | ||
format: Optional[str] = None, | ||
min_itemsize=None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is Union[Optional[int], Dict[str, int]] |
||
data_columns=None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional[List[str]] |
||
errors: str = "strict", | ||
encoding: str = "UTF-8", | ||
**kwargs, | ||
|
@@ -2471,6 +2473,8 @@ def to_hdf( | |
See the errors argument for :func:`open` for a full list | ||
of options. | ||
encoding : str, default "UTF-8" | ||
min_itemsize : dict, optional | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above |
||
Map column names to minimum string sizes for columns. | ||
data_columns : list of columns or True, optional | ||
List of columns to create as indexed data columns for on-disk | ||
queries, or True to use all columns. By default only the axes | ||
|
@@ -2530,6 +2534,8 @@ def to_hdf( | |
complib=complib, | ||
append=append, | ||
format=format, | ||
min_itemsize=min_itemsize, | ||
data_columns=data_columns, | ||
errors=errors, | ||
encoding=encoding, | ||
**kwargs, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,6 +259,8 @@ def to_hdf( | |
complib: Optional[str] = None, | ||
append: bool = False, | ||
format: Optional[str] = None, | ||
min_itemsize=None, | ||
data_columns=None, | ||
errors: str = "strict", | ||
encoding: str = "UTF-8", | ||
**kwargs, | ||
|
@@ -267,11 +269,25 @@ def to_hdf( | |
|
||
if append: | ||
f = lambda store: store.append( | ||
key, value, format=format, errors=errors, encoding=encoding, **kwargs | ||
key, | ||
value, | ||
format=format, | ||
min_itemsize=min_itemsize, | ||
data_columns=data_columns, | ||
errors=errors, | ||
encoding=encoding, | ||
**kwargs, | ||
) | ||
else: | ||
f = lambda store: store.put( | ||
key, value, format=format, errors=errors, encoding=encoding, **kwargs | ||
key, | ||
value, | ||
format=format, | ||
min_itemsize=min_itemsize, | ||
data_columns=data_columns, | ||
errors=errors, | ||
encoding=encoding, | ||
**kwargs, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah ok with removing the kwargs |
||
) | ||
|
||
path_or_buf = _stringify_path(path_or_buf) | ||
|
@@ -957,7 +973,22 @@ def func(_start, _stop, _where): | |
|
||
return it.get_result(coordinates=True) | ||
|
||
def put(self, key: str, value, format=None, append=False, **kwargs): | ||
def put( | ||
self, | ||
key: str, | ||
value: FrameOrSeries, | ||
format=None, | ||
index=True, | ||
append=False, | ||
complib=None, | ||
complevel: Optional[int] = None, | ||
min_itemsize=None, | ||
nan_rep=None, | ||
data_columns=None, | ||
encoding=None, | ||
errors: str = "strict", | ||
**kwargs, | ||
): | ||
""" | ||
Store object in HDFStore. | ||
|
||
|
@@ -986,8 +1017,22 @@ def put(self, key: str, value, format=None, append=False, **kwargs): | |
""" | ||
if format is None: | ||
format = get_option("io.hdf.default_format") or "fixed" | ||
kwargs = self._validate_format(format, kwargs) | ||
self._write_to_group(key, value, append=append, **kwargs) | ||
format = self._validate_format(format) | ||
self._write_to_group( | ||
key, | ||
value, | ||
format=format, | ||
index=index, | ||
append=append, | ||
complib=complib, | ||
complevel=complevel, | ||
min_itemsize=min_itemsize, | ||
nan_rep=nan_rep, | ||
data_columns=data_columns, | ||
encoding=encoding, | ||
errors=errors, | ||
**kwargs, | ||
) | ||
|
||
def remove(self, key: str, where=None, start=None, stop=None): | ||
""" | ||
|
@@ -1046,11 +1091,21 @@ def remove(self, key: str, where=None, start=None, stop=None): | |
def append( | ||
self, | ||
key: str, | ||
value, | ||
value: FrameOrSeries, | ||
format=None, | ||
axes=None, | ||
index=True, | ||
append=True, | ||
complib=None, | ||
complevel: Optional[int] = None, | ||
columns=None, | ||
min_itemsize=None, | ||
chunksize=None, | ||
expectedrows=None, | ||
dropna: Optional[bool] = None, | ||
data_columns=None, | ||
encoding=None, | ||
errors: str = "strict", | ||
**kwargs, | ||
): | ||
""" | ||
|
@@ -1096,8 +1151,25 @@ def append( | |
dropna = get_option("io.hdf.dropna_table") | ||
if format is None: | ||
format = get_option("io.hdf.default_format") or "table" | ||
kwargs = self._validate_format(format, kwargs) | ||
self._write_to_group(key, value, append=append, dropna=dropna, **kwargs) | ||
format = self._validate_format(format) | ||
self._write_to_group( | ||
key, | ||
value, | ||
format=format, | ||
axes=axes, | ||
index=index, | ||
append=append, | ||
complib=complib, | ||
complevel=complevel, | ||
min_itemsize=min_itemsize, | ||
chunksize=chunksize, | ||
expectedrows=expectedrows, | ||
dropna=dropna, | ||
data_columns=data_columns, | ||
encoding=encoding, | ||
errors=errors, | ||
**kwargs, | ||
) | ||
|
||
def append_to_multiple( | ||
self, | ||
|
@@ -1418,17 +1490,16 @@ def _check_if_open(self): | |
if not self.is_open: | ||
raise ClosedFileError(f"{self._path} file is not open!") | ||
|
||
def _validate_format(self, format: str, kwargs: Dict[str, Any]) -> Dict[str, Any]: | ||
def _validate_format(self, format: str) -> str: | ||
""" validate / deprecate formats; return the new kwargs """ | ||
kwargs = kwargs.copy() | ||
|
||
# validate | ||
try: | ||
kwargs["format"] = _FORMAT_MAP[format.lower()] | ||
format = _FORMAT_MAP[format.lower()] | ||
except KeyError: | ||
raise TypeError(f"invalid HDFStore format specified [{format}]") | ||
|
||
return kwargs | ||
return format | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could just return in try block and remove intermediate variable? |
||
|
||
def _create_storer( | ||
self, | ||
|
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.
could these keywords added here and in #29939 for the public API be keyword only, xref #27544
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.
i like this idea, will do in a dedicated PR