8000 BUG: Fixups for last changes to make CI pass · numpy/numpy@9a64758 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9a64758

Browse files
committed
BUG: Fixups for last changes to make CI pass
I had tested the refguide mainly (the functions part only), which missed a lot of smaller errors in the last iteration...
1 parent 9b3ae9f commit 9a64758

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

numpy/core/arrayprint.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def str_format(x):
408408
return str(x)
409409

410410
def _get_formatdict(data, *, precision, floatmode, suppress, sign, legacy,
411-
formatter, fmt=None, **kwargs):
411+
formatter, fmt=None, dtype=None, **kwargs):
412412
# note: extra arguments in kwargs are ignored
413413

414414
# wrapped in lambdas to avoid taking a code path with the wrong type of data
@@ -426,7 +426,7 @@ def _get_formatdict(data, *, precision, floatmode, suppress, sign, legacy,
426426
'longcomplexfloat': lambda: ComplexFloatingFormat(
427427
data, precision, floatmode, suppress, sign,
428428
legacy=legacy, fmt=fmt, longdouble_quoting=True),
429-
'datetime': lambda: DatetimeFormat(data, legacy=legacy),
429+
'datetime': lambda: DatetimeFormat(data, legacy=legacy, dtype=dtype),
430430
'timedelta': lambda: TimedeltaFormat(data),
431431
'object': lambda: _object_format,
432432
'void': lambda: str_format,
@@ -499,17 +499,14 @@ def get_formatter(*, dtype=None, data=None, fmt=None, options=None):
499499
fmt = None
500500

501501
if fmt is not None:
502-
if options is not None:
503-
raise TypeError("Use of options is only supported if `fmt=None`")
504-
505502
options = _default_format_options
506503

507504
if fmt is not repr and fmt is not str:
508505
raise TypeError(
509506
"get_formatter(): only `repr`, `str`, and None (or '') "
510507
"is currently supported for `fmt`.")
511508

512-
formatdict = _get_formatdict(data, fmt=fmt, **options)
509+
formatdict = _get_formatdict(data, dtype=dtype, fmt=fmt, **options)
513510

514511
dtypeobj = dtype.type
515512

@@ -548,7 +545,8 @@ def get_formatter(*, dtype=None, data=None, fmt=None, options=None):
548545
# given and `arr.dtype` cannot be a subarray dtype:
549546
assert data is None
550547
return SubArrayFormat(
551-
get_formatter(dtype=dtype.base, fmt=fmt, options=options))
548+
get_formatter(dtype=dtype.base, fmt=fmt,
549+
options=None if fmt is not None else options))
552550
else:
553551
return formatdict['void']()
554552
else:
@@ -1380,16 +1378,20 @@ def __call__(self, x):
13801378

13811379
class _TimelikeFormat:
13821380
def __init__(self, data):
1383-
non_nat = data[~isnat(data)]
1384-
if len(non_nat) > 0:
1385-
# Max str length of non-NaT elements
1386-
max_str_len = max(len(self._format_non_nat(np.max(non_nat))),
1387-
len(self._format_non_nat(np.min(non_nat))))
1381+
if data is not None:
1382+
non_nat = data[~isnat(data)]
1383+
if len(non_nat) > 0:
1384+
# Max str length of non-NaT elements
1385+
max_str_len = max(len(self._format_non_nat(np.max(non_nat))),
1386+
len(self._format_non_nat(np.min(non_nat))))
1387+
else:
1388+
max_str_len = 0
1389+
if len(non_nat) < data.size:
1390+
# data contains a NaT
1391+
max_str_len = max(max_str_len, 5)
13881392
else:
13891393
max_str_len = 0
1390-
if len(non_nat) < data.size:
1391-
# data contains a NaT
1392-
max_str_len = max(max_str_len, 5)
1394+
13931395
self._format = '%{}s'.format(max_str_len)
13941396
self._nat = "'NaT'".rjust(max_str_len)
13951397

@@ -1406,11 +1408,13 @@ def __call__(self, x):
14061408

14071409
class DatetimeFormat(_TimelikeFormat):
14081410
def __init__(self, x, unit=None, timezone=None, casting='same_kind',
1409-
legacy=False):
1411+
legacy=False, *, dtype=None):
14101412
# Get the unit from the dtype
14111413
if unit is None:
1412-
if x.dtype.kind == 'M':
1413-
unit = datetime_data(x.dtype)[0]
1414+
if dtype is None:
1415+
dtype = x.dtype
1416+
if dtype.kind == 'M':
1417+
unit = datetime_data(dtype)[0]
14141418
else:
14151419
unit = 's'
14161420

numpy/core/tests/test_arrayprint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ def test_sign_spacing_structured(self):
669669
assert_equal(repr(a),
670670
"array([(1., 1.), (1., 1.)], dtype=[('f0', '<f4'), ('f1', '<f4')])")
671671
assert_equal(repr(a[0]),
672-
"np.void((1., 1.), dtype=[('f0', '<f4'), ('f1', '<f4')])")
672+
"np.void((1.0, 1.0), dtype=[('f0', '<f4'), ('f1', '<f4')])")
673673

674674
def test_floatmode(self):
675675
x = np.array([0.6104, 0.922, 0.457, 0.0906, 0.3733, 0.007244,

numpy/core/tests/test_records.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def test_0d_recarray_repr(self):
132132

133133
record = arr_0d[()]
134134
assert_equal(repr(record),
135-
"np.record((1, 2., '2003'), "
135+
"np.record((1, 2.0, '2003'), "
136136
"dtype=[('f0', '<i4'), ('f1', & 42EF #39;<f8'), ('f2', '<M8[Y]')])")
137137
# 1.13 converted to python scalars before the repr
138138
try:

0 commit comments

Comments
 (0)
0