diff --git a/acro/acro_stata_parser.py b/acro/acro_stata_parser.py index b9e5cbc..d263413 100644 --- a/acro/acro_stata_parser.py +++ b/acro/acro_stata_parser.py @@ -138,6 +138,7 @@ def parse_table_details( >> table rowvar [colvar [supercolvar] [if] [in] [weight] [, options]. """ details: dict = {"errmsg": "", "rowvars": list([]), "colvars": list([])} + contents_found, content = False, [] if stata_version == "16": details["rowvars"] = [varlist.pop(0)] @@ -326,6 +327,7 @@ def extract_var_within_parentheses(input_string): """Given a string, this function extracts the words within the first parentheses from a string. """ + string = "" string_match = re.match(r"\((.*?)\)", input_string) if string_match: string = string_match.group(1).strip() @@ -335,6 +337,7 @@ def extract_var_within_parentheses(input_string): def extract_var_before_parentheses(input_string): """Given a string, this function extracts the words before the first parentheses.""" + string = "" string_match = re.match(r"^(.*?)\(", input_string) if string_match: string = string_match.group(1).strip() @@ -346,6 +349,7 @@ def extract_table_var(input_string): """Given a string, this function extracts the words within the parentheses. If there are no parentheses the string is returned. """ + string = "" # If the string starts with parentheses if input_string.startswith("("): string, _ = extract_var_within_parentheses(input_string) diff --git a/acro/acro_tables.py b/acro/acro_tables.py index c78c451..3c97a5e 100644 --- a/acro/acro_tables.py +++ b/acro/acro_tables.py @@ -555,13 +555,13 @@ def hist( # pylint: disable=too-many-arguments,too-many-locals self, data, column, - by=None, + by_val=None, grid=True, xlabelsize=None, xrot=None, ylabelsize=None, yrot=None, - ax=None, + axis=None, sharex=False, sharey=False, figsize=None, @@ -586,7 +586,7 @@ def hist( # pylint: disable=too-many-arguments,too-many-locals The pandas object holding the data. column : str The column that will be used to plot the histogram. - by : object, optional + by_val : object, optional If passed, then used to form histograms for separate groups. grid : bool, default True Whether to show axis grid lines. @@ -600,7 +600,7 @@ def hist( # pylint: disable=too-many-arguments,too-many-locals yrot : float, default None Rotation of y axis labels. For example, a value of 90 displays the y labels rotated 90 degrees clockwise. - ax : Matplotlib axes object, default None + axis : Matplotlib axes object, default None The axes to plot the histogram on. sharex : bool, default True if ax is None else False In case subplots=True, share x axis and set some x axis labels to invisible; @@ -662,13 +662,13 @@ def hist( # pylint: disable=too-many-arguments,too-many-locals else: # pragma: no cover data.hist( column=column, - by=by, + by=by_val, grid=grid, xlabelsize=xlabelsize, xrot=xrot, ylabelsize=ylabelsize, yrot=yrot, - ax=ax, + ax=axis, sharex=sharex, sharey=sharey, figsize=figsize, @@ -682,13 +682,13 @@ def hist( # pylint: disable=too-many-arguments,too-many-locals status = "review" data.hist( column=column, - by=by, + by=by_val, grid=grid, xlabelsize=xlabelsize, xrot=xrot, ylabelsize=ylabelsize, yrot=yrot, - ax=ax, + ax=axis, sharex=sharex, sharey=sharey, figsize=figsize, @@ -1364,15 +1364,31 @@ def create_dataframe(index, columns) -> DataFrame: Dataframe Table of the index and columns combined. """ - if isinstance(index, list): - index_df = pd.concat(index, axis=1) - elif isinstance(index, pd.Series): - index_df = pd.DataFrame({index.name: index}) - if isinstance(columns, list): - columns_df = pd.concat(columns, axis=1) - elif isinstance(columns, pd.Series): - columns_df = pd.DataFrame({columns.name: columns}) - data = pd.concat([index_df, columns_df], axis=1) + empty_dataframe = pd.DataFrame([]) + + index_df = empty_dataframe + try: + if isinstance(index, list): + index_df = pd.concat(index, axis=1) + elif isinstance(index, pd.Series): + index_df = pd.DataFrame({index.name: index}) + except ValueError: + index_df = empty_dataframe + + columns_df = empty_dataframe + try: + if isinstance(columns, list): + columns_df = pd.concat(columns, axis=1) + elif isinstance(columns, pd.Series): + columns_df = pd.DataFrame({columns.name: columns}) + except ValueError: + columns_df = empty_dataframe + + try: + data = pd.concat([index_df, columns_df], axis=1) + except ValueError: + data = empty_dataframe + return data