Skip to content

Commit

Permalink
Merge pull request #193 from AI-SDC/pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
[pre-commit.ci] pre-commit autoupdate
  • Loading branch information
mahaalbashir authored Feb 5, 2024
2 parents 63410e3 + 62e43d4 commit 4ccf5fb
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ repos:

# Black format Python and notebooks
- repo: https://github.com/psf/black
rev: 23.12.1
rev: 24.1.1
hooks:
- id: black-jupyter

Expand Down
1 change: 1 addition & 0 deletions acro/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""ACRO."""

from .acro import *
from .acro_regression import *
7 changes: 4 additions & 3 deletions acro/acro_stata_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Jim Smith 2023 @james.smith@uwe.ac.uk
MIT licenses apply.
"""

import pandas as pd
import statsmodels.iolib.summary as sm_iolib_summary

Expand Down Expand Up @@ -118,9 +119,9 @@ def parse_table_details(varlist: list, varnames: list, options: str) -> dict:
extras = superrows.split()
for word in extras:
if word not in varnames:
details[
"errmsg"
] = f"Error: word {word} in by-list is not a variables name"
details["errmsg"] = (
f"Error: word {word} in by-list is not a variables name"
)
return details
if word not in details["rowvars"]:
details["rowvars"].insert(0, word)
Expand Down
33 changes: 21 additions & 12 deletions acro/acro_tables.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""ACRO: Tables functions."""

# pylint: disable=too-many-lines
from __future__ import annotations

Expand Down Expand Up @@ -1237,35 +1238,43 @@ def get_queries(masks, aggfunc) -> list[str]:
if isinstance(row_label, tuple):
index_query = " & ".join(
[
f"({level} == {val})"
if isinstance(val, (int, float))
else f'({level} == "{val}")'
(
f"({level} == {val})"
if isinstance(val, (int, float))
else f'({level} == "{val}")'
)
for level, val in zip(index_level_names, row_label)
]
)
else:
index_query = " & ".join(
[
f"({index_level_names} == {row_label})"
if isinstance(row_label, (int, float))
else (f"({index_level_names}" f'== "{row_label}")')
(
f"({index_level_names} == {row_label})"
if isinstance(row_label, (int, float))
else (f"({index_level_names}" f'== "{row_label}")')
)
]
)
if isinstance(col_label, tuple):
column_query = " & ".join(
[
f"({level} == {val})"
if isinstance(val, (int, float))
else f'({level} == "{val}")'
(
f"({level} == {val})"
if isinstance(val, (int, float))
else f'({level} == "{val}")'
)
for level, val in zip(column_level_names, col_label)
]
)
else:
column_query = " & ".join(
[
f"({column_level_names} == {col_label})"
if isinstance(col_label, (int, float))
else (f"({column_level_names}" f'== "{col_label}")')
(
f"({column_level_names} == {col_label})"
if isinstance(col_label, (int, float))
else (f"({column_level_names}" f'== "{col_label}")')
)
]
)
query = f"{index_query} & {column_query}"
Expand Down
1 change: 1 addition & 0 deletions acro/stata_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
mutable hence use of lower case naming
Jim Smith 2023.
"""

import acro

stata_acro = acro.ACRO()
1 change: 1 addition & 0 deletions acro/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
"""ACRO version number."""

__version__ = "0.4.5"
6 changes: 3 additions & 3 deletions notebooks/acro_demo_v2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,9 @@
"df[\"children\"] = pd.to_numeric(df[\"children\"])\n",
"\n",
"df[\"children\"] = df.apply(\n",
" lambda row: row[\"children\"]\n",
" if row[\"children\"] in (1, 2, 3)\n",
" else np.random.randint(4, 10),\n",
" lambda row: (\n",
" row[\"children\"] if row[\"children\"] in (1, 2, 3) else np.random.randint(4, 10)\n",
" ),\n",
" axis=1,\n",
")"
]
Expand Down
6 changes: 3 additions & 3 deletions notebooks/test-nursery.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@
"df[\"children\"] = pd.to_numeric(df[\"children\"])\n",
"\n",
"df[\"children\"] = df.apply(\n",
" lambda row: row[\"children\"]\n",
" if row[\"children\"] in (1, 2, 3)\n",
" else np.random.randint(4, 10),\n",
" lambda row: (\n",
" row[\"children\"] if row[\"children\"] in (1, 2, 3) else np.random.randint(4, 10)\n",
" ),\n",
" axis=1,\n",
")"
]
Expand Down
6 changes: 3 additions & 3 deletions notebooks/test-nursery.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
df["children"] = pd.to_numeric(df["children"])

df["children"] = df.apply(
lambda row: row["children"]
if row["children"] in (1, 2, 3)
else np.random.randint(4, 10),
lambda row: (
row["children"] if row["children"] in (1, 2, 3) else np.random.randint(4, 10)
),
axis=1,
)

Expand Down

0 comments on commit 4ccf5fb

Please sign in to comment.