From aa721e044afcf5af577bd74852141c1f086bd190 Mon Sep 17 00:00:00 2001 From: RMxNinja <91172425+RupeshMangalam21@users.noreply.github.com> Date: Sun, 19 Jan 2025 00:12:18 +0530 Subject: [PATCH 1/4] Refactoring time slice selection --- ocf_data_sampler/select/select_time_slice.py | 21 +------------------ .../select/time_slice_for_dataset.py | 3 +-- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/ocf_data_sampler/select/select_time_slice.py b/ocf_data_sampler/select/select_time_slice.py index 8d5c31e..166686d 100644 --- a/ocf_data_sampler/select/select_time_slice.py +++ b/ocf_data_sampler/select/select_time_slice.py @@ -3,7 +3,6 @@ import numpy as np - def _sel_fillnan( da: xr.DataArray, start_dt: pd.Timestamp, @@ -25,17 +24,6 @@ def _sel_default( return da.sel(time_utc=slice(start_dt, end_dt)) -# TODO either implement this or remove it, which would tidy up the code -def _sel_fillinterp( - da: xr.DataArray, - start_dt: pd.Timestamp, - end_dt: pd.Timestamp, - sample_period_duration: pd.Timedelta, - ) -> xr.DataArray: - """Select a time slice from a DataArray, filling missing times with linear interpolation.""" - return NotImplemented - - def select_time_slice( ds: xr.DataArray, t0: pd.Timestamp, @@ -43,17 +31,10 @@ def select_time_slice( interval_end: pd.Timedelta, sample_period_duration: pd.Timedelta, fill_selection: bool = False, - max_steps_gap: int = 0, ): """Select a time slice from a Dataset or DataArray.""" - assert max_steps_gap >= 0, "max_steps_gap must be >= 0 " - if fill_selection and max_steps_gap == 0: - _sel = _sel_fillnan - elif fill_selection and max_steps_gap > 0: - _sel = _sel_fillinterp - else: - _sel = _sel_default + _sel = _sel_fillnan if fill_selection else _sel_default t0_datetime_utc = pd.Timestamp(t0) start_dt = t0_datetime_utc + interval_start diff --git a/ocf_data_sampler/select/time_slice_for_dataset.py b/ocf_data_sampler/select/time_slice_for_dataset.py index 1247ae6..c364ad4 100644 --- a/ocf_data_sampler/select/time_slice_for_dataset.py +++ b/ocf_data_sampler/select/time_slice_for_dataset.py @@ -51,7 +51,6 @@ def slice_datasets_by_time( sample_period_duration=minutes(sat_config.time_resolution_minutes), interval_start=minutes(sat_config.interval_start_minutes), interval_end=minutes(sat_config.interval_end_minutes), - max_steps_gap=2, ) # Randomly sample dropout @@ -122,4 +121,4 @@ def slice_datasets_by_time( site_dropout_time, ) - return sliced_datasets_dict + return sliced_datasets_dict \ No newline at end of file From f36cfaf28da9f9b22aef2b598023b050d70ed08a Mon Sep 17 00:00:00 2001 From: RMxNinja <91172425+RupeshMangalam21@users.noreply.github.com> Date: Wed, 22 Jan 2025 12:21:15 +0530 Subject: [PATCH 2/4] Add GitHub Actions workflow for Ruff linting --- .github/workflows/lint.yaml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/lint.yaml diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..57ffed6 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,30 @@ +name: Lint + +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install ruff + + - name: Run Ruff + run: | + # Check style and quality + ruff check . + # Check formatting + ruff format --check . \ No newline at end of file From 7548a9bf6621dff913781df31282662b314a0bdb Mon Sep 17 00:00:00 2001 From: RMxNinja <91172425+RupeshMangalam21@users.noreply.github.com> Date: Wed, 22 Jan 2025 12:29:40 +0530 Subject: [PATCH 3/4] Fix: Remove invalid format option from ruff.toml --- ruff.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/ruff.toml b/ruff.toml index 5df253f..21012bc 100644 --- a/ruff.toml +++ b/ruff.toml @@ -41,8 +41,6 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" target-version = "py310" fix = false -# Group violations by containing file. -format = "github" ignore-init-module-imports = true [mccabe] From 35bf0bc0c5543b1cb051af0170136d3116007e96 Mon Sep 17 00:00:00 2001 From: RMxNinja <91172425+RupeshMangalam21@users.noreply.github.com> Date: Wed, 22 Jan 2025 17:09:12 +0530 Subject: [PATCH 4/4] Updates: ruff.toml and python version --- .github/workflows/lint.yaml | 25 ++++++++---------------- ruff.toml | 38 ++++++++++++++++++------------------- 2 files changed, 26 insertions(+), 37 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 57ffed6..52e394d 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -1,30 +1,21 @@ name: Lint -on: - push: - branches: [ main, master ] - pull_request: - branches: [ main, master ] +on: [push] jobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v4 + - name: Install Python + uses: actions/setup-python@v5 with: - python-version: '3.10' - + python-version: '3.11' - name: Install dependencies run: | python -m pip install --upgrade pip pip install ruff - - - name: Run Ruff - run: | - # Check style and quality - ruff check . - # Check formatting - ruff format --check . \ No newline at end of file + - name: Run Ruff linting + run: ruff check --output-format=github . + - name: Run Ruff formatting + run: ruff format --check . \ No newline at end of file diff --git a/ruff.toml b/ruff.toml index 21012bc..23a1054 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,10 +1,8 @@ -# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default. -select = ["B", "E", "F", "D", "I"] -ignore = ["D200","D202","D210","D212","D415","D105",] - -# Allow autofix for all enabled rules (when `--fix`) is provided. -fixable = ["A", "B", "C", "D", "E", "F", "I"] -unfixable = [] +# Project configuration +line-length = 100 +target-version = "py311" +output-format = "github" # Add GitHub-specific output formatting +fix = true # Exclude a variety of commonly ignored directories. exclude = [ @@ -31,25 +29,25 @@ exclude = [ "tests", ] -# Same as Black. -line-length = 100 +[lint] +# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default. +select = ["B", "E", "F", "D", "I"] +ignore = ["D200", "D202", "D210", "D212", "D415", "D105"] + +# Allow autofix for all enabled rules (when `--fix`) is provided. +fixable = ["A", "B", "C", "D", "E", "F", "I"] +unfixable = [] # Allow unused variables when underscore-prefixed. dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" -# Assume Python 3.10. -target-version = "py310" -fix = false +# Per-file ignore rules +per-file-ignores = { "__init__.py" = ["F401", "E402"] } -ignore-init-module-imports = true - -[mccabe] +[lint.mccabe] # Unlike Flake8, default to a complexity level of 10. max-complexity = 10 -[pydocstyle] +[lint.pydocstyle] # Use Google-style docstrings. -convention = "google" - -[per-file-ignores] -"__init__.py" = ["F401", "E402"] +convention = "google" \ No newline at end of file