Skip to content

Commit

Permalink
Simpler Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauernfeind committed Feb 12, 2024
1 parent 3318474 commit 6efe258
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,11 @@ protected synchronized Object setVariable(String name, @Nullable Object newValue

@Override
protected Map<String, Object> getAllValues(@NotNull final Predicate<Map.Entry<String, Object>> predicate) {
final HashMap<String, Object> result = PyLib.ensureGil(() -> scope.getEntries()
.collect(HashMap::new, (map, entry) -> map.put(entry.getKey(), entry.getValue()), HashMap::putAll));
final HashMap<String, Object> result = PyLib.ensureGil(
() -> scope.getEntriesRaw().<Map.Entry<String, PyObject>>map(
e -> new AbstractMap.SimpleImmutableEntry<>(scope.convertStringKey(e.getKey()), e.getValue()))
.collect(HashMap::new, (map, entry) -> map.put(entry.getKey(), entry.getValue()),
HashMap::putAll));

final Iterator<Map.Entry<String, Object>> iter = result.entrySet().iterator();
while (iter.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
public class PythonObjectWrapper {
private static final PyModule PY_WRAPPER_MODULE = PyModule.importModule("deephaven._wrapper");

public static void init() {
// ensured that the class initializer runs during Jpy initialization
}
/**
* Ensure that the class initializer runs.
*/
public static void init() {}

/**
* Unwrap a Python object to return the wrapped Java object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ public class PyCallableWrapperJpyImpl implements PyCallableWrapper {
numpyType2JavaClass.put('O', Object.class);
}

public static void init() {
// ensured that the class initializer runs during Jpy initialization
}
/**
* Ensure that the class initializer runs.
*/
public static void init() {}

// TODO: support for vectorizing functions that return arrays
// https://github.com/deephaven/deephaven-core/issues/4649
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import org.jpy.PyDictWrapper;
import org.jpy.PyObject;

import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -133,16 +130,6 @@ default Stream<String> getKeys() {
.map(this::convertStringKey);
}

/**
* Equivalent to {@link #getEntriesRaw()}, where the keys have been converted via {@link #convertStringKey(Object)}
* but the values still need conversion via {@link #convertValue(Object)}.
*
* @return the string keys and original values
*/
default Stream<Entry<String, PyObj>> getEntries() {
return getEntriesRaw().map(e -> new SimpleImmutableEntry<>(convertStringKey(e.getKey()), e.getValue()));
}

/**
* Equivalent to {@link #getKeys()}.collect(someCollector)
*
Expand All @@ -153,17 +140,6 @@ default Collection<String> getKeysCollection() {
.collect(Collectors.toList());
}

/**
* Equivalent to {@link #getEntries()}.collect(someMapCollector)
*
* @return the string keys and converted values, as a map
*/
default Map<String, Object> getEntriesMap() {
return getEntries()
.map(e -> new SimpleImmutableEntry<>(e.getKey(), convertValue(e.getValue())))
.collect(HashMap::new, (map, entry) -> map.put(entry.getKey(), entry.getValue()), HashMap::putAll);
}

/**
* @return the Python's __main__ module namespace
*/
Expand Down

0 comments on commit 6efe258

Please sign in to comment.