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

read_json() dtype should support type[str] #798

Closed
RobertCraigie opened this issue Oct 17, 2023 · 2 comments
Closed

read_json() dtype should support type[str] #798

RobertCraigie opened this issue Oct 17, 2023 · 2 comments

Comments

@RobertCraigie
Copy link

Describe the bug

Currently the stub files for read_json() only support bool | Mapping[HashableT, DtypeArg] | None but at runtime, dtype=str works.

To Reproduce

import pandas as pd

df = pd.read_json('data.jsonl', lines=True, dtype=str).fillna("")

Where data.jsonl contains

{"prompt": "Translate the following English text to French: 'Hello, how are you?'", "completion": "Bonjour, comment ça va ?"}
{"prompt": "What is the capital of France?", "completion": "Paris"}
{"prompt": "Solve the following math problem: 2 + 2 = ?", "completion": "4"}

Please complete the following information:

  • OS: [e.g. Windows, Linux, MacOS] MacOS
  • OS Version [e.g. 22]
  • python version 3.9
  • version of type checker Pyright 1.1.326
  • version of installed pandas-stubs latest

Additional context

Apologies if this is incorrect, I personally have very limited pandas experience, I simply ran into this while porting someone elses code from an untyped codebase to a typed codebase.

@twoertwein
Copy link
Member

Based on the documentation, it has to be a bool or a dict of bools. I assume pandas interprets str as True'ish

@RobertCraigie
Copy link
Author

Ah sorry I should've just read the docs, thanks!

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

No branches or pull requests

2 participants