def _from_sequence_of_strings(cls, strings, *, dtype: Optional[Dtype] = None, copy: bool = False) -> IntegerArray: scalars = to_numeric(strings, errors="raise") return cls._from_sequence(scalars, dtype=dtype, copy=copy)
def _from_sequence_of_strings(cls, strings, *, dtype=None, copy: bool = False) -> FloatingArray: scalars = to_numeric(strings, errors="raise") return cls._from_sequence(scalars, dtype=dtype, copy=copy)
def _from_sequence_of_strings( cls: type[T], strings, *, dtype: Dtype | None = None, copy: bool = False ) -> T: from pandas.core.tools.numeric import to_numeric scalars = to_numeric(strings, errors="raise") return cls._from_sequence(scalars, dtype=dtype, copy=copy)
def melt_stub(df, stub, i, j, value_vars, sep): newdf = melt(df, id_vars=i, value_vars=value_vars, value_name=stub.rstrip(sep), var_name=j) newdf[j] = Categorical(newdf[j]) newdf[j] = newdf[j].str.replace(re.escape(stub + sep), "") # GH17627 Cast numerics suffixes to int/float newdf[j] = to_numeric(newdf[j], errors='ignore') return newdf.set_index(i + [j])
def _from_sequence_of_strings(cls, strings, *, dtype: Dtype | None = None, copy=False): """ Construct a new ExtensionArray from a sequence of strings. """ pa_type = to_pyarrow_type(dtype) if pa.types.is_timestamp(pa_type): from pandas.core.tools.datetimes import to_datetime scalars = to_datetime(strings, errors="raise") elif pa.types.is_date(pa_type): from pandas.core.tools.datetimes import to_datetime scalars = to_datetime(strings, errors="raise").date elif pa.types.is_duration(pa_type): from pandas.core.tools.timedeltas import to_timedelta scalars = to_timedelta(strings, errors="raise") elif pa.types.is_time(pa_type): from pandas.core.tools.times import to_time # "coerce" to allow "null times" (None) to not raise scalars = to_time(strings, errors="coerce") elif pa.types.is_boolean(pa_type): from pandas.core.arrays import BooleanArray scalars = BooleanArray._from_sequence_of_strings( strings).to_numpy() elif (pa.types.is_integer(pa_type) or pa.types.is_floating(pa_type) or pa.types.is_decimal(pa_type)): from pandas.core.tools.numeric import to_numeric scalars = to_numeric(strings, errors="raise") else: # Let pyarrow try to infer or raise scalars = strings return cls._from_sequence(scalars, dtype=pa_type, copy=copy)
def _from_sequence_of_strings(cls, strings, dtype=None, copy=False): scalars = to_numeric(strings, errors="raise") return cls._from_sequence(scalars, dtype, copy)
def _from_sequence_of_strings( cls, strings, dtype=None, copy: bool = False ) -> "IntegerArray": scalars = to_numeric(strings, errors="raise") return cls._from_sequence(scalars, dtype, copy)