Ozon3Org / Ozon3

An open-source Python package to easily obtain real-time, historical, or forecasted air quality data for anywhere in the world. Reliable, accurate and simple.
GNU General Public License v3.0
66 stars 23 forks source link

[BUG] Filename warning is inappropriate #151

Closed lahdjirayhan closed 2 years ago

lahdjirayhan commented 2 years ago

Describe the bug The warning emitted when not giving custom file name is inappropriate/misleading.

To Reproduce

  1. Just instantiate an Ozone object and you'll get a warning for not giving a custom filename.

    from ozone import Ozone
    api = Ozone(WAQI_TOKEN)

    The following message appears: UserWarning: You have not specified a custom save file name. Existing files with the same name may be overwritten!

  2. If you try to give a custom filename for output files, the warning won't appear.

    from ozone import Ozone
    api = Ozone(WAQI_TOKEN, file_name='something_custom')

    However, if you save into a file, the filename remains 'something_custom' and will get overwritten.

    # something_custom.csv contains London data
    api.get_city_air('London', data_format='csv')
    
    # something_custom.csv gets overwritten and now contains Paris data
    api.get_city_air('Paris', data_format='csv')

Proposed solution for better behavior

See comment below.

Environment

lahdjirayhan commented 2 years ago

File output feature

Ozone provides a way to automatically save the returned data into a file (csv, xlsx, json). There is a room for improvement here.

The user obviously needs to supply a location for the file output, but it's very not intuitive and clunky to do so. They have to:

  1. Specify a path. The file will not be saved in that location, but instead in a subfolder ozone_output located/created there,
  2. Specify a filename.
  3. Specify an output format.

1 & 2 are specified when instantiating Ozone, and 3 is specified when calling one of Ozone's public method through the data_format argument.

This can be improved, by either of the following:

Option 1: Don't offer to save

Remove the convenience feature of saving the file. Just return the dataframe and let the user handle it if they want to save. For what it's worth, this is not an unreasonable thing to do, given that all users need to do is to call df.to_csv or something else (Ozone does exactly just that under the hood).

If this option is considered unacceptable, I still propose to simplify

Option 2

  1. When instantiating Ozone: User specifies a path where output files will be saved. No extra ozone_output subdirectory. Default: current working directory.
  2. When user invokes public methods: User specifies a filename for the output files, if the method is invoked with data_format other than df, e.g. get_city_air('London', data_format='xlsx', filename='something') will write to something.xlsx. Default: None. If None, we can choose to either:

Doing this option implies removing file_name argument from __init__ and adding something like it into public methods instead.

Option 3

Conceptually same as Option 2 but only number 2. User can't specify a custom subfolder and if they want to, they'll have to supply something like filename='subfolder/filename' to public methods.


Doing the above introduces breaking changes. If we are going to make changes, might as well do it now and collect all the breaking changes together before moving to v2.

P.S.: I'm not sure where to put this (v2 discussion thread? start discussion? open issue?) but yeah I'll just put it here.

P.P.S.: Too late for v2, but never mind.

Milind220 commented 2 years ago

@lahdjirayhan

I think option one is best. Let's open a separate issue to address the changes that you mentioned there.