示例#1
0
 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)
示例#2
0
 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)
示例#3
0
    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)
示例#4
0
    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])
示例#5
0
    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])
示例#6
0
文件: array.py 项目: YarShev/pandas
    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)
示例#7
0
 def _from_sequence_of_strings(cls, strings, dtype=None, copy=False):
     scalars = to_numeric(strings, errors="raise")
     return cls._from_sequence(scalars, dtype, copy)
示例#8
0
 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)
示例#9
0
文件: integer.py 项目: pydata/pandas
 def _from_sequence_of_strings(cls, strings, dtype=None, copy=False):
     scalars = to_numeric(strings, errors="raise")
     return cls._from_sequence(scalars, dtype, copy)