Skip to content

Commit

Permalink
Format after updating ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeNaccarato committed Dec 22, 2023
1 parent 6ad95df commit 919c99e
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ repos:
hooks:
- id: "markdownlint-cli2-fix"
- repo: "https://github.com/charliermarsh/ruff-pre-commit"
rev: "v0.1.7"
rev: "v0.1.9"
hooks:
- id: "ruff"
types_or: ["python", "pyi", "jupyter"]
Expand Down
2 changes: 1 addition & 1 deletion .tools/requirements/requirements_both.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cachier@git+https://github.com/blakeNaccarato/cachier@0892f53dc8fd9fb8a7f959305a
# Type checking
pyright==1.1.336
# Pre-commit common requirements
ruff==0.1.6
ruff==0.1.9
# Testing
pytest==7.4.3
# Testing plugins
Expand Down
2 changes: 1 addition & 1 deletion .tools/scripts/pythonstartup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def filter_certain_warnings():


def get_default_warnings_for_src(
category: type[Warning]
category: type[Warning],
) -> tuple[WarningFilter, WarningFilter]:
"""Get filter which sets default warning behavior only for the package in `src`."""
package = next(path for path in Path("src").iterdir() if path.is_dir()).name
Expand Down
12 changes: 5 additions & 7 deletions src/boilercv/data/sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,11 @@ def get_dataset(
xr.Dataset({VIDEO: ds[VIDEO], HEADER: ds[HEADER]}).to_netcdf(
path=unc_source, encoding={VIDEO: {"zlib": False}}
)
return xr.Dataset(
{
VIDEO: unpack(ds[VIDEO].sel(frame=frame)),
ROI: roi_ds[ROI],
HEADER: ds[HEADER],
}
)
return xr.Dataset({
VIDEO: unpack(ds[VIDEO].sel(frame=frame)),
ROI: roi_ds[ROI],
HEADER: ds[HEADER],
})


def get_stage(name: str, stage: Stage = STAGE_DEFAULT) -> tuple[Path, Path]:
Expand Down
24 changes: 11 additions & 13 deletions src/boilercv/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,17 @@ def truncate(df: DfOrS, head: bool = False) -> tuple[pd.DataFrame, bool]:
df.columns = [str(col) for col in df.columns]
# Resolves ValueError: Length of names must match number of levels in MultiIndex.
ellipsis_index = ("...",) * df.index.nlevels
df = pd.concat(
[
df.head(pd.options.display.min_rows // 2),
df.iloc[[0]] # Resolves ValueError: cannot handle a non-unique multi-index!
.reindex(
pd.MultiIndex.from_tuples([ellipsis_index], names=df.index.names)
if isinstance(df.index, pd.MultiIndex)
else pd.Index(ellipsis_index, name=df.index.name)
)
.assign(**{col: "..." for col in df.columns}),
df.tail(pd.options.display.min_rows // 2),
]
)
df = pd.concat([
df.head(pd.options.display.min_rows // 2),
df.iloc[[0]] # Resolves ValueError: cannot handle a non-unique multi-index!
.reindex(
pd.MultiIndex.from_tuples([ellipsis_index], names=df.index.names)
if isinstance(df.index, pd.MultiIndex)
else pd.Index(ellipsis_index, name=df.index.name)
)
.assign(**{col: "..." for col in df.columns}),
df.tail(pd.options.display.min_rows // 2),
])
return df, True


Expand Down
9 changes: 6 additions & 3 deletions src/boilercv/examples/detect_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,12 @@ def find_boiling_surface(img: Img) -> tuple[Img, ArrInt]:
xpx_left = points.xpx.min()
xpx_right = points.xpx.max()
ypx_horizontal = np.round(points.ypx.mean()).astype(int)
boiling_surface_coords = np.array(
[ypx_horizontal, xpx_left, ypx_horizontal, xpx_right]
).astype(int)
boiling_surface_coords = np.array([
ypx_horizontal,
xpx_left,
ypx_horizontal,
xpx_right,
]).astype(int)

if PREVIEW:
view_images(
Expand Down
14 changes: 6 additions & 8 deletions src/boilercv/old/_contours.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,14 @@ def _get_contours(


def interact_with_images(_input_image, _masked, thresholded, contoured):
_plt, ax = subplot_mosaic(
_plt, ax = subplot_mosaic([
[
[
# "input",
# "masked",
"thresholded",
"contoured",
]
# "input",
# "masked",
"thresholded",
"contoured",
]
)
])
for ax_ in ax.values():
ax_.axis("off")
# ax["input"].imshow(input_image, cmap="gray")
Expand Down
22 changes: 9 additions & 13 deletions src/boilercv/stages/experiments/e230920_subcool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,11 @@ def crop_image(img, ylim, xlim):


def get_hists(df: pd.DataFrame, groupby: str, cols: list[str]) -> pd.DataFrame:
df = df.groupby(groupby, **GBC).agg(
**{
# type: ignore # pyright 1.1.333
col: pd.NamedAgg(column=col, aggfunc=sparkhist)
for col in cols
}
)
df = df.groupby(groupby, **GBC).agg(**{
# type: ignore # pyright 1.1.333
col: pd.NamedAgg(column=col, aggfunc=sparkhist)
for col in cols
})
# Can't one-shot this because of the comprehension {...: ... for col in hist_cols}
return df.assign(**{col: df[col].str.center(WIDTH, "▁") for col in cols})

Expand Down Expand Up @@ -163,12 +161,10 @@ def __post_init__(self):


def transform_cols(df: pd.DataFrame, cols: list[Col]) -> pd.DataFrame:
return df.assign(
**{
col.new: df[col.old] if col.scale == 1 else df[col.old] * col.scale
for col in cols
}
)[[col.new for col in cols]]
return df.assign(**{
col.new: df[col.old] if col.scale == 1 else df[col.old] * col.scale
for col in cols
})[[col.new for col in cols]]


class Conversion(TypedDict):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,18 +514,14 @@
" time=time,\n",
")\n",
"\n",
"nondimensionalized_departing_long_lived_objects = departing_long_lived_objects.assign(\n",
" **{\n",
" \"Bubble Fourier number\": lambda df: fourier(\n",
" initial_bubble_diameter=df[\"diameterinit\"],\n",
" liquid_thermal_diffusivity=liquid_thermal_diffusivity,\n",
" time=df[\"time\"],\n",
" ),\n",
" \"Dimensionless bubble diameter\": (\n",
" lambda df: df[\"diameter\"] / df[\"diameterinit\"]\n",
" ),\n",
" }\n",
")"
"nondimensionalized_departing_long_lived_objects = departing_long_lived_objects.assign(**{\n",
" \"Bubble Fourier number\": lambda df: fourier(\n",
" initial_bubble_diameter=df[\"diameterinit\"],\n",
" liquid_thermal_diffusivity=liquid_thermal_diffusivity,\n",
" time=df[\"time\"],\n",
" ),\n",
" \"Dimensionless bubble diameter\": (lambda df: df[\"diameter\"] / df[\"diameterinit\"]),\n",
"})"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,10 @@
"outputs": [],
"source": [
"scatterplot(\n",
" data=data.reset_index().assign(\n",
" **{\n",
" \"Time (s)\": lambda df: (df.time - df.time[0]).dt.total_seconds(),\n",
" \"Flux (W/cm^2)\": lambda df: df[\"Q34 (W)\"] / 0.712557392,\n",
" }\n",
" ),\n",
" data=data.reset_index().assign(**{\n",
" \"Time (s)\": lambda df: (df.time - df.time[0]).dt.total_seconds(),\n",
" \"Flux (W/cm^2)\": lambda df: df[\"Q34 (W)\"] / 0.712557392,\n",
" }),\n",
" x=\"superheat\",\n",
" y=\"Flux (W/cm^2)\",\n",
" hue=\"Time (s)\",\n",
Expand Down
47 changes: 19 additions & 28 deletions tests/boilercv_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,16 @@ def _project_session_path(tmp_path_factory):
@pytest.fixture(autouse=True)
def _filter_certain_warnings():
"""Filter certain warnings."""
filter_certain_warnings(
[
WarningFilter(
message=r"numpy\.ndarray size changed, may indicate binary incompatibility\. Expected \d+ from C header, got \d+ from PyObject",
category=RuntimeWarning,
),
WarningFilter(
message=r"A grouping was used that is not in the columns of the DataFrame and so was excluded from the result\. This grouping will be included in a future version of pandas\. Add the grouping as a column of the DataFrame to silence this warning\.",
category=FutureWarning,
),
]
)
filter_certain_warnings([
WarningFilter(
message=r"numpy\.ndarray size changed, may indicate binary incompatibility\. Expected \d+ from C header, got \d+ from PyObject",
category=RuntimeWarning,
),
WarningFilter(
message=r"A grouping was used that is not in the columns of the DataFrame and so was excluded from the result\. This grouping will be included in a future version of pandas\. Add the grouping as a column of the DataFrame to silence this warning\.",
category=FutureWarning,
),
])


# * -------------------------------------------------------------------------------- * #
Expand Down Expand Up @@ -109,22 +107,15 @@ def update_fixture_stores(

@pytest.fixture(scope="session")
def fixtures(nested_fixture_store) -> SimpleNamespace:
return SimpleNamespace(
**{
key: SimpleNamespace(
**{
key: SimpleNamespace(
**{
key: SimpleNamespace(**value)
for key, value in value.items()
}
)
for key, value in value.items()
}
)
for key, value in nested_fixture_store.items()
}
)
return SimpleNamespace(**{
key: SimpleNamespace(**{
key: SimpleNamespace(**{
key: SimpleNamespace(**value) for key, value in value.items()
})
for key, value in value.items()
})
for key, value in nested_fixture_store.items()
})


@pytest.fixture(scope="session")
Expand Down

0 comments on commit 919c99e

Please sign in to comment.