@@ -21,7 +21,7 @@ upload your datasets to HDX.
21
21
- [ Configuring Logging] ( #configuring-logging )
22
22
- [ Operations on HDX Objects] ( #operations-on-hdx-objects )
23
23
- [ Dataset Specific Operations] ( #dataset-specific-operations )
24
- - [ Reference Period] ( #reference -period )
24
+ - [ Time Period] ( #time -period )
25
25
- [ Expected Update Frequency] ( #expected-update-frequency )
26
26
- [ Location] ( #location )
27
27
- [ Tags] ( #tags )
@@ -52,6 +52,10 @@ The library has detailed API documentation which can be found in the menu at the
52
52
53
53
54
54
## Breaking Changes
55
+ From 6.1.5, any method or parameter with "reference_period" in it is renamed
56
+ to "time_period" and any method or parameter with "file_type" in it is renamed
57
+ to "format"
58
+
55
59
From 6.0.0, generate_resource_view is renamed to generate_quickcharts
56
60
57
61
From 5.9.9, get_location_iso3s returns uppercase codes instead of lowercase
@@ -221,7 +225,7 @@ virtualenv if not installed:
221
225
from HDX and view the date of the dataset:
222
226
223
227
dataset = Dataset.read_from_hdx("novel-coronavirus-2019-ncov-cases")
224
- print(dataset.get_reference_period ())
228
+ print(dataset.get_time_period ())
225
229
226
230
11 . You can search for datasets on HDX and get their resources:
227
231
@@ -239,14 +243,14 @@ virtualenv if not installed:
239
243
server. With a dataset to which you have permissions, change the dataset date:
240
244
241
245
dataset = Dataset.read_from_hdx("ID OR NAME OF DATASET")
242
- print(dataset.get_reference_period ()) # record this
243
- dataset.set_reference_period ("2015-07-26")
244
- print(dataset.get_reference_period ())
246
+ print(dataset.get_time_period ()) # record this
247
+ dataset.set_time_period ("2015-07-26")
248
+ print(dataset.get_time_period ())
245
249
dataset.update_in_hdx()
246
250
247
251
14 . You can view it on HDX before changing it back (if you have an API key):
248
252
249
- dataset.set_reference_period ("PREVIOUS DATE")
253
+ dataset.set_time_period ("PREVIOUS DATE")
250
254
dataset.update_in_hdx()
251
255
252
256
15 . If you are storing your data on HDX, you can upload a new file to a
@@ -532,47 +536,54 @@ object to update not existing.
532
536
533
537
A dataset can have resources and can be in a showcase.
534
538
535
- If you wish to add resources, you can supply a list and call
536
- the ** add_update_resources** function, for example:
537
-
538
- resources = [{
539
- "name": xlsx_resourcename,
540
- "format": "xlsx",
541
- "url": xlsx_url
542
- }, {
543
- "name": csv_resourcename,
544
- "format": "zipped csv",
545
- "url": csv_url
546
- }]
547
- for resource in resources:
548
- resource["description"] = resource["url"].rsplit("/", 1)[-1]
549
- dataset.add_update_resources(resources)
550
-
551
- Calling ** add_update_resources** creates a list of HDX Resource objects in
552
- dataset and operations can be performed on those objects.
553
-
554
- To see the list of resources, you use the ** get_resources** function eg.
539
+ If you wish to add a resource, you can create a resource dictionary and set the
540
+ format then call the ** add_update_resource** function, for example:
555
541
556
- resources = dataset.get_resources()
542
+ resource = Resource({
543
+ "name": "myfile.xlsx",
544
+ "description": "description",
545
+ })
546
+ resource.set_format("xlsx")
547
+ resource.set_file_to_upload(PATH_TO_FILE)
548
+ dataset.add_update_resource(resource)
557
549
558
- If you wish to add one resource, you can supply an id string, dictionary or Resource
559
- object and call the ** add_update_resource** function, for example:
550
+ It is also possible to supply a resource id string or dictionary to the
551
+ ** add_update_resource** function. A url can be given instead of uploading a
552
+ file to the HDX filestore (although using the filestore is preferred):
560
553
554
+ resource = Resource({
555
+ "name": "myfile.xlsx",
556
+ "description": "description",
557
+ "url": "https://www.blah.com/myfile.xlsx"
558
+ })
559
+ resource.set_format("xlsx")
561
560
dataset.add_update_resource(resource)
562
561
563
- You can delete a Resource object from the dataset using the ** delete_resource** function, for example:
562
+ You can delete a Resource object from the dataset using the ** delete_resource**
563
+ function, for example:
564
564
565
565
dataset.delete_resource(resource)
566
566
567
+ ** add_update_resources** creates a list of HDX Resource objects
568
+ in a dataset:
569
+
570
+ dataset.add_update_resources(resources)
571
+
572
+ To see the list of resources, you use the ** get_resources** function eg.
573
+
574
+ resources = dataset.get_resources()
575
+
567
576
You can get all the resources from a list of datasets as follows:
568
577
569
578
resources = Dataset.get_all_resources(datasets)
570
579
571
- To see the list of showcases a dataset is in, you use the ** get_showcases** function eg.
580
+ To see the list of showcases a dataset is in, you use the ** get_showcases**
581
+ function eg.
572
582
573
583
showcases = dataset.get_showcases()
574
584
575
- If you wish to add the dataset to a showcase, you must first create the showcase in HDX if it does not already exist:
585
+ If you wish to add the dataset to a showcase, you must first create the
586
+ showcase in HDX if it does not already exist:
576
587
577
588
showcase = Showcase({"name": "new-showcase-1",
578
589
"title": "MyShowcase1",
@@ -582,47 +593,47 @@ If you wish to add the dataset to a showcase, you must first create the showcase
582
593
"url": "http://visualisation/url/"})
583
594
showcase.create_in_hdx()
584
595
585
- Then you can supply an id, dictionary or Showcase object and call the ** add_showcase **
586
- function, for example:
596
+ Then you can supply an id, dictionary or Showcase object and call the
597
+ ** add_showcase ** function, for example:
587
598
588
599
dataset.add_showcase(showcase)
589
600
590
- You can remove the dataset from a showcase using the ** remove_showcase** function, for
591
- example:
601
+ You can remove the dataset from a showcase using the ** remove_showcase**
602
+ function, for example:
592
603
593
604
dataset.remove_showcase(showcase)
594
605
595
- ### Reference Period
606
+ ### Time Period
596
607
597
- Reference Period is a mandatory field in HDX. It is the time period for which
598
- data are collected or calculated and to which, as a result, they refer . The
599
- reference period may be of any length: a year, a month, or even a day. It
600
- should not to be confused with when data was last added/changed in the dataset.
601
- It can be a single date or a range.
608
+ Time Period is a mandatory field in HDX. It is the earliest start date and
609
+ latest end date across all the resources included in the dataset . The time
610
+ period may be of any length: a year, a month, or even a day. It should not to
611
+ be confused with when data was last added/changed in the dataset. It can be a
612
+ single date or a range.
602
613
603
- To get the reference period, you can do as shown below. It returns a dictionary containing
604
- keys "startdate" (start date as datetime), "enddate" (end date as datetime),
605
- "startdate_str" (start date as string), "enddate_str" (end date as string) and ongoing
606
- (whether the end date is a rolls forward every day). You can supply a
607
- [ date format] ( https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior ) .
614
+ To get the time period, you can do as shown below. It returns a dictionary
615
+ containing keys "startdate" (start date as datetime), "enddate" (end date as
616
+ datetime), "startdate_str" (start date as string), "enddate_str" (end date as
617
+ string) and ongoing (whether the end date is a rolls forward every day). You
618
+ can supply a [ date format] ( https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior ) .
608
619
If you do not, the output format will be an
609
620
[ ISO 8601 date] ( https://en.wikipedia.org/wiki/ISO_8601 ) eg. 2007-01-25.
610
621
611
- reference_period = dataset.get_reference_period ("OPTIONAL FORMAT")
622
+ time_period = dataset.get_time_period ("OPTIONAL FORMAT")
612
623
613
- To set the reference period, you must pass either datetime.datetime objects or strings to
624
+ To set the time period, you must pass either datetime.datetime objects or strings to
614
625
the function below. It accepts a start date and an optional end date which if not
615
626
supplied is assumed to be the same as the start date. Instead of the end date, the flag
616
627
"ongoing" which by default is False can be set to True which indicates that the end date
617
628
rolls forward every day.
618
629
619
- dataset.set_reference_period ("START DATE", "END DATE")
630
+ dataset.set_time_period ("START DATE", "END DATE")
620
631
621
- The method below allows you to set the reference period using a year range. The start and
632
+ The method below allows you to set the time period using a year range. The start and
622
633
end year can be supplied as integers or strings. If no end year is supplied then the
623
634
range will be from the beginning of the start year to the end of that year.
624
635
625
- dataset.set_reference_period_year_range (START YEAR, END YEAR)
636
+ dataset.set_time_period_year_range (START YEAR, END YEAR)
626
637
627
638
### Expected Update Frequency
628
639
@@ -794,7 +805,7 @@ A resource can be generated from a given list or tuple: HEADERS and an ITERATOR
794
805
which can return rows in list, tuple or dictionary form. A mapping from headers
795
806
to HXL hashtags, HXLTAGS, must be provided along with the FOLDER and FILENAME
796
807
where the file will be generated for upload to the filestore. The dataset
797
- reference period can optionally be set by supplying DATECOL for looking up
808
+ time period can optionally be set by supplying DATECOL for looking up
798
809
dates or YEARCOL for looking up years. DATECOl and YEARCOL can be a column name
799
810
or the index of a column. Note that any timezone information is ignored and UTC
800
811
is assumed.
@@ -804,7 +815,7 @@ in a row. It should accept a row and should return None to ignore the row or a
804
815
dictionary which can either be empty if there are no dates in the row or can be
805
816
populated with keys startdate and/or enddate which are of type timezone-aware
806
817
datetime. The lowest start date and highest end date are used to set the
807
- reference period and are returned in the results dictionary in keys startdate
818
+ time period and are returned in the results dictionary in keys startdate
808
819
and enddate.
809
820
810
821
dataset.generate_resource_from_iterator(HEADERS, ITERATOR, HXLTAGS,
0 commit comments