ENH: Detect mixed bytes/text inputs during array conversion

Abierto
#32,765 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
45/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
python
Área
backend

Línea de trabajo

The issue mentions _array_converter and shared C conversion machinery. Start by reading the linked PR #32757 and the related issues #15327, #19078, #19101 to understand the context. Look at the numpy source code for dtype discovery and array conversion logic, particularly around string/bytes handling. The goal is to add an opt-in detection mode for mixed bytes/text inputs before coercion to Unicode.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

01 - Enhancement
Proposed new feature or change:

Follow-up to Sebastian’s review comment on #32757.

NumPy currently infers Unicode for mixed bytes/text inputs:

>>> import numpy as np
>>> np.asarray([b"a", "b"])
array(['a', 'b'], dtype='<U1')
>>> np.concatenate(([b"a", "b"], ["c"]))
array(['a', 'b', 'c'], dtype='<U1')

We should add an opt-in mode (exposed to NumPy Python internals via _array_converter) that detects these mixtures during dtype discovery, before coercion happens and we lose track of the input dtypes. Shared C conversion machinery would let concatenate detect mixtures within its inputs as well as between them.

The same detection could support deprecating implicit Unicode inference for mixed bytes/text inputs. These should eventually produce object arrays that preserve the original values. Explicit conversions such as dtype="U" would remain supported.

This has come up in the past, in particular:

  • #15327 proposed deprecating implicit string/non-string promotion, including in concatenate.
  • #19078 described downstream difficulties with promotion warnings: callers wanted numeric inference for numeric inputs and object arrays for mixed inputs.
  • #19101 explored an opt-in object-fallback mode during dtype discovery; it was not merged.
Lenguaje dominante
Python
Estrellas
33.5k
Forks
13.1k
Merge medio
1 d 19 h
PR fusionados (30 d)
143

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de numpy/numpy

Todos los issues de numpy/numpy

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.