def test_ds(dsd, obs): # Write DataSet with Observations not in Series ds = DataSet(structured_by=dsd) ds.obs.append(obs) result = sdmx.to_xml(ds, pretty_print=True) print(result.decode())
def test_flat(): # Create a bare Message msg = DataMessage() # Recreate the content from exr-flat.json header = Header( id="62b5f19d-f1c9-495d-8446-a3661ed24753", prepared="2012-11-29T08:40:26Z", sender=model.Agency(id="ECB"), ) msg.header = header ds = DataSet() # Create a Key and attributes key = Key( FREQ="D", CURRENCY="NZD", CURRENCY_DENOM="EUR", EXR_TYPE="SP00", EXR_SUFFIX="A", TIME_PERIOD="2013-01-18", ) obs_status = DataAttribute(id="OBS_STATUS") attr = {"OBS_STATUS": AttributeValue(value_for=obs_status, value="A")} ds.obs.append( Observation(dimension=key, value=1.5931, attached_attribute=attr)) key = key.copy(TIME_PERIOD="2013-01-21") ds.obs.append( Observation(dimension=key, value=1.5925, attached_attribute=attr)) key = key.copy(CURRENCY="RUB", TIME_PERIOD="2013-01-18") ds.obs.append( Observation(dimension=key, value=40.3426, attached_attribute=attr)) key = key.copy(TIME_PERIOD="2013-01-21") ds.obs.append( Observation(dimension=key, value=40.3000, attached_attribute=attr)) msg.data.append(ds) # Write to pd.Dataframe df1 = sdmx.to_pandas(msg) with specimen("flat.json") as f: ref = sdmx.read_sdmx(f) df2 = sdmx.to_pandas(ref) assert_pd_equal(df1, df2)
def read_dataset(self, root, ds_key): ds = DataSet( action=ActionType[root["action"].lower()], valid_from=root.get("validFrom", None), ) # Process series for key_values, elem in root.get("series", {}).items(): series_key = self._make_key("series", key_values, base=ds_key) series_key.attrib = self._make_attrs("series", root.get("attributes", [])) ds.add_obs(self.read_obs(elem, series_key=series_key), series_key) # Process bare observations ds.add_obs(self.read_obs(root, base_key=ds_key)) return ds
def test_dataset(): # Enumeration values can be used to initialize from sdmx.model import ActionType DataSet(action=ActionType["information"])