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

Python DASK syntax error #4801

Closed
Bhagyarajd opened this issue Sep 5, 2023 · 5 comments
Closed

Python DASK syntax error #4801

Bhagyarajd opened this issue Sep 5, 2023 · 5 comments
Assignees

Comments

@Bhagyarajd
Copy link

Bhagyarajd commented Sep 5, 2023

Type: Bug

Hi
installed python Dask library and running in Python version 3.10.11 in VS code.
But when I use the below code it shows an syntax error in "Problems" tab. But when I run the code it's working fine. So, am not able to use auto fill option when I use DASK.

Below is the python code:

import dask.dataframe as dd
csv_file_1: str = "C:\\Users\\xxx\\yyy\\zzz\\Project\\ppp\\Data\\Dask data\\Test_2021_temp.csv"
dtype_mapping: dict = {'SocialNetwork': 'object', 'Source': 'object'}

df1: dd.DataFrame = dd.read_csv(csv_file_1, dtype=dtype_mapping)
print(df1.npartitions)
print(df1.head(100))

Below is the syntax error shows in "Problems" tab in VS code editor.

"read_csv" is not exported from module "dask"

VS Code version: Code 1.81.1 (6c3e3dba23e8fadc360aed75ce363ba185c49794, 2023-08-09T22:22:42.175Z)
OS version: Windows_NT x64 10.0.19045
Modes:

System Info
Item Value
CPUs 11th Gen Intel(R) Core(TM) i5-1145G7 @ 2.60GHz (8 x 1498)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 15.39GB (7.41GB free)
Process Argv --crash-reporter-id 4decefe6-c387-42ef-bc45-e57f8e19f6b9
Screen Reader no
VM 0%
Extensions (22)
Extension Author (truncated) Version
remotehub Git 0.60.0
vscode-dask joy 0.0.4
azure-dev ms- 0.7.0
vscode-azureappservice ms- 0.25.0
vscode-azurecontainerapps ms- 0.5.1
vscode-azurefunctions ms- 1.12.4
vscode-azureresourcegroups ms- 0.7.5
vscode-azurestorage ms- 0.15.3
vscode-azurevirtualmachines ms- 0.6.5
vscode-cosmosdb ms- 0.19.4
vscode-dotnet-runtime ms- 1.7.2
python ms- 2023.14.0
vscode-pylance ms- 2023.8.51
remote-ssh ms- 0.102.0
azure-account ms- 0.11.5
azure-repos ms- 0.36.0
azurecli ms- 0.5.0
notepadplusplus-keybindings ms- 1.0.7
remote-explorer ms- 0.4.1
remote-repositories ms- 0.38.1
vscode-node-azure-pack ms- 1.2.0
azurerm-vscode-tools msa 0.15.10
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vstes627:30244334
vslsvsres303:30308271
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscorecescf:30445987
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593:30376534
pythonvs932:30410667
py29gd2263cf:30792227
vscaat:30438848
vsclangdc:30486549
c4g48928:30535728
dsvsc012cf:30540253
pynewext54:30695312
azure-dev_surveyonecf:30548226
vsccc:30803844
2e4cg342:30602488
f6dab269:30613381
showlangstatbar:30737416
03d35959:30757346
pythonfmttext:30731395
fixshowwlkth:30771522
showindicator:30805244
pythongtdpath:30769146
i26e3531:30792625
pythonnosmt12:30797651
pythonidxptcf:30805731
pythonnoceb:30805159
dsvsc013:30795093
dsvsc014:30804076
diffeditorv2:30821572

@TylerLeonhardt TylerLeonhardt transferred this issue from microsoft/vscode Sep 5, 2023
@karthiknadig karthiknadig removed their assignment Sep 5, 2023
@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python Sep 6, 2023
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Sep 6, 2023
@debonte
Copy link
Contributor

debonte commented Sep 6, 2023

Dask is a "py.typed" library which means it contains inline type information.

When a library is marked "py.typed", Pyright (the type checker that underlies Pylance) applies certain rules to determine whether specific symbols are intended to be visible from a module. These rules are documented here.

The module dask/dataframe/__init__.py imports the read_csv symbol, but it does not indicate that that symbol should be re-exported — and therefore made visible externally. To do so, it would need to use a redundant form of import: from dask.dataframe.io import read_csv as read_csv. If you manually make that change in thedask/dataframe/__init__.py file, you'll see that dd.read_csv no longer generates an error.

If you believe that read_csv is meant to be visible from the dask.dataframe module, then this is a bug in the dask library, and you should report it to the dask maintainers.

As a workaround, you can access the read_csv symbol through the module that defines it: dask.dataframe.io.csv.

@debonte debonte closed this as completed Sep 6, 2023
@debonte debonte added by design and removed needs repro Issue has not been reproduced yet labels Sep 6, 2023
@Bhagyarajd
Copy link
Author

Thank you for the clarification and workaround @debonte.

dask.dataframe.io.csv is working fine now.

Thanks again :)

@flying-sheep
Copy link

flying-sheep commented Feb 14, 2025

To do so, it would need to use a redundant form of import: from dask.dataframe.io import read_csv as read_csv.

I’m pretty sure this isn’t a thing outside of PyRight/PyLance’s codebase. Re-exports are canonically done via __all__.

If this pattern is defined anywhere in a typing PEP, could you please direct me to it? Otherwise I don’t think you should recommend that people follow a non-standard pattern to get type checking to work. (as said, I’m pretty sure the only canonical way to signify an export is __all__)

@erictraut
Copy link
Contributor

If this pattern is defined anywhere in a typing PEP, could you please direct me to it?

This is documented in the Python typing spec here. All compliant type checkers and static analysis tools follow these rules for re-exports.

@flying-sheep
Copy link

I had no idea! Good to know, sorry for doubting you haha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants