|
12 | 12 | from statsmodels.stats.weightstats import DescrStatsW |
13 | 13 |
|
14 | 14 | from ..compat import _pattern_type, int_types, str2bytes |
15 | | -from ..tools import all_type, format_error, isiterable, operator |
| 15 | +from ..tools import all_type, format_error, isiterable, operator, make_Class |
16 | 16 | from ..tools.file import HDFFileManager, best_saver, file_dialog |
17 | 17 | from ..tools.widgets import RangeSelect |
18 | 18 | from .array import DataArray |
@@ -401,7 +401,10 @@ def section(datafile, x=None, y=None, z=None, r=None, accuracy=0.0, **kwargs): |
401 | 401 | if z is not None: |
402 | 402 | tmp.data = tmp.search(zcol, z, accuracy=accuracy) |
403 | 403 | if r is not None: |
404 | | - func = lambda x, row: r(row[xcol], row[ycol], row[zcol]) |
| 404 | + |
| 405 | + def func(_, row): |
| 406 | + return r(row[xcol], row[ycol], row[zcol]) |
| 407 | + |
405 | 408 | tmp.data = tmp.search(0, func, accuracy=accuracy) |
406 | 409 |
|
407 | 410 | if kwargs: # Fallback to working with select if nothing else. |
@@ -598,7 +601,7 @@ def split(datafile, *args, final="files"): |
598 | 601 | There has been a change in the arguments for the split function from version 0.8 of the Stoner |
599 | 602 | Package. |
600 | 603 | """ |
601 | | - from Stoner import DataFolder |
| 604 | + DataFolder = make_Class("DataFolder", None) |
602 | 605 |
|
603 | 606 | if not args: |
604 | 607 | xcol = datafile.setas._get_cols("xcol") |
@@ -753,7 +756,7 @@ def add_column(datafile, column_data, header=None, index=None, func_args=None, r |
753 | 756 | case (_, _): |
754 | 757 | (dr, dc) = datafile.data.shape |
755 | 758 | case _ if not datafile.data.shape: |
756 | | - datafile.data = np.array([list()]) |
| 759 | + datafile.data = np.array([[]]) |
757 | 760 | (dr, dc) = (0, 0) |
758 | 761 | case _: |
759 | 762 | raise ValueError("Data should be 1 or 2 dimensional") |
@@ -841,8 +844,7 @@ def columns(datafile, not_masked=False, reset=False): |
841 | 844 | continue |
842 | 845 | if reset: |
843 | 846 | return |
844 | | - else: |
845 | | - yield datafile.column(ix) |
| 847 | + yield datafile.column(ix) |
846 | 848 |
|
847 | 849 |
|
848 | 850 | def del_column(datafile, col=None, duplicates=False): |
@@ -903,11 +905,11 @@ def del_column(datafile, col=None, duplicates=False): |
903 | 905 | datafile.column_headers = ch |
904 | 906 | elif isiterable(col) and all_type(col, bool): # If col is an iterable of booleans then we index by that |
905 | 907 | col = ~np.array(col) |
| 908 | + col_hdrs = np.array(datafile.column_headers)[col] |
906 | 909 | new_setas = np.array(datafile.setas)[col] |
907 | | - new_column_headers = np.array(datafile.column_headers)[col] |
908 | 910 | datafile.data = datafile.data[:, col] |
909 | 911 | datafile.setas = new_setas |
910 | | - datafile.column_headers = new_column_headers |
| 912 | + datafile.column_headers = col_hdrs |
911 | 913 | else: # Otherwise find individual columns |
912 | 914 | c = datafile.find_col(col) |
913 | 915 | ch = datafile.column_headers |
@@ -1011,7 +1013,7 @@ def del_rows(datafile, col=None, val=None, invert=False): |
1011 | 1013 | return datafile |
1012 | 1014 |
|
1013 | 1015 |
|
1014 | | -def dir(datafile, pattern=None): |
| 1016 | +def dir(datafile, pattern=None): # pylint: disable=redefined-builtin |
1015 | 1017 | """Return a list of keys in the metadata, filtering with a regular expression if necessary. |
1016 | 1018 |
|
1017 | 1019 | Args: |
@@ -1156,8 +1158,7 @@ def rows(datafile, not_masked=False, reset=False): |
1156 | 1158 | continue |
1157 | 1159 | if reset: |
1158 | 1160 | return |
1159 | | - else: |
1160 | | - yield row |
| 1161 | + yield row |
1161 | 1162 |
|
1162 | 1163 |
|
1163 | 1164 | def save(datafile, filename=None, as_loaded=None, filetype=False): |
@@ -1262,7 +1263,9 @@ def to_pandas(datafile): |
1262 | 1263 | return df |
1263 | 1264 |
|
1264 | 1265 |
|
1265 | | -def format(datafile, key, mode="float", units=None, prefix=None, latex=False, fmt=None, escape=False): |
| 1266 | +def format( # pylint: disable=redefined-builtin |
| 1267 | + datafile, key, mode="float", units=None, prefix=None, latex=False, fmt=None, escape=False |
| 1268 | +): |
1266 | 1269 | r"""Return the contents of key pretty formatted using :py:func:`format_error`. |
1267 | 1270 |
|
1268 | 1271 | Args: |
|
0 commit comments