Skip to content

Refactor to library-first architecture with thin CLI wrapper#32

Merged
emmleroy merged 60 commits into
emmleroy-v1.0.0from
emmleroy-sc-20240-library-sc-20270-logging-v2
Jul 8, 2026
Merged

Refactor to library-first architecture with thin CLI wrapper#32
emmleroy merged 60 commits into
emmleroy-v1.0.0from
emmleroy-sc-20240-library-sc-20270-logging-v2

Conversation

@emmleroy

@emmleroy emmleroy commented Jul 2, 2026

Copy link
Copy Markdown

Summary

This PR restructures quantaq_py as an importable library with cli.py reduced to a thin wrapper around it.

Changes

  • renamed quantaq_cli/ to quantaq_py/
  • core functions moved to quantaq_py/toolkit/, still organized by individual module (e.g. concat.py), but re-exported in quantaq_py/__init__.py --> so they're importable directly as from quantaq_py import concat_files
  • cli commands on files are moved to cli.py (which first calls safe_load for functions that operate on dataframes)
  • added logging via loguru, with logging configs specified in log.py
  • removed feather support in favor of parquet (and added testing for parquet support)
  • infers data_model and data_source from the dataframe (for flagging)
  • always add sn column when calling safe_load on rawSD data
  • added pandera dtype checks when calling safe_load
  • removed tests for arisense data
  • added helper for fixing timestamp columns

emmleroy added 30 commits June 30, 2026 09:36
@emmleroy emmleroy requested a review from dhhagan July 2, 2026 15:10
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.64045% with 77 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.97%. Comparing base (8b95643) to head (06e2356).
⚠️ Report is 1 commits behind head on emmleroy-v1.0.0.

Files with missing lines Patch % Lines
quantaq_cli/utilities.py 84.31% 16 Missing ⚠️
quantaq_cli/cli.py 91.26% 11 Missing ⚠️
quantaq_cli/toolkit/flag.py 82.81% 11 Missing ⚠️
quantaq_cli/toolkit/merge.py 66.66% 11 Missing ⚠️
quantaq_cli/log.py 59.09% 9 Missing ⚠️
quantaq_cli/variables.py 73.52% 9 Missing ⚠️
quantaq_cli/toolkit/concat.py 82.35% 3 Missing ⚠️
tests/test_expunge.py 93.33% 3 Missing ⚠️
quantaq_cli/toolkit/expunge.py 90.90% 2 Missing ⚠️
quantaq_cli/toolkit/munge.py 85.71% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                 Coverage Diff                 @@
##           emmleroy-v1.0.0      #32      +/-   ##
===================================================
- Coverage            96.57%   90.97%   -5.60%     
===================================================
  Files                   17       21       +4     
  Lines                  846      931      +85     
===================================================
+ Hits                   817      847      +30     
- Misses                  29       84      +55     
Flag Coverage Δ
unittests 90.97% <87.64%> (-5.60%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
quantaq_cli/__init__.py 100.00% <100.00%> (ø)
quantaq_cli/schema.py 100.00% <100.00%> (ø)
quantaq_cli/toolkit/resample.py 98.24% <100.00%> (ø)
tests/test_clean.py 100.00% <100.00%> (ø)
tests/test_concat.py 100.00% <100.00%> (ø)
tests/test_flag.py 100.00% <100.00%> (ø)
tests/test_merge.py 100.00% <100.00%> (ø)
tests/test_resample.py 100.00% <100.00%> (ø)
tests/test_utilities.py 100.00% <100.00%> (ø)
quantaq_cli/toolkit/expunge.py 90.90% <90.90%> (ø)
... and 9 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread quantaq_cli/toolkit/concat.py
Comment thread quantaq_py/toolkit/concat.py Outdated
df = fix_timestamps(df, sort_values=True)

if df.empty:
raise Exception("No data")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add an error message here before the exception

@emmleroy emmleroy Jul 2, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 1e1d347

Comment thread quantaq_cli/toolkit/flag.py
Comment thread quantaq_py/cli.py Outdated
df = flag_dataframe(df)

logger.info("New flag summary:")
echo_flag_table(df)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to include a table, at least not by default as loghandlers can't pick it up easily. Should use logs instead where possible and/or include the table as a separate utility that can optionally be triggered?

@emmleroy emmleroy Jul 2, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it -- I removed this from the flag_command in 44a89e5. The logging in _add_flag() logs which flags are added and for how many rows (although we will modify _add_flag() later so that it is device-specific).

Comment thread quantaq_py/toolkit/merge.py Outdated
tmp = fix_timestamps(tmp, set_index=True, sort_values=True, localize_tz=True)

# merge with the other files
df = pd.merge(df, tmp, left_index=True, right_index=True, how='outer')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the goal here to merge two files together or n files? We probably want someway to pass the desired suffix for each file in the event of duplicate column names and/or provide the option to only keep 1?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh hmm I only considered using this to merge two files together, but I'm not sure?
I added an error for attempting to merge >2 files in a49159a.
Also passed desired suffixes for each file + option to only keep one in e739f6d.

Comment thread quantaq_cli/cli.py
Comment thread quantaq_cli/log.py
Comment thread quantaq_py/utilities.py Outdated
from quantaq_py.exceptions import InvalidFileExtension
from quantaq_py.schema import build_dtype_schema, COLUMN_DEFINITIONS

def infer_data_source(df):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comments on how we may want to improve this auto-detection

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made changes in d838aaa

Comment thread quantaq_py/utilities.py Outdated
df = df.sort_values(by=tscol)

# localize the timezone if needed
if localize_tz:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make sure we only do this if tscol is timestamp or timestamp_iso and NOT timestamp_local

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops good catch - see 583a903

Comment thread pyproject.toml Outdated
@@ -1,7 +1,7 @@
[tool.poetry]
name = "quantaq-cli"
name = "quantaq-py"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, we can change the name from quantaq-cli, but we probably don't want to use quantaq_py as we already have and maintain py_quantaq which may get a bit confusing...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kept as quantaq-cli in 06e2356

@emmleroy emmleroy merged commit 3201cd4 into emmleroy-v1.0.0 Jul 8, 2026
6 of 8 checks passed
@emmleroy emmleroy deleted the emmleroy-sc-20240-library-sc-20270-logging-v2 branch July 8, 2026 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants