Skip to content

STY: De-privatize functions in io.excel imported elsewhere #36104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions pandas/io/excel/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
validate_header_arg,
)
from pandas.io.excel._util import (
_fill_mi_header,
_get_default_writer,
_maybe_convert_usecols,
_pop_header_name,
fill_mi_header,
get_default_writer,
get_writer,
maybe_convert_usecols,
pop_header_name,
)
from pandas.io.parsers import TextParser

Expand Down Expand Up @@ -454,7 +454,7 @@ def parse(
sheet = self.get_sheet_by_index(asheetname)

data = self.get_sheet_data(sheet, convert_float)
usecols = _maybe_convert_usecols(usecols)
usecols = maybe_convert_usecols(usecols)

if not data:
output[asheetname] = DataFrame()
Expand All @@ -473,10 +473,10 @@ def parse(
if is_integer(skiprows):
row += skiprows

data[row], control_row = _fill_mi_header(data[row], control_row)
data[row], control_row = fill_mi_header(data[row], control_row)

if index_col is not None:
header_name, _ = _pop_header_name(data[row], index_col)
header_name, _ = pop_header_name(data[row], index_col)
header_names.append(header_name)

if is_list_like(index_col):
Expand Down Expand Up @@ -645,7 +645,7 @@ def __new__(cls, path, engine=None, **kwargs):
try:
engine = config.get_option(f"io.excel.{ext}.writer")
if engine == "auto":
engine = _get_default_writer(ext)
engine = get_default_writer(ext)
except KeyError as err:
raise ValueError(f"No engine for filetype: '{ext}'") from err
cls = get_writer(engine)
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/excel/_odswriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pandas._libs.json as json

from pandas.io.excel._base import ExcelWriter
from pandas.io.excel._util import _validate_freeze_panes
from pandas.io.excel._util import validate_freeze_panes
from pandas.io.formats.excel import ExcelCell


Expand Down Expand Up @@ -59,7 +59,7 @@ def write_cells(
wks = Table(name=sheet_name)
self.sheets[sheet_name] = wks

if _validate_freeze_panes(freeze_panes):
if validate_freeze_panes(freeze_panes):
assert freeze_panes is not None
self._create_freeze_panes(sheet_name, freeze_panes)

Expand Down
4 changes: 2 additions & 2 deletions pandas/io/excel/_openpyxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pandas.compat._optional import import_optional_dependency

from pandas.io.excel._base import ExcelWriter, _BaseExcelReader
from pandas.io.excel._util import _validate_freeze_panes
from pandas.io.excel._util import validate_freeze_panes

if TYPE_CHECKING:
from openpyxl.descriptors.serialisable import Serialisable
Expand Down Expand Up @@ -385,7 +385,7 @@ def write_cells(
wks.title = sheet_name
self.sheets[sheet_name] = wks

if _validate_freeze_panes(freeze_panes):
if validate_freeze_panes(freeze_panes):
wks.freeze_panes = wks.cell(
row=freeze_panes[0] + 1, column=freeze_panes[1] + 1
)
Expand Down
18 changes: 5 additions & 13 deletions pandas/io/excel/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def register_writer(klass):
_writers[engine_name] = klass


def _get_default_writer(ext):
def get_default_writer(ext):
"""
Return the default writer for the given extension.

Expand Down Expand Up @@ -121,7 +121,7 @@ def _range2cols(areas):
return cols


def _maybe_convert_usecols(usecols):
def maybe_convert_usecols(usecols):
"""
Convert `usecols` into a compatible format for parsing in `parsers.py`.

Expand Down Expand Up @@ -150,7 +150,7 @@ def _maybe_convert_usecols(usecols):
return usecols


def _validate_freeze_panes(freeze_panes):
def validate_freeze_panes(freeze_panes):
if freeze_panes is not None:
if len(freeze_panes) == 2 and all(
isinstance(item, int) for item in freeze_panes
Expand All @@ -167,15 +167,7 @@ def _validate_freeze_panes(freeze_panes):
return False


def _trim_excel_header(row):
# trim header row so auto-index inference works
# xlrd uses '' , openpyxl None
while len(row) > 0 and (row[0] == "" or row[0] is None):
row = row[1:]
return row


def _fill_mi_header(row, control_row):
def fill_mi_header(row, control_row):
"""
Forward fill blank entries in row but only inside the same parent index.

Expand Down Expand Up @@ -208,7 +200,7 @@ def _fill_mi_header(row, control_row):
return row, control_row


def _pop_header_name(row, index_col):
def pop_header_name(row, index_col):
"""
Pop the header name for MultiIndex parsing.

Expand Down
4 changes: 2 additions & 2 deletions pandas/io/excel/_xlsxwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pandas._libs.json as json

from pandas.io.excel._base import ExcelWriter
from pandas.io.excel._util import _validate_freeze_panes
from pandas.io.excel._util import validate_freeze_panes


class _XlsxStyler:
Expand Down Expand Up @@ -208,7 +208,7 @@ def write_cells(

style_dict = {"null": None}

if _validate_freeze_panes(freeze_panes):
if validate_freeze_panes(freeze_panes):
wks.freeze_panes(*(freeze_panes))

for cell in cells:
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/excel/_xlwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pandas._libs.json as json

from pandas.io.excel._base import ExcelWriter
from pandas.io.excel._util import _validate_freeze_panes
from pandas.io.excel._util import validate_freeze_panes

if TYPE_CHECKING:
from xlwt import XFStyle
Expand Down Expand Up @@ -48,7 +48,7 @@ def write_cells(
wks = self.book.add_sheet(sheet_name)
self.sheets[sheet_name] = wks

if _validate_freeze_panes(freeze_panes):
if validate_freeze_panes(freeze_panes):
wks.set_panes_frozen(True)
wks.set_horz_split_pos(freeze_panes[0])
wks.set_vert_split_pos(freeze_panes[1])
Expand Down