Skip to content

Commit dbe3e79

Browse files
committed
FIX: fixed dtype of year-only labels
should be int as with versions <0.32.2, not object
1 parent cde7bdb commit dbe3e79

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

larray_eurostat/tests/test_tsv.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ def test_eurostat_get_bad_dataset():
1212
msg = "HTTP Error 404: Not Found"
1313
with pytest.raises(HTTPError, match=f'^{re.escape(msg)}$'):
1414
eurostat_get(dataset)
15+
16+
17+
# https://github.com/larray-project/larray_eurostat/issues/33
18+
def test_year_only_axes_as_int_and_not_object():
19+
data = eurostat_get('avia_ec_enterp')
20+
assert data.time.dtype.kind == 'i'

larray_eurostat/tsv.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import gzip
22
from io import StringIO
33
from urllib.request import urlopen
4+
import numpy as np
45

56
from larray import Session, read_eurostat
67

78

89
def _remove_chars(s, chars):
910
return s.translate({ord(c): None for c in chars})
1011

12+
1113
def transform_time_labels(label):
1214
# Account for ambiguous label type (in multifreq larrays, year is str; in only-year larrays, year is given as int)
1315
# Need string format to search for patterns (e.g. Q1,M12), but return int format when only years are given.
@@ -24,8 +26,10 @@ def transform_time_labels(label):
2426
else:
2527
return str_label
2628

29+
2730
EUROSTAT_BASEURL = "https://ec.europa.eu/eurostat/api/dissemination/sdmx/2.1/data/"
2831

32+
2933
def _get_one(indicator, *, drop_markers=True):
3034
"""Get one Eurostat indicator and return it as an array."""
3135
url = f"{EUROSTAT_BASEURL}{indicator}?format=TSV&compressed=true"
@@ -41,7 +45,8 @@ def _get_one(indicator, *, drop_markers=True):
4145

4246
# Rename time axis. Rename time labels and reverse them (compatibility old API)
4347
la_data = la_data.rename(TIME_PERIOD='time')
44-
la_data = la_data.set_labels('time', transform_time_labels)
48+
if np.issubdtype(la_data.time.dtype, np.character):
49+
la_data = la_data.set_labels('time', transform_time_labels)
4550
la_data = la_data.reverse('time')
4651

4752
# If only one frequency: subset and return without redundant freq Axis (compatibility old API)

0 commit comments

Comments
 (0)