Skip to content
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

Adding support for jsonlines #35

Merged
merged 3 commits into from
Jun 25, 2024
Merged

Adding support for jsonlines #35

merged 3 commits into from
Jun 25, 2024

Conversation

pateash
Copy link
Collaborator

@pateash pateash commented Jun 25, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new function to read JSON and JSON Lines format.
    • Enhanced table display function to include colored information and improved row handling.
    • Added a new test to handle JSON Lines format.
  • Improvements

    • Improved version number update from "0.2.3.dev0" to "0.2.3".
  • Bug Fixes

    • Removed unnecessary debug log statements to improve performance and reduce noise in logs.
  • Tests

    • Updated and added new test cases to ensure robust handling of various data formats.
    • Introduced a new JSON Lines data file for testing purposes.

Copy link
Contributor

coderabbitai bot commented Jun 25, 2024

Walkthrough

This update includes versioning and debug logging adjustments along with new functionalities for data handling in the hckr module. The version number is advanced from 0.2.3.dev0 to 0.2.3, and debug logging of data head information is now commented out. Additionally, the DataUtils module sees the introduction of JSON reading capabilities and enhancements to data display. Changes also encompass the addition of new tests and inclusion of sample JSON Lines data.

Changes

File(s) Change Summary
src/hckr/__about__.py Updated version from 0.2.3.dev0 to 0.2.3.
src/hckr/cli/data.py Commented out debug log statements for printing data head information.
src/hckr/utils/DataUtils.py Added readJSON function for JSON/JSON Lines reading; enhanced print_df_as_table.
tests/cli/data/test_peek.py Renamed a test function and added a new test for JSON Lines format.
tests/cli/resources/data/peek/json-lines.json Added new JSON Lines format data sample.

Poem

CodeRabbit cheered, "Hooray, it's new!"
With updates fresh and functions deep,
The hckr's skills now take a leap.
Data reads JSON bright and clear,
While versioning brings nothing to fear.
Debug logs whispered hush, not shown,
Now let's see how this code has grown. 🎉✨🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @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.

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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@github-actions github-actions bot added enhancement New feature or request tests Changes to test release This will lead to a new release data labels Jun 25, 2024
Copy link

codecov bot commented Jun 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.93%. Comparing base (3bd6dc7) to head (9c93e40).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #35      +/-   ##
==========================================
+ Coverage   87.74%   87.93%   +0.19%     
==========================================
  Files          13       13              
  Lines         563      572       +9     
  Branches      141      141              
==========================================
+ Hits          494      503       +9     
  Misses         51       51              
  Partials       18       18              

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

@pateash pateash merged commit 2c3e08b into main Jun 25, 2024
18 checks passed
@pateash pateash deleted the adding-support-for-jsonlines branch June 25, 2024 14:08
Copy link
Contributor

@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

Outside diff range and nitpick comments (5)
src/hckr/utils/DataUtils.py (1)

Line range hint 43-43: Rename unused loop variable.

The variable index is unused in the loop and can be renamed to _ to indicate it is intentionally unused.

- for index, row in df.head(count).iterrows():
+ for _, row in df.head(count).iterrows():
Tools
Ruff

8-8: json imported but unused (F401)

Remove unused import: json

tests/cli/data/test_peek.py (2)

Line range hint 3-5: Remove unused imports.

The imports for pyarrow and pyarrow.parquet are not used in this file and should be removed to clean up the code.

- import pyarrow as pa  # type: ignore
- from pyarrow import parquet as pq  # type: ignore
Tools
Ruff

63-63: f-string without any placeholders (F541)

Remove extraneous f prefix


Line range hint 30-30: Remove extraneous f-string prefixes.

There are several f-string prefixes used without placeholders, which are unnecessary and should be removed.

- print(f"Reading from file :{FILE}")
+ print("Reading from file :", FILE)

- print(f"=" * 50)
+ print("=" * 50)

- print(f"Running for {_format}")
+ print("Running for", _format)

Also applies to: 37-37, 52-52, 63-63

Tools
Ruff

63-63: f-string without any placeholders (F541)

Remove extraneous f prefix

src/hckr/cli/data.py (2)

Line range hint 2-2: Remove unused imports.

The imports for logging and cron_descriptor.get_description are not used in this file and should be removed to clean up the code.

- import logging
- from cron_descriptor import get_description  # type: ignore

Also applies to: 9-9


Line range hint 103-103: Remove unnecessary open mode parameters.

The open mode parameters are unnecessary and should be removed to adhere to best practices and avoid potential bugs.

- with open(output, "wb") as out:
+ with open(output) as out:
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3e33ad7 and 9c93e40.

Files selected for processing (5)
  • src/hckr/about.py (1 hunks)
  • src/hckr/cli/data.py (2 hunks)
  • src/hckr/utils/DataUtils.py (4 hunks)
  • tests/cli/data/test_peek.py (2 hunks)
  • tests/cli/resources/data/peek/json-lines.json (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/hckr/about.py
Additional context used
Biome
tests/cli/resources/data/peek/json-lines.json

[error] 1-2: End of file expected (parse)

Use an array for a sequence of values: [1, 2]


[error] 2-3: End of file expected (parse)

Use an array for a sequence of values: [1, 2]

Ruff
src/hckr/utils/DataUtils.py

8-8: json imported but unused (F401)

Remove unused import: json


43-43: Loop control variable index not used within loop body (B007)

Rename unused index to _index

tests/cli/data/test_peek.py

3-3: pyarrow imported but unused (F401)

Remove unused import: pyarrow


5-5: pyarrow.parquet imported but unused (F401)

Remove unused import: pyarrow.parquet


30-30: f-string without any placeholders (F541)

Remove extraneous f prefix


37-37: f-string without any placeholders (F541)

Remove extraneous f prefix


52-52: f-string without any placeholders (F541)

Remove extraneous f prefix


63-63: f-string without any placeholders (F541)

Remove extraneous f prefix

src/hckr/cli/data.py

2-2: logging imported but unused (F401)

Remove unused import: logging


9-9: cron_descriptor.get_description imported but unused (F401)

Remove unused import: cron_descriptor.get_description


103-103: Unnecessary open mode parameters (UP015)

Remove open mode parameters

Additional comments not posted (1)
tests/cli/resources/data/peek/json-lines.json (1)

1-3: Consider wrapping JSON entries in an array for compatibility.

The static analysis tool suggests wrapping these individual JSON objects in an array. This would typically be necessary if the file is meant to be read as a single JSON array rather than JSON Lines. Please confirm the intended use.

If the intention is to use JSON Lines format, then the current format is correct and the tool's error can be ignored.

Verification successful

JSON Lines format is correctly used.

The application code correctly uses the pd.read_json method with the lines=True parameter, indicating that the JSON Lines format is intended and properly handled.

  • src/hckr/utils/DataUtils.py: df = pd.read_json(_file, lines=True)

The current format of the json-lines.json file is correct for JSON Lines and does not need to be wrapped in an array.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify if JSON Lines are being parsed correctly in the application.
# Test: Check for JSON Lines parsing logic in the application code.
rg --type python $'pd.read_json(.*lines=True.*)'

Length of output: 80



Script:

#!/bin/bash
# Description: Verify if JSON Lines are being parsed correctly in the application.
# Test: Check for JSON Lines parsing logic in the application code.
rg --type py 'pd.read_json\(.*lines=True.*\)'

Length of output: 120

Tools
Biome

[error] 1-2: End of file expected (parse)

Use an array for a sequence of values: [1, 2]


[error] 2-3: End of file expected (parse)

Use an array for a sequence of values: [1, 2]

import fastavro
import pandas as pd
import rich
from pyarrow import parquet as pq # type: ignore
from rich.table import Table
import json
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove unused import.

The json import is not used in this file and should be removed to clean up the code.

- import json
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
import json
Tools
Ruff

8-8: json imported but unused (F401)

Remove unused import: json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data enhancement New feature or request release This will lead to a new release tests Changes to test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant