From 41979a5a512fbcd55e9f144cbd5820c4adecbe69 Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Sun, 22 Sep 2019 10:38:37 +0100 Subject: [PATCH 01/27] fixing parameter discrepency in pandas.DataFrame.plot.scatter --- pandas/plotting/_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index fe6b339c2f4c8..ddcf65cb59f3a 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1404,7 +1404,7 @@ def scatter(self, x, y, s=None, c=None, **kwargs): - A column name or position whose values will be used to color the marker points according to a colormap. - **kwds + **kwargs Keyword arguments to pass on to :meth:`DataFrame.plot`. Returns From a2bd9a1d525c34acc42326d07dc6c5a734cf0c3f Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Sun, 22 Sep 2019 10:59:49 +0100 Subject: [PATCH 02/27] updated **kwds to **kwargs --- pandas/plotting/_core.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index ddcf65cb59f3a..07726c3d25abc 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -810,7 +810,7 @@ def line(self, x=None, y=None, **kwargs): The values to be plotted. Either the location or the label of the columns to be used. By default, it will use the remaining DataFrame numeric columns. - **kwds + **kwargs Keyword arguments to pass on to :meth:`DataFrame.plot`. Returns @@ -880,7 +880,7 @@ def bar(self, x=None, y=None, **kwargs): y : label or position, optional Allows plotting of one column versus another. If not specified, all numerical columns are used. - **kwds + **kwargs Additional keyword arguments are documented in :meth:`DataFrame.plot`. @@ -963,7 +963,7 @@ def barh(self, x=None, y=None, **kwargs): Column to be used for categories. y : label or position, default All numeric columns in dataframe Columns to be plotted from the DataFrame. - **kwds + **kwargs Keyword arguments to pass on to :meth:`DataFrame.plot`. Returns @@ -1049,7 +1049,7 @@ def box(self, by=None, **kwargs): ---------- by : str or sequence Column in the DataFrame to group by. - **kwds : optional + **kwargs : optional Additional keywords are documented in :meth:`DataFrame.plot`. @@ -1092,7 +1092,7 @@ def hist(self, by=None, bins=10, **kwargs): Column in the DataFrame to group by. bins : int, default 10 Number of histogram bins to be used. - **kwds + **kwargs Additional keyword arguments are documented in :meth:`DataFrame.plot`. @@ -1148,7 +1148,7 @@ def kde(self, bw_method=None, ind=None, **kwargs): 1000 equally spaced points are used. If `ind` is a NumPy array, the KDE is evaluated at the points passed. If `ind` is an integer, `ind` number of equally spaced points are used. - **kwds : optional + **kwargs : optional Additional keyword arguments are documented in :meth:`pandas.%(this-datatype)s.plot`. @@ -1322,7 +1322,7 @@ def pie(self, **kwargs): y : int or label, optional Label or position of the column to plot. If not provided, ``subplots=True`` argument must be passed. - **kwds + **kwargs Keyword arguments to pass on to :meth:`DataFrame.plot`. Returns @@ -1476,7 +1476,7 @@ def hexbin(self, x, y, C=None, reduce_C_function=None, gridsize=None, **kwargs): Alternatively, gridsize can be a tuple with two elements specifying the number of hexagons in the x-direction and the y-direction. - **kwds + **kwargs Additional keyword arguments are documented in :meth:`DataFrame.plot`. From 8136c0ecf556a07c2ae5a7630947d3de2c0150b9 Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Mon, 23 Sep 2019 20:32:04 +0100 Subject: [PATCH 03/27] updating **kwargs optional to **kwargs --- pandas/plotting/_core.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 07726c3d25abc..45876c8e24be5 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1049,7 +1049,7 @@ def box(self, by=None, **kwargs): ---------- by : str or sequence Column in the DataFrame to group by. - **kwargs : optional + **kwargs Additional keywords are documented in :meth:`DataFrame.plot`. @@ -1148,7 +1148,7 @@ def kde(self, bw_method=None, ind=None, **kwargs): 1000 equally spaced points are used. If `ind` is a NumPy array, the KDE is evaluated at the points passed. If `ind` is an integer, `ind` number of equally spaced points are used. - **kwargs : optional + **kwargs Additional keyword arguments are documented in :meth:`pandas.%(this-datatype)s.plot`. @@ -1250,7 +1250,7 @@ def area(self, x=None, y=None, **kwargs): stacked : bool, default True Area plots are stacked by default. Set to False to create a unstacked plot. - **kwds : optional + **kwargs Additional keyword arguments are documented in :meth:`DataFrame.plot`. From 78419d0bd349f60446c70b89db0b2dd13f603507 Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Mon, 23 Sep 2019 20:39:20 +0100 Subject: [PATCH 04/27] updating the other **kwds to **kwargs to keep things consistent in the _core.py file --- pandas/plotting/_core.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 45876c8e24be5..af63396fc4c9e 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -28,7 +28,7 @@ def hist_series( yrot=None, figsize=None, bins=10, - **kwds + **kwargs ): """ Draw histogram of the input series using matplotlib. @@ -56,7 +56,7 @@ def hist_series( bin edges are calculated and returned. If bins is a sequence, gives bin edges, including left edge of first bin and right edge of last bin. In this case, bins is returned unmodified. - `**kwds` : keywords + `**kwargs To be passed to the actual plotting function Returns @@ -80,7 +80,7 @@ def hist_series( yrot=yrot, figsize=figsize, bins=bins, - **kwds + **kwargs ) @@ -99,7 +99,7 @@ def hist_frame( figsize=None, layout=None, bins=10, - **kwds + **kwargs ): """ Make a histogram of the DataFrame's. @@ -151,7 +151,7 @@ def hist_frame( bin edges are calculated and returned. If bins is a sequence, gives bin edges, including left edge of first bin and right edge of last bin. In this case, bins is returned unmodified. - **kwds + **kwargs All other plotting keyword arguments to be passed to :meth:`matplotlib.pyplot.hist`. @@ -194,7 +194,7 @@ def hist_frame( figsize=figsize, layout=layout, bins=bins, - **kwds + **kwargs ) @@ -209,7 +209,7 @@ def boxplot( figsize=None, layout=None, return_type=None, - **kwds + **kwargs ): """ Make a box plot from DataFrame columns. @@ -260,7 +260,7 @@ def boxplot( If ``return_type`` is `None`, a NumPy array of axes with the same shape as ``layout`` is returned. - **kwds + **kwargs All other plotting keyword arguments to be passed to :func:`matplotlib.pyplot.boxplot`. @@ -385,7 +385,7 @@ def boxplot( figsize=figsize, layout=layout, return_type=return_type, - **kwds + **kwargs ) @@ -401,7 +401,7 @@ def boxplot_frame( figsize=None, layout=None, return_type=None, - **kwds + **kwargs ): plot_backend = _get_plot_backend() return plot_backend.boxplot_frame( @@ -415,7 +415,7 @@ def boxplot_frame( figsize=figsize, layout=layout, return_type=return_type, - **kwds + **kwargs ) @@ -431,7 +431,7 @@ def boxplot_frame_groupby( layout=None, sharex=False, sharey=True, - **kwds + **kwargs ): """ Make box plots from DataFrameGroupBy data. @@ -459,7 +459,7 @@ def boxplot_frame_groupby( Whether y-axes will be shared among subplots .. versionadded:: 0.23.1 - `**kwds` : Keyword Arguments + `**kwargs All other plotting keyword arguments to be passed to matplotlib's boxplot function @@ -495,7 +495,7 @@ def boxplot_frame_groupby( layout=layout, sharex=sharex, sharey=sharey, - **kwds + **kwargs ) @@ -586,7 +586,7 @@ class PlotAccessor(PandasObject): labels with "(right)" in the legend include_bool : bool, default is False If True, boolean values can be plotted. - `**kwds` : keywords + `**kwargs Options to pass to matplotlib plotting method. Returns From 60151af6ceca6ee1392f9047621522ed04c06a4b Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Tue, 24 Sep 2019 18:57:28 +0100 Subject: [PATCH 05/27] removed " before **kwargs' --- pandas/plotting/_core.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index af63396fc4c9e..8724382d9ec55 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -56,7 +56,7 @@ def hist_series( bin edges are calculated and returned. If bins is a sequence, gives bin edges, including left edge of first bin and right edge of last bin. In this case, bins is returned unmodified. - `**kwargs + **kwargs To be passed to the actual plotting function Returns @@ -459,7 +459,7 @@ def boxplot_frame_groupby( Whether y-axes will be shared among subplots .. versionadded:: 0.23.1 - `**kwargs + **kwargs All other plotting keyword arguments to be passed to matplotlib's boxplot function @@ -586,7 +586,7 @@ class PlotAccessor(PandasObject): labels with "(right)" in the legend include_bool : bool, default is False If True, boolean values can be plotted. - `**kwargs + **kwargs Options to pass to matplotlib plotting method. Returns From 6ca5b7a88cd38a2d367ce118b2f952e381af8af5 Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Tue, 24 Sep 2019 19:34:20 +0100 Subject: [PATCH 06/27] splitting comment in test_sort over multiple lines as it is causing the CI to fail --- pandas/tests/groupby/test_categorical.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/tests/groupby/test_categorical.py b/pandas/tests/groupby/test_categorical.py index e09af3fd48ee6..1fd7b1f583049 100644 --- a/pandas/tests/groupby/test_categorical.py +++ b/pandas/tests/groupby/test_categorical.py @@ -782,7 +782,9 @@ def test_categorical_no_compress(): def test_sort(): - # http://stackoverflow.com/questions/23814368/sorting-pandas-categorical-labels-after-groupby # noqa: flake8 + # http://stackoverflow.com/questions/23814368/ + # sorting-pandas-categorical-labels-after-groupby + # noqa: flake8 # This should result in a properly sorted Series so that the plot # has a sorted x axis # self.cat.groupby(['value_group'])['value_group'].count().plot(kind='bar') From b5692e05189da3721b73c8390b056d31a4b7a7ed Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Thu, 26 Sep 2019 16:57:47 +0100 Subject: [PATCH 07/27] changing pandas.dataframe methods from boolean to bool --- pandas/core/frame.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index ed05691d33d07..b6bc87165b542 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -322,7 +322,7 @@ class DataFrame(NDFrame): RangeIndex (0, 1, 2, ..., n) if no column labels are provided dtype : dtype, default None Data type to force. Only a single dtype is allowed. If None, infer - copy : boolean, default False + copy : bool, default False Copy data from inputs. Only affects DataFrame / 2d ndarray input See Also @@ -1553,7 +1553,7 @@ def from_records( columns. Otherwise this argument indicates the order of the columns in the result (any names not found in the data will become all-NA columns) - coerce_float : boolean, default False + coerce_float : bool, default False Attempt to convert values of non-string, non-numeric objects (like decimal.Decimal) to floating point, useful for SQL result sets nrows : int, default None @@ -4775,7 +4775,7 @@ def drop_duplicates(self, subset=None, keep="first", inplace=False): - ``first`` : Drop duplicates except for the first occurrence. - ``last`` : Drop duplicates except for the last occurrence. - False : Drop all duplicates. - inplace : boolean, default False + inplace : bool, default False Whether to drop duplicates in place or to return a copy Returns @@ -5850,14 +5850,14 @@ def pivot(self, index=None, columns=None, values=None): is function or list of functions fill_value : scalar, default None Value to replace missing values with - margins : boolean, default False + margins : bool, default False Add all row / columns (e.g. for subtotal / grand totals) - dropna : boolean, default True + dropna : bool, default True Do not include columns whose entries are all NaN margins_name : string, default 'All' Name of the row / column that will contain the totals when margins is True. - observed : boolean, default False + observed : bool, default False This only applies if any of the groupers are Categoricals. If True: only show observed values for categorical groupers. If False: show all values for categorical groupers. @@ -6894,11 +6894,11 @@ def append(self, other, ignore_index=False, verify_integrity=False, sort=None): ---------- other : DataFrame or Series/dict-like object, or list of these The data to append. - ignore_index : boolean, default False + ignore_index : bool, default False If True, do not use the index labels. - verify_integrity : boolean, default False + verify_integrity : bool, default False If True, raise ValueError on creating index with duplicates. - sort : boolean, default None + sort : bool, default None Sort columns if the columns of `self` and `other` are not aligned. The default sorting is deprecated and will change to not-sorting in a future version of pandas. Explicitly pass ``sort=True`` to @@ -7940,7 +7940,7 @@ def idxmin(self, axis=0, skipna=True): ---------- axis : {0 or 'index', 1 or 'columns'}, default 0 0 or 'index' for row-wise, 1 or 'columns' for column-wise - skipna : boolean, default True + skipna : bool, default True Exclude NA/null values. If an entire row/column is NA, the result will be NA. @@ -7977,7 +7977,7 @@ def idxmax(self, axis=0, skipna=True): ---------- axis : {0 or 'index', 1 or 'columns'}, default 0 0 or 'index' for row-wise, 1 or 'columns' for column-wise - skipna : boolean, default True + skipna : bool, default True Exclude NA/null values. If an entire row/column is NA, the result will be NA. From d20973e68549e924be866fb91286b654e7133f5c Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Thu, 26 Sep 2019 17:02:49 +0100 Subject: [PATCH 08/27] changing pandas.dataframe methods from boolean to bool --- pandas/core/frame.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index b6bc87165b542..a5cfcd6ccc99d 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1542,7 +1542,7 @@ def from_records( Parameters ---------- data : ndarray (structured dtype), list of tuples, dict, or DataFrame - index : string, list of fields, array-like + index : str, list of fields, array-like Field of array to use as the index, alternately a specific set of input labels to use exclude : sequence, default None @@ -3461,7 +3461,7 @@ def insert(self, loc, column, value, allow_duplicates=False): ---------- loc : int Insertion index. Must verify 0 <= loc <= len(columns) - column : string, number, or hashable object + column : str, number, or hashable object label of the inserted column value : int, Series, or array-like allow_duplicates : bool, optional @@ -5197,7 +5197,7 @@ def swaplevel(self, i=-2, j=-1, axis=0): Parameters ---------- - i, j : int, string (can be mixed) + i, j : int, str (can be mixed) Level of index to be swapped. Can pass level name as string. Returns @@ -5723,12 +5723,12 @@ def update( Parameters ----------%s - index : string or object, optional + index : str or object, optional Column to use to make new frame's index. If None, uses existing index. - columns : string or object + columns : str or object Column to use to make new frame's columns. - values : string, object or a list of the previous, optional + values : str, object or a list of the previous, optional Column(s) to use for populating new frame's values. If not specified, all remaining columns will be used and the result will have hierarchically indexed columns. @@ -6231,7 +6231,7 @@ def unstack(self, level=-1, fill_value=None): Parameters ---------- - level : int, string, or list of these, default -1 (last level) + level : int, str, or list of these, default -1 (last level) Level(s) of index to unstack, can pass level name fill_value : replace NaN with this value if the unstack produces missing values @@ -6305,7 +6305,7 @@ def unstack(self, level=-1, fill_value=None): ``frame.columns.name`` or 'variable'. value_name : scalar, default 'value' Name to use for the 'value' column. - col_level : int or string, optional + col_level : int or str, optional If columns are a MultiIndex then use this level to melt. Returns From 32f06b98288e52b35e8ee007c0535925c29eff0d Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Thu, 26 Sep 2019 17:04:32 +0100 Subject: [PATCH 09/27] Revert "changing pandas.dataframe methods from boolean to bool" This reverts commit d20973e68549e924be866fb91286b654e7133f5c. --- pandas/core/frame.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index a5cfcd6ccc99d..b6bc87165b542 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1542,7 +1542,7 @@ def from_records( Parameters ---------- data : ndarray (structured dtype), list of tuples, dict, or DataFrame - index : str, list of fields, array-like + index : string, list of fields, array-like Field of array to use as the index, alternately a specific set of input labels to use exclude : sequence, default None @@ -3461,7 +3461,7 @@ def insert(self, loc, column, value, allow_duplicates=False): ---------- loc : int Insertion index. Must verify 0 <= loc <= len(columns) - column : str, number, or hashable object + column : string, number, or hashable object label of the inserted column value : int, Series, or array-like allow_duplicates : bool, optional @@ -5197,7 +5197,7 @@ def swaplevel(self, i=-2, j=-1, axis=0): Parameters ---------- - i, j : int, str (can be mixed) + i, j : int, string (can be mixed) Level of index to be swapped. Can pass level name as string. Returns @@ -5723,12 +5723,12 @@ def update( Parameters ----------%s - index : str or object, optional + index : string or object, optional Column to use to make new frame's index. If None, uses existing index. - columns : str or object + columns : string or object Column to use to make new frame's columns. - values : str, object or a list of the previous, optional + values : string, object or a list of the previous, optional Column(s) to use for populating new frame's values. If not specified, all remaining columns will be used and the result will have hierarchically indexed columns. @@ -6231,7 +6231,7 @@ def unstack(self, level=-1, fill_value=None): Parameters ---------- - level : int, str, or list of these, default -1 (last level) + level : int, string, or list of these, default -1 (last level) Level(s) of index to unstack, can pass level name fill_value : replace NaN with this value if the unstack produces missing values @@ -6305,7 +6305,7 @@ def unstack(self, level=-1, fill_value=None): ``frame.columns.name`` or 'variable'. value_name : scalar, default 'value' Name to use for the 'value' column. - col_level : int or str, optional + col_level : int or string, optional If columns are a MultiIndex then use this level to melt. Returns From 40424559f5d02da0e550b154ec33e48f78b5a50d Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Thu, 26 Sep 2019 17:11:56 +0100 Subject: [PATCH 10/27] changing pandas.dataframe methods from string to str --- pandas/core/frame.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index b6bc87165b542..fe6d487185078 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1542,7 +1542,7 @@ def from_records( Parameters ---------- data : ndarray (structured dtype), list of tuples, dict, or DataFrame - index : string, list of fields, array-like + index : str, list of fields, array-like Field of array to use as the index, alternately a specific set of input labels to use exclude : sequence, default None @@ -5197,7 +5197,7 @@ def swaplevel(self, i=-2, j=-1, axis=0): Parameters ---------- - i, j : int, string (can be mixed) + i, j : int, str (can be mixed) Level of index to be swapped. Can pass level name as string. Returns @@ -5723,12 +5723,12 @@ def update( Parameters ----------%s - index : string or object, optional + index : str or object, optional Column to use to make new frame's index. If None, uses existing index. - columns : string or object + columns : str or object Column to use to make new frame's columns. - values : string, object or a list of the previous, optional + values : str, object or a list of the previous, optional Column(s) to use for populating new frame's values. If not specified, all remaining columns will be used and the result will have hierarchically indexed columns. @@ -5854,7 +5854,7 @@ def pivot(self, index=None, columns=None, values=None): Add all row / columns (e.g. for subtotal / grand totals) dropna : bool, default True Do not include columns whose entries are all NaN - margins_name : string, default 'All' + margins_name : str, default 'All' Name of the row / column that will contain the totals when margins is True. observed : bool, default False @@ -6231,7 +6231,7 @@ def unstack(self, level=-1, fill_value=None): Parameters ---------- - level : int, string, or list of these, default -1 (last level) + level : int, str, or list of these, default -1 (last level) Level(s) of index to unstack, can pass level name fill_value : replace NaN with this value if the unstack produces missing values @@ -6305,7 +6305,7 @@ def unstack(self, level=-1, fill_value=None): ``frame.columns.name`` or 'variable'. value_name : scalar, default 'value' Name to use for the 'value' column. - col_level : int or string, optional + col_level : int or str, optional If columns are a MultiIndex then use this level to melt. Returns From 46d9d312555fa8d01aff0b334d61acb9e3c2ddc6 Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Thu, 26 Sep 2019 17:14:25 +0100 Subject: [PATCH 11/27] changing pandas.dataframe.insert from string to str --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index fe6d487185078..e4a44a89998e3 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3461,7 +3461,7 @@ def insert(self, loc, column, value, allow_duplicates=False): ---------- loc : int Insertion index. Must verify 0 <= loc <= len(columns) - column : string, number, or hashable object + column : str, number, or hashable object label of the inserted column value : int, Series, or array-like allow_duplicates : bool, optional From 400430e2fc8999616fc62eeb69c7fbbd8b92b6ab Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Thu, 26 Sep 2019 17:23:19 +0100 Subject: [PATCH 12/27] changing pandas.groupby methods from boolean to bool --- pandas/core/groupby/groupby.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index e010e615e176e..2e075f3d5d2dc 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -2099,13 +2099,13 @@ def rank( * max: highest rank in group * first: ranks assigned in order they appear in the array * dense: like 'min', but rank always increases by 1 between groups - ascending : boolean, default True + ascending : bool, default True False for ranks by high (1) to low (N) na_option : {'keep', 'top', 'bottom'}, default 'keep' * keep: leave NA values where they are * top: smallest rank if ascending * bottom: smallest rank if descending - pct : boolean, default False + pct : bool, default False Compute percentage rank of data within each group axis : int, default 0 The axis of the object over which to compute the rank. From 0ebb04b9865cbf472db5e8fb0e6cec94c67ebf28 Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Thu, 26 Sep 2019 17:24:21 +0100 Subject: [PATCH 13/27] changing pandas.groupby methods from integer to int --- pandas/core/groupby/groupby.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 2e075f3d5d2dc..7912d35d2043e 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -1253,7 +1253,7 @@ def std(self, ddof=1, *args, **kwargs): Parameters ---------- - ddof : integer, default 1 + ddof : int, default 1 degrees of freedom Returns @@ -1276,7 +1276,7 @@ def var(self, ddof=1, *args, **kwargs): Parameters ---------- - ddof : integer, default 1 + ddof : int, default 1 degrees of freedom Returns @@ -1311,7 +1311,7 @@ def sem(self, ddof=1): Parameters ---------- - ddof : integer, default 1 + ddof : int, default 1 degrees of freedom Returns @@ -1623,7 +1623,7 @@ def pad(self, limit=None): Parameters ---------- - limit : integer, optional + limit : int, optional limit of how many values to fill Returns @@ -1649,7 +1649,7 @@ def backfill(self, limit=None): Parameters ---------- - limit : integer, optional + limit : int, optional limit of how many values to fill Returns @@ -2313,7 +2313,7 @@ def shift(self, periods=1, freq=None, axis=0, fill_value=None): Parameters ---------- - periods : integer, default 1 + periods : int, default 1 number of periods to shift freq : frequency string axis : axis to shift, default 0 From 5dcceb222da8725f2375271b6c9ed66a7a5f8bad Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Thu, 26 Sep 2019 17:25:11 +0100 Subject: [PATCH 14/27] changing pandas.groupby methods from string to str --- pandas/core/groupby/groupby.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 7912d35d2043e..6facbe7e01c57 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -1032,7 +1032,7 @@ class GroupBy(_GroupBy): Most users should ignore this exclusions : array-like, optional List of columns to exclude - name : string + name : str Most users should ignore this Returns From 69a91a4c502c80a1b49c3769b3a306e140c81695 Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Thu, 26 Sep 2019 18:54:33 +0100 Subject: [PATCH 15/27] changing pandas.grouper docstring from boolean to bool and string to str --- pandas/core/groupby/grouper.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/groupby/grouper.py b/pandas/core/groupby/grouper.py index 2ebfbed0b132a..2d37121d28308 100644 --- a/pandas/core/groupby/grouper.py +++ b/pandas/core/groupby/grouper.py @@ -48,17 +48,17 @@ class Grouper: Parameters ---------- - key : string, defaults to None + key : str, defaults to None groupby key, which selects the grouping column of the target level : name/number, defaults to None the level for the target index - freq : string / frequency object, defaults to None + freq : str / frequency object, defaults to None This will groupby the specified frequency if the target selection (via key or level) is a datetime-like object. For full specification of available frequencies, please see `here `_. axis : number/name of the axis, defaults to 0 - sort : boolean, default to False + sort : bool, default to False whether to sort the resulting labels closed : {'left' or 'right'} Closed end of interval. Only when `freq` parameter is passed. @@ -69,7 +69,7 @@ class Grouper: If grouper is PeriodIndex and `freq` parameter is passed. base : int, default 0 Only when `freq` parameter is passed. - loffset : string, DateOffset, timedelta object + loffset : str, DateOffset, timedelta object Only when `freq` parameter is passed. Returns From 3aa3057f76b03b3cf0216dd9a3f44414e3590e7a Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Thu, 26 Sep 2019 19:02:03 +0100 Subject: [PATCH 16/27] changing pandas.datetimeindex methods docstring from boolean to bool --- pandas/core/indexes/datetimes.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index cce390d98c037..db05be9591bbd 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -106,7 +106,7 @@ class DatetimeIndex(DatetimeIndexOpsMixin, Int64Index, DatetimeDelegateMixin): Optional datetime-like data to construct index with copy : bool Make a copy of input ndarray - freq : string or pandas offset object, optional + freq : str or pandas offset object, optional One of pandas date offset strings or corresponding objects. The string 'infer' can be passed in order to set the frequency of the index as the inferred frequency upon creation @@ -129,7 +129,7 @@ class DatetimeIndex(DatetimeIndexOpsMixin, Int64Index, DatetimeDelegateMixin): .. deprecated:: 0.24.0 - closed : string or None, default None + closed : str or None, default None Make the interval closed with respect to the given frequency to the 'left', 'right', or both sides (None) @@ -1371,8 +1371,8 @@ def indexer_between_time( datetime.time or string in appropriate format ("%H:%M", "%H%M", "%I:%M%p", "%I%M%p", "%H:%M:%S", "%H%M%S", "%I:%M:%S%p", "%I%M%S%p"). - include_start : boolean, default True - include_end : boolean, default True + include_start : bool, default True + include_end : bool, default True Returns ------- From 6c49a81c808d923e74df3cf1ddaaf7ea0a2537e6 Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Thu, 26 Sep 2019 19:06:23 +0100 Subject: [PATCH 17/27] changing pandas.read_sas docstring from string to str --- pandas/io/sas/sasreader.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/io/sas/sasreader.py b/pandas/io/sas/sasreader.py index 571c544d48b29..6bd3532d538c7 100644 --- a/pandas/io/sas/sasreader.py +++ b/pandas/io/sas/sasreader.py @@ -29,12 +29,12 @@ def read_sas( By file-like object, we refer to objects with a ``read()`` method, such as a file handler (e.g. via builtin ``open`` function) or ``StringIO``. - format : string {'xport', 'sas7bdat'} or None + format : str {'xport', 'sas7bdat'} or None If None, file format is inferred from file extension. If 'xport' or 'sas7bdat', uses the corresponding format. index : identifier of index column, defaults to None Identifier of column that should be used as index of the DataFrame. - encoding : string, default is None + encoding : str, default is None Encoding for text data. If None, text data are stored as raw bytes. chunksize : int Read file `chunksize` lines at a time, returns iterator. From b0c09b4a3d66db09d15be10c47c94d314c3e480d Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Thu, 26 Sep 2019 19:59:49 +0100 Subject: [PATCH 18/27] fixing parameter type inconsistencies for pandas.bdate_range --- pandas/core/indexes/datetimes.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index db05be9591bbd..ece2b352907dd 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1598,22 +1598,22 @@ def bdate_range( Parameters ---------- - start : string or datetime-like, default None + start : str or datetime-like, default None Left bound for generating dates. - end : string or datetime-like, default None + end : str or datetime-like, default None Right bound for generating dates. - periods : integer, default None + periods : int, default None Number of periods to generate. - freq : string or DateOffset, default 'B' (business daily) + freq : str or DateOffset, default 'B' (business daily) Frequency strings can have multiples, e.g. '5H'. - tz : string or None + tz : str or None Time zone name for returning localized DatetimeIndex, for example Asia/Beijing. normalize : bool, default False Normalize start/end dates to midnight before generating date range. - name : string, default None + name : str, default None Name of the resulting DatetimeIndex. - weekmask : string or None, default None + weekmask : str or None, default None Weekmask of valid business days, passed to ``numpy.busdaycalendar``, only used when custom frequency strings are passed. The default value None is equivalent to 'Mon Tue Wed Thu Fri'. @@ -1627,7 +1627,7 @@ def bdate_range( .. versionadded:: 0.21.0 - closed : string, default None + closed : str, default None Make the interval closed with respect to the given frequency to the 'left', 'right', or both sides (None). **kwargs From ff13a6991d12d8c542376cf9537704f55baad129 Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Thu, 26 Sep 2019 20:04:28 +0100 Subject: [PATCH 19/27] fixing parameter type inconsistencies for pandas.to_datetim --- pandas/core/tools/datetimes.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pandas/core/tools/datetimes.py b/pandas/core/tools/datetimes.py index b07647cf5b5fb..32dc3c1f3e8f2 100644 --- a/pandas/core/tools/datetimes.py +++ b/pandas/core/tools/datetimes.py @@ -577,7 +577,7 @@ def to_datetime( Parameters ---------- - arg : integer, float, string, datetime, list, tuple, 1-d array, Series + arg : int, float, str, datetime, list, tuple, 1-d array, Series or DataFrame/dict-like errors : {'ignore', 'raise', 'coerce'}, default 'raise' @@ -585,13 +585,13 @@ def to_datetime( - If 'raise', then invalid parsing will raise an exception - If 'coerce', then invalid parsing will be set as NaT - If 'ignore', then invalid parsing will return the input - dayfirst : boolean, default False + dayfirst : bool, default False Specify a date parse order if `arg` is str or its list-likes. If True, parses dates with the day first, eg 10/11/12 is parsed as 2012-11-10. Warning: dayfirst=True is not strict, but will prefer to parse with day first (this is a known bug, based on dateutil behavior). - yearfirst : boolean, default False + yearfirst : bool, default False Specify a date parse order if `arg` is str or its list-likes. - If True parses dates with the year first, eg 10/11/12 is parsed as @@ -604,10 +604,10 @@ def to_datetime( .. versionadded:: 0.16.1 - utc : boolean, default None + utc : bool, default None Return UTC DatetimeIndex if True (converting any tz-aware datetime.datetime objects as well). - box : boolean, default True + box : bool, default True - If True returns a DatetimeIndex or Index-like object - If False returns ndarray of values. @@ -617,22 +617,22 @@ def to_datetime( instead to get an ndarray of values or numpy.datetime64, respectively. - format : string, default None + format : str, default None strftime to parse time, eg "%d/%m/%Y", note that "%f" will parse all the way up to nanoseconds. See strftime documentation for more information on choices: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior - exact : boolean, True by default + exact : bool, True by default - If True, require an exact format match. - If False, allow the format to match anywhere in the target string. - unit : string, default 'ns' + unit : str, default 'ns' unit of the arg (D,s,ms,us,ns) denote the unit, which is an integer or float number. This will be based off the origin. Example, with unit='ms' and origin='unix' (the default), this would calculate the number of milliseconds to the unix epoch start. - infer_datetime_format : boolean, default False + infer_datetime_format : bool, default False If True and no `format` is given, attempt to infer the format of the datetime strings, and if it can be inferred, switch to a faster method of parsing them. In some cases this can increase the parsing @@ -649,7 +649,7 @@ def to_datetime( origin. .. versionadded:: 0.20.0 - cache : boolean, default True + cache : bool, default True If True, use a cache of unique, converted dates to apply the datetime conversion. May produce significant speed-up when parsing duplicate date strings, especially ones with timezone offsets. From 4ef0b642ada3daac9b964b5b2ce4c4736210591f Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Thu, 26 Sep 2019 20:07:56 +0100 Subject: [PATCH 20/27] fixing parameter type inconsistencies for pandas.date_range --- pandas/core/indexes/datetimes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index ece2b352907dd..0b20df38e7d42 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1435,7 +1435,7 @@ def date_range( Left bound for generating dates. end : str or datetime-like, optional Right bound for generating dates. - periods : integer, optional + periods : int, optional Number of periods to generate. freq : str or DateOffset, default 'D' Frequency strings can have multiples, e.g. '5H'. See From 42f273410abd888e9822e1902c73d793d017b2ce Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Thu, 26 Sep 2019 20:13:37 +0100 Subject: [PATCH 21/27] changing pandas.index methods docstring from string to str --- pandas/core/indexes/base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 62662edb692a7..bb060c76fec70 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -904,7 +904,7 @@ def repeat(self, repeats, axis=None): Parameters ---------- - name : string, optional + name : str, optional deep : boolean, default False dtype : numpy dtype or pandas type @@ -1172,7 +1172,7 @@ def to_series(self, index=None, name=None): ---------- index : Index, optional index of resulting Series. If None, defaults to original index - name : string, optional + name : str, optional name of resulting Series. If None, defaults to name of original index @@ -4924,7 +4924,7 @@ def slice_indexer(self, start=None, end=None, step=None, kind=None): end : label, default None If None, defaults to the end step : int, default None - kind : string, default None + kind : str, default None Returns ------- From d57f6672aad0f49339177f0728025ebfc3c4acdb Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Thu, 26 Sep 2019 20:16:15 +0100 Subject: [PATCH 22/27] changing pandas.index methods docstring from boolean to bool --- pandas/core/indexes/base.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index bb060c76fec70..0b633602f3ed0 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -905,7 +905,7 @@ def repeat(self, repeats, axis=None): Parameters ---------- name : str, optional - deep : boolean, default False + deep : bool, default False dtype : numpy dtype or pandas type Returns @@ -1198,7 +1198,7 @@ def to_frame(self, index=True, name=None): Parameters ---------- - index : boolean, default True + index : bool, default True Set the index of the returned DataFrame as the original Index. name : object, default None @@ -1401,7 +1401,7 @@ def rename(self, name, inplace=False): ---------- name : label or list of labels Name(s) to set. - inplace : boolean, default False + inplace : bool, default False Modifies the object directly, instead of creating a new Index or MultiIndex. @@ -1494,7 +1494,7 @@ def sortlevel(self, level=None, ascending=True, sort_remaining=None): Parameters ---------- - ascending : boolean, default True + ascending : bool, default True False to sort in descending order level, sort_remaining are compat parameters @@ -3415,8 +3415,8 @@ def _reindex_non_unique(self, target): other : Index how : {'left', 'right', 'inner', 'outer'} level : int or level name, default None - return_indexers : boolean, default False - sort : boolean, default False + return_indexers : bool, default False + sort : bool, default False Sort the join keys lexicographically in the result Index. If False, the order of the join keys depends on the join type (how keyword) @@ -3942,7 +3942,7 @@ def memory_usage(self, deep=False): Parameters ---------- - cond : boolean array-like with the same length as self + cond : bool array-like with the same length as self other : scalar, or array-like Returns From 0bb2b544cb20d13611b419bf0c677cbb757d24c3 Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Thu, 26 Sep 2019 20:27:30 +0100 Subject: [PATCH 23/27] changing pandas.resampler methods docstring from integer to int --- pandas/core/resample.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/core/resample.py b/pandas/core/resample.py index a5d0e2cb3b58f..545bc21dd6d1b 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -423,7 +423,7 @@ def pad(self, limit=None): Parameters ---------- - limit : integer, optional + limit : int, optional limit of how many values to fill Returns @@ -514,7 +514,7 @@ def backfill(self, limit=None): Parameters ---------- - limit : integer, optional + limit : int, optional Limit of how many values to fill. Returns @@ -628,7 +628,7 @@ def fillna(self, method, limit=None): * 'backfill' or 'bfill': use next valid observation to fill gap. * 'nearest': use nearest valid observation to fill gap. - limit : integer, optional + limit : int, optional Limit of how many consecutive missing values to fill. Returns @@ -823,7 +823,7 @@ def std(self, ddof=1, *args, **kwargs): Parameters ---------- - ddof : integer, default 1 + ddof : int, default 1 Degrees of freedom. Returns @@ -840,7 +840,7 @@ def var(self, ddof=1, *args, **kwargs): Parameters ---------- - ddof : integer, default 1 + ddof : int, default 1 degrees of freedom Returns From 0523b7ae3208f9b07a97517489cf34564f82a3b5 Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Tue, 1 Oct 2019 12:04:42 +0100 Subject: [PATCH 24/27] replaced self.path with setup_path fixture --- pandas/tests/io/pytables/test_pytables.py | 604 ++++++++++++++-------- 1 file changed, 398 insertions(+), 206 deletions(-) diff --git a/pandas/tests/io/pytables/test_pytables.py b/pandas/tests/io/pytables/test_pytables.py index ae604b1141204..2ff6fc458bef2 100644 --- a/pandas/tests/io/pytables/test_pytables.py +++ b/pandas/tests/io/pytables/test_pytables.py @@ -51,6 +51,12 @@ tables = pytest.importorskip("tables") +@pytest.fixture +def setup_path(): + """Fixture for setup path""" + return "tmp.__{}__.h5".format(tm.rands(10)) + + # TODO: # remove when gh-24839 is fixed; this affects numpy 1.16 # and pytables 3.4.4 @@ -162,7 +168,8 @@ def teardown_class(cls): tm.set_testing_mode() def setup_method(self, method): - self.path = "tmp.__{}__.h5".format(tm.rands(10)) + setup_path\ + = "tmp.__{}__.h5".format(tm.rands(10)) def teardown_method(self, method): pass @@ -172,12 +179,14 @@ def teardown_method(self, method): class TestHDFStore(Base): def test_format_kwarg_in_constructor(self): # GH 13291 - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: with pytest.raises(ValueError): HDFStore(path, format="table") def test_context(self): - path = create_tempfile(self.path) + path = create_tempfile(setup_path + ) try: with HDFStore(path) as tbl: raise ValueError("blah") @@ -197,7 +206,8 @@ def test_context(self): safe_remove(path) def test_conv_read_write(self): - path = create_tempfile(self.path) + path = create_tempfile(setup_path + ) try: def roundtrip(key, obj, **kwargs): @@ -229,7 +239,8 @@ def test_long_strings(self): {"a": tm.rands_array(100, size=10)}, index=tm.rands_array(100, size=10) ) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.append("df", df, data_columns=["a"]) result = store.select("df") @@ -239,7 +250,8 @@ def test_api(self): # GH4584 # API issue when to_hdf doesn't accept append AND format args - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df = tm.makeDataFrame() df.iloc[:10].to_hdf(path, "df", append=True, format="table") @@ -251,7 +263,8 @@ def test_api(self): df.iloc[10:].to_hdf(path, "df", append=True, format="table") assert_frame_equal(read_hdf(path, "df"), df) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df = tm.makeDataFrame() df.iloc[:10].to_hdf(path, "df", append=True) @@ -263,7 +276,8 @@ def test_api(self): df.iloc[10:].to_hdf(path, "df", append=True) assert_frame_equal(read_hdf(path, "df"), df) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df = tm.makeDataFrame() df.to_hdf(path, "df", append=False, format="fixed") @@ -278,7 +292,8 @@ def test_api(self): df.to_hdf(path, "df") assert_frame_equal(read_hdf(path, "df"), df) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: path = store._path df = tm.makeDataFrame() @@ -305,7 +320,8 @@ def test_api(self): store.append("df", df.iloc[10:], append=True, format=None) assert_frame_equal(store.select("df"), df) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: # Invalid. df = tm.makeDataFrame() @@ -329,7 +345,8 @@ def test_api(self): def test_api_default_format(self): # default_format option - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: df = tm.makeDataFrame() pd.set_option("io.hdf.default_format", "fixed") @@ -349,7 +366,8 @@ def test_api_default_format(self): pd.set_option("io.hdf.default_format", None) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df = tm.makeDataFrame() @@ -372,7 +390,8 @@ def test_api_default_format(self): def test_keys(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store["a"] = tm.makeTimeSeries() store["b"] = tm.makeStringSeries() store["c"] = tm.makeDataFrame() @@ -387,7 +406,8 @@ def test_keys_ignore_hdf_softlink(self): # GH 20523 # Puts a softlink into HDF file and rereads - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: df = DataFrame(dict(A=range(5), B=range(5))) store.put("df", df) @@ -401,13 +421,15 @@ def test_keys_ignore_hdf_softlink(self): def test_iter_empty(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: # GH 12221 assert list(store) == [] def test_repr(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: repr(store) store.info() store["a"] = tm.makeTimeSeries() @@ -441,7 +463,8 @@ def test_repr(self): store.info() # storers - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: df = tm.makeDataFrame() store.append("df", df) @@ -453,7 +476,8 @@ def test_repr(self): @ignore_natural_naming_warning def test_contains(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store["a"] = tm.makeTimeSeries() store["b"] = tm.makeDataFrame() store["foo/bar"] = tm.makeDataFrame() @@ -472,7 +496,8 @@ def test_contains(self): def test_versioning(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store["a"] = tm.makeTimeSeries() store["b"] = tm.makeDataFrame() df = tm.makeTimeDataFrame() @@ -499,7 +524,8 @@ def test_mode(self): def check(mode): - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: # constructor if mode in ["r", "r+"]: @@ -511,7 +537,8 @@ def check(mode): assert store._handle.mode == mode store.close() - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: # context if mode in ["r", "r+"]: @@ -522,7 +549,8 @@ def check(mode): with HDFStore(path, mode=mode) as store: assert store._handle.mode == mode - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: # conv write if mode in ["r", "r+"]: @@ -543,7 +571,8 @@ def check(mode): def check_default_mode(): # read_hdf uses default mode - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df.to_hdf(path, "df", mode="w") result = read_hdf(path, "df") assert_frame_equal(result, df) @@ -556,7 +585,8 @@ def check_default_mode(): def test_reopen_handle(self): - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: store = HDFStore(path, mode="a") store["a"] = tm.makeTimeSeries() @@ -604,7 +634,8 @@ def test_reopen_handle(self): def test_open_args(self): - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df = tm.makeDataFrame() @@ -625,14 +656,16 @@ def test_open_args(self): def test_flush(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store["a"] = tm.makeTimeSeries() store.flush() store.flush(fsync=True) def test_get(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store["a"] = tm.makeTimeSeries() left = store.get("a") right = store["a"] @@ -707,7 +740,8 @@ def test_walk(self, where, expected): def test_getattr(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: s = tm.makeTimeSeries() store["a"] = s @@ -734,7 +768,8 @@ def test_getattr(self): def test_put(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: ts = tm.makeTimeSeries() df = tm.makeTimeDataFrame() @@ -765,7 +800,8 @@ def test_put(self): def test_put_string_index(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: index = Index( ["I am a very long string index: {i}".format(i=i) for i in range(20)] @@ -794,7 +830,8 @@ def test_put_string_index(self): def test_put_compression(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: df = tm.makeTimeDataFrame() store.put("c", df, format="table", complib="zlib") @@ -808,7 +845,8 @@ def test_put_compression(self): def test_put_compression_blosc(self): df = tm.makeTimeDataFrame() - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: # can't compress if format='fixed' with pytest.raises(ValueError): @@ -823,7 +861,8 @@ def test_complibs_default_settings(self): # Set complevel and check if complib is automatically set to # default value - with ensure_clean_path(self.path) as tmpfile: + with ensure_clean_path(setup_path + ) as tmpfile: df.to_hdf(tmpfile, "df", complevel=9) result = pd.read_hdf(tmpfile, "df") tm.assert_frame_equal(result, df) @@ -834,7 +873,8 @@ def test_complibs_default_settings(self): assert node.filters.complib == "zlib" # Set complib and check to see if compression is disabled - with ensure_clean_path(self.path) as tmpfile: + with ensure_clean_path(setup_path + ) as tmpfile: df.to_hdf(tmpfile, "df", complib="zlib") result = pd.read_hdf(tmpfile, "df") tm.assert_frame_equal(result, df) @@ -845,7 +885,8 @@ def test_complibs_default_settings(self): assert node.filters.complib is None # Check if not setting complib or complevel results in no compression - with ensure_clean_path(self.path) as tmpfile: + with ensure_clean_path(setup_path + ) as tmpfile: df.to_hdf(tmpfile, "df") result = pd.read_hdf(tmpfile, "df") tm.assert_frame_equal(result, df) @@ -856,7 +897,8 @@ def test_complibs_default_settings(self): assert node.filters.complib is None # Check if file-defaults can be overridden on a per table basis - with ensure_clean_path(self.path) as tmpfile: + with ensure_clean_path(setup_path + ) as tmpfile: store = pd.HDFStore(tmpfile) store.append("dfc", df, complevel=9, complib="blosc") store.append("df", df) @@ -887,7 +929,8 @@ def test_complibs(self): all_tests = [(lib, lvl) for lib in all_complibs for lvl in all_levels] for (lib, lvl) in all_tests: - with ensure_clean_path(self.path) as tmpfile: + with ensure_clean_path(setup_path + ) as tmpfile: gname = "foo" # Write and read file to see if data is consistent @@ -928,7 +971,8 @@ def test_put_mixed_type(self): df.loc[3:6, ["obj1"]] = np.nan df = df._consolidate()._convert(datetime=True) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: _maybe_remove(store, "df") # PerformanceWarning @@ -944,7 +988,8 @@ def test_put_mixed_type(self): ) def test_append(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: # this is allowed by almost always don't want to do it # tables.NaturalNameWarning): @@ -1012,7 +1057,8 @@ def test_append(self): def test_append_series(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: # basic ss = tm.makeStringSeries() @@ -1060,7 +1106,8 @@ def test_store_index_types(self): # GH5386 # test storing various index types - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: def check(format, index): df = DataFrame(np.random.randn(10, 2), columns=list("AB")) @@ -1095,7 +1142,8 @@ def check(format, index): ) def test_encoding(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: df = DataFrame(dict(A="foo", B="bar"), index=range(5)) df.loc[2, "A"] = np.nan df.loc[3, "B"] = np.nan @@ -1130,7 +1178,8 @@ def test_latin_encoding(self, dtype, val): val = [x.decode(enc) if isinstance(x, bytes) else x for x in val] ser = pd.Series(val, dtype=dtype) - with ensure_clean_path(self.path) as store: + with ensure_clean_path(setup_path + ) as store: ser.to_hdf(store, key, format="table", encoding=enc, nan_rep=nan_rep) retr = read_hdf(store, key) @@ -1149,7 +1198,8 @@ def test_latin_encoding(self, dtype, val): def test_append_some_nans(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: df = DataFrame( { "A": Series(np.random.randn(20)).astype("int32"), @@ -1195,7 +1245,8 @@ def test_append_some_nans(self): def test_append_all_nans(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: df = DataFrame( {"A1": np.random.randn(20), "A2": np.random.randn(20)}, @@ -1283,14 +1334,16 @@ def test_append_all_nans(self): {"col1": [0, np.nan, 2], "col2": [1, np.nan, np.nan]} ) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df_with_missing.to_hdf(path, "df_with_missing", format="table") reloaded = read_hdf(path, "df_with_missing") tm.assert_frame_equal(df_with_missing, reloaded) def test_read_missing_key_close_store(self): # GH 25766 - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df = pd.DataFrame({"a": range(2), "b": range(2)}) df.to_hdf(path, "k1") @@ -1303,7 +1356,8 @@ def test_read_missing_key_close_store(self): def test_append_frame_column_oriented(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: # column oriented df = tm.makeTimeDataFrame() @@ -1328,7 +1382,8 @@ def test_append_frame_column_oriented(self): def test_append_with_different_block_ordering(self): # GH 4096; using same frames, but different block orderings - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: for i in range(10): @@ -1351,7 +1406,8 @@ def test_append_with_different_block_ordering(self): # test a different ordering but with more fields (like invalid # combinate) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: df = DataFrame(np.random.randn(10, 2), columns=list("AB"), dtype="float64") df["int64"] = Series([1] * len(df), dtype="int64") @@ -1370,7 +1426,8 @@ def test_append_with_different_block_ordering(self): def test_append_with_strings(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: with catch_warnings(record=True): def check_col(key, name, size): @@ -1444,7 +1501,8 @@ def check_col(key, name, size): result = store.select("df") tm.assert_frame_equal(result, df) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: def check_col(key, name, size): assert getattr( @@ -1486,7 +1544,8 @@ def check_col(key, name, size): def test_append_with_empty_string(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: # with all empty strings (GH 12242) df = DataFrame({"x": ["a", "b", "c", "d", "e", "f", ""]}) @@ -1496,7 +1555,8 @@ def test_append_with_empty_string(self): def test_to_hdf_with_min_itemsize(self): - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: # min_itemsize in index with to_hdf (GH 10381) df = tm.makeMixedDataFrame().set_index("C") @@ -1520,7 +1580,8 @@ def test_to_hdf_errors(self, format): data = ["\ud800foo"] ser = pd.Series(data, index=pd.Index(data)) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: # GH 20835 ser.to_hdf(path, "table", format=format, errors="surrogatepass") @@ -1529,7 +1590,8 @@ def test_to_hdf_errors(self, format): def test_append_with_data_columns(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: df = tm.makeTimeDataFrame() df.iloc[0, df.columns.get_loc("B")] = 1.0 _maybe_remove(store, "df") @@ -1570,7 +1632,8 @@ def check_col(key, name, size): == size ) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: _maybe_remove(store, "df") store.append( "df", df_new, data_columns=["string"], min_itemsize={"string": 30} @@ -1585,7 +1648,8 @@ def check_col(key, name, size): ) check_col("df", "string", 30) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: df_new["string2"] = "foobarbah" df_new["string_block1"] = "foobarbah1" df_new["string_block2"] = "foobarbah2" @@ -1600,7 +1664,8 @@ def check_col(key, name, size): check_col("df", "string2", 40) check_col("df", "values_block_1", 50) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: # multiple data columns df_new = df.copy() df_new.iloc[0, df_new.columns.get_loc("A")] = 1.0 @@ -1633,7 +1698,8 @@ def check_col(key, name, size): expected = df_new[(df_new.string == "foo") & (df_new.string2 == "cool")] tm.assert_frame_equal(result, expected, check_index_type=False) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: # doc example df_dc = df.copy() df_dc["string"] = "foo" @@ -1657,7 +1723,8 @@ def check_col(key, name, size): expected = df_dc[(df_dc.B > 0) & (df_dc.C > 0) & (df_dc.string == "foo")] tm.assert_frame_equal(result, expected, check_index_type=False) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: # doc example part 2 np.random.seed(1234) index = date_range("1/1/2000", periods=8) @@ -1683,7 +1750,8 @@ def check_col(key, name, size): def test_create_table_index(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: with catch_warnings(record=True): @@ -1721,7 +1789,8 @@ def test_append_hierarchical(self): ) df = DataFrame(np.random.randn(10, 3), index=index, columns=["A", "B", "C"]) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.append("mi", df) result = store.select("mi") tm.assert_frame_equal(result, df) @@ -1749,7 +1818,8 @@ def test_column_multiindex(self): if isinstance(expected.index, RangeIndex): expected.index = Int64Index(expected.index) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.put("df", df) tm.assert_frame_equal( @@ -1767,7 +1837,8 @@ def test_column_multiindex(self): store.put("df3", df, format="table", data_columns=True) # appending multi-column on existing table (see GH 6167) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.append("df2", df) store.append("df2", df) @@ -1781,7 +1852,8 @@ def test_column_multiindex(self): if isinstance(expected.index, RangeIndex): expected.index = Int64Index(expected.index) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.put("df1", df, format="table") tm.assert_frame_equal( @@ -1792,7 +1864,8 @@ def test_store_multiindex(self): # validate multi-index names # GH 5527 - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: def make_index(names=None): return MultiIndex.from_tuples( @@ -1872,7 +1945,8 @@ def test_select_columns_in_where(self): # With a DataFrame df = DataFrame(np.random.randn(10, 3), index=index, columns=["A", "B", "C"]) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.put("df", df, format="table") expected = df[["A"]] @@ -1882,7 +1956,8 @@ def test_select_columns_in_where(self): # With a Series s = Series(np.random.randn(10), index=index, name="A") - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.put("s", s, format="table") tm.assert_series_equal(store.select("s", where="columns=['A']"), s) @@ -1893,7 +1968,8 @@ def test_mi_data_columns(self): ) df = pd.DataFrame({"a": [1.1, 1.2, 1.3, 1.4, 1.5]}, index=idx) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.append("df", df, data_columns=True) actual = store.select("df", where="id == 1") @@ -1904,7 +1980,8 @@ def test_pass_spec_to_storer(self): df = tm.makeDataFrame() - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.put("df", df) with pytest.raises(TypeError): store.select("df", columns=["A"]) @@ -1914,7 +1991,8 @@ def test_pass_spec_to_storer(self): @xfail_non_writeable def test_append_misc(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: df = tm.makeDataFrame() store.append("df", df, chunksize=1) result = store.select("df") @@ -1927,7 +2005,8 @@ def test_append_misc(self): # more chunksize in append tests def check(obj, comparator): for c in [10, 200, 1000]: - with ensure_clean_store(self.path, mode="w") as store: + with ensure_clean_store(setup_path + , mode="w") as store: store.append("obj", obj, chunksize=c) result = store.select("obj") comparator(result, obj) @@ -1942,7 +2021,8 @@ def check(obj, comparator): check(df, tm.assert_frame_equal) # empty frame, GH4273 - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: # 0 len df_empty = DataFrame(columns=list("ABC")) @@ -1964,7 +2044,8 @@ def check(obj, comparator): def test_append_raise(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: # test append with invalid input to get good error messages @@ -2011,14 +2092,16 @@ def test_table_index_incompatible_dtypes(self): df1 = DataFrame({"a": [1, 2, 3]}) df2 = DataFrame({"a": [4, 5, 6]}, index=date_range("1/1/2000", periods=3)) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.put("frame", df1, format="table") with pytest.raises(TypeError): store.put("frame", df2, format="table", append=True) def test_table_values_dtypes_roundtrip(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: df1 = DataFrame({"a": [1, 2, 3]}, dtype="f8") store.append("df_f8", df1) assert_series_equal(df1.dtypes, store["df_f8"].dtypes) @@ -2090,13 +2173,15 @@ def test_table_mixed_dtypes(self): df.loc[3:6, ["obj1"]] = np.nan df = df._consolidate()._convert(datetime=True) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.append("df1_mixed", df) tm.assert_frame_equal(store.select("df1_mixed"), df) def test_unimplemented_dtypes_table_columns(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: dtypes = [("date", datetime.date(2001, 1, 2))] @@ -2114,7 +2199,8 @@ def test_unimplemented_dtypes_table_columns(self): df["datetime1"] = datetime.date(2001, 1, 2) df = df._consolidate()._convert(datetime=True) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: # this fails because we have a date in the object block...... with pytest.raises(TypeError): store.append("df_unimplemented", df) @@ -2145,7 +2231,8 @@ def test_calendar_roundtrip_issue(self): s = Series(dts.weekday, dts).map(Series("Mon Tue Wed Thu Fri Sat Sun".split())) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.put("fixed", s) result = store.select("fixed") @@ -2160,7 +2247,8 @@ def test_roundtrip_tz_aware_index(self): time = pd.Timestamp("2000-01-01 01:00:00", tz="US/Eastern") df = pd.DataFrame(data=[0], index=[time]) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.put("frame", df, format="fixed") recons = store["frame"] tm.assert_frame_equal(recons, df) @@ -2182,7 +2270,8 @@ def test_append_with_timedelta(self): df["C"] = df["A"] - df["B"] df.loc[3:5, "C"] = np.nan - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: # table _maybe_remove(store, "df") @@ -2217,7 +2306,8 @@ def test_append_with_timedelta(self): def test_remove(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: ts = tm.makeTimeSeries() df = tm.makeDataFrame() @@ -2257,7 +2347,8 @@ def test_remove(self): def test_invalid_terms(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: with catch_warnings(record=True): @@ -2279,7 +2370,8 @@ def test_invalid_terms(self): store.select("df", "index>") # from the docs - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: dfq = DataFrame( np.random.randn(10, 4), columns=list("ABCD"), @@ -2294,7 +2386,8 @@ def test_invalid_terms(self): read_hdf(path, "dfq", where="A>0 or C>0") # catch the invalid reference - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: dfq = DataFrame( np.random.randn(10, 4), columns=list("ABCD"), @@ -2307,7 +2400,8 @@ def test_invalid_terms(self): def test_same_name_scoping(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: import pandas as pd @@ -2447,7 +2541,8 @@ def test_frame(self, compression): tdf = tm.makeTimeDataFrame() self._check_roundtrip(tdf, tm.assert_frame_equal, compression=compression) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: # not consolidated df["foo"] = np.random.randn(len(df)) store["df"] = df @@ -2499,7 +2594,8 @@ def test_store_hierarchical(self): self._check_roundtrip(frame["A"], tm.assert_series_equal) # check that the names are stored - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store["frame"] = frame recons = store["frame"] tm.assert_frame_equal(recons, frame) @@ -2508,7 +2604,8 @@ def test_store_index_name(self): df = tm.makeDataFrame() df.index.name = "foo" - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store["frame"] = df recons = store["frame"] tm.assert_frame_equal(recons, df) @@ -2520,7 +2617,8 @@ def test_store_index_name_with_tz(self): df.index = df.index.tz_localize("UTC") df.index.name = "foo" - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.put("frame", df, format="table") recons = store["frame"] tm.assert_frame_equal(recons, df) @@ -2539,7 +2637,8 @@ def test_store_index_name_numpy_str(self, table_format): df = pd.DataFrame(np.arange(4).reshape(2, 2), columns=idx, index=idx1) # This used to fail, returning numpy strings instead of python strings. - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df.to_hdf(path, "df", format=table_format) df2 = read_hdf(path, "df") @@ -2552,7 +2651,8 @@ def test_store_series_name(self): df = tm.makeDataFrame() series = df["A"] - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store["series"] = series recons = store["series"] tm.assert_series_equal(recons, series) @@ -2578,7 +2678,8 @@ def _make_one(): self._check_roundtrip(df1, tm.assert_frame_equal) self._check_roundtrip(df2, tm.assert_frame_equal) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store["obj"] = df1 tm.assert_frame_equal(store["obj"], df1) store["obj"] = df2 @@ -2604,7 +2705,8 @@ def test_select_with_dups(self): df = DataFrame(np.random.randn(10, 4), columns=["A", "A", "B", "B"]) df.index = date_range("20130101 9:30", periods=10, freq="T") - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.append("df", df) result = store.select("df") @@ -2631,7 +2733,8 @@ def test_select_with_dups(self): ) df.index = date_range("20130101 9:30", periods=10, freq="T") - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.append("df", df) result = store.select("df") @@ -2651,7 +2754,8 @@ def test_select_with_dups(self): assert_frame_equal(result, expected, by_blocks=True) # duplicates on both index and columns - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.append("df", df) store.append("df", df) @@ -2662,7 +2766,8 @@ def test_select_with_dups(self): def test_overwrite_node(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store["a"] = tm.makeTimeDataFrame() ts = tm.makeTimeSeries() store["a"] = ts @@ -2671,7 +2776,8 @@ def test_overwrite_node(self): def test_select(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: with catch_warnings(record=True): @@ -2711,7 +2817,8 @@ def test_select(self): def test_select_dtypes(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: # with a Timestamp data column (GH #2637) df = DataFrame( dict(ts=bdate_range("2012-01-01", periods=300), A=np.random.randn(300)) @@ -2767,7 +2874,8 @@ def test_select_dtypes(self): expected = df.reindex(index=list(df.index)[0:10], columns=["A"]) tm.assert_frame_equal(expected, result) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: # floats w/o NaN df = DataFrame(dict(cols=range(11), values=range(11)), dtype="float64") @@ -2806,7 +2914,8 @@ def test_select_dtypes(self): # test selection with comparison against numpy scalar # GH 11283 - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: df = tm.makeDataFrame() expected = df[df["A"] > 0] @@ -2818,7 +2927,8 @@ def test_select_dtypes(self): def test_select_with_many_inputs(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: df = DataFrame( dict( @@ -2872,7 +2982,8 @@ def test_select_with_many_inputs(self): def test_select_iterator(self): # single table - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: df = tm.makeTimeDataFrame(500) _maybe_remove(store, "df") @@ -2893,7 +3004,8 @@ def test_select_iterator(self): result = concat(results) tm.assert_frame_equal(result, expected) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df = tm.makeTimeDataFrame(500) df.to_hdf(path, "df_non_table") @@ -2904,7 +3016,8 @@ def test_select_iterator(self): with pytest.raises(TypeError): read_hdf(path, "df_non_table", iterator=True) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df = tm.makeTimeDataFrame(500) df.to_hdf(path, "df", format="table") @@ -2918,7 +3031,8 @@ def test_select_iterator(self): # multiple - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: df1 = tm.makeTimeDataFrame(500) store.append("df1", df1, data_columns=True) @@ -2946,7 +3060,8 @@ def test_select_iterator_complete_8014(self): chunksize = 1e4 # no iterator - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: expected = tm.makeTimeDataFrame(100064, "S") _maybe_remove(store, "df") @@ -2980,7 +3095,8 @@ def test_select_iterator_complete_8014(self): tm.assert_frame_equal(expected, result) # with iterator, full range - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: expected = tm.makeTimeDataFrame(100064, "S") _maybe_remove(store, "df") @@ -3021,7 +3137,8 @@ def test_select_iterator_non_complete_8014(self): chunksize = 1e4 # with iterator, non complete range - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: expected = tm.makeTimeDataFrame(100064, "S") _maybe_remove(store, "df") @@ -3056,7 +3173,8 @@ def test_select_iterator_non_complete_8014(self): tm.assert_frame_equal(rexpected, result) # with iterator, empty where - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: expected = tm.makeTimeDataFrame(100064, "S") _maybe_remove(store, "df") @@ -3077,7 +3195,8 @@ def test_select_iterator_many_empty_frames(self): chunksize = int(1e4) # with iterator, range limited to the first chunk - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: expected = tm.makeTimeDataFrame(100000, "S") _maybe_remove(store, "df") @@ -3141,7 +3260,8 @@ def test_retain_index_attributes(self): dict(A=Series(range(3), index=date_range("2000-1-1", periods=3, freq="H"))) ) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: _maybe_remove(store, "data") store.put("data", df, format="table") @@ -3195,7 +3315,8 @@ def test_retain_index_attributes(self): "ignore:\\nthe :pandas.io.pytables.AttributeConflictWarning" ) def test_retain_index_attributes2(self): - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: with catch_warnings(record=True): @@ -3236,7 +3357,8 @@ def test_frame_select(self): df = tm.makeTimeDataFrame() - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.put("frame", df, format="table") date = df.index[len(df) // 2] @@ -3272,7 +3394,8 @@ def test_frame_select_complex(self): df["string"] = "foo" df.loc[df.index[0:4], "string"] = "bar" - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.put("df", df, format="table", data_columns=["string"]) # empty @@ -3387,7 +3510,8 @@ def test_invalid_filtering(self): df = tm.makeTimeDataFrame() - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.put("df", df, format="table") # not implemented @@ -3400,7 +3524,8 @@ def test_invalid_filtering(self): def test_string_select(self): # GH 2973 - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: df = tm.makeTimeDataFrame() @@ -3444,7 +3569,8 @@ def test_read_column(self): df = tm.makeTimeDataFrame() - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: _maybe_remove(store, "df") # GH 17912 @@ -3516,7 +3642,8 @@ def test_read_column(self): def test_coordinates(self): df = tm.makeTimeDataFrame() - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: _maybe_remove(store, "df") store.append("df", df) @@ -3561,7 +3688,8 @@ def test_coordinates(self): tm.assert_frame_equal(result, expected) # pass array/mask as the coordinates - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: df = DataFrame( np.random.randn(1000, 2), index=date_range("20000101", periods=1000) @@ -3623,7 +3751,8 @@ def test_append_to_multiple(self): df2["foo"] = "bar" df = concat([df1, df2], axis=1) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: # exceptions with pytest.raises(ValueError): @@ -3653,7 +3782,8 @@ def test_append_to_multiple_dropna(self): df1.iloc[1, df1.columns.get_indexer(["A", "B"])] = np.nan df = concat([df1, df2], axis=1) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: # dropna=True should guarantee rows are synchronized store.append_to_multiple( @@ -3673,7 +3803,8 @@ def test_append_to_multiple_dropna_false(self): df1.iloc[1, df1.columns.get_indexer(["A", "B"])] = np.nan df = concat([df1, df2], axis=1) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: # dropna=False shouldn't synchronize row indexes store.append_to_multiple( @@ -3691,7 +3822,8 @@ def test_select_as_multiple(self): df2 = tm.makeTimeDataFrame().rename(columns="{}_2".format) df2["foo"] = "bar" - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: # no tables stored with pytest.raises(Exception): @@ -3761,7 +3893,8 @@ def test_select_as_multiple(self): ) def test_nan_selection_bug_4858(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: df = DataFrame(dict(cols=range(6), values=range(6)), dtype="float64") df["cols"] = (df["cols"] + 10).apply(str) @@ -3779,7 +3912,8 @@ def test_nan_selection_bug_4858(self): def test_start_stop_table(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: # table df = DataFrame(dict(A=np.random.rand(20), B=np.random.rand(20))) @@ -3798,7 +3932,8 @@ def test_start_stop_table(self): def test_start_stop_multiple(self): # GH 16209 - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: df = DataFrame({"foo": [1, 2], "bar": [1, 2]}) @@ -3813,7 +3948,8 @@ def test_start_stop_multiple(self): def test_start_stop_fixed(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: # fixed, GH 8287 df = DataFrame( @@ -3857,7 +3993,8 @@ def test_select_filter_corner(self): df.index = ["{c:3d}".format(c=c) for c in df.index] df.columns = ["{c:3d}".format(c=c) for c in df.columns] - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.put("frame", df, format="table") crit = "columns=df.columns[:75]" @@ -3887,7 +4024,8 @@ def test_contiguous_mixed_data_table(self, start, stop): } ) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.append("test_dataset", df) result = store.select("test_dataset", start=start, stop=stop) @@ -3934,7 +4072,8 @@ def _check_roundtrip(self, obj, comparator, compression=False, **kwargs): if compression: options["complib"] = _default_compressor - with ensure_clean_store(self.path, "w", **options) as store: + with ensure_clean_store(setup_path + , "w", **options) as store: store["obj"] = obj retrieved = store["obj"] comparator(retrieved, obj, **kwargs) @@ -3944,7 +4083,8 @@ def _check_double_roundtrip(self, obj, comparator, compression=False, **kwargs): if compression: options["complib"] = compression or _default_compressor - with ensure_clean_store(self.path, "w", **options) as store: + with ensure_clean_store(setup_path + , "w", **options) as store: store["obj"] = obj retrieved = store["obj"] comparator(retrieved, obj, **kwargs) @@ -3957,7 +4097,8 @@ def _check_roundtrip_table(self, obj, comparator, compression=False): if compression: options["complib"] = _default_compressor - with ensure_clean_store(self.path, "w", **options) as store: + with ensure_clean_store(setup_path + , "w", **options) as store: store.put("obj", obj, format="table") retrieved = store["obj"] @@ -3966,7 +4107,8 @@ def _check_roundtrip_table(self, obj, comparator, compression=False): def test_multiple_open_close(self): # gh-4409: open & close multiple times - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df = tm.makeDataFrame() df.to_hdf(path, "df", mode="w", format="table") @@ -3980,7 +4122,8 @@ def test_multiple_open_close(self): assert "CLOSED" in store.info() assert not store.is_open - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: if pytables._table_file_open_policy_is_strict: @@ -4042,7 +4185,8 @@ def test_multiple_open_close(self): assert not store2.is_open # ops on a closed store - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df = tm.makeDataFrame() df.to_hdf(path, "df", mode="w", format="table") @@ -4179,7 +4323,8 @@ def do_copy(f, new_f=None, keys=None, propindexes=True, **kwargs): df = tm.makeDataFrame() try: - path = create_tempfile(self.path) + path = create_tempfile(setup_path + ) st = HDFStore(path) st.append("df", df, data_columns=["A"]) st.close() @@ -4190,7 +4335,8 @@ def do_copy(f, new_f=None, keys=None, propindexes=True, **kwargs): def test_store_datetime_fractional_secs(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: dt = datetime.datetime(2012, 1, 2, 3, 4, 5, 123456) series = Series([0], [dt]) store["a"] = series @@ -4198,7 +4344,8 @@ def test_store_datetime_fractional_secs(self): def test_tseries_indices_series(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: idx = tm.makeDateIndex(10) ser = Series(np.random.randn(len(idx)), idx) store["a"] = ser @@ -4219,7 +4366,8 @@ def test_tseries_indices_series(self): def test_tseries_indices_frame(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: idx = tm.makeDateIndex(10) df = DataFrame(np.random.randn(len(idx), 3), index=idx) store["a"] = df @@ -4252,13 +4400,15 @@ def test_unicode_longer_encoded(self): # GH 11234 char = "\u0394" df = pd.DataFrame({"A": [char]}) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.put("df", df, format="table", encoding="utf-8") result = store.get("df") tm.assert_frame_equal(result, df) df = pd.DataFrame({"A": ["a", char], "B": ["b", "b"]}) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.put("df", df, format="table", encoding="utf-8") result = store.get("df") tm.assert_frame_equal(result, df) @@ -4288,7 +4438,8 @@ def test_append_with_diff_col_name_types_raises_value_error(self): df4 = DataFrame({("1", 2): np.random.randn(10)}) df5 = DataFrame({("1", 2, object): np.random.randn(10)}) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: name = "df_{}".format(tm.rands(10)) store.append(name, df) @@ -4304,14 +4455,16 @@ def test_query_with_nested_special_character(self): } ) expected = df[df.a == "test & test"] - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.append("test", df, format="table", data_columns=True) result = store.select("test", 'a = "test & test"') tm.assert_frame_equal(expected, result) def test_categorical(self): - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: # Basic _maybe_remove(store, "s") @@ -4443,7 +4596,8 @@ def test_categorical_conversion(self): # We are expecting an empty DataFrame matching types of df expected = df.iloc[[], :] - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df.to_hdf(path, "df", format="table", data_columns=True) result = read_hdf(path, "df", where="obsids=B") tm.assert_frame_equal(result, expected) @@ -4454,7 +4608,8 @@ def test_categorical_conversion(self): # We are expecting an empty DataFrame matching types of df expected = df.iloc[[], :] - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df.to_hdf(path, "df", format="table", data_columns=True) result = read_hdf(path, "df", where="obsids=B") tm.assert_frame_equal(result, expected) @@ -4475,7 +4630,8 @@ def test_categorical_nan_only_columns(self): df["b"] = df.b.astype("category") df["d"] = df.b.astype("category") expected = df - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df.to_hdf(path, "df", format="table", data_columns=True) result = read_hdf(path, "df") tm.assert_frame_equal(result, expected) @@ -4483,7 +4639,8 @@ def test_categorical_nan_only_columns(self): def test_duplicate_column_name(self): df = DataFrame(columns=["a", "a"], data=[[0, 0]]) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: with pytest.raises(ValueError): df.to_hdf(path, "df", format="fixed") @@ -4498,7 +4655,8 @@ def test_round_trip_equals(self): # GH 9330 df = DataFrame({"B": [1, 2], "A": ["x", "y"]}) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df.to_hdf(path, "df", format="table") other = read_hdf(path, "df") tm.assert_frame_equal(df, other) @@ -4512,7 +4670,8 @@ def test_preserve_timedeltaindex_type(self): df = DataFrame(np.random.normal(size=(10, 5))) df.index = timedelta_range(start="0s", periods=10, freq="1s", name="example") - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store["df"] = df assert_frame_equal(store["df"], df) @@ -4527,7 +4686,8 @@ def test_columns_multiindex_modified(self): df = df.set_index(keys="E", append=True) data_columns = df.index.names + df.columns.tolist() - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df.to_hdf( path, "df", @@ -4562,7 +4722,8 @@ def test_to_hdf_with_object_column_names(self): for index in types_should_fail: df = DataFrame(np.random.randn(10, 2), columns=index(2)) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: with catch_warnings(record=True): msg = "cannot have non-object label DataIndexableCol" with pytest.raises(ValueError, match=msg): @@ -4570,7 +4731,8 @@ def test_to_hdf_with_object_column_names(self): for index in types_should_run: df = DataFrame(np.random.randn(10, 2), columns=index(2)) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: with catch_warnings(record=True): df.to_hdf(path, "df", format="table", data_columns=True) result = pd.read_hdf( @@ -4585,7 +4747,8 @@ def test_read_hdf_open_store(self): df.index.name = "letters" df = df.set_index(keys="E", append=True) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df.to_hdf(path, "df", mode="w") direct = read_hdf(path, "df") store = HDFStore(path, mode="r") @@ -4599,7 +4762,8 @@ def test_read_hdf_iterator(self): df.index.name = "letters" df = df.set_index(keys="E", append=True) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df.to_hdf(path, "df", mode="w", format="t") direct = read_hdf(path, "df") iterator = read_hdf(path, "df", iterator=True) @@ -4611,7 +4775,8 @@ def test_read_hdf_iterator(self): def test_read_hdf_errors(self): df = DataFrame(np.random.rand(4, 5), index=list("abcd"), columns=list("ABCDE")) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: with pytest.raises(IOError): read_hdf(path, "key") @@ -4628,7 +4793,8 @@ def test_read_hdf_generic_buffer_errors(self): def test_invalid_complib(self): df = DataFrame(np.random.rand(4, 5), index=list("abcd"), columns=list("ABCDE")) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: with pytest.raises(ValueError): df.to_hdf(path, "df", complib="foolib") @@ -4639,7 +4805,8 @@ def test_read_nokey(self): # Categorical dtype not supported for "fixed" format. So no need # to test with that dtype in the dataframe here. - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df.to_hdf(path, "df", mode="a") reread = read_hdf(path) assert_frame_equal(df, reread) @@ -4652,7 +4819,8 @@ def test_read_nokey_table(self): # GH13231 df = DataFrame({"i": range(5), "c": Series(list("abacd"), dtype="category")}) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df.to_hdf(path, "df", mode="a", format="table") reread = read_hdf(path) assert_frame_equal(df, reread) @@ -4662,7 +4830,8 @@ def test_read_nokey_table(self): read_hdf(path) def test_read_nokey_empty(self): - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: store = HDFStore(path) store.close() @@ -4678,7 +4847,8 @@ def test_read_from_pathlib_path(self): expected = DataFrame( np.random.rand(4, 5), index=list("abcd"), columns=list("ABCDE") ) - with ensure_clean_path(self.path) as filename: + with ensure_clean_path(setup_path + ) as filename: path_obj = Path(filename) expected.to_hdf(path_obj, "df", mode="a") @@ -4695,7 +4865,8 @@ def test_read_from_py_localpath(self): expected = DataFrame( np.random.rand(4, 5), index=list("abcd"), columns=list("ABCDE") ) - with ensure_clean_path(self.path) as filename: + with ensure_clean_path(setup_path + ) as filename: path_obj = LocalPath(filename) expected.to_hdf(path_obj, "df", mode="a") @@ -4707,7 +4878,8 @@ def test_query_long_float_literal(self): # GH 14241 df = pd.DataFrame({"A": [1000000000.0009, 1000000000.0011, 1000000000.0015]}) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.append("test", df, format="table", data_columns=True) cutoff = 1000000000.0006 @@ -4736,7 +4908,8 @@ def test_query_compare_column_type(self): columns=["date", "real_date", "float", "int"], ) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.append("test", df, format="table", data_columns=True) ts = pd.Timestamp("2014-01-01") # noqa @@ -4778,7 +4951,8 @@ def test_read_hdf_series_mode_r(self, format): # Tests that reading a Series saved to an HDF file # still works if a mode='r' argument is supplied series = tm.makeFloatSeries() - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: series.to_hdf(path, key="data", format=format) result = pd.read_hdf(path, key="data", mode="r") tm.assert_series_equal(result, series) @@ -4840,7 +5014,8 @@ def test_to_hdf_multiindex_extension_dtype(self, idx): # GH 7775 mi = MultiIndex.from_arrays([idx, idx]) df = pd.DataFrame(0, index=mi, columns=["a"]) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: with pytest.raises(NotImplementedError, match="Saving a MultiIndex"): df.to_hdf(path, "df") @@ -4855,7 +5030,8 @@ def test_complex_fixed(self): columns=list("ABCDE"), ) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df.to_hdf(path, "df") reread = read_hdf(path, "df") assert_frame_equal(df, reread) @@ -4865,7 +5041,8 @@ def test_complex_fixed(self): index=list("abcd"), columns=list("ABCDE"), ) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df.to_hdf(path, "df") reread = read_hdf(path, "df") assert_frame_equal(df, reread) @@ -4877,7 +5054,8 @@ def test_complex_table(self): columns=list("ABCDE"), ) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df.to_hdf(path, "df", format="table") reread = read_hdf(path, "df") assert_frame_equal(df, reread) @@ -4888,7 +5066,8 @@ def test_complex_table(self): columns=list("ABCDE"), ) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df.to_hdf(path, "df", format="table", mode="w") reread = read_hdf(path, "df") assert_frame_equal(df, reread) @@ -4911,7 +5090,8 @@ def test_complex_mixed_fixed(self): }, index=list("abcd"), ) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df.to_hdf(path, "df") reread = read_hdf(path, "df") assert_frame_equal(df, reread) @@ -4934,12 +5114,14 @@ def test_complex_mixed_table(self): index=list("abcd"), ) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.append("df", df, data_columns=["A", "B"]) result = store.select("df", where="A>2") assert_frame_equal(df.loc[df.A > 2], result) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: df.to_hdf(path, "df", format="table") reread = read_hdf(path, "df") assert_frame_equal(df, reread) @@ -4953,7 +5135,8 @@ def test_complex_across_dimensions_fixed(self): objs = [s, df] comps = [tm.assert_series_equal, tm.assert_frame_equal] for obj, comp in zip(objs, comps): - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: obj.to_hdf(path, "obj", format="fixed") reread = read_hdf(path, "obj") comp(obj, reread) @@ -4968,7 +5151,8 @@ def test_complex_across_dimensions(self): objs = [df] comps = [tm.assert_frame_equal] for obj, comp in zip(objs, comps): - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: obj.to_hdf(path, "obj", format="table") reread = read_hdf(path, "obj") comp(obj, reread) @@ -4981,7 +5165,8 @@ def test_complex_indexing_error(self): {"A": [1, 2, 3, 4], "B": ["a", "b", "c", "d"], "C": complex128}, index=list("abcd"), ) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: with pytest.raises(TypeError): store.append("df", df, data_columns=["C"]) @@ -4989,11 +5174,13 @@ def test_complex_series_error(self): complex128 = np.array([1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j]) s = Series(complex128, index=list("abcd")) - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: with pytest.raises(TypeError): s.to_hdf(path, "obj", format="t") - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: s.to_hdf(path, "obj", format="t", index=False) reread = read_hdf(path, "obj") tm.assert_series_equal(s, reread) @@ -5003,14 +5190,16 @@ def test_complex_append(self): {"a": np.random.randn(100).astype(np.complex128), "b": np.random.randn(100)} ) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: store.append("df", df, data_columns=["b"]) store.append("df", df) result = store.select("df") assert_frame_equal(pd.concat([df, df], 0), result) -class TestTimezones(Base): +# @pytest.mark.usefixtures("setup_path") +class TestTimezones(): def _compare_with_tz(self, a, b): tm.assert_frame_equal(a, b) @@ -5024,7 +5213,7 @@ def _compare_with_tz(self, a, b): "invalid tz comparison [{a_e}] [{b_e}]".format(a_e=a_e, b_e=b_e) ) - def test_append_with_timezones_dateutil(self): + def test_append_with_timezones_dateutil(self, setup_path): from datetime import timedelta @@ -5035,7 +5224,7 @@ def test_append_with_timezones_dateutil(self): gettz = lambda x: maybe_get_tz("dateutil/" + x) # as columns - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path) as store: _maybe_remove(store, "df_tz") df = DataFrame( @@ -5101,7 +5290,7 @@ def test_append_with_timezones_dateutil(self): store.append("df_tz", df) # as index - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path) as store: # GH 4098 example df = DataFrame( @@ -5125,12 +5314,12 @@ def test_append_with_timezones_dateutil(self): result = store.select("df") assert_frame_equal(result, df) - def test_append_with_timezones_pytz(self): + def test_append_with_timezones_pytz(self, setup_path): from datetime import timedelta # as columns - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path) as store: _maybe_remove(store, "df_tz") df = DataFrame( @@ -5195,7 +5384,7 @@ def test_append_with_timezones_pytz(self): store.append("df_tz", df) # as index - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path) as store: # GH 4098 example df = DataFrame( @@ -5219,7 +5408,7 @@ def test_append_with_timezones_pytz(self): result = store.select("df") assert_frame_equal(result, df) - def test_tseries_select_index_column(self): + def test_tseries_select_index_column(self, setup_path): # GH7777 # selecting a UTC datetimeindex column did # not preserve UTC tzinfo set before storing @@ -5228,7 +5417,7 @@ def test_tseries_select_index_column(self): rng = date_range("1/1/2000", "1/30/2000") frame = DataFrame(np.random.randn(len(rng), 4), index=rng) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path) as store: store.append("frame", frame) result = store.select_column("frame", "index") assert rng.tz == DatetimeIndex(result.values).tz @@ -5237,7 +5426,7 @@ def test_tseries_select_index_column(self): rng = date_range("1/1/2000", "1/30/2000", tz="UTC") frame = DataFrame(np.random.randn(len(rng), 4), index=rng) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path) as store: store.append("frame", frame) result = store.select_column("frame", "index") assert rng.tz == result.dt.tz @@ -5246,13 +5435,13 @@ def test_tseries_select_index_column(self): rng = date_range("1/1/2000", "1/30/2000", tz="US/Eastern") frame = DataFrame(np.random.randn(len(rng), 4), index=rng) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path) as store: store.append("frame", frame) result = store.select_column("frame", "index") assert rng.tz == result.dt.tz - def test_timezones_fixed(self): - with ensure_clean_store(self.path) as store: + def test_timezones_fixed(self, setup_path): + with ensure_clean_store(setup_path) as store: # index rng = date_range("1/1/2000", "1/30/2000", tz="US/Eastern") @@ -5277,24 +5466,24 @@ def test_timezones_fixed(self): result = store["df"] assert_frame_equal(result, df) - def test_fixed_offset_tz(self): + def test_fixed_offset_tz(self, setup_path): rng = date_range("1/1/2000 00:00:00-07:00", "1/30/2000 00:00:00-07:00") frame = DataFrame(np.random.randn(len(rng), 4), index=rng) - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path) as store: store["frame"] = frame recons = store["frame"] tm.assert_index_equal(recons.index, rng) assert rng.tz == recons.index.tz @td.skip_if_windows - def test_store_timezone(self): + def test_store_timezone(self, setup_path): # GH2852 # issue storing datetime.date with a timezone as it resets when read # back in a new timezone # original method - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path) as store: today = datetime.date(2013, 9, 10) df = DataFrame([1, 2, 3], index=[today, today, today]) @@ -5303,7 +5492,8 @@ def test_store_timezone(self): assert_frame_equal(result, df) # with tz setting - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: with set_timezone("EST5EDT"): today = datetime.date(2013, 9, 10) @@ -5315,7 +5505,7 @@ def test_store_timezone(self): assert_frame_equal(result, df) - def test_legacy_datetimetz_object(self, datapath): + def test_legacy_datetimetz_object(self, datapath, setup_path): # legacy from < 0.17.0 # 8260 expected = DataFrame( @@ -5331,9 +5521,10 @@ def test_legacy_datetimetz_object(self, datapath): result = store["df"] assert_frame_equal(result, expected) - def test_dst_transitions(self): + def test_dst_transitions(self, setup_path): # make sure we are not failing on transitions - with ensure_clean_store(self.path) as store: + with ensure_clean_store(setup_path + ) as store: times = pd.date_range( "2013-10-26 23:00", "2013-10-27 01:00", @@ -5349,7 +5540,7 @@ def test_dst_transitions(self): result = store.select("df") assert_frame_equal(result, df) - def test_read_with_where_tz_aware_index(self): + def test_read_with_where_tz_aware_index(self, setup_path): # GH 11926 periods = 10 dts = pd.date_range("20151201", periods=periods, freq="D", tz="UTC") @@ -5357,13 +5548,14 @@ def test_read_with_where_tz_aware_index(self): expected = pd.DataFrame({"MYCOL": 0}, index=mi) key = "mykey" - with ensure_clean_path(self.path) as path: + with ensure_clean_path(setup_path + ) as path: with pd.HDFStore(path) as store: store.append(key, expected, format="table", append=True) result = pd.read_hdf(path, key, where="DATE > 20151130") assert_frame_equal(result, expected) - def test_py2_created_with_datetimez(self, datapath): + def test_py2_created_with_datetimez(self, datapath, setup_path): # The test HDF5 file was created in Python 2, but could not be read in # Python 3. # From 319bbd7e2808e1d9a59167b5fd50fc98c9899bd3 Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Tue, 1 Oct 2019 12:24:22 +0100 Subject: [PATCH 25/27] created fixtures for base class methods --- pandas/tests/io/pytables/test_pytables.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandas/tests/io/pytables/test_pytables.py b/pandas/tests/io/pytables/test_pytables.py index 2ff6fc458bef2..26bddd661ce54 100644 --- a/pandas/tests/io/pytables/test_pytables.py +++ b/pandas/tests/io/pytables/test_pytables.py @@ -57,6 +57,13 @@ def setup_path(): return "tmp.__{}__.h5".format(tm.rands(10)) +@pytest.fixture(scope="class", autouse=True) +def setup_mode(): + tm.reset_testing_mode() + yield + tm.set_testing_mode() + + # TODO: # remove when gh-24839 is fixed; this affects numpy 1.16 # and pytables 3.4.4 From 3c7f7fde46f8938f16055289f09165c47ed7f486 Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Tue, 1 Oct 2019 13:41:05 +0100 Subject: [PATCH 26/27] updated self.path to setup_path and made self.path in individual function into an argument --- pandas/tests/io/pytables/test_pytables.py | 423 ++++++++++------------ 1 file changed, 201 insertions(+), 222 deletions(-) diff --git a/pandas/tests/io/pytables/test_pytables.py b/pandas/tests/io/pytables/test_pytables.py index 26bddd661ce54..fbfaca0ea4505 100644 --- a/pandas/tests/io/pytables/test_pytables.py +++ b/pandas/tests/io/pytables/test_pytables.py @@ -161,37 +161,16 @@ def _maybe_remove(store, key): pass -class Base: - @classmethod - def setup_class(cls): - - # Pytables 3.0.0 deprecates lots of things - tm.reset_testing_mode() - - @classmethod - def teardown_class(cls): - - # Pytables 3.0.0 deprecates lots of things - tm.set_testing_mode() - - def setup_method(self, method): - setup_path\ - = "tmp.__{}__.h5".format(tm.rands(10)) - - def teardown_method(self, method): - pass - - @pytest.mark.single -class TestHDFStore(Base): - def test_format_kwarg_in_constructor(self): +class TestHDFStore(): + def test_format_kwarg_in_constructor(self, setup_path): # GH 13291 with ensure_clean_path(setup_path ) as path: with pytest.raises(ValueError): HDFStore(path, format="table") - def test_context(self): + def test_context(self, setup_path): path = create_tempfile(setup_path ) try: @@ -212,7 +191,7 @@ def test_context(self): finally: safe_remove(path) - def test_conv_read_write(self): + def test_conv_read_write(self, setup_path): path = create_tempfile(setup_path ) try: @@ -239,7 +218,7 @@ def roundtrip(key, obj, **kwargs): finally: safe_remove(path) - def test_long_strings(self): + def test_long_strings(self, setup_path): # GH6166 df = DataFrame( @@ -253,7 +232,7 @@ def test_long_strings(self): result = store.select("df") assert_frame_equal(df, result) - def test_api(self): + def test_api(self, setup_path): # GH4584 # API issue when to_hdf doesn't accept append AND format args @@ -349,7 +328,7 @@ def test_api(self): with pytest.raises(FileNotFoundError): read_hdf(path, "df") - def test_api_default_format(self): + def test_api_default_format(self, setup_path): # default_format option with ensure_clean_store(setup_path @@ -395,7 +374,7 @@ def test_api_default_format(self): pd.set_option("io.hdf.default_format", None) - def test_keys(self): + def test_keys(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -408,7 +387,7 @@ def test_keys(self): assert set(store.keys()) == expected assert set(store) == expected - def test_keys_ignore_hdf_softlink(self): + def test_keys_ignore_hdf_softlink(self, setup_path): # GH 20523 # Puts a softlink into HDF file and rereads @@ -426,14 +405,14 @@ def test_keys_ignore_hdf_softlink(self): # Should ignore the softlink assert store.keys() == ["/df"] - def test_iter_empty(self): + def test_iter_empty(self, setup_path): with ensure_clean_store(setup_path ) as store: # GH 12221 assert list(store) == [] - def test_repr(self): + def test_repr(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -481,7 +460,7 @@ def test_repr(self): str(s) @ignore_natural_naming_warning - def test_contains(self): + def test_contains(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -501,7 +480,7 @@ def test_contains(self): store["node())"] = tm.makeDataFrame() assert "node())" in store - def test_versioning(self): + def test_versioning(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -525,7 +504,7 @@ def test_versioning(self): with pytest.raises(Exception): store.select("df2") - def test_mode(self): + def test_mode(self, setup_path): df = tm.makeTimeDataFrame() @@ -590,7 +569,7 @@ def check_default_mode(): check("w") check_default_mode() - def test_reopen_handle(self): + def test_reopen_handle(self, setup_path): with ensure_clean_path(setup_path ) as path: @@ -639,7 +618,7 @@ def test_reopen_handle(self): store.close() assert not store.is_open - def test_open_args(self): + def test_open_args(self, setup_path): with ensure_clean_path(setup_path ) as path: @@ -661,7 +640,7 @@ def test_open_args(self): # the file should not have actually been written assert not os.path.exists(path) - def test_flush(self): + def test_flush(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -669,7 +648,7 @@ def test_flush(self): store.flush() store.flush(fsync=True) - def test_get(self): + def test_get(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -706,7 +685,7 @@ def test_get(self): ), ], ) - def test_walk(self, where, expected): + def test_walk(self, where, expected, setup_path): # GH10143 objs = { "df1": pd.DataFrame([1, 2, 3]), @@ -745,7 +724,7 @@ def test_walk(self, where, expected): else: tm.assert_series_equal(obj, objs[leaf]) - def test_getattr(self): + def test_getattr(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -773,7 +752,7 @@ def test_getattr(self): for x in ["mode", "path", "handle", "complib"]: getattr(store, "_{x}".format(x=x)) - def test_put(self): + def test_put(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -805,7 +784,7 @@ def test_put(self): store.put("c", df[:10], format="table", append=False) tm.assert_frame_equal(df[:10], store["c"]) - def test_put_string_index(self): + def test_put_string_index(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -835,7 +814,7 @@ def test_put_string_index(self): store["b"] = df tm.assert_frame_equal(store["b"], df) - def test_put_compression(self): + def test_put_compression(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -849,7 +828,7 @@ def test_put_compression(self): store.put("b", df, format="fixed", complib="zlib") @td.skip_if_windows_python_3 - def test_put_compression_blosc(self): + def test_put_compression_blosc(self, setup_path): df = tm.makeTimeDataFrame() with ensure_clean_store(setup_path @@ -862,7 +841,7 @@ def test_put_compression_blosc(self): store.put("c", df, format="table", complib="blosc") tm.assert_frame_equal(store["c"], df) - def test_complibs_default_settings(self): + def test_complibs_default_settings(self, setup_path): # GH15943 df = tm.makeDataFrame() @@ -919,7 +898,7 @@ def test_complibs_default_settings(self): assert node.filters.complevel == 9 assert node.filters.complib == "blosc" - def test_complibs(self): + def test_complibs(self, setup_path): # GH14478 df = tm.makeDataFrame() @@ -956,13 +935,13 @@ def test_complibs(self): assert node.filters.complib == lib h5table.close() - def test_put_integer(self): + def test_put_integer(self, setup_path): # non-date, non-string index df = DataFrame(np.random.randn(50, 100)) - self._check_roundtrip(df, tm.assert_frame_equal) + self._check_roundtrip(df, tm.assert_frame_equal, setup_path) @xfail_non_writeable - def test_put_mixed_type(self): + def test_put_mixed_type(self, setup_path): df = tm.makeTimeDataFrame() df["obj1"] = "foo" df["obj2"] = "bar" @@ -993,7 +972,7 @@ def test_put_mixed_type(self): @pytest.mark.filterwarnings( "ignore:object name:tables.exceptions.NaturalNameWarning" ) - def test_append(self): + def test_append(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -1062,7 +1041,7 @@ def test_append(self): store.append("uints", uint_data, data_columns=["u08", "u16", "u32"]) tm.assert_frame_equal(store["uints"], uint_data) - def test_append_series(self): + def test_append_series(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -1109,7 +1088,7 @@ def test_append_series(self): store.append("mi", s) tm.assert_series_equal(store["mi"], s) - def test_store_index_types(self): + def test_store_index_types(self, setup_path): # GH5386 # test storing various index types @@ -1147,7 +1126,7 @@ def check(format, index): @pytest.mark.skipif( not is_platform_little_endian(), reason="reason platform is not little endian" ) - def test_encoding(self): + def test_encoding(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -1177,7 +1156,7 @@ def test_encoding(self): ], ) @pytest.mark.parametrize("dtype", ["category", object]) - def test_latin_encoding(self, dtype, val): + def test_latin_encoding(self, setup_path, dtype, val): enc = "latin-1" nan_rep = "" key = "data" @@ -1203,7 +1182,7 @@ def test_latin_encoding(self, dtype, val): # for x in examples: # roundtrip(s, nan_rep=b'\xf8\xfc') - def test_append_some_nans(self): + def test_append_some_nans(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -1250,7 +1229,7 @@ def test_append_some_nans(self): store.append("df3", df3[10:]) tm.assert_frame_equal(store["df3"], df3) - def test_append_all_nans(self): + def test_append_all_nans(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -1347,7 +1326,7 @@ def test_append_all_nans(self): reloaded = read_hdf(path, "df_with_missing") tm.assert_frame_equal(df_with_missing, reloaded) - def test_read_missing_key_close_store(self): + def test_read_missing_key_close_store(self, setup_path): # GH 25766 with ensure_clean_path(setup_path ) as path: @@ -1361,7 +1340,7 @@ def test_read_missing_key_close_store(self): # read with KeyError before another write df.to_hdf(path, "k2") - def test_append_frame_column_oriented(self): + def test_append_frame_column_oriented(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -1386,7 +1365,7 @@ def test_append_frame_column_oriented(self): with pytest.raises(TypeError): store.select("df1", "columns=A and index>df.index[4]") - def test_append_with_different_block_ordering(self): + def test_append_with_different_block_ordering(self, setup_path): # GH 4096; using same frames, but different block orderings with ensure_clean_store(setup_path @@ -1431,7 +1410,7 @@ def test_append_with_different_block_ordering(self): with pytest.raises(ValueError): store.append("df", df) - def test_append_with_strings(self): + def test_append_with_strings(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -1549,7 +1528,7 @@ def check_col(key, name, size): with pytest.raises(ValueError): store.append("df", df, min_itemsize={"foo": 20, "foobar": 20}) - def test_append_with_empty_string(self): + def test_append_with_empty_string(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -1560,7 +1539,7 @@ def test_append_with_empty_string(self): store.append("df", df[-1:], min_itemsize={"x": 1}) tm.assert_frame_equal(store.select("df"), df) - def test_to_hdf_with_min_itemsize(self): + def test_to_hdf_with_min_itemsize(self, setup_path): with ensure_clean_path(setup_path ) as path: @@ -1583,7 +1562,7 @@ def test_to_hdf_with_min_itemsize(self): @pytest.mark.parametrize( "format", [pytest.param("fixed", marks=xfail_non_writeable), "table"] ) - def test_to_hdf_errors(self, format): + def test_to_hdf_errors(self, format, setup_path): data = ["\ud800foo"] ser = pd.Series(data, index=pd.Index(data)) @@ -1595,7 +1574,7 @@ def test_to_hdf_errors(self, format): result = pd.read_hdf(path, "table", errors="surrogatepass") tm.assert_series_equal(result, ser) - def test_append_with_data_columns(self): + def test_append_with_data_columns(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -1755,7 +1734,7 @@ def check_col(key, name, size): expected = df_dc[(df_dc.B > 0) & (df_dc.C > 0) & (df_dc.string == "foo")] tm.assert_frame_equal(result, expected) - def test_create_table_index(self): + def test_create_table_index(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -1788,7 +1767,7 @@ def col(t, column): with pytest.raises(TypeError): store.create_table_index("f2") - def test_append_hierarchical(self): + def test_append_hierarchical(self, setup_path): index = MultiIndex( levels=[["foo", "bar", "baz", "qux"], ["one", "two", "three"]], codes=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3], [0, 1, 2, 0, 1, 1, 2, 0, 1, 2]], @@ -1813,7 +1792,7 @@ def test_append_hierarchical(self): expected = df.reindex(columns=["A", "B"]) tm.assert_frame_equal(result, expected) - def test_column_multiindex(self): + def test_column_multiindex(self, setup_path): # GH 4710 # recreate multi-indexes properly @@ -1867,7 +1846,7 @@ def test_column_multiindex(self): store["df1"], expected, check_index_type=True, check_column_type=True ) - def test_store_multiindex(self): + def test_store_multiindex(self, setup_path): # validate multi-index names # GH 5527 @@ -1938,7 +1917,7 @@ def make_index(names=None): store.append("df", df) tm.assert_frame_equal(store.select("df"), df) - def test_select_columns_in_where(self): + def test_select_columns_in_where(self, setup_path): # GH 6169 # recreate multi-indexes when columns is passed @@ -1968,7 +1947,7 @@ def test_select_columns_in_where(self): store.put("s", s, format="table") tm.assert_series_equal(store.select("s", where="columns=['A']"), s) - def test_mi_data_columns(self): + def test_mi_data_columns(self, setup_path): # GH 14435 idx = pd.MultiIndex.from_arrays( [date_range("2000-01-01", periods=5), range(5)], names=["date", "id"] @@ -1983,7 +1962,7 @@ def test_mi_data_columns(self): expected = df.iloc[[1], :] tm.assert_frame_equal(actual, expected) - def test_pass_spec_to_storer(self): + def test_pass_spec_to_storer(self, setup_path): df = tm.makeDataFrame() @@ -1996,7 +1975,7 @@ def test_pass_spec_to_storer(self): store.select("df", where=[("columns=A")]) @xfail_non_writeable - def test_append_misc(self): + def test_append_misc(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -2049,7 +2028,7 @@ def check(obj, comparator): store.put("df2", df) assert_frame_equal(store.select("df2"), df) - def test_append_raise(self): + def test_append_raise(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -2095,7 +2074,7 @@ def test_append_raise(self): with pytest.raises(ValueError): store.append("df", df) - def test_table_index_incompatible_dtypes(self): + def test_table_index_incompatible_dtypes(self, setup_path): df1 = DataFrame({"a": [1, 2, 3]}) df2 = DataFrame({"a": [4, 5, 6]}, index=date_range("1/1/2000", periods=3)) @@ -2105,7 +2084,7 @@ def test_table_index_incompatible_dtypes(self): with pytest.raises(TypeError): store.put("frame", df2, format="table", append=True) - def test_table_values_dtypes_roundtrip(self): + def test_table_values_dtypes_roundtrip(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -2162,7 +2141,7 @@ def test_table_values_dtypes_roundtrip(self): expected = expected.sort_index() tm.assert_series_equal(result, expected) - def test_table_mixed_dtypes(self): + def test_table_mixed_dtypes(self, setup_path): # frame df = tm.makeDataFrame() @@ -2185,7 +2164,7 @@ def test_table_mixed_dtypes(self): store.append("df1_mixed", df) tm.assert_frame_equal(store.select("df1_mixed"), df) - def test_unimplemented_dtypes_table_columns(self): + def test_unimplemented_dtypes_table_columns(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -2220,7 +2199,7 @@ def test_unimplemented_dtypes_table_columns(self): "exactly equal to 1.15.0: gh-22098" ), ) - def test_calendar_roundtrip_issue(self): + def test_calendar_roundtrip_issue(self, setup_path): # 8591 # doc example from tseries holiday section @@ -2249,7 +2228,7 @@ def test_calendar_roundtrip_issue(self): result = store.select("table") assert_series_equal(result, s) - def test_roundtrip_tz_aware_index(self): + def test_roundtrip_tz_aware_index(self, setup_path): # GH 17618 time = pd.Timestamp("2000-01-01 01:00:00", tz="US/Eastern") df = pd.DataFrame(data=[0], index=[time]) @@ -2261,7 +2240,7 @@ def test_roundtrip_tz_aware_index(self): tm.assert_frame_equal(recons, df) assert recons.index[0].value == 946706400000000000 - def test_append_with_timedelta(self): + def test_append_with_timedelta(self, setup_path): # GH 3577 # append timedelta @@ -2311,7 +2290,7 @@ def test_append_with_timedelta(self): result = store.select("df2") assert_frame_equal(result, df) - def test_remove(self): + def test_remove(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -2352,7 +2331,7 @@ def test_remove(self): del store["b"] assert len(store) == 0 - def test_invalid_terms(self): + def test_invalid_terms(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -2405,7 +2384,7 @@ def test_invalid_terms(self): with pytest.raises(ValueError): read_hdf(path, "dfq", where="A>0 or C>0") - def test_same_name_scoping(self): + def test_same_name_scoping(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -2432,29 +2411,29 @@ def test_same_name_scoping(self): result = store.select("df", "index>datetime(2013,1,5)") assert_frame_equal(result, expected) - def test_series(self): + def test_series(self, setup_path): s = tm.makeStringSeries() - self._check_roundtrip(s, tm.assert_series_equal) + self._check_roundtrip(s, tm.assert_series_equal, path=setup_path) ts = tm.makeTimeSeries() - self._check_roundtrip(ts, tm.assert_series_equal) + self._check_roundtrip(ts, tm.assert_series_equal, path=setup_path) ts2 = Series(ts.index, Index(ts.index, dtype=object)) - self._check_roundtrip(ts2, tm.assert_series_equal) + self._check_roundtrip(ts2, tm.assert_series_equal, path=setup_path) ts3 = Series(ts.values, Index(np.asarray(ts.index, dtype=object), dtype=object)) - self._check_roundtrip(ts3, tm.assert_series_equal, check_index_type=False) + self._check_roundtrip(ts3, tm.assert_series_equal, path=setup_path, check_index_type=False) - def test_float_index(self): + def test_float_index(self, setup_path): # GH #454 index = np.random.randn(10) s = Series(np.random.randn(10), index=index) - self._check_roundtrip(s, tm.assert_series_equal) + self._check_roundtrip(s, tm.assert_series_equal, path=setup_path) @xfail_non_writeable - def test_tuple_index(self): + def test_tuple_index(self, setup_path): # GH #492 col = np.arange(10) @@ -2464,11 +2443,11 @@ def test_tuple_index(self): with catch_warnings(record=True): simplefilter("ignore", pd.errors.PerformanceWarning) - self._check_roundtrip(DF, tm.assert_frame_equal) + self._check_roundtrip(DF, tm.assert_frame_equal, path=setup_path) @xfail_non_writeable @pytest.mark.filterwarnings("ignore::pandas.errors.PerformanceWarning") - def test_index_types(self): + def test_index_types(self, setup_path): with catch_warnings(record=True): values = np.random.randn(2) @@ -2479,54 +2458,54 @@ def test_index_types(self): with catch_warnings(record=True): ser = Series(values, [0, "y"]) - self._check_roundtrip(ser, func) + self._check_roundtrip(ser, func, path=setup_path) with catch_warnings(record=True): ser = Series(values, [datetime.datetime.today(), 0]) - self._check_roundtrip(ser, func) + self._check_roundtrip(ser, func, path=setup_path) with catch_warnings(record=True): ser = Series(values, ["y", 0]) - self._check_roundtrip(ser, func) + self._check_roundtrip(ser, func, path=setup_path) with catch_warnings(record=True): ser = Series(values, [datetime.date.today(), "a"]) - self._check_roundtrip(ser, func) + self._check_roundtrip(ser, func, path=setup_path) with catch_warnings(record=True): ser = Series(values, [0, "y"]) - self._check_roundtrip(ser, func) + self._check_roundtrip(ser, func, path=setup_path) ser = Series(values, [datetime.datetime.today(), 0]) - self._check_roundtrip(ser, func) + self._check_roundtrip(ser, func, path=setup_path) ser = Series(values, ["y", 0]) - self._check_roundtrip(ser, func) + self._check_roundtrip(ser, func, path=setup_path) ser = Series(values, [datetime.date.today(), "a"]) - self._check_roundtrip(ser, func) + self._check_roundtrip(ser, func, path=setup_path) ser = Series(values, [1.23, "b"]) - self._check_roundtrip(ser, func) + self._check_roundtrip(ser, func, path=setup_path) ser = Series(values, [1, 1.53]) - self._check_roundtrip(ser, func) + self._check_roundtrip(ser, func, path=setup_path) ser = Series(values, [1, 5]) - self._check_roundtrip(ser, func) + self._check_roundtrip(ser, func, path=setup_path) ser = Series( values, [datetime.datetime(2012, 1, 1), datetime.datetime(2012, 1, 2)] ) - self._check_roundtrip(ser, func) + self._check_roundtrip(ser, func, path=setup_path) - def test_timeseries_preepoch(self): + def test_timeseries_preepoch(self, setup_path): dr = bdate_range("1/1/1940", "1/1/1960") ts = Series(np.random.randn(len(dr)), index=dr) try: - self._check_roundtrip(ts, tm.assert_series_equal) + self._check_roundtrip(ts, tm.assert_series_equal, path=setup_path) except OverflowError: pytest.skip("known failer on some windows platforms") @@ -2534,7 +2513,7 @@ def test_timeseries_preepoch(self): @pytest.mark.parametrize( "compression", [False, pytest.param(True, marks=td.skip_if_windows_python_3)] ) - def test_frame(self, compression): + def test_frame(self, compression, setup_path): df = tm.makeDataFrame() @@ -2542,11 +2521,11 @@ def test_frame(self, compression): df.values[0, 0] = np.nan df.values[5, 3] = np.nan - self._check_roundtrip_table(df, tm.assert_frame_equal, compression=compression) - self._check_roundtrip(df, tm.assert_frame_equal, compression=compression) + self._check_roundtrip_table(df, tm.assert_frame_equal, path=setup_path, compression=compression) + self._check_roundtrip(df, tm.assert_frame_equal, path=setup_path, compression=compression) tdf = tm.makeTimeDataFrame() - self._check_roundtrip(tdf, tm.assert_frame_equal, compression=compression) + self._check_roundtrip(tdf, tm.assert_frame_equal, path=setup_path, compression=compression) with ensure_clean_store(setup_path ) as store: @@ -2557,38 +2536,38 @@ def test_frame(self, compression): assert recons._data.is_consolidated() # empty - self._check_roundtrip(df[:0], tm.assert_frame_equal) + self._check_roundtrip(df[:0], tm.assert_frame_equal, path=setup_path) @xfail_non_writeable - def test_empty_series_frame(self): + def test_empty_series_frame(self, setup_path): s0 = Series() s1 = Series(name="myseries") df0 = DataFrame() df1 = DataFrame(index=["a", "b", "c"]) df2 = DataFrame(columns=["d", "e", "f"]) - self._check_roundtrip(s0, tm.assert_series_equal) - self._check_roundtrip(s1, tm.assert_series_equal) - self._check_roundtrip(df0, tm.assert_frame_equal) - self._check_roundtrip(df1, tm.assert_frame_equal) - self._check_roundtrip(df2, tm.assert_frame_equal) + self._check_roundtrip(s0, tm.assert_series_equal, path=setup_path) + self._check_roundtrip(s1, tm.assert_series_equal, path=setup_path) + self._check_roundtrip(df0, tm.assert_frame_equal, path=setup_path) + self._check_roundtrip(df1, tm.assert_frame_equal, path=setup_path) + self._check_roundtrip(df2, tm.assert_frame_equal, path=setup_path) @xfail_non_writeable @pytest.mark.parametrize( "dtype", [np.int64, np.float64, np.object, "m8[ns]", "M8[ns]"] ) - def test_empty_series(self, dtype): + def test_empty_series(self, dtype, setup_path): s = Series(dtype=dtype) - self._check_roundtrip(s, tm.assert_series_equal) + self._check_roundtrip(s, tm.assert_series_equal, path=setup_path) - def test_can_serialize_dates(self): + def test_can_serialize_dates(self, setup_path): rng = [x.date() for x in bdate_range("1/1/2000", "1/30/2000")] frame = DataFrame(np.random.randn(len(rng), 4), index=rng) - self._check_roundtrip(frame, tm.assert_frame_equal) + self._check_roundtrip(frame, tm.assert_frame_equal, path=setup_path) - def test_store_hierarchical(self): + def test_store_hierarchical(self, setup_path): index = MultiIndex( levels=[["foo", "bar", "baz", "qux"], ["one", "two", "three"]], codes=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3], [0, 1, 2, 0, 1, 1, 2, 0, 1, 2]], @@ -2596,9 +2575,9 @@ def test_store_hierarchical(self): ) frame = DataFrame(np.random.randn(10, 3), index=index, columns=["A", "B", "C"]) - self._check_roundtrip(frame, tm.assert_frame_equal) - self._check_roundtrip(frame.T, tm.assert_frame_equal) - self._check_roundtrip(frame["A"], tm.assert_series_equal) + self._check_roundtrip(frame, tm.assert_frame_equal, path=setup_path) + self._check_roundtrip(frame.T, tm.assert_frame_equal, path=setup_path) + self._check_roundtrip(frame["A"], tm.assert_series_equal, path=setup_path) # check that the names are stored with ensure_clean_store(setup_path @@ -2607,7 +2586,7 @@ def test_store_hierarchical(self): recons = store["frame"] tm.assert_frame_equal(recons, frame) - def test_store_index_name(self): + def test_store_index_name(self, setup_path): df = tm.makeDataFrame() df.index.name = "foo" @@ -2617,7 +2596,7 @@ def test_store_index_name(self): recons = store["frame"] tm.assert_frame_equal(recons, df) - def test_store_index_name_with_tz(self): + def test_store_index_name_with_tz(self, setup_path): # GH 13884 df = pd.DataFrame({"A": [1, 2]}) df.index = pd.DatetimeIndex([1234567890123456787, 1234567890123456788]) @@ -2631,7 +2610,7 @@ def test_store_index_name_with_tz(self): tm.assert_frame_equal(recons, df) @pytest.mark.parametrize("table_format", ["table", "fixed"]) - def test_store_index_name_numpy_str(self, table_format): + def test_store_index_name_numpy_str(self, table_format, setup_path): # GH #13492 idx = pd.Index( pd.to_datetime([datetime.date(2000, 1, 1), datetime.date(2000, 1, 2)]), @@ -2654,7 +2633,7 @@ def test_store_index_name_numpy_str(self, table_format): assert type(df2.index.name) == str assert type(df2.columns.name) == str - def test_store_series_name(self): + def test_store_series_name(self, setup_path): df = tm.makeDataFrame() series = df["A"] @@ -2668,7 +2647,7 @@ def test_store_series_name(self): @pytest.mark.parametrize( "compression", [False, pytest.param(True, marks=td.skip_if_windows_python_3)] ) - def test_store_mixed(self, compression): + def test_store_mixed(self, compression, setup_path): def _make_one(): df = tm.makeDataFrame() df["obj1"] = "foo" @@ -2682,8 +2661,8 @@ def _make_one(): df1 = _make_one() df2 = _make_one() - self._check_roundtrip(df1, tm.assert_frame_equal) - self._check_roundtrip(df2, tm.assert_frame_equal) + self._check_roundtrip(df1, tm.assert_frame_equal, path=setup_path) + self._check_roundtrip(df2, tm.assert_frame_equal, path=setup_path) with ensure_clean_store(setup_path ) as store: @@ -2694,19 +2673,19 @@ def _make_one(): # check that can store Series of all of these types self._check_roundtrip( - df1["obj1"], tm.assert_series_equal, compression=compression + df1["obj1"], tm.assert_series_equal, path=setup_path, compression=compression ) self._check_roundtrip( - df1["bool1"], tm.assert_series_equal, compression=compression + df1["bool1"], tm.assert_series_equal, path=setup_path, compression=compression ) self._check_roundtrip( - df1["int1"], tm.assert_series_equal, compression=compression + df1["int1"], tm.assert_series_equal, path=setup_path, compression=compression ) @pytest.mark.filterwarnings( "ignore:\\nduplicate:pandas.io.pytables.DuplicateWarning" ) - def test_select_with_dups(self): + def test_select_with_dups(self, setup_path): # single dtypes df = DataFrame(np.random.randn(10, 4), columns=["A", "A", "B", "B"]) @@ -2771,7 +2750,7 @@ def test_select_with_dups(self): result = store.select("df", columns=["B", "A"]) assert_frame_equal(result, expected, by_blocks=True) - def test_overwrite_node(self): + def test_overwrite_node(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -2781,7 +2760,7 @@ def test_overwrite_node(self): tm.assert_series_equal(store["a"], ts) - def test_select(self): + def test_select(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -2822,7 +2801,7 @@ def test_select(self): expected = df[df.A > 0].reindex(columns=["C", "D"]) tm.assert_frame_equal(expected, result) - def test_select_dtypes(self): + def test_select_dtypes(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -2932,7 +2911,7 @@ def test_select_dtypes(self): result = store.select("df", where=["A>np_zero"]) tm.assert_frame_equal(expected, result) - def test_select_with_many_inputs(self): + def test_select_with_many_inputs(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -2986,7 +2965,7 @@ def test_select_with_many_inputs(self): tm.assert_frame_equal(expected, result) assert len(result) == 100 - def test_select_iterator(self): + def test_select_iterator(self, setup_path): # single table with ensure_clean_store(setup_path @@ -3060,7 +3039,7 @@ def test_select_iterator(self): result = concat(results) tm.assert_frame_equal(expected, result) - def test_select_iterator_complete_8014(self): + def test_select_iterator_complete_8014(self, setup_path): # GH 8014 # using iterator and where clause @@ -3137,7 +3116,7 @@ def test_select_iterator_complete_8014(self): result = concat(results) tm.assert_frame_equal(expected, result) - def test_select_iterator_non_complete_8014(self): + def test_select_iterator_non_complete_8014(self, setup_path): # GH 8014 # using iterator and where clause @@ -3194,7 +3173,7 @@ def test_select_iterator_non_complete_8014(self): results = [s for s in store.select("df", where=where, chunksize=chunksize)] assert 0 == len(results) - def test_select_iterator_many_empty_frames(self): + def test_select_iterator_many_empty_frames(self, setup_path): # GH 8014 # using iterator and where clause can return many empty @@ -3260,7 +3239,7 @@ def test_select_iterator_many_empty_frames(self): @pytest.mark.filterwarnings( "ignore:\\nthe :pandas.io.pytables.AttributeConflictWarning" ) - def test_retain_index_attributes(self): + def test_retain_index_attributes(self, setup_path): # GH 3499, losing frequency info on index recreation df = DataFrame( @@ -3321,7 +3300,7 @@ def test_retain_index_attributes(self): @pytest.mark.filterwarnings( "ignore:\\nthe :pandas.io.pytables.AttributeConflictWarning" ) - def test_retain_index_attributes2(self): + def test_retain_index_attributes2(self, setup_path): with ensure_clean_path(setup_path ) as path: @@ -3360,7 +3339,7 @@ def test_retain_index_attributes2(self): assert read_hdf(path, "data").index.name is None - def test_frame_select(self): + def test_frame_select(self, setup_path): df = tm.makeTimeDataFrame() @@ -3394,7 +3373,7 @@ def test_frame_select(self): # with pytest.raises(ValueError): # store.select('frame', [crit1, crit2]) - def test_frame_select_complex(self): + def test_frame_select_complex(self, setup_path): # select via complex criteria df = tm.makeTimeDataFrame() @@ -3447,7 +3426,7 @@ def test_frame_select_complex(self): expected = df.loc[df.index > df.index[3]].reindex(columns=["A", "B"]) tm.assert_frame_equal(result, expected) - def test_frame_select_complex2(self): + def test_frame_select_complex2(self, setup_path): with ensure_clean_path(["parms.hdf", "hist.hdf"]) as paths: @@ -3511,7 +3490,7 @@ def test_frame_select_complex2(self): store.close() - def test_invalid_filtering(self): + def test_invalid_filtering(self, setup_path): # can't use more than one filter (atm) @@ -3529,7 +3508,7 @@ def test_invalid_filtering(self): with pytest.raises(NotImplementedError): store.select("df", "columns=['A','B'] & columns=['C']") - def test_string_select(self): + def test_string_select(self, setup_path): # GH 2973 with ensure_clean_store(setup_path ) as store: @@ -3572,7 +3551,7 @@ def test_string_select(self): expected = df[df.int != 2] assert_frame_equal(result, expected) - def test_read_column(self): + def test_read_column(self, setup_path): df = tm.makeTimeDataFrame() @@ -3646,7 +3625,7 @@ def test_read_column(self): result = store.select_column("df4", "B") tm.assert_series_equal(result, expected) - def test_coordinates(self): + def test_coordinates(self, setup_path): df = tm.makeTimeDataFrame() with ensure_clean_store(setup_path @@ -3752,7 +3731,7 @@ def test_coordinates(self): expected = df[5:10] tm.assert_frame_equal(result, expected) - def test_append_to_multiple(self): + def test_append_to_multiple(self, setup_path): df1 = tm.makeTimeDataFrame() df2 = tm.makeTimeDataFrame().rename(columns="{}_2".format) df2["foo"] = "bar" @@ -3783,7 +3762,7 @@ def test_append_to_multiple(self): expected = df[(df.A > 0) & (df.B > 0)] tm.assert_frame_equal(result, expected) - def test_append_to_multiple_dropna(self): + def test_append_to_multiple_dropna(self, setup_path): df1 = tm.makeTimeDataFrame() df2 = tm.makeTimeDataFrame().rename(columns="{}_2".format) df1.iloc[1, df1.columns.get_indexer(["A", "B"])] = np.nan @@ -3804,7 +3783,7 @@ def test_append_to_multiple_dropna(self): @pytest.mark.xfail( run=False, reason="append_to_multiple_dropna_false is not raising as failed" ) - def test_append_to_multiple_dropna_false(self): + def test_append_to_multiple_dropna_false(self, setup_path): df1 = tm.makeTimeDataFrame() df2 = tm.makeTimeDataFrame().rename(columns="{}_2".format) df1.iloc[1, df1.columns.get_indexer(["A", "B"])] = np.nan @@ -3823,7 +3802,7 @@ def test_append_to_multiple_dropna_false(self): assert not store.select("df1a").index.equals(store.select("df2a").index) - def test_select_as_multiple(self): + def test_select_as_multiple(self, setup_path): df1 = tm.makeTimeDataFrame() df2 = tm.makeTimeDataFrame().rename(columns="{}_2".format) @@ -3898,7 +3877,7 @@ def test_select_as_multiple(self): LooseVersion(tables.__version__) < LooseVersion("3.1.0"), reason=("tables version does not support fix for nan selection bug: GH 4858"), ) - def test_nan_selection_bug_4858(self): + def test_nan_selection_bug_4858(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -3917,7 +3896,7 @@ def test_nan_selection_bug_4858(self): result = store.select("df", where="values>2.0") assert_frame_equal(result, expected) - def test_start_stop_table(self): + def test_start_stop_table(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -3936,7 +3915,7 @@ def test_start_stop_table(self): expected = df.loc[30:40, ["A"]] tm.assert_frame_equal(result, expected) - def test_start_stop_multiple(self): + def test_start_stop_multiple(self, setup_path): # GH 16209 with ensure_clean_store(setup_path @@ -3953,7 +3932,7 @@ def test_start_stop_multiple(self): expected = df.loc[[0], ["foo", "bar"]] tm.assert_frame_equal(result, expected) - def test_start_stop_fixed(self): + def test_start_stop_fixed(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -3994,7 +3973,7 @@ def test_start_stop_fixed(self): df.iloc[3:5, 1:3] = np.nan df.iloc[8:10, -2] = np.nan - def test_select_filter_corner(self): + def test_select_filter_corner(self, setup_path): df = DataFrame(np.random.randn(50, 100)) df.index = ["{c:3d}".format(c=c) for c in df.index] @@ -4012,7 +3991,7 @@ def test_select_filter_corner(self): result = store.select("frame", [crit]) tm.assert_frame_equal(result, df.loc[:, df.columns[:75:2]]) - def test_path_pathlib(self): + def test_path_pathlib(self, setup_path): df = tm.makeDataFrame() result = tm.round_trip_pathlib( @@ -4021,7 +4000,7 @@ def test_path_pathlib(self): tm.assert_frame_equal(df, result) @pytest.mark.parametrize("start, stop", [(0, 2), (1, 2), (None, None)]) - def test_contiguous_mixed_data_table(self, start, stop): + def test_contiguous_mixed_data_table(self, start, stop, setup_path): # GH 17021 # ValueError when reading a contiguous mixed-data table ft. VLArray df = DataFrame( @@ -4038,7 +4017,7 @@ def test_contiguous_mixed_data_table(self, start, stop): result = store.select("test_dataset", start=start, stop=stop) assert_frame_equal(df[start:stop], result) - def test_path_pathlib_hdfstore(self): + def test_path_pathlib_hdfstore(self, setup_path): df = tm.makeDataFrame() def writer(path): @@ -4052,14 +4031,14 @@ def reader(path): result = tm.round_trip_pathlib(writer, reader) tm.assert_frame_equal(df, result) - def test_pickle_path_localpath(self): + def test_pickle_path_localpath(self, setup_path): df = tm.makeDataFrame() result = tm.round_trip_pathlib( lambda p: df.to_hdf(p, "df"), lambda p: pd.read_hdf(p, "df") ) tm.assert_frame_equal(df, result) - def test_path_localpath_hdfstore(self): + def test_path_localpath_hdfstore(self, setup_path): df = tm.makeDataFrame() def writer(path): @@ -4073,24 +4052,24 @@ def reader(path): result = tm.round_trip_localpath(writer, reader) tm.assert_frame_equal(df, result) - def _check_roundtrip(self, obj, comparator, compression=False, **kwargs): + def _check_roundtrip(self, obj, comparator, path, compression=False, **kwargs): options = {} if compression: options["complib"] = _default_compressor - with ensure_clean_store(setup_path + with ensure_clean_store(path , "w", **options) as store: store["obj"] = obj retrieved = store["obj"] comparator(retrieved, obj, **kwargs) - def _check_double_roundtrip(self, obj, comparator, compression=False, **kwargs): + def _check_double_roundtrip(self, obj, comparator, path, compression=False, **kwargs): options = {} if compression: options["complib"] = compression or _default_compressor - with ensure_clean_store(setup_path + with ensure_clean_store(path , "w", **options) as store: store["obj"] = obj retrieved = store["obj"] @@ -4099,19 +4078,19 @@ def _check_double_roundtrip(self, obj, comparator, compression=False, **kwargs): again = store["obj"] comparator(again, obj, **kwargs) - def _check_roundtrip_table(self, obj, comparator, compression=False): + def _check_roundtrip_table(self, obj, comparator, path, compression=False): options = {} if compression: options["complib"] = _default_compressor - with ensure_clean_store(setup_path + with ensure_clean_store(path , "w", **options) as store: store.put("obj", obj, format="table") retrieved = store["obj"] comparator(retrieved, obj) - def test_multiple_open_close(self): + def test_multiple_open_close(self, setup_path): # gh-4409: open & close multiple times with ensure_clean_path(setup_path @@ -4237,7 +4216,7 @@ def test_multiple_open_close(self): with pytest.raises(ClosedFileError, match="file is not open"): store.select("df") - def test_pytables_native_read(self, datapath): + def test_pytables_native_read(self, datapath, setup_path): with ensure_clean_store( datapath("io", "data", "legacy_hdf/pytables_native.h5"), mode="r" ) as store: @@ -4247,7 +4226,7 @@ def test_pytables_native_read(self, datapath): @pytest.mark.skipif( is_platform_windows(), reason="native2 read fails oddly on windows" ) - def test_pytables_native2_read(self, datapath): + def test_pytables_native2_read(self, datapath, setup_path): with ensure_clean_store( datapath("io", "data", "legacy_hdf", "pytables_native2.h5"), mode="r" ) as store: @@ -4256,7 +4235,7 @@ def test_pytables_native2_read(self, datapath): assert isinstance(d1, DataFrame) @xfail_non_writeable - def test_legacy_table_fixed_format_read_py2(self, datapath): + def test_legacy_table_fixed_format_read_py2(self, datapath, setup_path): # GH 24510 # legacy table with fixed format written in Python 2 with ensure_clean_store( @@ -4270,7 +4249,7 @@ def test_legacy_table_fixed_format_read_py2(self, datapath): ) assert_frame_equal(expected, result) - def test_legacy_table_read_py2(self, datapath): + def test_legacy_table_read_py2(self, datapath, setup_path): # issue: 24925 # legacy table written in Python 2 with ensure_clean_store( @@ -4281,7 +4260,7 @@ def test_legacy_table_read_py2(self, datapath): expected = pd.DataFrame({"a": ["a", "b"], "b": [2, 3]}) assert_frame_equal(expected, result) - def test_copy(self): + def test_copy(self, setup_path): with catch_warnings(record=True): @@ -4340,7 +4319,7 @@ def do_copy(f, new_f=None, keys=None, propindexes=True, **kwargs): finally: safe_remove(path) - def test_store_datetime_fractional_secs(self): + def test_store_datetime_fractional_secs(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -4349,7 +4328,7 @@ def test_store_datetime_fractional_secs(self): store["a"] = series assert store["a"].index[0] == dt - def test_tseries_indices_series(self): + def test_tseries_indices_series(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -4371,7 +4350,7 @@ def test_tseries_indices_series(self): assert result.index.freq == ser.index.freq tm.assert_class_equal(result.index, ser.index, obj="series index") - def test_tseries_indices_frame(self): + def test_tseries_indices_frame(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -4393,7 +4372,7 @@ def test_tseries_indices_frame(self): assert result.index.freq == df.index.freq tm.assert_class_equal(result.index, df.index, obj="dataframe index") - def test_unicode_index(self): + def test_unicode_index(self, setup_path): unicode_values = ["\u03c3", "\u03c3\u03c3"] @@ -4401,9 +4380,9 @@ def test_unicode_index(self): with catch_warnings(record=True): simplefilter("ignore", pd.errors.PerformanceWarning) s = Series(np.random.randn(len(unicode_values)), unicode_values) - self._check_roundtrip(s, tm.assert_series_equal) + self._check_roundtrip(s, tm.assert_series_equal, path=setup_path) - def test_unicode_longer_encoded(self): + def test_unicode_longer_encoded(self, setup_path): # GH 11234 char = "\u0394" df = pd.DataFrame({"A": [char]}) @@ -4421,12 +4400,12 @@ def test_unicode_longer_encoded(self): tm.assert_frame_equal(result, df) @xfail_non_writeable - def test_store_datetime_mixed(self): + def test_store_datetime_mixed(self, setup_path): df = DataFrame({"a": [1, 2, 3], "b": [1.0, 2.0, 3.0], "c": ["a", "b", "c"]}) ts = tm.makeTimeSeries() df["d"] = ts.index[:3] - self._check_roundtrip(df, tm.assert_frame_equal) + self._check_roundtrip(df, tm.assert_frame_equal, path=setup_path) # FIXME: don't leave commented-out code # def test_cant_write_multiindex_table(self): @@ -4438,7 +4417,7 @@ def test_store_datetime_mixed(self): # with pytest.raises(Exception): # store.put('foo', df, format='table') - def test_append_with_diff_col_name_types_raises_value_error(self): + def test_append_with_diff_col_name_types_raises_value_error(self, setup_path): df = DataFrame(np.random.randn(10, 1)) df2 = DataFrame({"a": np.random.randn(10)}) df3 = DataFrame({(1, 2): np.random.randn(10)}) @@ -4454,7 +4433,7 @@ def test_append_with_diff_col_name_types_raises_value_error(self): with pytest.raises(ValueError): store.append(name, d) - def test_query_with_nested_special_character(self): + def test_query_with_nested_special_character(self, setup_path): df = DataFrame( { "a": ["a", "a", "c", "b", "test & test", "c", "b", "e"], @@ -4468,7 +4447,7 @@ def test_query_with_nested_special_character(self): result = store.select("test", 'a = "test & test"') tm.assert_frame_equal(expected, result) - def test_categorical(self): + def test_categorical(self, setup_path): with ensure_clean_store(setup_path ) as store: @@ -4589,7 +4568,7 @@ def test_categorical(self): ): store.select("df3/meta/s/meta") - def test_categorical_conversion(self): + def test_categorical_conversion(self, setup_path): # GH13322 # Check that read_hdf with categorical columns doesn't return rows if @@ -4621,7 +4600,7 @@ def test_categorical_conversion(self): result = read_hdf(path, "df", where="obsids=B") tm.assert_frame_equal(result, expected) - def test_categorical_nan_only_columns(self): + def test_categorical_nan_only_columns(self, setup_path): # GH18413 # Check that read_hdf with categorical columns with NaN-only values can # be read back. @@ -4643,7 +4622,7 @@ def test_categorical_nan_only_columns(self): result = read_hdf(path, "df") tm.assert_frame_equal(result, expected) - def test_duplicate_column_name(self): + def test_duplicate_column_name(self, setup_path): df = DataFrame(columns=["a", "a"], data=[[0, 0]]) with ensure_clean_path(setup_path @@ -4658,7 +4637,7 @@ def test_duplicate_column_name(self): assert df.equals(other) assert other.equals(df) - def test_round_trip_equals(self): + def test_round_trip_equals(self, setup_path): # GH 9330 df = DataFrame({"B": [1, 2], "A": ["x", "y"]}) @@ -4670,7 +4649,7 @@ def test_round_trip_equals(self): assert df.equals(other) assert other.equals(df) - def test_preserve_timedeltaindex_type(self): + def test_preserve_timedeltaindex_type(self, setup_path): # GH9635 # Storing TimedeltaIndexed DataFrames in fixed stores did not preserve # the type of the index. @@ -4683,7 +4662,7 @@ def test_preserve_timedeltaindex_type(self): store["df"] = df assert_frame_equal(store["df"], df) - def test_columns_multiindex_modified(self): + def test_columns_multiindex_modified(self, setup_path): # BUG: 7212 # read_hdf store.select modified the passed columns parameters # when multi-indexed. @@ -4709,7 +4688,7 @@ def test_columns_multiindex_modified(self): assert cols2load_original == cols2load @ignore_natural_naming_warning - def test_to_hdf_with_object_column_names(self): + def test_to_hdf_with_object_column_names(self, setup_path): # GH9057 # Writing HDF5 table format should only work for string-like # column types @@ -4747,7 +4726,7 @@ def test_to_hdf_with_object_column_names(self): ) assert len(result) - def test_read_hdf_open_store(self): + def test_read_hdf_open_store(self, setup_path): # GH10330 # No check for non-string path_or-buf, and no test of open store df = DataFrame(np.random.rand(4, 5), index=list("abcd"), columns=list("ABCDE")) @@ -4764,7 +4743,7 @@ def test_read_hdf_open_store(self): assert store.is_open store.close() - def test_read_hdf_iterator(self): + def test_read_hdf_iterator(self, setup_path): df = DataFrame(np.random.rand(4, 5), index=list("abcd"), columns=list("ABCDE")) df.index.name = "letters" df = df.set_index(keys="E", append=True) @@ -4779,7 +4758,7 @@ def test_read_hdf_iterator(self): tm.assert_frame_equal(direct, indirect) iterator.store.close() - def test_read_hdf_errors(self): + def test_read_hdf_errors(self, setup_path): df = DataFrame(np.random.rand(4, 5), index=list("abcd"), columns=list("ABCDE")) with ensure_clean_path(setup_path @@ -4798,7 +4777,7 @@ def test_read_hdf_generic_buffer_errors(self): with pytest.raises(NotImplementedError): read_hdf(BytesIO(b""), "df") - def test_invalid_complib(self): + def test_invalid_complib(self, setup_path): df = DataFrame(np.random.rand(4, 5), index=list("abcd"), columns=list("ABCDE")) with ensure_clean_path(setup_path ) as path: @@ -4807,7 +4786,7 @@ def test_invalid_complib(self): # GH10443 - def test_read_nokey(self): + def test_read_nokey(self, setup_path): df = DataFrame(np.random.rand(4, 5), index=list("abcd"), columns=list("ABCDE")) # Categorical dtype not supported for "fixed" format. So no need @@ -4822,7 +4801,7 @@ def test_read_nokey(self): with pytest.raises(ValueError): read_hdf(path) - def test_read_nokey_table(self): + def test_read_nokey_table(self, setup_path): # GH13231 df = DataFrame({"i": range(5), "c": Series(list("abacd"), dtype="category")}) @@ -4836,7 +4815,7 @@ def test_read_nokey_table(self): with pytest.raises(ValueError): read_hdf(path) - def test_read_nokey_empty(self): + def test_read_nokey_empty(self, setup_path): with ensure_clean_path(setup_path ) as path: store = HDFStore(path) @@ -4846,7 +4825,7 @@ def test_read_nokey_empty(self): read_hdf(path) @td.skip_if_no("pathlib") - def test_read_from_pathlib_path(self): + def test_read_from_pathlib_path(self, setup_path): # GH11773 from pathlib import Path @@ -4864,7 +4843,7 @@ def test_read_from_pathlib_path(self): tm.assert_frame_equal(expected, actual) @td.skip_if_no("py.path") - def test_read_from_py_localpath(self): + def test_read_from_py_localpath(self, setup_path): # GH11773 from py.path import local as LocalPath @@ -4881,7 +4860,7 @@ def test_read_from_py_localpath(self): tm.assert_frame_equal(expected, actual) - def test_query_long_float_literal(self): + def test_query_long_float_literal(self, setup_path): # GH 14241 df = pd.DataFrame({"A": [1000000000.0009, 1000000000.0011, 1000000000.0015]}) @@ -4903,7 +4882,7 @@ def test_query_long_float_literal(self): expected = df.loc[[1], :] tm.assert_frame_equal(expected, result) - def test_query_compare_column_type(self): + def test_query_compare_column_type(self, setup_path): # GH 15492 df = pd.DataFrame( { @@ -4953,7 +4932,7 @@ def test_query_compare_column_type(self): tm.assert_frame_equal(expected, result) @pytest.mark.parametrize("format", ["fixed", "table"]) - def test_read_hdf_series_mode_r(self, format): + def test_read_hdf_series_mode_r(self, format, setup_path): # GH 16583 # Tests that reading a Series saved to an HDF file # still works if a mode='r' argument is supplied @@ -5017,7 +4996,7 @@ def test_select_empty_where(self, where): CategoricalIndex(list("abc")), ], ) - def test_to_hdf_multiindex_extension_dtype(self, idx): + def test_to_hdf_multiindex_extension_dtype(self, idx, setup_path): # GH 7775 mi = MultiIndex.from_arrays([idx, idx]) df = pd.DataFrame(0, index=mi, columns=["a"]) @@ -5027,10 +5006,10 @@ def test_to_hdf_multiindex_extension_dtype(self, idx): df.to_hdf(path, "df") -class TestHDFComplexValues(Base): +class TestHDFComplexValues(): # GH10447 - def test_complex_fixed(self): + def test_complex_fixed(self, setup_path): df = DataFrame( np.random.rand(4, 5).astype(np.complex64), index=list("abcd"), @@ -5054,7 +5033,7 @@ def test_complex_fixed(self): reread = read_hdf(path, "df") assert_frame_equal(df, reread) - def test_complex_table(self): + def test_complex_table(self, setup_path): df = DataFrame( np.random.rand(4, 5).astype(np.complex64), index=list("abcd"), @@ -5080,7 +5059,7 @@ def test_complex_table(self): assert_frame_equal(df, reread) @xfail_non_writeable - def test_complex_mixed_fixed(self): + def test_complex_mixed_fixed(self, setup_path): complex64 = np.array( [1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j], dtype=np.complex64 ) @@ -5103,7 +5082,7 @@ def test_complex_mixed_fixed(self): reread = read_hdf(path, "df") assert_frame_equal(df, reread) - def test_complex_mixed_table(self): + def test_complex_mixed_table(self, setup_path): complex64 = np.array( [1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j], dtype=np.complex64 ) @@ -5133,7 +5112,7 @@ def test_complex_mixed_table(self): reread = read_hdf(path, "df") assert_frame_equal(df, reread) - def test_complex_across_dimensions_fixed(self): + def test_complex_across_dimensions_fixed(self, setup_path): with catch_warnings(record=True): complex128 = np.array([1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j]) s = Series(complex128, index=list("abcd")) @@ -5148,7 +5127,7 @@ def test_complex_across_dimensions_fixed(self): reread = read_hdf(path, "obj") comp(obj, reread) - def test_complex_across_dimensions(self): + def test_complex_across_dimensions(self, setup_path): complex128 = np.array([1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j]) s = Series(complex128, index=list("abcd")) df = DataFrame({"A": s, "B": s}) @@ -5164,7 +5143,7 @@ def test_complex_across_dimensions(self): reread = read_hdf(path, "obj") comp(obj, reread) - def test_complex_indexing_error(self): + def test_complex_indexing_error(self, setup_path): complex128 = np.array( [1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j], dtype=np.complex128 ) @@ -5177,7 +5156,7 @@ def test_complex_indexing_error(self): with pytest.raises(TypeError): store.append("df", df, data_columns=["C"]) - def test_complex_series_error(self): + def test_complex_series_error(self, setup_path): complex128 = np.array([1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j]) s = Series(complex128, index=list("abcd")) @@ -5192,7 +5171,7 @@ def test_complex_series_error(self): reread = read_hdf(path, "obj") tm.assert_series_equal(s, reread) - def test_complex_append(self): + def test_complex_append(self, setup_path): df = DataFrame( {"a": np.random.randn(100).astype(np.complex128), "b": np.random.randn(100)} ) From 10ce368b964d0784d9dcc4af48f79fd1bbd13ab0 Mon Sep 17 00:00:00 2001 From: Tola Alade Date: Tue, 1 Oct 2019 14:10:55 +0100 Subject: [PATCH 27/27] ran black for formatting --- pandas/tests/io/pytables/test_pytables.py | 593 ++++++++-------------- 1 file changed, 214 insertions(+), 379 deletions(-) diff --git a/pandas/tests/io/pytables/test_pytables.py b/pandas/tests/io/pytables/test_pytables.py index fbfaca0ea4505..46d8ef04dd8e5 100644 --- a/pandas/tests/io/pytables/test_pytables.py +++ b/pandas/tests/io/pytables/test_pytables.py @@ -162,17 +162,15 @@ def _maybe_remove(store, key): @pytest.mark.single -class TestHDFStore(): +class TestHDFStore: def test_format_kwarg_in_constructor(self, setup_path): # GH 13291 - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: with pytest.raises(ValueError): HDFStore(path, format="table") def test_context(self, setup_path): - path = create_tempfile(setup_path - ) + path = create_tempfile(setup_path) try: with HDFStore(path) as tbl: raise ValueError("blah") @@ -192,8 +190,7 @@ def test_context(self, setup_path): safe_remove(path) def test_conv_read_write(self, setup_path): - path = create_tempfile(setup_path - ) + path = create_tempfile(setup_path) try: def roundtrip(key, obj, **kwargs): @@ -225,8 +222,7 @@ def test_long_strings(self, setup_path): {"a": tm.rands_array(100, size=10)}, index=tm.rands_array(100, size=10) ) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.append("df", df, data_columns=["a"]) result = store.select("df") @@ -236,8 +232,7 @@ def test_api(self, setup_path): # GH4584 # API issue when to_hdf doesn't accept append AND format args - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df = tm.makeDataFrame() df.iloc[:10].to_hdf(path, "df", append=True, format="table") @@ -249,8 +244,7 @@ def test_api(self, setup_path): df.iloc[10:].to_hdf(path, "df", append=True, format="table") assert_frame_equal(read_hdf(path, "df"), df) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df = tm.makeDataFrame() df.iloc[:10].to_hdf(path, "df", append=True) @@ -262,8 +256,7 @@ def test_api(self, setup_path): df.iloc[10:].to_hdf(path, "df", append=True) assert_frame_equal(read_hdf(path, "df"), df) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df = tm.makeDataFrame() df.to_hdf(path, "df", append=False, format="fixed") @@ -278,8 +271,7 @@ def test_api(self, setup_path): df.to_hdf(path, "df") assert_frame_equal(read_hdf(path, "df"), df) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: path = store._path df = tm.makeDataFrame() @@ -306,8 +298,7 @@ def test_api(self, setup_path): store.append("df", df.iloc[10:], append=True, format=None) assert_frame_equal(store.select("df"), df) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: # Invalid. df = tm.makeDataFrame() @@ -331,8 +322,7 @@ def test_api(self, setup_path): def test_api_default_format(self, setup_path): # default_format option - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: df = tm.makeDataFrame() pd.set_option("io.hdf.default_format", "fixed") @@ -352,8 +342,7 @@ def test_api_default_format(self, setup_path): pd.set_option("io.hdf.default_format", None) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df = tm.makeDataFrame() @@ -376,8 +365,7 @@ def test_api_default_format(self, setup_path): def test_keys(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store["a"] = tm.makeTimeSeries() store["b"] = tm.makeStringSeries() store["c"] = tm.makeDataFrame() @@ -392,8 +380,7 @@ def test_keys_ignore_hdf_softlink(self, setup_path): # GH 20523 # Puts a softlink into HDF file and rereads - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: df = DataFrame(dict(A=range(5), B=range(5))) store.put("df", df) @@ -407,15 +394,13 @@ def test_keys_ignore_hdf_softlink(self, setup_path): def test_iter_empty(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: # GH 12221 assert list(store) == [] def test_repr(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: repr(store) store.info() store["a"] = tm.makeTimeSeries() @@ -449,8 +434,7 @@ def test_repr(self, setup_path): store.info() # storers - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: df = tm.makeDataFrame() store.append("df", df) @@ -462,8 +446,7 @@ def test_repr(self, setup_path): @ignore_natural_naming_warning def test_contains(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store["a"] = tm.makeTimeSeries() store["b"] = tm.makeDataFrame() store["foo/bar"] = tm.makeDataFrame() @@ -482,8 +465,7 @@ def test_contains(self, setup_path): def test_versioning(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store["a"] = tm.makeTimeSeries() store["b"] = tm.makeDataFrame() df = tm.makeTimeDataFrame() @@ -510,8 +492,7 @@ def test_mode(self, setup_path): def check(mode): - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: # constructor if mode in ["r", "r+"]: @@ -523,8 +504,7 @@ def check(mode): assert store._handle.mode == mode store.close() - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: # context if mode in ["r", "r+"]: @@ -535,8 +515,7 @@ def check(mode): with HDFStore(path, mode=mode) as store: assert store._handle.mode == mode - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: # conv write if mode in ["r", "r+"]: @@ -557,8 +536,7 @@ def check(mode): def check_default_mode(): # read_hdf uses default mode - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df.to_hdf(path, "df", mode="w") result = read_hdf(path, "df") assert_frame_equal(result, df) @@ -571,8 +549,7 @@ def check_default_mode(): def test_reopen_handle(self, setup_path): - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: store = HDFStore(path, mode="a") store["a"] = tm.makeTimeSeries() @@ -620,8 +597,7 @@ def test_reopen_handle(self, setup_path): def test_open_args(self, setup_path): - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df = tm.makeDataFrame() @@ -642,16 +618,14 @@ def test_open_args(self, setup_path): def test_flush(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store["a"] = tm.makeTimeSeries() store.flush() store.flush(fsync=True) def test_get(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store["a"] = tm.makeTimeSeries() left = store.get("a") right = store["a"] @@ -726,8 +700,7 @@ def test_walk(self, where, expected, setup_path): def test_getattr(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: s = tm.makeTimeSeries() store["a"] = s @@ -754,8 +727,7 @@ def test_getattr(self, setup_path): def test_put(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: ts = tm.makeTimeSeries() df = tm.makeTimeDataFrame() @@ -786,8 +758,7 @@ def test_put(self, setup_path): def test_put_string_index(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: index = Index( ["I am a very long string index: {i}".format(i=i) for i in range(20)] @@ -816,8 +787,7 @@ def test_put_string_index(self, setup_path): def test_put_compression(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: df = tm.makeTimeDataFrame() store.put("c", df, format="table", complib="zlib") @@ -831,8 +801,7 @@ def test_put_compression(self, setup_path): def test_put_compression_blosc(self, setup_path): df = tm.makeTimeDataFrame() - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: # can't compress if format='fixed' with pytest.raises(ValueError): @@ -847,8 +816,7 @@ def test_complibs_default_settings(self, setup_path): # Set complevel and check if complib is automatically set to # default value - with ensure_clean_path(setup_path - ) as tmpfile: + with ensure_clean_path(setup_path) as tmpfile: df.to_hdf(tmpfile, "df", complevel=9) result = pd.read_hdf(tmpfile, "df") tm.assert_frame_equal(result, df) @@ -859,8 +827,7 @@ def test_complibs_default_settings(self, setup_path): assert node.filters.complib == "zlib" # Set complib and check to see if compression is disabled - with ensure_clean_path(setup_path - ) as tmpfile: + with ensure_clean_path(setup_path) as tmpfile: df.to_hdf(tmpfile, "df", complib="zlib") result = pd.read_hdf(tmpfile, "df") tm.assert_frame_equal(result, df) @@ -871,8 +838,7 @@ def test_complibs_default_settings(self, setup_path): assert node.filters.complib is None # Check if not setting complib or complevel results in no compression - with ensure_clean_path(setup_path - ) as tmpfile: + with ensure_clean_path(setup_path) as tmpfile: df.to_hdf(tmpfile, "df") result = pd.read_hdf(tmpfile, "df") tm.assert_frame_equal(result, df) @@ -883,8 +849,7 @@ def test_complibs_default_settings(self, setup_path): assert node.filters.complib is None # Check if file-defaults can be overridden on a per table basis - with ensure_clean_path(setup_path - ) as tmpfile: + with ensure_clean_path(setup_path) as tmpfile: store = pd.HDFStore(tmpfile) store.append("dfc", df, complevel=9, complib="blosc") store.append("df", df) @@ -915,8 +880,7 @@ def test_complibs(self, setup_path): all_tests = [(lib, lvl) for lib in all_complibs for lvl in all_levels] for (lib, lvl) in all_tests: - with ensure_clean_path(setup_path - ) as tmpfile: + with ensure_clean_path(setup_path) as tmpfile: gname = "foo" # Write and read file to see if data is consistent @@ -957,8 +921,7 @@ def test_put_mixed_type(self, setup_path): df.loc[3:6, ["obj1"]] = np.nan df = df._consolidate()._convert(datetime=True) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: _maybe_remove(store, "df") # PerformanceWarning @@ -974,8 +937,7 @@ def test_put_mixed_type(self, setup_path): ) def test_append(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: # this is allowed by almost always don't want to do it # tables.NaturalNameWarning): @@ -1043,8 +1005,7 @@ def test_append(self, setup_path): def test_append_series(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: # basic ss = tm.makeStringSeries() @@ -1092,8 +1053,7 @@ def test_store_index_types(self, setup_path): # GH5386 # test storing various index types - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: def check(format, index): df = DataFrame(np.random.randn(10, 2), columns=list("AB")) @@ -1128,8 +1088,7 @@ def check(format, index): ) def test_encoding(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: df = DataFrame(dict(A="foo", B="bar"), index=range(5)) df.loc[2, "A"] = np.nan df.loc[3, "B"] = np.nan @@ -1164,8 +1123,7 @@ def test_latin_encoding(self, setup_path, dtype, val): val = [x.decode(enc) if isinstance(x, bytes) else x for x in val] ser = pd.Series(val, dtype=dtype) - with ensure_clean_path(setup_path - ) as store: + with ensure_clean_path(setup_path) as store: ser.to_hdf(store, key, format="table", encoding=enc, nan_rep=nan_rep) retr = read_hdf(store, key) @@ -1184,8 +1142,7 @@ def test_latin_encoding(self, setup_path, dtype, val): def test_append_some_nans(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: df = DataFrame( { "A": Series(np.random.randn(20)).astype("int32"), @@ -1231,8 +1188,7 @@ def test_append_some_nans(self, setup_path): def test_append_all_nans(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: df = DataFrame( {"A1": np.random.randn(20), "A2": np.random.randn(20)}, @@ -1320,16 +1276,14 @@ def test_append_all_nans(self, setup_path): {"col1": [0, np.nan, 2], "col2": [1, np.nan, np.nan]} ) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df_with_missing.to_hdf(path, "df_with_missing", format="table") reloaded = read_hdf(path, "df_with_missing") tm.assert_frame_equal(df_with_missing, reloaded) def test_read_missing_key_close_store(self, setup_path): # GH 25766 - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df = pd.DataFrame({"a": range(2), "b": range(2)}) df.to_hdf(path, "k1") @@ -1342,8 +1296,7 @@ def test_read_missing_key_close_store(self, setup_path): def test_append_frame_column_oriented(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: # column oriented df = tm.makeTimeDataFrame() @@ -1368,8 +1321,7 @@ def test_append_frame_column_oriented(self, setup_path): def test_append_with_different_block_ordering(self, setup_path): # GH 4096; using same frames, but different block orderings - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: for i in range(10): @@ -1392,8 +1344,7 @@ def test_append_with_different_block_ordering(self, setup_path): # test a different ordering but with more fields (like invalid # combinate) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: df = DataFrame(np.random.randn(10, 2), columns=list("AB"), dtype="float64") df["int64"] = Series([1] * len(df), dtype="int64") @@ -1412,8 +1363,7 @@ def test_append_with_different_block_ordering(self, setup_path): def test_append_with_strings(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: with catch_warnings(record=True): def check_col(key, name, size): @@ -1487,8 +1437,7 @@ def check_col(key, name, size): result = store.select("df") tm.assert_frame_equal(result, df) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: def check_col(key, name, size): assert getattr( @@ -1530,8 +1479,7 @@ def check_col(key, name, size): def test_append_with_empty_string(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: # with all empty strings (GH 12242) df = DataFrame({"x": ["a", "b", "c", "d", "e", "f", ""]}) @@ -1541,8 +1489,7 @@ def test_append_with_empty_string(self, setup_path): def test_to_hdf_with_min_itemsize(self, setup_path): - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: # min_itemsize in index with to_hdf (GH 10381) df = tm.makeMixedDataFrame().set_index("C") @@ -1566,8 +1513,7 @@ def test_to_hdf_errors(self, format, setup_path): data = ["\ud800foo"] ser = pd.Series(data, index=pd.Index(data)) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: # GH 20835 ser.to_hdf(path, "table", format=format, errors="surrogatepass") @@ -1576,8 +1522,7 @@ def test_to_hdf_errors(self, format, setup_path): def test_append_with_data_columns(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: df = tm.makeTimeDataFrame() df.iloc[0, df.columns.get_loc("B")] = 1.0 _maybe_remove(store, "df") @@ -1618,8 +1563,7 @@ def check_col(key, name, size): == size ) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: _maybe_remove(store, "df") store.append( "df", df_new, data_columns=["string"], min_itemsize={"string": 30} @@ -1634,8 +1578,7 @@ def check_col(key, name, size): ) check_col("df", "string", 30) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: df_new["string2"] = "foobarbah" df_new["string_block1"] = "foobarbah1" df_new["string_block2"] = "foobarbah2" @@ -1650,8 +1593,7 @@ def check_col(key, name, size): check_col("df", "string2", 40) check_col("df", "values_block_1", 50) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: # multiple data columns df_new = df.copy() df_new.iloc[0, df_new.columns.get_loc("A")] = 1.0 @@ -1684,8 +1626,7 @@ def check_col(key, name, size): expected = df_new[(df_new.string == "foo") & (df_new.string2 == "cool")] tm.assert_frame_equal(result, expected, check_index_type=False) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: # doc example df_dc = df.copy() df_dc["string"] = "foo" @@ -1709,8 +1650,7 @@ def check_col(key, name, size): expected = df_dc[(df_dc.B > 0) & (df_dc.C > 0) & (df_dc.string == "foo")] tm.assert_frame_equal(result, expected, check_index_type=False) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: # doc example part 2 np.random.seed(1234) index = date_range("1/1/2000", periods=8) @@ -1736,8 +1676,7 @@ def check_col(key, name, size): def test_create_table_index(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: with catch_warnings(record=True): @@ -1775,8 +1714,7 @@ def test_append_hierarchical(self, setup_path): ) df = DataFrame(np.random.randn(10, 3), index=index, columns=["A", "B", "C"]) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.append("mi", df) result = store.select("mi") tm.assert_frame_equal(result, df) @@ -1804,8 +1742,7 @@ def test_column_multiindex(self, setup_path): if isinstance(expected.index, RangeIndex): expected.index = Int64Index(expected.index) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.put("df", df) tm.assert_frame_equal( @@ -1823,8 +1760,7 @@ def test_column_multiindex(self, setup_path): store.put("df3", df, format="table", data_columns=True) # appending multi-column on existing table (see GH 6167) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.append("df2", df) store.append("df2", df) @@ -1838,8 +1774,7 @@ def test_column_multiindex(self, setup_path): if isinstance(expected.index, RangeIndex): expected.index = Int64Index(expected.index) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.put("df1", df, format="table") tm.assert_frame_equal( @@ -1850,8 +1785,7 @@ def test_store_multiindex(self, setup_path): # validate multi-index names # GH 5527 - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: def make_index(names=None): return MultiIndex.from_tuples( @@ -1931,8 +1865,7 @@ def test_select_columns_in_where(self, setup_path): # With a DataFrame df = DataFrame(np.random.randn(10, 3), index=index, columns=["A", "B", "C"]) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.put("df", df, format="table") expected = df[["A"]] @@ -1942,8 +1875,7 @@ def test_select_columns_in_where(self, setup_path): # With a Series s = Series(np.random.randn(10), index=index, name="A") - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.put("s", s, format="table") tm.assert_series_equal(store.select("s", where="columns=['A']"), s) @@ -1954,8 +1886,7 @@ def test_mi_data_columns(self, setup_path): ) df = pd.DataFrame({"a": [1.1, 1.2, 1.3, 1.4, 1.5]}, index=idx) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.append("df", df, data_columns=True) actual = store.select("df", where="id == 1") @@ -1966,8 +1897,7 @@ def test_pass_spec_to_storer(self, setup_path): df = tm.makeDataFrame() - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.put("df", df) with pytest.raises(TypeError): store.select("df", columns=["A"]) @@ -1977,8 +1907,7 @@ def test_pass_spec_to_storer(self, setup_path): @xfail_non_writeable def test_append_misc(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: df = tm.makeDataFrame() store.append("df", df, chunksize=1) result = store.select("df") @@ -1991,8 +1920,7 @@ def test_append_misc(self, setup_path): # more chunksize in append tests def check(obj, comparator): for c in [10, 200, 1000]: - with ensure_clean_store(setup_path - , mode="w") as store: + with ensure_clean_store(setup_path, mode="w") as store: store.append("obj", obj, chunksize=c) result = store.select("obj") comparator(result, obj) @@ -2007,8 +1935,7 @@ def check(obj, comparator): check(df, tm.assert_frame_equal) # empty frame, GH4273 - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: # 0 len df_empty = DataFrame(columns=list("ABC")) @@ -2030,8 +1957,7 @@ def check(obj, comparator): def test_append_raise(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: # test append with invalid input to get good error messages @@ -2078,16 +2004,14 @@ def test_table_index_incompatible_dtypes(self, setup_path): df1 = DataFrame({"a": [1, 2, 3]}) df2 = DataFrame({"a": [4, 5, 6]}, index=date_range("1/1/2000", periods=3)) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.put("frame", df1, format="table") with pytest.raises(TypeError): store.put("frame", df2, format="table", append=True) def test_table_values_dtypes_roundtrip(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: df1 = DataFrame({"a": [1, 2, 3]}, dtype="f8") store.append("df_f8", df1) assert_series_equal(df1.dtypes, store["df_f8"].dtypes) @@ -2159,15 +2083,13 @@ def test_table_mixed_dtypes(self, setup_path): df.loc[3:6, ["obj1"]] = np.nan df = df._consolidate()._convert(datetime=True) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.append("df1_mixed", df) tm.assert_frame_equal(store.select("df1_mixed"), df) def test_unimplemented_dtypes_table_columns(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: dtypes = [("date", datetime.date(2001, 1, 2))] @@ -2185,8 +2107,7 @@ def test_unimplemented_dtypes_table_columns(self, setup_path): df["datetime1"] = datetime.date(2001, 1, 2) df = df._consolidate()._convert(datetime=True) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: # this fails because we have a date in the object block...... with pytest.raises(TypeError): store.append("df_unimplemented", df) @@ -2217,8 +2138,7 @@ def test_calendar_roundtrip_issue(self, setup_path): s = Series(dts.weekday, dts).map(Series("Mon Tue Wed Thu Fri Sat Sun".split())) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.put("fixed", s) result = store.select("fixed") @@ -2233,8 +2153,7 @@ def test_roundtrip_tz_aware_index(self, setup_path): time = pd.Timestamp("2000-01-01 01:00:00", tz="US/Eastern") df = pd.DataFrame(data=[0], index=[time]) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.put("frame", df, format="fixed") recons = store["frame"] tm.assert_frame_equal(recons, df) @@ -2256,8 +2175,7 @@ def test_append_with_timedelta(self, setup_path): df["C"] = df["A"] - df["B"] df.loc[3:5, "C"] = np.nan - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: # table _maybe_remove(store, "df") @@ -2292,8 +2210,7 @@ def test_append_with_timedelta(self, setup_path): def test_remove(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: ts = tm.makeTimeSeries() df = tm.makeDataFrame() @@ -2333,8 +2250,7 @@ def test_remove(self, setup_path): def test_invalid_terms(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: with catch_warnings(record=True): @@ -2356,8 +2272,7 @@ def test_invalid_terms(self, setup_path): store.select("df", "index>") # from the docs - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: dfq = DataFrame( np.random.randn(10, 4), columns=list("ABCD"), @@ -2372,8 +2287,7 @@ def test_invalid_terms(self, setup_path): read_hdf(path, "dfq", where="A>0 or C>0") # catch the invalid reference - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: dfq = DataFrame( np.random.randn(10, 4), columns=list("ABCD"), @@ -2386,8 +2300,7 @@ def test_invalid_terms(self, setup_path): def test_same_name_scoping(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: import pandas as pd @@ -2423,7 +2336,9 @@ def test_series(self, setup_path): self._check_roundtrip(ts2, tm.assert_series_equal, path=setup_path) ts3 = Series(ts.values, Index(np.asarray(ts.index, dtype=object), dtype=object)) - self._check_roundtrip(ts3, tm.assert_series_equal, path=setup_path, check_index_type=False) + self._check_roundtrip( + ts3, tm.assert_series_equal, path=setup_path, check_index_type=False + ) def test_float_index(self, setup_path): @@ -2521,14 +2436,19 @@ def test_frame(self, compression, setup_path): df.values[0, 0] = np.nan df.values[5, 3] = np.nan - self._check_roundtrip_table(df, tm.assert_frame_equal, path=setup_path, compression=compression) - self._check_roundtrip(df, tm.assert_frame_equal, path=setup_path, compression=compression) + self._check_roundtrip_table( + df, tm.assert_frame_equal, path=setup_path, compression=compression + ) + self._check_roundtrip( + df, tm.assert_frame_equal, path=setup_path, compression=compression + ) tdf = tm.makeTimeDataFrame() - self._check_roundtrip(tdf, tm.assert_frame_equal, path=setup_path, compression=compression) + self._check_roundtrip( + tdf, tm.assert_frame_equal, path=setup_path, compression=compression + ) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: # not consolidated df["foo"] = np.random.randn(len(df)) store["df"] = df @@ -2580,8 +2500,7 @@ def test_store_hierarchical(self, setup_path): self._check_roundtrip(frame["A"], tm.assert_series_equal, path=setup_path) # check that the names are stored - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store["frame"] = frame recons = store["frame"] tm.assert_frame_equal(recons, frame) @@ -2590,8 +2509,7 @@ def test_store_index_name(self, setup_path): df = tm.makeDataFrame() df.index.name = "foo" - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store["frame"] = df recons = store["frame"] tm.assert_frame_equal(recons, df) @@ -2603,8 +2521,7 @@ def test_store_index_name_with_tz(self, setup_path): df.index = df.index.tz_localize("UTC") df.index.name = "foo" - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.put("frame", df, format="table") recons = store["frame"] tm.assert_frame_equal(recons, df) @@ -2623,8 +2540,7 @@ def test_store_index_name_numpy_str(self, table_format, setup_path): df = pd.DataFrame(np.arange(4).reshape(2, 2), columns=idx, index=idx1) # This used to fail, returning numpy strings instead of python strings. - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df.to_hdf(path, "df", format=table_format) df2 = read_hdf(path, "df") @@ -2637,8 +2553,7 @@ def test_store_series_name(self, setup_path): df = tm.makeDataFrame() series = df["A"] - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store["series"] = series recons = store["series"] tm.assert_series_equal(recons, series) @@ -2664,8 +2579,7 @@ def _make_one(): self._check_roundtrip(df1, tm.assert_frame_equal, path=setup_path) self._check_roundtrip(df2, tm.assert_frame_equal, path=setup_path) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store["obj"] = df1 tm.assert_frame_equal(store["obj"], df1) store["obj"] = df2 @@ -2673,13 +2587,22 @@ def _make_one(): # check that can store Series of all of these types self._check_roundtrip( - df1["obj1"], tm.assert_series_equal, path=setup_path, compression=compression + df1["obj1"], + tm.assert_series_equal, + path=setup_path, + compression=compression, ) self._check_roundtrip( - df1["bool1"], tm.assert_series_equal, path=setup_path, compression=compression + df1["bool1"], + tm.assert_series_equal, + path=setup_path, + compression=compression, ) self._check_roundtrip( - df1["int1"], tm.assert_series_equal, path=setup_path, compression=compression + df1["int1"], + tm.assert_series_equal, + path=setup_path, + compression=compression, ) @pytest.mark.filterwarnings( @@ -2691,8 +2614,7 @@ def test_select_with_dups(self, setup_path): df = DataFrame(np.random.randn(10, 4), columns=["A", "A", "B", "B"]) df.index = date_range("20130101 9:30", periods=10, freq="T") - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.append("df", df) result = store.select("df") @@ -2719,8 +2641,7 @@ def test_select_with_dups(self, setup_path): ) df.index = date_range("20130101 9:30", periods=10, freq="T") - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.append("df", df) result = store.select("df") @@ -2740,8 +2661,7 @@ def test_select_with_dups(self, setup_path): assert_frame_equal(result, expected, by_blocks=True) # duplicates on both index and columns - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.append("df", df) store.append("df", df) @@ -2752,8 +2672,7 @@ def test_select_with_dups(self, setup_path): def test_overwrite_node(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store["a"] = tm.makeTimeDataFrame() ts = tm.makeTimeSeries() store["a"] = ts @@ -2762,8 +2681,7 @@ def test_overwrite_node(self, setup_path): def test_select(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: with catch_warnings(record=True): @@ -2803,8 +2721,7 @@ def test_select(self, setup_path): def test_select_dtypes(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: # with a Timestamp data column (GH #2637) df = DataFrame( dict(ts=bdate_range("2012-01-01", periods=300), A=np.random.randn(300)) @@ -2860,8 +2777,7 @@ def test_select_dtypes(self, setup_path): expected = df.reindex(index=list(df.index)[0:10], columns=["A"]) tm.assert_frame_equal(expected, result) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: # floats w/o NaN df = DataFrame(dict(cols=range(11), values=range(11)), dtype="float64") @@ -2900,8 +2816,7 @@ def test_select_dtypes(self, setup_path): # test selection with comparison against numpy scalar # GH 11283 - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: df = tm.makeDataFrame() expected = df[df["A"] > 0] @@ -2913,8 +2828,7 @@ def test_select_dtypes(self, setup_path): def test_select_with_many_inputs(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: df = DataFrame( dict( @@ -2968,8 +2882,7 @@ def test_select_with_many_inputs(self, setup_path): def test_select_iterator(self, setup_path): # single table - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: df = tm.makeTimeDataFrame(500) _maybe_remove(store, "df") @@ -2990,8 +2903,7 @@ def test_select_iterator(self, setup_path): result = concat(results) tm.assert_frame_equal(result, expected) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df = tm.makeTimeDataFrame(500) df.to_hdf(path, "df_non_table") @@ -3002,8 +2914,7 @@ def test_select_iterator(self, setup_path): with pytest.raises(TypeError): read_hdf(path, "df_non_table", iterator=True) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df = tm.makeTimeDataFrame(500) df.to_hdf(path, "df", format="table") @@ -3017,8 +2928,7 @@ def test_select_iterator(self, setup_path): # multiple - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: df1 = tm.makeTimeDataFrame(500) store.append("df1", df1, data_columns=True) @@ -3046,8 +2956,7 @@ def test_select_iterator_complete_8014(self, setup_path): chunksize = 1e4 # no iterator - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: expected = tm.makeTimeDataFrame(100064, "S") _maybe_remove(store, "df") @@ -3081,8 +2990,7 @@ def test_select_iterator_complete_8014(self, setup_path): tm.assert_frame_equal(expected, result) # with iterator, full range - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: expected = tm.makeTimeDataFrame(100064, "S") _maybe_remove(store, "df") @@ -3123,8 +3031,7 @@ def test_select_iterator_non_complete_8014(self, setup_path): chunksize = 1e4 # with iterator, non complete range - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: expected = tm.makeTimeDataFrame(100064, "S") _maybe_remove(store, "df") @@ -3159,8 +3066,7 @@ def test_select_iterator_non_complete_8014(self, setup_path): tm.assert_frame_equal(rexpected, result) # with iterator, empty where - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: expected = tm.makeTimeDataFrame(100064, "S") _maybe_remove(store, "df") @@ -3181,8 +3087,7 @@ def test_select_iterator_many_empty_frames(self, setup_path): chunksize = int(1e4) # with iterator, range limited to the first chunk - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: expected = tm.makeTimeDataFrame(100000, "S") _maybe_remove(store, "df") @@ -3246,8 +3151,7 @@ def test_retain_index_attributes(self, setup_path): dict(A=Series(range(3), index=date_range("2000-1-1", periods=3, freq="H"))) ) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: _maybe_remove(store, "data") store.put("data", df, format="table") @@ -3301,8 +3205,7 @@ def test_retain_index_attributes(self, setup_path): "ignore:\\nthe :pandas.io.pytables.AttributeConflictWarning" ) def test_retain_index_attributes2(self, setup_path): - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: with catch_warnings(record=True): @@ -3343,8 +3246,7 @@ def test_frame_select(self, setup_path): df = tm.makeTimeDataFrame() - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.put("frame", df, format="table") date = df.index[len(df) // 2] @@ -3380,8 +3282,7 @@ def test_frame_select_complex(self, setup_path): df["string"] = "foo" df.loc[df.index[0:4], "string"] = "bar" - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.put("df", df, format="table", data_columns=["string"]) # empty @@ -3496,8 +3397,7 @@ def test_invalid_filtering(self, setup_path): df = tm.makeTimeDataFrame() - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.put("df", df, format="table") # not implemented @@ -3510,8 +3410,7 @@ def test_invalid_filtering(self, setup_path): def test_string_select(self, setup_path): # GH 2973 - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: df = tm.makeTimeDataFrame() @@ -3555,8 +3454,7 @@ def test_read_column(self, setup_path): df = tm.makeTimeDataFrame() - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: _maybe_remove(store, "df") # GH 17912 @@ -3628,8 +3526,7 @@ def test_read_column(self, setup_path): def test_coordinates(self, setup_path): df = tm.makeTimeDataFrame() - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: _maybe_remove(store, "df") store.append("df", df) @@ -3674,8 +3571,7 @@ def test_coordinates(self, setup_path): tm.assert_frame_equal(result, expected) # pass array/mask as the coordinates - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: df = DataFrame( np.random.randn(1000, 2), index=date_range("20000101", periods=1000) @@ -3737,8 +3633,7 @@ def test_append_to_multiple(self, setup_path): df2["foo"] = "bar" df = concat([df1, df2], axis=1) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: # exceptions with pytest.raises(ValueError): @@ -3768,8 +3663,7 @@ def test_append_to_multiple_dropna(self, setup_path): df1.iloc[1, df1.columns.get_indexer(["A", "B"])] = np.nan df = concat([df1, df2], axis=1) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: # dropna=True should guarantee rows are synchronized store.append_to_multiple( @@ -3789,8 +3683,7 @@ def test_append_to_multiple_dropna_false(self, setup_path): df1.iloc[1, df1.columns.get_indexer(["A", "B"])] = np.nan df = concat([df1, df2], axis=1) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: # dropna=False shouldn't synchronize row indexes store.append_to_multiple( @@ -3808,8 +3701,7 @@ def test_select_as_multiple(self, setup_path): df2 = tm.makeTimeDataFrame().rename(columns="{}_2".format) df2["foo"] = "bar" - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: # no tables stored with pytest.raises(Exception): @@ -3879,8 +3771,7 @@ def test_select_as_multiple(self, setup_path): ) def test_nan_selection_bug_4858(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: df = DataFrame(dict(cols=range(6), values=range(6)), dtype="float64") df["cols"] = (df["cols"] + 10).apply(str) @@ -3898,8 +3789,7 @@ def test_nan_selection_bug_4858(self, setup_path): def test_start_stop_table(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: # table df = DataFrame(dict(A=np.random.rand(20), B=np.random.rand(20))) @@ -3918,8 +3808,7 @@ def test_start_stop_table(self, setup_path): def test_start_stop_multiple(self, setup_path): # GH 16209 - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: df = DataFrame({"foo": [1, 2], "bar": [1, 2]}) @@ -3934,8 +3823,7 @@ def test_start_stop_multiple(self, setup_path): def test_start_stop_fixed(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: # fixed, GH 8287 df = DataFrame( @@ -3979,8 +3867,7 @@ def test_select_filter_corner(self, setup_path): df.index = ["{c:3d}".format(c=c) for c in df.index] df.columns = ["{c:3d}".format(c=c) for c in df.columns] - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.put("frame", df, format="table") crit = "columns=df.columns[:75]" @@ -4010,8 +3897,7 @@ def test_contiguous_mixed_data_table(self, start, stop, setup_path): } ) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.append("test_dataset", df) result = store.select("test_dataset", start=start, stop=stop) @@ -4058,19 +3944,19 @@ def _check_roundtrip(self, obj, comparator, path, compression=False, **kwargs): if compression: options["complib"] = _default_compressor - with ensure_clean_store(path - , "w", **options) as store: + with ensure_clean_store(path, "w", **options) as store: store["obj"] = obj retrieved = store["obj"] comparator(retrieved, obj, **kwargs) - def _check_double_roundtrip(self, obj, comparator, path, compression=False, **kwargs): + def _check_double_roundtrip( + self, obj, comparator, path, compression=False, **kwargs + ): options = {} if compression: options["complib"] = compression or _default_compressor - with ensure_clean_store(path - , "w", **options) as store: + with ensure_clean_store(path, "w", **options) as store: store["obj"] = obj retrieved = store["obj"] comparator(retrieved, obj, **kwargs) @@ -4083,8 +3969,7 @@ def _check_roundtrip_table(self, obj, comparator, path, compression=False): if compression: options["complib"] = _default_compressor - with ensure_clean_store(path - , "w", **options) as store: + with ensure_clean_store(path, "w", **options) as store: store.put("obj", obj, format="table") retrieved = store["obj"] @@ -4093,8 +3978,7 @@ def _check_roundtrip_table(self, obj, comparator, path, compression=False): def test_multiple_open_close(self, setup_path): # gh-4409: open & close multiple times - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df = tm.makeDataFrame() df.to_hdf(path, "df", mode="w", format="table") @@ -4108,8 +3992,7 @@ def test_multiple_open_close(self, setup_path): assert "CLOSED" in store.info() assert not store.is_open - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: if pytables._table_file_open_policy_is_strict: @@ -4171,8 +4054,7 @@ def test_multiple_open_close(self, setup_path): assert not store2.is_open # ops on a closed store - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df = tm.makeDataFrame() df.to_hdf(path, "df", mode="w", format="table") @@ -4309,8 +4191,7 @@ def do_copy(f, new_f=None, keys=None, propindexes=True, **kwargs): df = tm.makeDataFrame() try: - path = create_tempfile(setup_path - ) + path = create_tempfile(setup_path) st = HDFStore(path) st.append("df", df, data_columns=["A"]) st.close() @@ -4321,8 +4202,7 @@ def do_copy(f, new_f=None, keys=None, propindexes=True, **kwargs): def test_store_datetime_fractional_secs(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: dt = datetime.datetime(2012, 1, 2, 3, 4, 5, 123456) series = Series([0], [dt]) store["a"] = series @@ -4330,8 +4210,7 @@ def test_store_datetime_fractional_secs(self, setup_path): def test_tseries_indices_series(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: idx = tm.makeDateIndex(10) ser = Series(np.random.randn(len(idx)), idx) store["a"] = ser @@ -4352,8 +4231,7 @@ def test_tseries_indices_series(self, setup_path): def test_tseries_indices_frame(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: idx = tm.makeDateIndex(10) df = DataFrame(np.random.randn(len(idx), 3), index=idx) store["a"] = df @@ -4386,15 +4264,13 @@ def test_unicode_longer_encoded(self, setup_path): # GH 11234 char = "\u0394" df = pd.DataFrame({"A": [char]}) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.put("df", df, format="table", encoding="utf-8") result = store.get("df") tm.assert_frame_equal(result, df) df = pd.DataFrame({"A": ["a", char], "B": ["b", "b"]}) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.put("df", df, format="table", encoding="utf-8") result = store.get("df") tm.assert_frame_equal(result, df) @@ -4424,8 +4300,7 @@ def test_append_with_diff_col_name_types_raises_value_error(self, setup_path): df4 = DataFrame({("1", 2): np.random.randn(10)}) df5 = DataFrame({("1", 2, object): np.random.randn(10)}) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: name = "df_{}".format(tm.rands(10)) store.append(name, df) @@ -4441,16 +4316,14 @@ def test_query_with_nested_special_character(self, setup_path): } ) expected = df[df.a == "test & test"] - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.append("test", df, format="table", data_columns=True) result = store.select("test", 'a = "test & test"') tm.assert_frame_equal(expected, result) def test_categorical(self, setup_path): - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: # Basic _maybe_remove(store, "s") @@ -4582,8 +4455,7 @@ def test_categorical_conversion(self, setup_path): # We are expecting an empty DataFrame matching types of df expected = df.iloc[[], :] - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df.to_hdf(path, "df", format="table", data_columns=True) result = read_hdf(path, "df", where="obsids=B") tm.assert_frame_equal(result, expected) @@ -4594,8 +4466,7 @@ def test_categorical_conversion(self, setup_path): # We are expecting an empty DataFrame matching types of df expected = df.iloc[[], :] - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df.to_hdf(path, "df", format="table", data_columns=True) result = read_hdf(path, "df", where="obsids=B") tm.assert_frame_equal(result, expected) @@ -4616,8 +4487,7 @@ def test_categorical_nan_only_columns(self, setup_path): df["b"] = df.b.astype("category") df["d"] = df.b.astype("category") expected = df - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df.to_hdf(path, "df", format="table", data_columns=True) result = read_hdf(path, "df") tm.assert_frame_equal(result, expected) @@ -4625,8 +4495,7 @@ def test_categorical_nan_only_columns(self, setup_path): def test_duplicate_column_name(self, setup_path): df = DataFrame(columns=["a", "a"], data=[[0, 0]]) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: with pytest.raises(ValueError): df.to_hdf(path, "df", format="fixed") @@ -4641,8 +4510,7 @@ def test_round_trip_equals(self, setup_path): # GH 9330 df = DataFrame({"B": [1, 2], "A": ["x", "y"]}) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df.to_hdf(path, "df", format="table") other = read_hdf(path, "df") tm.assert_frame_equal(df, other) @@ -4656,8 +4524,7 @@ def test_preserve_timedeltaindex_type(self, setup_path): df = DataFrame(np.random.normal(size=(10, 5))) df.index = timedelta_range(start="0s", periods=10, freq="1s", name="example") - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store["df"] = df assert_frame_equal(store["df"], df) @@ -4672,8 +4539,7 @@ def test_columns_multiindex_modified(self, setup_path): df = df.set_index(keys="E", append=True) data_columns = df.index.names + df.columns.tolist() - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df.to_hdf( path, "df", @@ -4708,8 +4574,7 @@ def test_to_hdf_with_object_column_names(self, setup_path): for index in types_should_fail: df = DataFrame(np.random.randn(10, 2), columns=index(2)) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: with catch_warnings(record=True): msg = "cannot have non-object label DataIndexableCol" with pytest.raises(ValueError, match=msg): @@ -4717,8 +4582,7 @@ def test_to_hdf_with_object_column_names(self, setup_path): for index in types_should_run: df = DataFrame(np.random.randn(10, 2), columns=index(2)) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: with catch_warnings(record=True): df.to_hdf(path, "df", format="table", data_columns=True) result = pd.read_hdf( @@ -4733,8 +4597,7 @@ def test_read_hdf_open_store(self, setup_path): df.index.name = "letters" df = df.set_index(keys="E", append=True) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df.to_hdf(path, "df", mode="w") direct = read_hdf(path, "df") store = HDFStore(path, mode="r") @@ -4748,8 +4611,7 @@ def test_read_hdf_iterator(self, setup_path): df.index.name = "letters" df = df.set_index(keys="E", append=True) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df.to_hdf(path, "df", mode="w", format="t") direct = read_hdf(path, "df") iterator = read_hdf(path, "df", iterator=True) @@ -4761,8 +4623,7 @@ def test_read_hdf_iterator(self, setup_path): def test_read_hdf_errors(self, setup_path): df = DataFrame(np.random.rand(4, 5), index=list("abcd"), columns=list("ABCDE")) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: with pytest.raises(IOError): read_hdf(path, "key") @@ -4779,8 +4640,7 @@ def test_read_hdf_generic_buffer_errors(self): def test_invalid_complib(self, setup_path): df = DataFrame(np.random.rand(4, 5), index=list("abcd"), columns=list("ABCDE")) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: with pytest.raises(ValueError): df.to_hdf(path, "df", complib="foolib") @@ -4791,8 +4651,7 @@ def test_read_nokey(self, setup_path): # Categorical dtype not supported for "fixed" format. So no need # to test with that dtype in the dataframe here. - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df.to_hdf(path, "df", mode="a") reread = read_hdf(path) assert_frame_equal(df, reread) @@ -4805,8 +4664,7 @@ def test_read_nokey_table(self, setup_path): # GH13231 df = DataFrame({"i": range(5), "c": Series(list("abacd"), dtype="category")}) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df.to_hdf(path, "df", mode="a", format="table") reread = read_hdf(path) assert_frame_equal(df, reread) @@ -4816,8 +4674,7 @@ def test_read_nokey_table(self, setup_path): read_hdf(path) def test_read_nokey_empty(self, setup_path): - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: store = HDFStore(path) store.close() @@ -4833,8 +4690,7 @@ def test_read_from_pathlib_path(self, setup_path): expected = DataFrame( np.random.rand(4, 5), index=list("abcd"), columns=list("ABCDE") ) - with ensure_clean_path(setup_path - ) as filename: + with ensure_clean_path(setup_path) as filename: path_obj = Path(filename) expected.to_hdf(path_obj, "df", mode="a") @@ -4851,8 +4707,7 @@ def test_read_from_py_localpath(self, setup_path): expected = DataFrame( np.random.rand(4, 5), index=list("abcd"), columns=list("ABCDE") ) - with ensure_clean_path(setup_path - ) as filename: + with ensure_clean_path(setup_path) as filename: path_obj = LocalPath(filename) expected.to_hdf(path_obj, "df", mode="a") @@ -4864,8 +4719,7 @@ def test_query_long_float_literal(self, setup_path): # GH 14241 df = pd.DataFrame({"A": [1000000000.0009, 1000000000.0011, 1000000000.0015]}) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.append("test", df, format="table", data_columns=True) cutoff = 1000000000.0006 @@ -4894,8 +4748,7 @@ def test_query_compare_column_type(self, setup_path): columns=["date", "real_date", "float", "int"], ) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.append("test", df, format="table", data_columns=True) ts = pd.Timestamp("2014-01-01") # noqa @@ -4937,8 +4790,7 @@ def test_read_hdf_series_mode_r(self, format, setup_path): # Tests that reading a Series saved to an HDF file # still works if a mode='r' argument is supplied series = tm.makeFloatSeries() - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: series.to_hdf(path, key="data", format=format) result = pd.read_hdf(path, key="data", mode="r") tm.assert_series_equal(result, series) @@ -5000,13 +4852,12 @@ def test_to_hdf_multiindex_extension_dtype(self, idx, setup_path): # GH 7775 mi = MultiIndex.from_arrays([idx, idx]) df = pd.DataFrame(0, index=mi, columns=["a"]) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: with pytest.raises(NotImplementedError, match="Saving a MultiIndex"): df.to_hdf(path, "df") -class TestHDFComplexValues(): +class TestHDFComplexValues: # GH10447 def test_complex_fixed(self, setup_path): @@ -5016,8 +4867,7 @@ def test_complex_fixed(self, setup_path): columns=list("ABCDE"), ) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df.to_hdf(path, "df") reread = read_hdf(path, "df") assert_frame_equal(df, reread) @@ -5027,8 +4877,7 @@ def test_complex_fixed(self, setup_path): index=list("abcd"), columns=list("ABCDE"), ) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df.to_hdf(path, "df") reread = read_hdf(path, "df") assert_frame_equal(df, reread) @@ -5040,8 +4889,7 @@ def test_complex_table(self, setup_path): columns=list("ABCDE"), ) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df.to_hdf(path, "df", format="table") reread = read_hdf(path, "df") assert_frame_equal(df, reread) @@ -5052,8 +4900,7 @@ def test_complex_table(self, setup_path): columns=list("ABCDE"), ) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df.to_hdf(path, "df", format="table", mode="w") reread = read_hdf(path, "df") assert_frame_equal(df, reread) @@ -5076,8 +4923,7 @@ def test_complex_mixed_fixed(self, setup_path): }, index=list("abcd"), ) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df.to_hdf(path, "df") reread = read_hdf(path, "df") assert_frame_equal(df, reread) @@ -5100,14 +4946,12 @@ def test_complex_mixed_table(self, setup_path): index=list("abcd"), ) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.append("df", df, data_columns=["A", "B"]) result = store.select("df", where="A>2") assert_frame_equal(df.loc[df.A > 2], result) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: df.to_hdf(path, "df", format="table") reread = read_hdf(path, "df") assert_frame_equal(df, reread) @@ -5121,8 +4965,7 @@ def test_complex_across_dimensions_fixed(self, setup_path): objs = [s, df] comps = [tm.assert_series_equal, tm.assert_frame_equal] for obj, comp in zip(objs, comps): - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: obj.to_hdf(path, "obj", format="fixed") reread = read_hdf(path, "obj") comp(obj, reread) @@ -5137,8 +4980,7 @@ def test_complex_across_dimensions(self, setup_path): objs = [df] comps = [tm.assert_frame_equal] for obj, comp in zip(objs, comps): - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: obj.to_hdf(path, "obj", format="table") reread = read_hdf(path, "obj") comp(obj, reread) @@ -5151,8 +4993,7 @@ def test_complex_indexing_error(self, setup_path): {"A": [1, 2, 3, 4], "B": ["a", "b", "c", "d"], "C": complex128}, index=list("abcd"), ) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: with pytest.raises(TypeError): store.append("df", df, data_columns=["C"]) @@ -5160,13 +5001,11 @@ def test_complex_series_error(self, setup_path): complex128 = np.array([1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j]) s = Series(complex128, index=list("abcd")) - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: with pytest.raises(TypeError): s.to_hdf(path, "obj", format="t") - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: s.to_hdf(path, "obj", format="t", index=False) reread = read_hdf(path, "obj") tm.assert_series_equal(s, reread) @@ -5176,8 +5015,7 @@ def test_complex_append(self, setup_path): {"a": np.random.randn(100).astype(np.complex128), "b": np.random.randn(100)} ) - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: store.append("df", df, data_columns=["b"]) store.append("df", df) result = store.select("df") @@ -5185,7 +5023,7 @@ def test_complex_append(self, setup_path): # @pytest.mark.usefixtures("setup_path") -class TestTimezones(): +class TestTimezones: def _compare_with_tz(self, a, b): tm.assert_frame_equal(a, b) @@ -5478,8 +5316,7 @@ def test_store_timezone(self, setup_path): assert_frame_equal(result, df) # with tz setting - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: with set_timezone("EST5EDT"): today = datetime.date(2013, 9, 10) @@ -5509,8 +5346,7 @@ def test_legacy_datetimetz_object(self, datapath, setup_path): def test_dst_transitions(self, setup_path): # make sure we are not failing on transitions - with ensure_clean_store(setup_path - ) as store: + with ensure_clean_store(setup_path) as store: times = pd.date_range( "2013-10-26 23:00", "2013-10-27 01:00", @@ -5534,8 +5370,7 @@ def test_read_with_where_tz_aware_index(self, setup_path): expected = pd.DataFrame({"MYCOL": 0}, index=mi) key = "mykey" - with ensure_clean_path(setup_path - ) as path: + with ensure_clean_path(setup_path) as path: with pd.HDFStore(path) as store: store.append(key, expected, format="table", append=True) result = pd.read_hdf(path, key, where="DATE > 20151130")