Skip to content

Conversation

iclectic
Copy link
Contributor

This PR adds a test for DataFrame.from_records() with tuple data to validate type annotations work correctly. The test ensures the method properly returns a DataFrame when called with a list of tuples and column names, addressing the type checking issues raised in the original issue.

…ange np.ndarray to np_2d_array for data parameter- Change SequenceNotStr[str] to ListLike for columns and exclude parameters- Add test case with pd.Index as columns parameterAddresses review feedback from Dr-Irv
@iclectic iclectic changed the title Add test for DataFrame.from_records with list of tuples input Fix #1334: Update DataFrame.from_records signature and add tests Aug 21, 2025
@iclectic iclectic changed the title Fix #1334: Update DataFrame.from_records signature and add tests Update DataFrame.from_records signature and add tests Aug 21, 2025
@iclectic iclectic changed the title Update DataFrame.from_records signature and add tests Fix #1335: Update DataFrame.from_records signature and add tests Aug 21, 2025
@iclectic iclectic changed the title Fix #1335: Update DataFrame.from_records signature and add tests Update DataFrame.from_records signature and add tests Aug 21, 2025
@iclectic iclectic changed the title Update DataFrame.from_records signature and add tests Fix #1334: Update DataFrame.from_records signature and add tests Aug 21, 2025
@iclectic iclectic force-pushed the development branch 2 times, most recently from e6c054f to 44fd08e Compare August 21, 2025 07:59
… use Sequence[SequenceNotStr] | Sequence[Mapping[str, Scalar]] | Mapping[str, Sequence[Scalar]]- Update columns and exclude parameters to use ListLike | None = None- Update index parameter to use SequenceNotStr for better type precisionAddresses review feedback from Dr-Irv on issue pandas-dev#1334
… np_2darray support to data parameter type annotation- Add comprehensive tests for DataFrame.from_records in test_frame.py- Fix NumPy 2.0 compatibility in test (S1 instead of a1)- Test covers np.ndarray, list of tuples, pd.Index columns, and structured arrays- Addresses GitHub issue pandas-dev#1334
@iclectic iclectic requested a review from Dr-Irv August 21, 2025 10:00
Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

Be sure to test locally. Set up your environment as shown here:
https://github.com/pandas-dev/pandas-stubs/blob/main/docs/setup.md

Then do poe test to make sure the tests pass locally.

- Update data parameter types to accept Sequence[Mapping[str, Any]] and Mapping[str, SequenceNotStr[Any]]
- Add comprehensive tests for np.ndarray, tuples, and mapping inputs
- Address GitHub issue pandas-dev#1334 per Dr-Irv feedback
- All 207 DataFrame tests pass with no issues
Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

Make sure you are setting up the pre-commit, because your code needs to be formatted with black.

…-dev#1334

The main changes include:

- Updated data parameter types from overly restrictive Scalar to more flexible Any types
- Added .reshape(2, 2) to numpy array test to handle CI compatibility issues across different numpy versions
- Included a test for mapping of sequences using DataFrame constructor (which seems to be the right approach for that data type)

All 207 DataFrame tests still pass
Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

Now the CI is passing, so that's good.

Still 2 issues in terms of testing DataFrame.from_records() with a list of dicts, and just a dict.

…-dev#1334

Addresses Dr-Irv's feedback:
- Updated data parameter types from restrictive Scalar to flexible Any
- Added .reshape(2, 2) to numpy test for CI compatibility
- Added proper dictionary tests (list and single) without tuple conversion
- Added Mapping[str, Any] type support for single dictionaries
- Used DataFrame constructor for mapping sequences test

All tests pass.
Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

CI also failing because you are not using the pre-commit hooks and making sure that black is used.

iclectic and others added 2 commits August 25, 2025 10:09
… values

- Change index parameter type from SequenceNotStr[str] to SequenceNotStr[Hashable]
- Apply black formatting to test files
- Resolves CI type checking issues per Dr-Irv feedback

This allows index parameter to accept integers and other hashable values,
not just strings, matching pandas runtime behavior.
Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

I resolved an issue by mistake. One thing to fix in the tests.

…mapping dict test. Applied black formatting and pre-commit fixes
Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

thanks @iclectic

@Dr-Irv Dr-Irv merged commit 3033eea into pandas-dev:main Aug 25, 2025
13 checks passed
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.

DataFrame.from_records() needs better annotations
2 participants