Skip to content

Passing classifying vars and keys on as parameters. #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

PhilippVerpoort
Copy link

@PhilippVerpoort PhilippVerpoort commented Jun 6, 2025

Passing the classifying variables and keys as arguments to the Table.get_data() function no longer works. The changes in this PR add this option back.

Here is an example:

from pystatis import Table

t = Table(name='51000-0014')
t.get_data(startyear=2019, endyear=2024, classifyingvariable1='WAM8', classifyingkey1='WA28141000,WA28142000')

This used to work in previous versions of pystatis, it stopped working at some point, and this PR tries to bring back that functionality.

This is related to issue #157.

Summary by CodeRabbit

  • New Features
    • Added support for up to three pairs of classifying variables and keys when retrieving data, allowing for more detailed and flexible data requests.

Copy link

coderabbitai bot commented Jun 6, 2025

Walkthrough

The get_data method of the Table class in src/pystatis/table.py was updated to accept up to three pairs of new optional string parameters for classifying variables and keys. These parameters are added to the data request if provided, allowing more flexible data queries.

Changes

File(s) Change Summary
src/pystatis/table.py Extended get_data method signature with six new optional parameters for classifying variables/keys; incorporated these into request params if set.

Poem

In the land of data, new fields bloom bright,
Classifying variables join the flight.
Three pairs now hop along,
Making queries robust and strong.
A rabbit’s cheer for options anew—
More ways to fetch, more ways to view!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/pystatis/table.py (1)

151-162: LGTM! Consider reducing repetition.

The parameter processing logic is correct and will properly add the classifying variables and keys to the API request when provided. The conditional checks ensure only non-empty values are included.

Consider refactoring to reduce repetition and improve maintainability:

-        if classifyingvariable1:
-            params['classifyingvariable1'] = classifyingvariable1
-        if classifyingkey1:
-            params['classifyingkey1'] = classifyingkey1
-        if classifyingvariable2:
-            params['classifyingvariable2'] = classifyingvariable2
-        if classifyingkey2:
-            params['classifyingkey2'] = classifyingkey2
-        if classifyingvariable3:
-            params['classifyingvariable3'] = classifyingvariable3
-        if classifyingkey3:
-            params['classifyingkey3'] = classifyingkey3
+        # Add classifying variables and keys if provided
+        classifying_params = {
+            'classifyingvariable1': classifyingvariable1,
+            'classifyingkey1': classifyingkey1,
+            'classifyingvariable2': classifyingvariable2,
+            'classifyingkey2': classifyingkey2,
+            'classifyingvariable3': classifyingvariable3,
+            'classifyingkey3': classifyingkey3,
+        }
+        params.update({k: v for k, v in classifying_params.items() if v})
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9beb108 and 23c1489.

📒 Files selected for processing (1)
  • src/pystatis/table.py (2 hunks)

Comment on lines +44 to +49
classifyingvariable1: str = "",
classifyingkey1: str = "",
classifyingvariable2: str = "",
classifyingkey2: str = "",
classifyingvariable3: str = "",
classifyingkey3: str = "",
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add documentation for the new parameters.

The new classifying variable and key parameters are not documented in the method's docstring. Given the comprehensive documentation for all other parameters, these should be documented as well to maintain consistency and help users understand their purpose.

Add documentation for the new parameters in the docstring. Also consider refactoring to use a more structured approach for the classifying pairs to improve maintainability:

+            classifyingvariable1 (str, optional): Code of the first classifying variable for data filtering.
+            classifyingkey1 (str, optional): Key value(s) for the first classifying variable. 
+                Multiple values can be passed as a comma-separated list.
+            classifyingvariable2 (str, optional): Code of the second classifying variable for data filtering.
+            classifyingkey2 (str, optional): Key value(s) for the second classifying variable.
+                Multiple values can be passed as a comma-separated list.
+            classifyingvariable3 (str, optional): Code of the third classifying variable for data filtering.
+            classifyingkey3 (str, optional): Key value(s) for the third classifying variable.
+                Multiple values can be passed as a comma-separated list.

Alternatively, consider accepting a more structured parameter like classifying_pairs: list[tuple[str, str]] = None for better maintainability.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
classifyingvariable1: str = "",
classifyingkey1: str = "",
classifyingvariable2: str = "",
classifyingkey2: str = "",
classifyingvariable3: str = "",
classifyingkey3: str = "",
def get_data(
self,
series: str,
start_time: datetime | date | str,
end_time: datetime | date | str,
include_observations: bool = False,
classifyingvariable1: str = "",
classifyingkey1: str = "",
classifyingvariable2: str = "",
classifyingkey2: str = "",
classifyingvariable3: str = "",
classifyingkey3: str = "",
) -> DataFrame:
"""
Fetch data for the given series between start and end times.
Parameters:
series (str): Code of the data series.
start_time (datetime|date|str): Start of the time range.
end_time (datetime|date|str): End of the time range.
include_observations (bool, optional): Whether to include observations.
classifyingvariable1 (str, optional): Code of the first classifying variable for data filtering.
classifyingkey1 (str, optional): Key value(s) for the first classifying variable.
Multiple values can be passed as a comma-separated list.
classifyingvariable2 (str, optional): Code of the second classifying variable for data filtering.
classifyingkey2 (str, optional): Key value(s) for the second classifying variable.
Multiple values can be passed as a comma-separated list.
classifyingvariable3 (str, optional): Code of the third classifying variable for data filtering.
classifyingkey3 (str, optional): Key value(s) for the third classifying variable.
Multiple values can be passed as a comma-separated list.
Returns:
DataFrame: The requested time series data.
"""
# method body follows…
🤖 Prompt for AI Agents
In src/pystatis/table.py around lines 44 to 49, the new parameters
classifyingvariable1, classifyingkey1, classifyingvariable2, classifyingkey2,
classifyingvariable3, and classifyingkey3 lack documentation in the method's
docstring. Add clear descriptions for each of these parameters in the docstring
to maintain consistency and clarify their purpose. Additionally, consider
refactoring the method signature to replace these multiple parameters with a
single structured parameter like classifying_pairs: list[tuple[str, str]] = None
to improve code maintainability and readability.

@pmayd pmayd changed the base branch from main to dev June 6, 2025 18:22
Copy link

codecov bot commented Jun 6, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 80.26%. Comparing base (9beb108) to head (23c1489).
Report is 2 commits behind head on dev.

Files with missing lines Patch % Lines
src/pystatis/table.py 50.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #188      +/-   ##
==========================================
- Coverage   80.89%   80.26%   -0.63%     
==========================================
  Files          12       12              
  Lines         581      593      +12     
==========================================
+ Hits          470      476       +6     
- Misses        111      117       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@pmayd pmayd left a comment

Choose a reason for hiding this comment

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

just a small correction, and pls add the new parameters to the docstring Args section so they are properly documented

@@ -142,6 +148,19 @@ def get_data(
"format": "ffcsv",
}

if classifyingvariable1:
Copy link
Collaborator

Choose a reason for hiding this comment

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

you actually don't need to check the variable here, it doesn't hurt to add empty variables this will be just ignored by the API

@@ -142,6 +148,19 @@ def get_data(
"format": "ffcsv",
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can directly add the parameters here

@pmayd
Copy link
Collaborator

pmayd commented Jun 6, 2025

to pass the ci you need to run uv run ruff format to format the file properly. This is also part of the pre-commit hooks ,so you can also use uv run pre-commit init and uv run pre-commit run --all

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