Skip to content

Commit

Permalink
Merge pull request #97 from ocefpaf/fix_warnings
Browse files Browse the repository at this point in the history
~~Fix warnings~~ Fix numpy 2.0 failures
  • Loading branch information
ocefpaf authored Jun 18, 2024
2 parents f563f17 + 0906ca6 commit acd977b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ updates:
interval: "daily"
labels:
- "Bot"
groups:
github-actions:
patterns:
- '*'
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
os: [windows-latest, ubuntu-latest, macos-latest]
fail-fast: false

Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
- requirements-dev.txt

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.8
rev: v0.4.9
hooks:
- id: ruff

Expand Down
2 changes: 2 additions & 0 deletions pocean/dsg/trajectoryProfile/cr.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
get_ncdata_from_series,
nativize_times,
normalize_countable_array,
upscale_int8,
)


Expand Down Expand Up @@ -323,6 +324,7 @@ def to_dataframe(self, clean_cols=True, clean_rows=True, **kwargs):
df_data[dnam] = vdata

df = pd.DataFrame(df_data)
df = upscale_int8(df)

# Drop all data columns with no data
if clean_cols:
Expand Down
6 changes: 3 additions & 3 deletions pocean/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_generic_masked_bad_min_max_value(self):
# to make sure it doesn't error
b = ncd.createVariable('imabyte', 'b')
b.valid_min = 0
b.valid_max = 600 # this is over a byte and thus invalid
b.valid_max = np.int16(600) # this is over a byte and thus invalid
b[:] = 3
r = generic_masked(b[:], attrs=ncd.vatts(b.name))
assert np.all(r.mask == False) # noqa
Expand Down Expand Up @@ -203,7 +203,7 @@ def test_normalization_of_string_arrays_netcdf4(self):

# Single str (no dimension)
ncd.createVariable('single_str', str)
ncd.createVariable('single_unicode_', np.unicode_)
ncd.createVariable('single_unicode_', np.str_)
ncd.createVariable('single_U', '<U1')
ncd.createVariable('single_S', 'S1', ('n',))

Expand All @@ -216,7 +216,7 @@ def test_normalization_of_string_arrays_netcdf4(self):

# Array of str
ncd.createVariable('many_str', str, ('n',))
ncd.createVariable('many_unicode_', np.unicode_, ('n',))
ncd.createVariable('many_unicode_', np.str_, ('n',))
ncd.createVariable('many_U', '<U1', ('n',))
ncd.createVariable('many_S', 'S1', ('n', 'n',))

Expand Down
7 changes: 7 additions & 0 deletions pocean/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,13 @@ def dict_update(d, u):
return d


def upscale_int8(df):
"""Numpy 2.0 no linger upcast dtypes.
In order to preserve the data's original dtype we upcast it here after reading it.
"""
return df.astype({col: "int16" for col in df.columns[df.dtypes == "int8"]})

class JSONEncoder(json.JSONEncoder):

def default(self, obj):
Expand Down

0 comments on commit acd977b

Please sign in to comment.