Skip to content

Commit 2da4599

Browse files
jbrockmendeljreback
authored andcommitted
TST: parametrize pytable test (#27032)
1 parent 8ea2d08 commit 2da4599

File tree

4 files changed

+41
-44
lines changed

4 files changed

+41
-44
lines changed

pandas/core/arrays/base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class ExtensionArray:
115115
# ------------------------------------------------------------------------
116116
# Constructors
117117
# ------------------------------------------------------------------------
118+
118119
@classmethod
119120
def _from_sequence(cls, scalars, dtype=None, copy=False):
120121
"""
@@ -286,6 +287,7 @@ def __iter__(self):
286287
# ------------------------------------------------------------------------
287288
# Required attributes
288289
# ------------------------------------------------------------------------
290+
289291
@property
290292
def dtype(self) -> ExtensionDtype:
291293
"""
@@ -319,6 +321,7 @@ def nbytes(self) -> int:
319321
# ------------------------------------------------------------------------
320322
# Additional Methods
321323
# ------------------------------------------------------------------------
324+
322325
def astype(self, dtype, copy=True):
323326
"""
324327
Cast to a NumPy array with 'dtype'.
@@ -479,8 +482,7 @@ def dropna(self):
479482
def shift(
480483
self,
481484
periods: int = 1,
482-
fill_value: object = None,
483-
) -> ABCExtensionArray:
485+
fill_value: object = None) -> ABCExtensionArray:
484486
"""
485487
Shift values by desired number.
486488
@@ -836,6 +838,7 @@ def copy(self, deep: bool = False) -> ABCExtensionArray:
836838
# ------------------------------------------------------------------------
837839
# Printing
838840
# ------------------------------------------------------------------------
841+
839842
def __repr__(self):
840843
from pandas.io.formats.printing import format_object_summary
841844

pandas/core/groupby/generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ def first_not_none(values):
480480
# if we have date/time like in the original, then coerce dates
481481
# as we are stacking can easily have object dtypes here
482482
so = self._selected_obj
483-
if (so.ndim == 2 and so.dtypes.apply(is_datetimelike).any()):
483+
if so.ndim == 2 and so.dtypes.apply(is_datetimelike).any():
484484
result = result.apply(
485485
lambda x: to_numeric(x, errors='ignore'))
486486
date_cols = self._selected_obj.select_dtypes(

pandas/core/internals/managers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ def set(self, item, value):
10271027
value_is_extension_type = (is_extension_type(value) or
10281028
is_extension_array_dtype(value))
10291029

1030-
# categorical/spares/datetimetz
1030+
# categorical/sparse/datetimetz
10311031
if value_is_extension_type:
10321032

10331033
def value_getitem(placement):

pandas/tests/io/pytables/test_pytables.py

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,47 +1070,41 @@ def test_encoding(self):
10701070
result = store.select('df', Term('columns=A', encoding='ascii'))
10711071
tm.assert_frame_equal(result, expected)
10721072

1073-
def test_latin_encoding(self):
1074-
1075-
values = [[b'E\xc9, 17', b'', b'a', b'b', b'c'],
1076-
[b'E\xc9, 17', b'a', b'b', b'c'],
1077-
[b'EE, 17', b'', b'a', b'b', b'c'],
1078-
[b'E\xc9, 17', b'\xf8\xfc', b'a', b'b', b'c'],
1079-
[b'', b'a', b'b', b'c'],
1080-
[b'\xf8\xfc', b'a', b'b', b'c'],
1081-
[b'A\xf8\xfc', b'', b'a', b'b', b'c'],
1082-
[np.nan, b'', b'b', b'c'],
1083-
[b'A\xf8\xfc', np.nan, b'', b'b', b'c']]
1084-
1085-
def _try_decode(x, encoding='latin-1'):
1086-
try:
1087-
return x.decode(encoding)
1088-
except AttributeError:
1089-
return x
1090-
# not sure how to remove latin-1 from code in python 2 and 3
1091-
values = [[_try_decode(x) for x in y] for y in values]
1092-
1093-
examples = []
1094-
for dtype in ['category', object]:
1095-
for val in values:
1096-
examples.append(pd.Series(val, dtype=dtype))
1097-
1098-
def roundtrip(s, key='data', encoding='latin-1', nan_rep=''):
1099-
with ensure_clean_path(self.path) as store:
1100-
s.to_hdf(store, key, format='table', encoding=encoding,
1101-
nan_rep=nan_rep)
1102-
retr = read_hdf(store, key)
1103-
s_nan = s.replace(nan_rep, np.nan)
1104-
if is_categorical_dtype(s_nan):
1105-
assert is_categorical_dtype(retr)
1106-
assert_series_equal(s_nan, retr, check_dtype=False,
1107-
check_categorical=False)
1108-
else:
1109-
assert_series_equal(s_nan, retr)
1110-
1111-
for s in examples:
1112-
roundtrip(s)
1073+
@pytest.mark.parametrize('val', [
1074+
[b'E\xc9, 17', b'', b'a', b'b', b'c'],
1075+
[b'E\xc9, 17', b'a', b'b', b'c'],
1076+
[b'EE, 17', b'', b'a', b'b', b'c'],
1077+
[b'E\xc9, 17', b'\xf8\xfc', b'a', b'b', b'c'],
1078+
[b'', b'a', b'b', b'c'],
1079+
[b'\xf8\xfc', b'a', b'b', b'c'],
1080+
[b'A\xf8\xfc', b'', b'a', b'b', b'c'],
1081+
[np.nan, b'', b'b', b'c'],
1082+
[b'A\xf8\xfc', np.nan, b'', b'b', b'c']
1083+
])
1084+
@pytest.mark.parametrize('dtype', ['category', object])
1085+
def test_latin_encoding(self, dtype, val):
1086+
enc = 'latin-1'
1087+
nan_rep = ''
1088+
key = 'data'
1089+
1090+
val = [x.decode(enc) if isinstance(x, bytes) else x for x in val]
1091+
ser = pd.Series(val, dtype=dtype)
1092+
1093+
with ensure_clean_path(self.path) as store:
1094+
ser.to_hdf(store, key, format='table', encoding=enc,
1095+
nan_rep=nan_rep)
1096+
retr = read_hdf(store, key)
1097+
1098+
s_nan = ser.replace(nan_rep, np.nan)
1099+
1100+
if is_categorical_dtype(s_nan):
1101+
assert is_categorical_dtype(retr)
1102+
assert_series_equal(s_nan, retr, check_dtype=False,
1103+
check_categorical=False)
1104+
else:
1105+
assert_series_equal(s_nan, retr)
11131106

1107+
# FIXME: don't leave commented-out
11141108
# fails:
11151109
# for x in examples:
11161110
# roundtrip(s, nan_rep=b'\xf8\xfc')

0 commit comments

Comments
 (0)