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

Also consider cellname as y #11

Merged
merged 2 commits into from
Nov 20, 2023
Merged

Also consider cellname as y #11

merged 2 commits into from
Nov 20, 2023

Conversation

noborus
Copy link
Owner

@noborus noborus commented Nov 20, 2023

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue with the XLSX reader to correctly increment and utilize the cellY parameter, ensuring accurate data processing and naming.

Copy link

coderabbitai bot commented Nov 20, 2023

Walkthrough

The update involves a consistent change across the reader.go file, where a new parameter cellY is introduced and utilized within two functions: nameType and cellName. This parameter is incremented and passed through, suggesting a refinement in how cell positions are handled, likely to improve the reading of XLSX files.

Changes

File(s) Change Summary
reader.go Added cellY parameter to nameType and cellName functions; incremented cellY in NewXLSXReader function.

🐇🌼 In the code where cells align,
A rabbit hopped through, with a tweak so fine.
With spring in its step and a fresh commit sign,
It's a hop, skip, and jump to code divine! 🌱✨


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

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.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c9c8a92 and 6fa9402.
Files selected for processing (1)
  • reader.go (4 hunks)
Additional comments: 2
reader.go (2)
  • 138-142: The cellName function has been updated to increment both x and y by 1 before converting them to a cell name. This change aligns with the pull request summary that cellY should be considered when determining the cell name. However, it's important to ensure that this increment does not cause any off-by-one errors elsewhere in the code, especially if cellX and cellY are already at the correct values when passed to this function. If the increment is necessary due to the excelize library's coordinate system starting at 1, then this change is correct.

  • 199-210: The nameType function now accepts cellY as a parameter, which is used when generating a unique name for a column if there is a collision in the header names. The logic checks if the header name already exists in the nameMap and, if so, attempts to generate a new name using cellName. If there is an error, it appends the column index to the original name. This logic seems to handle name collisions, but it's important to ensure that the nameMap is correctly populated and that the cellName function is called with the correct coordinates. Additionally, the error handling should be reviewed to ensure that it is appropriate to continue processing with a modified name in case of an error in cellName.

Comment on lines 46 to 50
}
isFilter = true
cellX--
cellY--
}
Copy link

Choose a reason for hiding this comment

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

The decrement of cellY has been removed in the latest commit, which suggests that the previous logic was incorrect. However, the increment of cellY by 1 is not present in the provided code. If the intention was to increment cellY, this change is missing and should be added to correctly reflect the pull request summary. If the increment is happening elsewhere in the code not shown in the diff, ensure that it is correctly implemented and tested.

Modified to stop decrementing when skip is set,
because cellY was decreased by 1.
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.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6fa9402 and 0eda609.
Files selected for processing (1)
  • reader.go (5 hunks)
Additional comments: 2
reader.go (2)
  • 46-50: The decrement of cellX and cellY has been removed, which aligns with the pull request summary stating that cellY should be incremented. However, the increment is not visible in the provided code. If the increment is intended to align with a 1-based index system, it should be added here unless it is handled elsewhere in the codebase.

  • 135-139: The cellName function correctly increments both x and y by 1 before converting them to a cell name, which is consistent with the 1-based indexing used in spreadsheet software. This change is in line with the pull request summary.

Comment on lines +88 to 99
r.names, r.types = nameType(rows[header], cellX, cellY, columnNum, opts.InHeader)
rowNum := len(rows) - skip
body := make([][]any, 0, rowNum)
validColumns := make([]bool, columnNum)
for i := 0; i < len(r.names); i++ {
if r.names[i] != "" {
validColumns[i] = true
} else {
name, err := cellName(cellX + i)
name, err := cellName(cellX+i, cellY)
if err != nil {
return nil, err
}
Copy link

Choose a reason for hiding this comment

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

The loop on lines 92-99 is using cellX+i and cellY to generate cell names for columns without names. However, there is a potential off-by-one error because cellX is decremented earlier in the code (lines 48-49), which is not reflected in the loop. This could lead to incorrect cell names if cellX is not zero. Ensure that the logic correctly calculates the cell name based on the actual X and Y coordinates.

Comment on lines +196 to 207
func nameType(row []string, cellX int, cellY int, columnNum int, header bool) ([]string, []string) {
nameMap := make(map[string]bool)
names := make([]string, columnNum)
types := make([]string, columnNum)
c := 0
for i := cellX; i < cellX+columnNum; i++ {
if header && len(row) > i && row[i] != "" {
if _, ok := nameMap[row[i]]; ok {
name, err := cellName(cellX + i)
name, err := cellName(cellX+i, cellY)
if err != nil {
names[c] = row[i] + "_" + fmt.Sprint(i)
} else {
Copy link

Choose a reason for hiding this comment

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

The nameType function now includes cellY as a parameter, which is consistent with the pull request summary. However, there is a potential issue with the error handling in the loop on lines 204-206. If an error occurs when calling cellName, the code falls back to concatenating the row name with the index i. This fallback does not seem to handle the error properly, as it does not log or return the error. It is important to handle errors appropriately to avoid silent failures and ensure that the caller is aware of any issues.

@noborus noborus merged commit d296683 into main Nov 20, 2023
1 check passed
@noborus noborus deleted the cellname-y branch November 20, 2023 21:49
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.

1 participant