python-esios 0.1.3__tar.gz → 0.1.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-esios
3
- Version: 0.1.3
3
+ Version: 0.1.4
4
4
  Summary: A Python wrapper for the ESIOS API
5
5
  Home-page: https://github.com/datons/python-esios
6
6
  Author: Jesús López
@@ -87,6 +87,10 @@ class Indicators(APIClient):
87
87
  response = self._api_call('GET', endpoint, params=params)
88
88
  return IndicatorData(response.json())
89
89
 
90
+ class IndicatorData:
91
+ def __init__(self, data):
92
+ self.data = data
93
+
90
94
  class IndicatorData:
91
95
  def __init__(self, data):
92
96
  self.data = data
@@ -109,18 +113,19 @@ class IndicatorData:
109
113
 
110
114
  if values:
111
115
  df = pd.DataFrame(values)
112
- df = df.set_index('datetime')
113
- df.index = pd.to_datetime(df.index, utc=True)
114
-
115
- columns = df.columns
116
- mask = columns.str.contains('time')
116
+ if 'datetime' in df.columns:
117
+ df['datetime'] = pd.to_datetime(df['datetime'], utc=True)
118
+ df = df.set_index('datetime')
119
+ df.index = df.index.tz_convert('Europe/Madrid')
117
120
 
118
- df.drop(columns=columns[mask], inplace=True)
121
+ # Drop all columns that contain the word 'time' in them
122
+ df = df[[col for col in df.columns if not 'time' in col]]
119
123
 
120
- if column_name != 'value':
121
- df = df.rename(columns={'value': data[column_name]})
124
+ # Rename 'value' column if a different column_name is requested
125
+ if column_name in data and column_name != 'value':
126
+ df.rename(columns={'value': data[column_name]}, inplace=True)
122
127
 
123
- return df.tz_convert('Europe/Madrid')
128
+ return df
124
129
  else:
125
130
  return pd.DataFrame()
126
131
 
@@ -133,9 +138,7 @@ class IndicatorData:
133
138
  dict
134
139
  A dictionary containing the metadata of the indicator.
135
140
  """
141
+ metadata = self.data.get('indicator', {}).copy() # Use a copy to avoid mutating original data
142
+ metadata.pop('values', None) # Remove values key to extract only metadata
136
143
 
137
- # extract all inside indicator key, except values
138
- metadata = self.data.get('indicator', {})
139
- metadata.pop('values', None)
140
-
141
- return metadata
144
+ return metadata
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-esios
3
- Version: 0.1.3
3
+ Version: 0.1.4
4
4
  Summary: A Python wrapper for the ESIOS API
5
5
  Home-page: https://github.com/datons/python-esios
6
6
  Author: Jesús López
@@ -7,7 +7,7 @@ long_description = (this_directory / "README.md").read_text(encoding='utf-8')
7
7
 
8
8
  setup(
9
9
  name='python-esios',
10
- version='0.1.3',
10
+ version='0.1.4',
11
11
  packages=find_packages(),
12
12
  install_requires=[
13
13
  'requests',
File without changes
File without changes
File without changes