Beispiel #1
0
    def __new__(
        cls,
        path: Union[FilePathOrBuffer, ExcelWriter],
        engine=None,
        date_format=None,
        datetime_format=None,
        mode: str = "w",
        storage_options: StorageOptions = None,
        engine_kwargs: Optional[Dict] = None,
        **kwargs,
    ):
        if kwargs:
            if engine_kwargs is not None:
                raise ValueError("Cannot use both engine_kwargs and **kwargs")
            warnings.warn(
                "Use of **kwargs is deprecated, use engine_kwargs instead.",
                FutureWarning,
                stacklevel=2,
            )

        # only switch class if generic(ExcelWriter)

        if cls is ExcelWriter:
            if engine is None or (isinstance(engine, str)
                                  and engine == "auto"):
                if isinstance(path, str):
                    ext = os.path.splitext(path)[-1][1:]
                else:
                    ext = "xlsx"

                try:
                    engine = config.get_option(f"io.excel.{ext}.writer",
                                               silent=True)
                    if engine == "auto":
                        engine = get_default_engine(ext, mode="writer")
                except KeyError as err:
                    raise ValueError(
                        f"No engine for filetype: '{ext}'") from err

            if engine == "xlwt":
                xls_config_engine = config.get_option("io.excel.xls.writer",
                                                      silent=True)
                # Don't warn a 2nd time if user has changed the default engine for xls
                if xls_config_engine != "xlwt":
                    warnings.warn(
                        "As the xlwt package is no longer maintained, the xlwt "
                        "engine will be removed in a future version of pandas. "
                        "This is the only engine in pandas that supports writing "
                        "in the xls format. Install openpyxl and write to an xlsx "
                        "file instead. You can set the option io.excel.xls.writer "
                        "to 'xlwt' to silence this warning. While this option is "
                        "deprecated and will also raise a warning, it can "
                        "be globally set and the warning suppressed.",
                        FutureWarning,
                        stacklevel=4,
                    )

            cls = get_writer(engine)

        return object.__new__(cls)
Beispiel #2
0
    def __new__(cls, path, engine=None, **kwargs):
        # only switch class if generic(ExcelWriter)

        if cls is ExcelWriter:
            if engine is None or (isinstance(engine, str) and engine == "auto"):
                if isinstance(path, str):
                    ext = os.path.splitext(path)[-1][1:]
                else:
                    ext = "xlsx"

                try:
                    engine = config.get_option(f"io.excel.{ext}.writer")
                    if engine == "auto":
                        engine = get_default_writer(ext)
                except KeyError as err:
                    raise ValueError(f"No engine for filetype: '{ext}'") from err
            cls = get_writer(engine)

        return object.__new__(cls)
Beispiel #3
0
    def __new__(cls, path, engine=None, **kwargs):
        # only switch class if generic(ExcelWriter)

        if issubclass(cls, ExcelWriter):
            if engine is None or (isinstance(engine, string_types)
                                  and engine == 'auto'):
                if isinstance(path, string_types):
                    ext = os.path.splitext(path)[-1][1:]
                else:
                    ext = 'xlsx'

                try:
                    engine = config.get_option(
                        'io.excel.{ext}.writer'.format(ext=ext))
                    if engine == 'auto':
                        engine = _get_default_writer(ext)
                except KeyError:
                    raise ValueError(
                        "No engine for filetype: '{ext}'".format(ext=ext))
            cls = get_writer(engine)

        return object.__new__(cls)
Beispiel #4
0
    def __new__(cls, path, engine=None, **kwargs):
        # only switch class if generic(ExcelWriter)

        if issubclass(cls, ExcelWriter):
            if engine is None or (isinstance(engine, str) and
                                  engine == 'auto'):
                if isinstance(path, str):
                    ext = os.path.splitext(path)[-1][1:]
                else:
                    ext = 'xlsx'

                try:
                    engine = config.get_option('io.excel.{ext}.writer'
                                               .format(ext=ext))
                    if engine == 'auto':
                        engine = _get_default_writer(ext)
                except KeyError:
                    raise ValueError("No engine for filetype: '{ext}'"
                                     .format(ext=ext))
            cls = get_writer(engine)

        return object.__new__(cls)