shrecc 0.0.5.dev1__tar.gz → 0.0.5.dev2__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.
Files changed (21) hide show
  1. {shrecc-0.0.5.dev1/shrecc.egg-info → shrecc-0.0.5.dev2}/PKG-INFO +1 -1
  2. {shrecc-0.0.5.dev1 → shrecc-0.0.5.dev2}/shrecc/__init__.py +1 -1
  3. {shrecc-0.0.5.dev1 → shrecc-0.0.5.dev2}/shrecc/database.py +7 -4
  4. {shrecc-0.0.5.dev1 → shrecc-0.0.5.dev2/shrecc.egg-info}/PKG-INFO +1 -1
  5. {shrecc-0.0.5.dev1 → shrecc-0.0.5.dev2}/tests/test_database.py +45 -0
  6. {shrecc-0.0.5.dev1 → shrecc-0.0.5.dev2}/LICENSE +0 -0
  7. {shrecc-0.0.5.dev1 → shrecc-0.0.5.dev2}/MANIFEST.in +0 -0
  8. {shrecc-0.0.5.dev1 → shrecc-0.0.5.dev2}/README.md +0 -0
  9. {shrecc-0.0.5.dev1 → shrecc-0.0.5.dev2}/pyproject.toml +0 -0
  10. {shrecc-0.0.5.dev1 → shrecc-0.0.5.dev2}/setup.cfg +0 -0
  11. {shrecc-0.0.5.dev1 → shrecc-0.0.5.dev2}/shrecc/data/el_map_all_norm.csv +0 -0
  12. {shrecc-0.0.5.dev1 → shrecc-0.0.5.dev2}/shrecc/data/generation_units_by_country.csv +0 -0
  13. {shrecc-0.0.5.dev1 → shrecc-0.0.5.dev2}/shrecc/data/techs_agg.json +0 -0
  14. {shrecc-0.0.5.dev1 → shrecc-0.0.5.dev2}/shrecc/download.py +0 -0
  15. {shrecc-0.0.5.dev1 → shrecc-0.0.5.dev2}/shrecc/treatment.py +0 -0
  16. {shrecc-0.0.5.dev1 → shrecc-0.0.5.dev2}/shrecc.egg-info/SOURCES.txt +0 -0
  17. {shrecc-0.0.5.dev1 → shrecc-0.0.5.dev2}/shrecc.egg-info/dependency_links.txt +0 -0
  18. {shrecc-0.0.5.dev1 → shrecc-0.0.5.dev2}/shrecc.egg-info/requires.txt +0 -0
  19. {shrecc-0.0.5.dev1 → shrecc-0.0.5.dev2}/shrecc.egg-info/top_level.txt +0 -0
  20. {shrecc-0.0.5.dev1 → shrecc-0.0.5.dev2}/tests/test_download.py +0 -0
  21. {shrecc-0.0.5.dev1 → shrecc-0.0.5.dev2}/tests/test_treatment.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: shrecc
3
- Version: 0.0.5.dev1
3
+ Version: 0.0.5.dev2
4
4
  Summary: SHRECC: Smooth Hourly Resolution Electricity Consumption Calculation
5
5
  Author-email: Sabina Bednářová <sabina.bednarova@list.lu>
6
6
  Maintainer-email: Sabina Bednářová <sabina.bednarova@list.lu>
@@ -16,4 +16,4 @@ from .database import create_database, filt_cutoff
16
16
  from .download import get_data
17
17
  from .treatment import data_processing
18
18
 
19
- __version__ = "0.0.5.dev1"
19
+ __version__ = "0.0.5.dev2"
@@ -20,7 +20,7 @@ UNUSED_SOURCE = "Import balance (physical)"
20
20
 
21
21
  def filt_cutoff(
22
22
  countries,
23
- times=0,
23
+ times=[],
24
24
  general_range=0,
25
25
  refined_range=0,
26
26
  freq=0,
@@ -59,8 +59,9 @@ def filt_cutoff(
59
59
 
60
60
  if general_range:
61
61
  year = datetime.strptime(general_range[0], "%Y-%m-%d %H:%M:%S").year
62
- elif times:
63
- year = datetime.strptime(times[0], "%Y-%m-%d %H:%M:%S").year
62
+ elif len(times):
63
+ times = pd.to_datetime(times)
64
+ year = times[0].year
64
65
  else:
65
66
  raise ValueError("Either `times` or `general_range` must be provided")
66
67
 
@@ -70,7 +71,9 @@ def filt_cutoff(
70
71
  dataframe = dataframe.droplevel("source", axis=1)
71
72
  dataframe = filter_by_countries(dataframe, countries)
72
73
 
73
- if times:
74
+ if len(times):
75
+ # For backwards compatibility and making sure datetime is used in the filtering
76
+ times = pd.to_datetime(times)
74
77
  dataframe = filter_by_times(dataframe, times)
75
78
  if general_range:
76
79
  dataframe = filter_by_range(dataframe, general_range, refined_range, freq)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: shrecc
3
- Version: 0.0.5.dev1
3
+ Version: 0.0.5.dev2
4
4
  Summary: SHRECC: Smooth Hourly Resolution Electricity Consumption Calculation
5
5
  Author-email: Sabina Bednářová <sabina.bednarova@list.lu>
6
6
  Maintainer-email: Sabina Bednářová <sabina.bednarova@list.lu>
@@ -915,6 +915,51 @@ def test_filter_by_times_no_matching_times():
915
915
  assert result.shape[1] == 0
916
916
 
917
917
 
918
+ @pytest.mark.parametrize(
919
+ "times_input",
920
+ [
921
+ pytest.param(
922
+ ["2023-06-01 08:00:00", "2023-06-01 10:00:00"],
923
+ id="list_of_strings",
924
+ ),
925
+ pytest.param(
926
+ pd.to_datetime(["2023-06-01 08:00:00", "2023-06-01 10:00:00"]),
927
+ id="datetime_index",
928
+ ),
929
+ ],
930
+ )
931
+ def test_filter_by_times_accepts_strings_and_datetimeindex(times_input):
932
+ """filter_by_times should accept either a list of strings or a pd.DatetimeIndex
933
+ and produce the same filtered DataFrame, regardless of whether the columns'
934
+ `time` level is stored as strings or as datetime objects.
935
+ """
936
+ time_values = pd.to_datetime(
937
+ [
938
+ "2023-06-01 08:00:00",
939
+ "2023-06-01 09:00:00",
940
+ "2023-06-01 10:00:00",
941
+ "2023-06-01 11:00:00",
942
+ ]
943
+ )
944
+ countries = ["FR", "DE", "IT", "FR"]
945
+ columns = pd.MultiIndex.from_arrays(
946
+ [time_values, countries], names=["time", "country"]
947
+ )
948
+ index = pd.MultiIndex.from_tuples(
949
+ [("FR", "tech1", "electricity, high voltage", "kWh")],
950
+ names=["geography", "activityName", "prod", "unit"],
951
+ )
952
+ df = pd.DataFrame([[1, 2, 3, 4]], index=index, columns=columns)
953
+
954
+ result = filter_by_times(df, times_input)
955
+
956
+ expected_times = pd.to_datetime(["2023-06-01 08:00:00", "2023-06-01 10:00:00"])
957
+ assert isinstance(result, pd.DataFrame)
958
+ assert result.shape == (1, 2)
959
+ assert set(result.columns.get_level_values("time")) == set(expected_times)
960
+ assert list(result.values.flatten()) == [1, 3]
961
+
962
+
918
963
  # ────────────────────────────────────────────────────────────────
919
964
  # Tests for: filter_by_range() — requires multiple sub-tests
920
965
  # ────────────────────────────────────────────────────────────────
File without changes
File without changes
File without changes
File without changes
File without changes