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

Skip to content

Commit ce4166f

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 ce4166f

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

numpy/core/arrayprint.py

Lines changed: 14 additions & 11 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,7 +1378,10 @@ def __call__(self, x):
13801378

13811379
class _TimelikeFormat:
13821380
def __init__(self, data):
1383-
non_nat = data[~isnat(data)]
1381+
if data is None:
1382+
non_nat = []
1383+
else:
1384+
non_nat = data[~isnat(data)]
13841385
if len(non_nat) > 0:
13851386
# Max str length of non-NaT elements
13861387
max_str_len = max(len(self._format_non_nat(np.max(non_nat))),
@@ -1406,11 +1407,13 @@ def __call__(self, x):
14061407

14071408
class DatetimeFormat(_TimelikeFormat):
14081409
def __init__(self, x, unit=None, timezone=None, casting='same_kind',
1409-
legacy=False):
1410+
legacy=False, *, dtype=None):
14101411
# Get the unit from the dtype
14111412
if unit is None:
1412-
if x.dtype.kind == 'M':
1413-
unit = datetime_data(x.dtype)[0]
1413+
if dtype is None:
1414+
dtype = x.dtype
1415+
if dtype.kind == 'M':
1416+
unit = datetime_data(dtype)[0]
14141417
else:
14151418
unit = 's'
14161419

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,

0 commit comments

Comments
 (0)
0